aboutsummaryrefslogtreecommitdiff
path: root/src/common/cryptohash.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2020-12-14 12:38:13 +0900
committerMichael Paquier <michael@paquier.xyz>2020-12-14 12:38:13 +0900
commit9b584953e7bf91e342af87ef44606acd6206cd1c (patch)
tree878bf508cb9e6c6f484ea502ad3f383783d89120 /src/common/cryptohash.c
parentdf9274adf3096feafbbde2562311c8ab80405267 (diff)
downloadpostgresql-9b584953e7bf91e342af87ef44606acd6206cd1c.tar.gz
postgresql-9b584953e7bf91e342af87ef44606acd6206cd1c.zip
Improve some code around cryptohash functions
This adjusts some code related to recent changes for cryptohash functions: - Add a variable in md5.h to track down the size of a computed result, moved from pgcrypto. Note that pg_md5_hash() assumed a result of this size already. - Call explicit_bzero() on the hashed data when freeing the context for fallback implementations. For MD5, particularly, it would be annoying to leave some non-zeroed data around. - Clean up some code related to recent changes of uuid-ossp. .gitignore still included md5.c and a comment was incorrect. Discussion: https://postgr.es/m/X9HXKTgrvJvYO7Oh@paquier.xyz
Diffstat (limited to 'src/common/cryptohash.c')
-rw-r--r--src/common/cryptohash.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/common/cryptohash.c b/src/common/cryptohash.c
index 5cc2572eb6e..cf4588bad72 100644
--- a/src/common/cryptohash.c
+++ b/src/common/cryptohash.c
@@ -197,6 +197,26 @@ pg_cryptohash_free(pg_cryptohash_ctx *ctx)
{
if (ctx == NULL)
return;
+
+ switch (ctx->type)
+ {
+ case PG_MD5:
+ explicit_bzero(ctx->data, sizeof(pg_md5_ctx));
+ break;
+ case PG_SHA224:
+ explicit_bzero(ctx->data, sizeof(pg_sha224_ctx));
+ break;
+ case PG_SHA256:
+ explicit_bzero(ctx->data, sizeof(pg_sha256_ctx));
+ break;
+ case PG_SHA384:
+ explicit_bzero(ctx->data, sizeof(pg_sha384_ctx));
+ break;
+ case PG_SHA512:
+ explicit_bzero(ctx->data, sizeof(pg_sha512_ctx));
+ break;
+ }
+
FREE(ctx->data);
explicit_bzero(ctx, sizeof(pg_cryptohash_ctx));
FREE(ctx);