scrypt-jane-mix_salsa.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #if !defined(SCRYPT_CHOOSE_COMPILETIME) || !defined(SCRYPT_SALSA_INCLUDED)
  2. #undef SCRYPT_MIX
  3. #define SCRYPT_MIX "Salsa20/8 Ref"
  4. #undef SCRYPT_SALSA_INCLUDED
  5. #define SCRYPT_SALSA_INCLUDED
  6. #define SCRYPT_SALSA_BASIC
  7. static void
  8. salsa_core_basic(uint32_t state[16]) {
  9. size_t rounds = 8;
  10. uint32_t x0,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,t;
  11. x0 = state[0];
  12. x1 = state[1];
  13. x2 = state[2];
  14. x3 = state[3];
  15. x4 = state[4];
  16. x5 = state[5];
  17. x6 = state[6];
  18. x7 = state[7];
  19. x8 = state[8];
  20. x9 = state[9];
  21. x10 = state[10];
  22. x11 = state[11];
  23. x12 = state[12];
  24. x13 = state[13];
  25. x14 = state[14];
  26. x15 = state[15];
  27. #define quarter(a,b,c,d) \
  28. t = a+d; t = ROTL32(t, 7); b ^= t; \
  29. t = b+a; t = ROTL32(t, 9); c ^= t; \
  30. t = c+b; t = ROTL32(t, 13); d ^= t; \
  31. t = d+c; t = ROTL32(t, 18); a ^= t; \
  32. for (; rounds; rounds -= 2) {
  33. quarter( x0, x4, x8,x12)
  34. quarter( x5, x9,x13, x1)
  35. quarter(x10,x14, x2, x6)
  36. quarter(x15, x3, x7,x11)
  37. quarter( x0, x1, x2, x3)
  38. quarter( x5, x6, x7, x4)
  39. quarter(x10,x11, x8, x9)
  40. quarter(x15,x12,x13,x14)
  41. }
  42. state[0] += x0;
  43. state[1] += x1;
  44. state[2] += x2;
  45. state[3] += x3;
  46. state[4] += x4;
  47. state[5] += x5;
  48. state[6] += x6;
  49. state[7] += x7;
  50. state[8] += x8;
  51. state[9] += x9;
  52. state[10] += x10;
  53. state[11] += x11;
  54. state[12] += x12;
  55. state[13] += x13;
  56. state[14] += x14;
  57. state[15] += x15;
  58. #undef quarter
  59. }
  60. #endif