X-Git-Url: http://wagner.pp.ru/gitweb/?a=blobdiff_plain;f=gosthash2012.c;h=201fe317ec23fb954e023c6b7a9fc48b5b0993eb;hb=11777554bd63b16bb13aa3b7358d8e7809f17523;hp=e94273df0635022fa38c99e921fc97a76b178629;hpb=6ca3db8d47a111dced8858b4e5bda8005bf1500c;p=openssl-gost%2Fengine.git diff --git a/gosthash2012.c b/gosthash2012.c index e94273d..201fe31 100644 --- a/gosthash2012.c +++ b/gosthash2012.c @@ -35,21 +35,22 @@ void init_gost2012_hash_ctx(gost2012_hash_ctx * CTX, memset(CTX, 0, sizeof(gost2012_hash_ctx)); CTX->digest_size = digest_size; + /* + * IV for 512-bit hash should be 0^512 + * IV for 256-bit hash should be (00000001)^64 + * + * It's already zeroed when CTX is cleared above, so we only + * need to set it to 0x01-s for 256-bit hash. + */ if (digest_size == 256) memset(&CTX->h, 0x01, sizeof(uint512_u)); - else - memset(&CTX->h, 0x00, sizeof(uint512_u)); } static INLINE void pad(gost2012_hash_ctx * CTX) { - unsigned char buf[64]; - - memset(&buf, 0x00, sizeof buf); - memcpy(&buf, CTX->buffer, CTX->bufsize); + memset(&(CTX->buffer[CTX->bufsize]), 0, sizeof(CTX->buffer) - CTX->bufsize); + CTX->buffer[CTX->bufsize] = 1; - buf[CTX->bufsize] = 0x01; - memcpy(CTX->buffer, &buf, sizeof buf); } static INLINE void add512(const union uint512_u *x,