aboutsummaryrefslogtreecommitdiff
path: root/src/common/cryptohash.c
diff options
context:
space:
mode:
authorMichael Paquier <michael@paquier.xyz>2021-01-23 11:33:04 +0900
committerMichael Paquier <michael@paquier.xyz>2021-01-23 11:33:04 +0900
commita8ed6bb8f4cf259b95c1bff5da09a8f4c79dca46 (patch)
treed8a97d8a0a0dae12bb6b96caf6ce3b4d625229a4 /src/common/cryptohash.c
parent3fc81ce459e1696f7e5e5b3b8229409413bf64b4 (diff)
downloadpostgresql-a8ed6bb8f4cf259b95c1bff5da09a8f4c79dca46.tar.gz
postgresql-a8ed6bb8f4cf259b95c1bff5da09a8f4c79dca46.zip
Introduce SHA1 implementations in the cryptohash infrastructure
With this commit, SHA1 goes through the implementation provided by OpenSSL via EVP when building the backend with it, and uses as fallback implementation KAME which was located in pgcrypto and already shaped for an integration with a set of init, update and final routines. Structures and routines have been renamed to make things consistent with the fallback implementations of MD5 and SHA2. uuid-ossp has used for ages a shortcut with pgcrypto to fetch a copy of SHA1 if needed. This was built depending on the build options within ./configure, so this cleans up some code and removes the build dependency between pgcrypto and uuid-ossp. Note that this will help with the refactoring of HMAC, as pgcrypto offers the option to use MD5, SHA1 or SHA2, so only the second option was missing to make that possible. Author: Michael Paquier Reviewed-by: Heikki Linnakangas Discussion: https://postgr.es/m/X9HXKTgrvJvYO7Oh@paquier.xyz
Diffstat (limited to 'src/common/cryptohash.c')
-rw-r--r--src/common/cryptohash.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/common/cryptohash.c b/src/common/cryptohash.c
index efedadd6263..5b2c050d799 100644
--- a/src/common/cryptohash.c
+++ b/src/common/cryptohash.c
@@ -25,6 +25,7 @@
#include "common/cryptohash.h"
#include "md5_int.h"
+#include "sha1_int.h"
#include "sha2_int.h"
/*
@@ -47,6 +48,7 @@ struct pg_cryptohash_ctx
union
{
pg_md5_ctx md5;
+ pg_sha1_ctx sha1;
pg_sha224_ctx sha224;
pg_sha256_ctx sha256;
pg_sha384_ctx sha384;
@@ -97,6 +99,9 @@ pg_cryptohash_init(pg_cryptohash_ctx *ctx)
case PG_MD5:
pg_md5_init(&ctx->data.md5);
break;
+ case PG_SHA1:
+ pg_sha1_init(&ctx->data.sha1);
+ break;
case PG_SHA224:
pg_sha224_init(&ctx->data.sha224);
break;
@@ -132,6 +137,9 @@ pg_cryptohash_update(pg_cryptohash_ctx *ctx, const uint8 *data, size_t len)
case PG_MD5:
pg_md5_update(&ctx->data.md5, data, len);
break;
+ case PG_SHA1:
+ pg_sha1_update(&ctx->data.sha1, data, len);
+ break;
case PG_SHA224:
pg_sha224_update(&ctx->data.sha224, data, len);
break;
@@ -167,6 +175,9 @@ pg_cryptohash_final(pg_cryptohash_ctx *ctx, uint8 *dest)
case PG_MD5:
pg_md5_final(&ctx->data.md5, dest);
break;
+ case PG_SHA1:
+ pg_sha1_final(&ctx->data.sha1, dest);
+ break;
case PG_SHA224:
pg_sha224_final(&ctx->data.sha224, dest);
break;