sha512_final.c (599B)
1 /* ISC license. */ 2 3 #include <string.h> 4 5 #include <skalibs/uint64.h> 6 #include <skalibs/sha512.h> 7 #include "sha512-internal.h" 8 9 void sha512_final (SHA512Schedule *ctx, char *digest) 10 { 11 unsigned int pad = ctx->len & 0x7fU ; 12 13 ctx->buf[pad++] = 0x80 ; 14 if (pad > 112) 15 { 16 memset(ctx->buf + pad, 0, 128 - pad) ; 17 sha512_transform(ctx, ctx->buf) ; 18 pad = 0 ; 19 } 20 memset(ctx->buf + pad, 0, 120 - pad) ; 21 uint64_pack_big((char *)ctx->buf + 120, ctx->len << 3) ; 22 sha512_transform(ctx, ctx->buf) ; 23 24 for (unsigned int i = 0 ; i < 8 ; i++) uint64_pack_big(digest + (i << 3), ctx->h[i]) ; 25 }