summaryrefslogtreecommitdiff
path: root/contrib/pgcrypto/internal.c
diff options
context:
space:
mode:
authorMichael Paquier2021-01-23 02:33:04 +0000
committerMichael Paquier2021-01-23 02:33:04 +0000
commita8ed6bb8f4cf259b95c1bff5da09a8f4c79dca46 (patch)
treed8a97d8a0a0dae12bb6b96caf6ce3b4d625229a4 /contrib/pgcrypto/internal.c
parent3fc81ce459e1696f7e5e5b3b8229409413bf64b4 (diff)
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 'contrib/pgcrypto/internal.c')
-rw-r--r--contrib/pgcrypto/internal.c34
1 files changed, 14 insertions, 20 deletions
diff --git a/contrib/pgcrypto/internal.c b/contrib/pgcrypto/internal.c
index 79ce5135992..ef6ce2fb1ef 100644
--- a/contrib/pgcrypto/internal.c
+++ b/contrib/pgcrypto/internal.c
@@ -36,18 +36,10 @@
#include "blf.h"
#include "px.h"
#include "rijndael.h"
-#include "sha1.h"
#include "common/cryptohash.h"
#include "common/md5.h"
-
-#ifndef SHA1_DIGEST_LENGTH
-#ifdef SHA1_RESULTLEN
-#define SHA1_DIGEST_LENGTH SHA1_RESULTLEN
-#else
-#define SHA1_DIGEST_LENGTH 20
-#endif
-#endif
+#include "common/sha1.h"
#define SHA1_BLOCK_SIZE 64
#define MD5_BLOCK_SIZE 64
@@ -144,34 +136,36 @@ int_sha1_block_len(PX_MD *h)
static void
int_sha1_update(PX_MD *h, const uint8 *data, unsigned dlen)
{
- SHA1_CTX *ctx = (SHA1_CTX *) h->p.ptr;
+ pg_cryptohash_ctx *ctx = (pg_cryptohash_ctx *) h->p.ptr;
- SHA1Update(ctx, data, dlen);
+ if (pg_cryptohash_update(ctx, data, dlen) < 0)
+ elog(ERROR, "could not update %s context", "SHA1");
}
static void
int_sha1_reset(PX_MD *h)
{
- SHA1_CTX *ctx = (SHA1_CTX *) h->p.ptr;
+ pg_cryptohash_ctx *ctx = (pg_cryptohash_ctx *) h->p.ptr;
- SHA1Init(ctx);
+ if (pg_cryptohash_init(ctx) < 0)
+ elog(ERROR, "could not initialize %s context", "SHA1");
}
static void
int_sha1_finish(PX_MD *h, uint8 *dst)
{
- SHA1_CTX *ctx = (SHA1_CTX *) h->p.ptr;
+ pg_cryptohash_ctx *ctx = (pg_cryptohash_ctx *) h->p.ptr;
- SHA1Final(dst, ctx);
+ if (pg_cryptohash_final(ctx, dst) < 0)
+ elog(ERROR, "could not finalize %s context", "SHA1");
}
static void
int_sha1_free(PX_MD *h)
{
- SHA1_CTX *ctx = (SHA1_CTX *) h->p.ptr;
+ pg_cryptohash_ctx *ctx = (pg_cryptohash_ctx *) h->p.ptr;
- px_memset(ctx, 0, sizeof(*ctx));
- pfree(ctx);
+ pg_cryptohash_free(ctx);
pfree(h);
}
@@ -199,9 +193,9 @@ init_md5(PX_MD *md)
static void
init_sha1(PX_MD *md)
{
- SHA1_CTX *ctx;
+ pg_cryptohash_ctx *ctx;
- ctx = palloc0(sizeof(*ctx));
+ ctx = pg_cryptohash_create(PG_SHA1);
md->p.ptr = ctx;