mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-06 16:36:16 +08:00
Do not clean ctx in <digest>_finish
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user