Home | History | Annotate | Download | only in nanohub

Lines Matching refs:state

21 void sha2init(struct Sha2state *state)
23 state->h[0] = 0x6a09e667;
24 state->h[1] = 0xbb67ae85;
25 state->h[2] = 0x3c6ef372;
26 state->h[3] = 0xa54ff53a;
27 state->h[4] = 0x510e527f;
28 state->h[5] = 0x9b05688c;
29 state->h[6] = 0x1f83d9ab;
30 state->h[7] = 0x5be0cd19;
31 state->msgLen = 0;
32 state->bufBytesUsed = 0;
56 static void sha2processBlock(struct Sha2state *state)
72 state->w[i] = __builtin_bswap32(state->w[i]);
76 uint32_t s0 = ror(state->w[i-15], 7) ^ ror(state->w[i-15], 18) ^ (state->w[i-15] >> 3);
77 uint32_t s1 = ror(state->w[i-2], 17) ^ ror(state->w[i-2], 19) ^ (state->w[i-2] >> 10);
78 state->w[i] = state->w[i - 16] + s0 + state->w[i - 7] + s1;
82 a = state->h[0];
83 b = state->h[1];
84 c = state->h[2];
85 d = state->h[3];
86 e = state->h[4];
87 f = state->h[5];
88 g = state->h[6];
89 h = state->h[7];
95 uint32_t temp1 = h + s1 + ch + k[i] + state->w[i];
110 //put result back into state
111 state->h[0] += a;
112 state->h[1] += b;
113 state->h[2] += c;
114 state->h[3] += d;
115 state->h[4] += e;
116 state->h[5] += f;
117 state->h[6] += g;
118 state->h[7] += h;
121 void sha2processBytes(struct Sha2state *state, const void *bytes, uint32_t numBytes)
125 state->msgLen += numBytes;
129 //step 1: copy data into state if there is space & there is data
131 if (bytesToCopy > SHA2_BLOCK_SIZE - state->bufBytesUsed)
132 bytesToCopy = SHA2_BLOCK_SIZE - state->bufBytesUsed;
133 memcpy(state->b + state->bufBytesUsed, inBytes, bytesToCopy);
136 state->bufBytesUsed += bytesToCopy;
139 if (state->bufBytesUsed == SHA2_BLOCK_SIZE) {
140 sha2processBlock(state);
141 state->bufBytesUsed = 0;
146 const uint32_t* sha2finish(struct Sha2state *state)
149 uint64_t dataLenInBits = state->msgLen * 8;
153 sha2processBytes(state, &appendend, 1);
157 while (state->bufBytesUsed != 56)
158 sha2processBytes(state, &appendend, 1);
160 //append the length in bits (we can safely write into state since we're sure where to write to (we're definitely 56-bytes into a block)
162 state->b[63 - i] = dataLenInBits;
165 sha2processBlock(state);
168 return state->h;