13 #define ROTL(a, b) (((a) << (b)) | ((a) >> (32 - (b))))
15 inline void xor_salsa8(uint32_t B[16], const uint32_t Bx[16]) {
16 uint32_t x00,x01,x02,x03,x04,x05,x06,x07,x08,x09,x10,x11,x12,x13,x14,x15;
19 x00 = (B[ 0] ^= Bx[ 0]);
20 x01 = (B[ 1] ^= Bx[ 1]);
21 x02 = (B[ 2] ^= Bx[ 2]);
22 x03 = (B[ 3] ^= Bx[ 3]);
23 x04 = (B[ 4] ^= Bx[ 4]);
24 x05 = (B[ 5] ^= Bx[ 5]);
25 x06 = (B[ 6] ^= Bx[ 6]);
26 x07 = (B[ 7] ^= Bx[ 7]);
27 x08 = (B[ 8] ^= Bx[ 8]);
28 x09 = (B[ 9] ^= Bx[ 9]);
29 x10 = (B[10] ^= Bx[10]);
30 x11 = (B[11] ^= Bx[11]);
31 x12 = (B[12] ^= Bx[12]);
32 x13 = (B[13] ^= Bx[13]);
33 x14 = (B[14] ^= Bx[14]);
34 x15 = (B[15] ^= Bx[15]);
35 for (i = 0; i < 8; i += 2) {
36 /* Operate on columns. */
37 x04 ^= ROTL(x00 + x12, 7); x09 ^= ROTL(x05 + x01, 7);
38 x14 ^= ROTL(x10 + x06, 7); x03 ^= ROTL(x15 + x11, 7);
40 x08 ^= ROTL(x04 + x00, 9); x13 ^= ROTL(x09 + x05, 9);
41 x02 ^= ROTL(x14 + x10, 9); x07 ^= ROTL(x03 + x15, 9);
43 x12 ^= ROTL(x08 + x04, 13); x01 ^= ROTL(x13 + x09, 13);
44 x06 ^= ROTL(x02 + x14, 13); x11 ^= ROTL(x07 + x03, 13);
46 x00 ^= ROTL(x12 + x08, 18); x05 ^= ROTL(x01 + x13, 18);
47 x10 ^= ROTL(x06 + x02, 18); x15 ^= ROTL(x11 + x07, 18);
49 /* Operate on rows. */
50 x01 ^= ROTL(x00 + x03, 7); x06 ^= ROTL(x05 + x04, 7);
51 x11 ^= ROTL(x10 + x09, 7); x12 ^= ROTL(x15 + x14, 7);
53 x02 ^= ROTL(x01 + x00, 9); x07 ^= ROTL(x06 + x05, 9);
54 x08 ^= ROTL(x11 + x10, 9); x13 ^= ROTL(x12 + x15, 9);
56 x03 ^= ROTL(x02 + x01, 13); x04 ^= ROTL(x07 + x06, 13);
57 x09 ^= ROTL(x08 + x11, 13); x14 ^= ROTL(x13 + x12, 13);
59 x00 ^= ROTL(x03 + x02, 18); x05 ^= ROTL(x04 + x07, 18);
60 x10 ^= ROTL(x09 + x08, 18); x15 ^= ROTL(x14 + x13, 18);
82 uint32_t get(uint32_t i) const {
83 if(i<16) return lo.w[i];
84 else if(i<32) return hi.w[i-16];
87 void xor_other(const Words32& other) {
88 for(int i=0; i<16; i++) lo.w[i]^=other.lo.w[i];
89 for(int i=0; i<16; i++) hi.w[i]^=other.hi.w[i];
95 const Words32& get(uint32_t i) const {
100 printf("\nprint scrypt items\n");
101 for(int i = 0; i < 16; i++) {
103 printf(" %u ", uint32_t(this->get(0).lo.w[i]));
106 void scrypt(Words32& X) {
107 for (int i = 0; i < 1024; i++) {
109 xor_salsa8(X.lo.w, X.hi.w);
110 xor_salsa8(X.hi.w, X.lo.w);
112 for (int i = 0; i < 1024; i++) {
113 int j = X.hi.w[0] & 1023;
115 xor_salsa8(X.lo.w, X.hi.w);
116 xor_salsa8(X.hi.w, X.lo.w);