diff --git a/src/md5.c b/src/md5.c index d7a25d24..f7b3a025 100644 --- a/src/md5.c +++ b/src/md5.c @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 The GmSSL Project. All Rights Reserved. + * Copyright 2014-2023 The GmSSL Project. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. @@ -168,7 +168,6 @@ void md5_finish(MD5_CTX *ctx, unsigned char *dgst) PUTU32_LE(dgst, ctx->state[i]); dgst += sizeof(uint32_t); } - memset(ctx, 0, sizeof(*ctx)); } void md5_digest(const unsigned char *data, size_t datalen, @@ -178,4 +177,5 @@ void md5_digest(const unsigned char *data, size_t datalen, md5_init(&ctx); md5_update(&ctx, data, datalen); md5_finish(&ctx, dgst); + memset(&ctx, 0, sizeof(ctx)); } diff --git a/src/sha1.c b/src/sha1.c index 909e83b6..7154f0be 100644 --- a/src/sha1.c +++ b/src/sha1.c @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 The GmSSL Project. All Rights Reserved. + * Copyright 2014-2023 The GmSSL Project. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. @@ -158,7 +158,6 @@ void sha1_finish(SHA1_CTX *ctx, unsigned char *dgst) for (i = 0; i < 5; i++) { PUTU32(dgst + i*4, ctx->state[i]); } - memset(ctx, 0, sizeof(*ctx)); } void sha1_digest(const unsigned char *data, size_t datalen, diff --git a/src/sha256.c b/src/sha256.c index 96f2dc18..fa8f3bda 100644 --- a/src/sha256.c +++ b/src/sha256.c @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 The GmSSL Project. All Rights Reserved. + * Copyright 2014-2023 The GmSSL Project. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. @@ -167,7 +167,6 @@ void sha256_finish(SHA256_CTX *ctx, unsigned char dgst[SHA256_DIGEST_SIZE]) PUTU32(dgst, ctx->state[i]); dgst += sizeof(uint32_t); } - memset(ctx, 0, sizeof(*ctx)); } void sha256_digest(const unsigned char *data, size_t datalen, @@ -177,6 +176,7 @@ void sha256_digest(const unsigned char *data, size_t datalen, sha256_init(&ctx); sha256_update(&ctx, data, datalen); sha256_finish(&ctx, dgst); + memset(&ctx, 0, sizeof(ctx)); } @@ -213,4 +213,5 @@ void sha224_digest(const unsigned char *data, size_t datalen, sha224_init(&ctx); sha224_update(&ctx, data, datalen); sha224_finish(&ctx, dgst); + memset(&ctx, 0, sizeof(ctx)); } diff --git a/src/sha512.c b/src/sha512.c index 6bed48e7..8f38f4bf 100644 --- a/src/sha512.c +++ b/src/sha512.c @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 The GmSSL Project. All Rights Reserved. + * Copyright 2014-2023 The GmSSL Project. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. @@ -85,7 +85,6 @@ void sha512_finish(SHA512_CTX *ctx, unsigned char dgst[SHA512_DIGEST_SIZE]) PUTU64(dgst, ctx->state[i]); dgst += sizeof(uint64_t); } - memset(ctx, 0, sizeof(SHA512_CTX)); } #define Ch(X, Y, Z) (((X) & (Y)) ^ ((~(X)) & (Z))) @@ -188,6 +187,7 @@ void sha512_digest(const unsigned char *data, size_t datalen, sha512_init(&ctx); sha512_update(&ctx, data, datalen); sha512_finish(&ctx, dgst); + memset(&ctx, 0, sizeof(ctx)); } @@ -229,5 +229,6 @@ void sha384_digest(const unsigned char *data, size_t datalen, sha384_init(&ctx); sha384_update(&ctx, data, datalen); sha384_finish(&ctx, dgst); + memset(&ctx, 0, sizeof(ctx)); } diff --git a/src/sm3.c b/src/sm3.c index 196a88f8..a82f9015 100644 --- a/src/sm3.c +++ b/src/sm3.c @@ -1,5 +1,5 @@ /* - * Copyright 2014-2022 The GmSSL Project. All Rights Reserved. + * Copyright 2014-2023 The GmSSL Project. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the License); you may * not use this file except in compliance with the License. @@ -364,7 +364,6 @@ void sm3_finish(SM3_CTX *ctx, uint8_t *digest) for (i = 0; i < 8; i++) { PUTU32(digest + i*4, ctx->digest[i]); } - memset(ctx, 0, sizeof(SM3_CTX)); } void sm3_digest(const uint8_t *msg, size_t msglen, @@ -374,4 +373,5 @@ void sm3_digest(const uint8_t *msg, size_t msglen, sm3_init(&ctx); sm3_update(&ctx, msg, msglen); sm3_finish(&ctx, dgst); + memset(&ctx, 0, sizeof(ctx)); }