UINT64_C(0x81c2c92e47edaee6), UINT64_C(0x92722c851482353b),
UINT64_C(0xa2bfe8a14cf10364), UINT64_C(0xa81a664bbc423001),
UINT64_C(0xc24b8b70d0f89791), UINT64_C(0xc76c51a30654be30),
UINT64_C(0x81c2c92e47edaee6), UINT64_C(0x92722c851482353b),
UINT64_C(0xa2bfe8a14cf10364), UINT64_C(0xa81a664bbc423001),
UINT64_C(0xc24b8b70d0f89791), UINT64_C(0xc76c51a30654be30),
#define S(x, n) ROR64c(x, n)
#define R(x, n) (((x) &UINT64_C(0xFFFFFFFFFFFFFFFF))>>((uint64_t)n))
#define Sigma0(x) (S(x, 28) ^ S(x, 34) ^ S(x, 39))
#define S(x, n) ROR64c(x, n)
#define R(x, n) (((x) &UINT64_C(0xFFFFFFFFFFFFFFFF))>>((uint64_t)n))
#define Sigma0(x) (S(x, 28) ^ S(x, 34) ^ S(x, 39))
{
uint64_t S[8], W[80], t0, t1;
int i;
{
uint64_t S[8], W[80], t0, t1;
int i;
/* Compress */
#define RND(a,b,c,d,e,f,g,h,i) \
/* Compress */
#define RND(a,b,c,d,e,f,g,h,i) \
-int sha512_update (sha512_context * md, const unsigned char *in, size_t inlen)
-{
+int sha512_update(sha512_context *md, const void *vin, size_t inlen)
+{
+ const unsigned char *in = vin;
- size_t i;
- int err;
- if (md == NULL) return 1;
- if (in == NULL) return 1;
- if (md->curlen > sizeof(md->buf)) {
- return 1;
- }
- while (inlen > 0) {
- if (md->curlen == 0 && inlen >= 128) {
- if ((err = sha512_compress (md, (unsigned char *)in)) != 0) {
- return err;
- }
- md->length += 128 * 8;
- in += 128;
- inlen -= 128;
- } else {
+ size_t i;
+ int err;
+ if (md == NULL) return 1;
+ if (in == NULL) return 1;
+ if (md->curlen > sizeof(md->buf)) {
+ return 1;
+ }
+ while (inlen > 0) {
+ if (md->curlen == 0 && inlen >= 128) {
+ if ((err = sha512_compress (md, in)) != 0) {
+ return err;
+ }
+ md->length += 128 * 8;
+ in += 128;
+ inlen -= 128;
+ } else {
n = MIN(inlen, (128 - md->curlen));
for (i = 0; i < n; i++) {
n = MIN(inlen, (128 - md->curlen));
for (i = 0; i < n; i++) {
- md->curlen += n;
- in += n;
- inlen -= n;
- if (md->curlen == 128) {
- if ((err = sha512_compress (md, md->buf)) != 0) {
- return err;
- }
- md->length += 8*128;
- md->curlen = 0;
- }
- }
- }
- return 0;
+ md->curlen += n;
+ in += n;
+ inlen -= n;
+ if (md->curlen == 128) {
+ if ((err = sha512_compress (md, md->buf)) != 0) {
+ return err;
+ }
+ md->length += 8*128;
+ md->curlen = 0;
+ }
+ }
+ }
+ return 0;
if (md == NULL) return 1;
if (out == NULL) return 1;
if (md->curlen >= sizeof(md->buf)) {
if (md == NULL) return 1;
if (out == NULL) return 1;
if (md->curlen >= sizeof(md->buf)) {
/* if the length is currently above 112 bytes we append zeros
* then compress. Then we can fall back to padding zeros and length
/* if the length is currently above 112 bytes we append zeros
* then compress. Then we can fall back to padding zeros and length
* note: that from 112 to 120 is the 64 MSB of the length. We assume that you won't hash
* > 2^64 bits of data... :-)
*/
* note: that from 112 to 120 is the 64 MSB of the length. We assume that you won't hash
* > 2^64 bits of data... :-)
*/
-STORE64H(md->length, md->buf+120);
-sha512_compress(md, md->buf);
+ STORE64H(md->length, md->buf+120);
+ sha512_compress(md, md->buf);
-for (i = 0; i < 8; i++) {
- STORE64H(md->state[i], out+(8*i));
-}
+ for (i = 0; i < 8; i++) {
+ STORE64H(md->state[i], out+(8*i));
+ }
- if (ret = sha512_init(&ctx)) return ret;
- if (ret = sha512_update(&ctx, message, message_len)) return ret;
- if (ret = sha512_final(&ctx, out)) return ret;
+ if ((ret = sha512_init(&ctx))) return ret;
+ if ((ret = sha512_update(&ctx, message, message_len))) return ret;
+ if ((ret = sha512_final(&ctx, out))) return ret;