| 260 | } |
| 261 | |
| 262 | void sha512(uchar *hash, const uchar *msg, int msglen) |
| 263 | { |
| 264 | uint64_t state[8] = { 0x6a09e667f3bcc908ULL, 0xbb67ae8584caa73bULL, 0x3c6ef372fe94f82bULL, 0xa54ff53a5f1d36f1ULL, |
| 265 | 0x510e527fade682d1ULL, 0x9b05688c2b3e6c1fULL, 0x1f83d9abfb41bd6bULL, 0x5be0cd19137e2179ULL }; |
| 266 | uint64_t total = msglen * 8ULL; |
| 267 | for(; msglen >= 128; msglen -= 128) |
| 268 | { |
| 269 | sha512_compress(state, msg); |
| 270 | msg += 128; |
| 271 | } |
| 272 | uchar endmsg[128] = { 0 }; |
| 273 | memcpy(endmsg, msg, msglen); |
| 274 | endmsg[msglen] = 0x80; |
| 275 | if(msglen > 111) |
| 276 | { |
| 277 | sha512_compress(state, endmsg); |
| 278 | memset(endmsg, 0, 128); |
| 279 | } |
| 280 | *((uint64_t*)(endmsg + 120)) = bigswap(total); |
| 281 | sha512_compress(state, endmsg); |
| 282 | loopi(8) ((uint64_t*)hash)[i] = bigswap(state[i]); |
| 283 | } |
| 284 | #undef RR64 |
| 285 | #undef SHA512ROUND |
| 286 |
no test coverage detected