aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/cryptohash.c20
-rw-r--r--src/common/md5_common.c2
-rw-r--r--src/include/common/md5.h4
3 files changed, 25 insertions, 1 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);
diff --git a/src/common/md5_common.c b/src/common/md5_common.c
index 74c274175fe..abf79e5918f 100644
--- a/src/common/md5_common.c
+++ b/src/common/md5_common.c
@@ -69,7 +69,7 @@ bytesToHex(uint8 b[16], char *s)
bool
pg_md5_hash(const void *buff, size_t len, char *hexsum)
{
- uint8 sum[16];
+ uint8 sum[MD5_DIGEST_LENGTH];
pg_cryptohash_ctx *ctx;
ctx = pg_cryptohash_create(PG_MD5);
diff --git a/src/include/common/md5.h b/src/include/common/md5.h
index 53036d2d17e..5dac70cbc50 100644
--- a/src/include/common/md5.h
+++ b/src/include/common/md5.h
@@ -16,6 +16,10 @@
#ifndef PG_MD5_H
#define PG_MD5_H
+/* Size of result generated by MD5 computation */
+#define MD5_DIGEST_LENGTH 16
+
+/* password-related data */
#define MD5_PASSWD_CHARSET "0123456789abcdef"
#define MD5_PASSWD_LEN 35