| 167 | } |
| 168 | |
| 169 | void sha512_process( sha512_context *ctx, const unsigned char data[128] ) |
| 170 | { |
| 171 | int i; |
| 172 | uint64_t temp1, temp2, W[80]; |
| 173 | uint64_t A, B, C, D, E, F, G, H; |
| 174 | |
| 175 | #define SHR(x,n) (x >> n) |
| 176 | #define ROTR(x,n) (SHR(x,n) | (x << (64 - n))) |
| 177 | |
| 178 | #define S0(x) (ROTR(x, 1) ^ ROTR(x, 8) ^ SHR(x, 7)) |
| 179 | #define S1(x) (ROTR(x,19) ^ ROTR(x,61) ^ SHR(x, 6)) |
| 180 | |
| 181 | #define S2(x) (ROTR(x,28) ^ ROTR(x,34) ^ ROTR(x,39)) |
| 182 | #define S3(x) (ROTR(x,14) ^ ROTR(x,18) ^ ROTR(x,41)) |
| 183 | |
| 184 | #define F0(x,y,z) ((x & y) | (z & (x | y))) |
| 185 | #define F1(x,y,z) (z ^ (x & (y ^ z))) |
| 186 | |
| 187 | #define P(a,b,c,d,e,f,g,h,x,K) \ |
| 188 | { \ |
| 189 | temp1 = h + S3(e) + F1(e,f,g) + K + x; \ |
| 190 | temp2 = S2(a) + F0(a,b,c); \ |
| 191 | d += temp1; h = temp1 + temp2; \ |
| 192 | } |
| 193 | |
| 194 | for( i = 0; i < 16; i++ ) |
| 195 | { |
| 196 | GET_UINT64_BE( W[i], data, i << 3 ); |
| 197 | } |
| 198 | |
| 199 | for( ; i < 80; i++ ) |
| 200 | { |
| 201 | W[i] = S1(W[i - 2]) + W[i - 7] + |
| 202 | S0(W[i - 15]) + W[i - 16]; |
| 203 | } |
| 204 | |
| 205 | A = ctx->state[0]; |
| 206 | B = ctx->state[1]; |
| 207 | C = ctx->state[2]; |
| 208 | D = ctx->state[3]; |
| 209 | E = ctx->state[4]; |
| 210 | F = ctx->state[5]; |
| 211 | G = ctx->state[6]; |
| 212 | H = ctx->state[7]; |
| 213 | i = 0; |
| 214 | |
| 215 | do |
| 216 | { |
| 217 | P( A, B, C, D, E, F, G, H, W[i], K[i] ); i++; |
| 218 | P( H, A, B, C, D, E, F, G, W[i], K[i] ); i++; |
| 219 | P( G, H, A, B, C, D, E, F, W[i], K[i] ); i++; |
| 220 | P( F, G, H, A, B, C, D, E, W[i], K[i] ); i++; |
| 221 | P( E, F, G, H, A, B, C, D, W[i], K[i] ); i++; |
| 222 | P( D, E, F, G, H, A, B, C, W[i], K[i] ); i++; |
| 223 | P( C, D, E, F, G, H, A, B, W[i], K[i] ); i++; |
| 224 | P( B, C, D, E, F, G, H, A, W[i], K[i] ); i++; |
| 225 | } |
| 226 | while( i < 80 ); |