mirror of
https://github.com/postgres/postgres.git
synced 2025-12-24 06:01:07 +03:00
Refactor SHA2 functions and move them to src/common/.
This way both frontend and backends can use them. The functions are taken from pgcrypto, which now fetches the source files it needs from src/common/. A new interface is designed for the SHA2 functions, which allow linking to either OpenSSL or the in-core stuff taken from KAME as needed. Michael Paquier, reviewed by Robert Haas. Discussion: https://www.postgresql.org/message-id/CAB7nPqTGKuTM5jiZriHrNaQeVqp5e_iT3X4BFLWY_HyHxLvySQ%40mail.gmail.com
This commit is contained in:
@@ -33,8 +33,8 @@
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "common/sha2.h"
|
||||
#include "px.h"
|
||||
#include "sha2.h"
|
||||
|
||||
void init_sha224(PX_MD *h);
|
||||
void init_sha256(PX_MD *h);
|
||||
@@ -46,43 +46,43 @@ void init_sha512(PX_MD *h);
|
||||
static unsigned
|
||||
int_sha224_len(PX_MD *h)
|
||||
{
|
||||
return SHA224_DIGEST_LENGTH;
|
||||
return PG_SHA224_DIGEST_LENGTH;
|
||||
}
|
||||
|
||||
static unsigned
|
||||
int_sha224_block_len(PX_MD *h)
|
||||
{
|
||||
return SHA224_BLOCK_LENGTH;
|
||||
return PG_SHA224_BLOCK_LENGTH;
|
||||
}
|
||||
|
||||
static void
|
||||
int_sha224_update(PX_MD *h, const uint8 *data, unsigned dlen)
|
||||
{
|
||||
SHA224_CTX *ctx = (SHA224_CTX *) h->p.ptr;
|
||||
pg_sha224_ctx *ctx = (pg_sha224_ctx *) h->p.ptr;
|
||||
|
||||
SHA224_Update(ctx, data, dlen);
|
||||
pg_sha224_update(ctx, data, dlen);
|
||||
}
|
||||
|
||||
static void
|
||||
int_sha224_reset(PX_MD *h)
|
||||
{
|
||||
SHA224_CTX *ctx = (SHA224_CTX *) h->p.ptr;
|
||||
pg_sha224_ctx *ctx = (pg_sha224_ctx *) h->p.ptr;
|
||||
|
||||
SHA224_Init(ctx);
|
||||
pg_sha224_init(ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
int_sha224_finish(PX_MD *h, uint8 *dst)
|
||||
{
|
||||
SHA224_CTX *ctx = (SHA224_CTX *) h->p.ptr;
|
||||
pg_sha224_ctx *ctx = (pg_sha224_ctx *) h->p.ptr;
|
||||
|
||||
SHA224_Final(dst, ctx);
|
||||
pg_sha224_final(ctx, dst);
|
||||
}
|
||||
|
||||
static void
|
||||
int_sha224_free(PX_MD *h)
|
||||
{
|
||||
SHA224_CTX *ctx = (SHA224_CTX *) h->p.ptr;
|
||||
pg_sha224_ctx *ctx = (pg_sha224_ctx *) h->p.ptr;
|
||||
|
||||
px_memset(ctx, 0, sizeof(*ctx));
|
||||
px_free(ctx);
|
||||
@@ -94,43 +94,43 @@ int_sha224_free(PX_MD *h)
|
||||
static unsigned
|
||||
int_sha256_len(PX_MD *h)
|
||||
{
|
||||
return SHA256_DIGEST_LENGTH;
|
||||
return PG_SHA256_DIGEST_LENGTH;
|
||||
}
|
||||
|
||||
static unsigned
|
||||
int_sha256_block_len(PX_MD *h)
|
||||
{
|
||||
return SHA256_BLOCK_LENGTH;
|
||||
return PG_SHA256_BLOCK_LENGTH;
|
||||
}
|
||||
|
||||
static void
|
||||
int_sha256_update(PX_MD *h, const uint8 *data, unsigned dlen)
|
||||
{
|
||||
SHA256_CTX *ctx = (SHA256_CTX *) h->p.ptr;
|
||||
pg_sha256_ctx *ctx = (pg_sha256_ctx *) h->p.ptr;
|
||||
|
||||
SHA256_Update(ctx, data, dlen);
|
||||
pg_sha256_update(ctx, data, dlen);
|
||||
}
|
||||
|
||||
static void
|
||||
int_sha256_reset(PX_MD *h)
|
||||
{
|
||||
SHA256_CTX *ctx = (SHA256_CTX *) h->p.ptr;
|
||||
pg_sha256_ctx *ctx = (pg_sha256_ctx *) h->p.ptr;
|
||||
|
||||
SHA256_Init(ctx);
|
||||
pg_sha256_init(ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
int_sha256_finish(PX_MD *h, uint8 *dst)
|
||||
{
|
||||
SHA256_CTX *ctx = (SHA256_CTX *) h->p.ptr;
|
||||
pg_sha256_ctx *ctx = (pg_sha256_ctx *) h->p.ptr;
|
||||
|
||||
SHA256_Final(dst, ctx);
|
||||
pg_sha256_final(ctx, dst);
|
||||
}
|
||||
|
||||
static void
|
||||
int_sha256_free(PX_MD *h)
|
||||
{
|
||||
SHA256_CTX *ctx = (SHA256_CTX *) h->p.ptr;
|
||||
pg_sha256_ctx *ctx = (pg_sha256_ctx *) h->p.ptr;
|
||||
|
||||
px_memset(ctx, 0, sizeof(*ctx));
|
||||
px_free(ctx);
|
||||
@@ -142,43 +142,43 @@ int_sha256_free(PX_MD *h)
|
||||
static unsigned
|
||||
int_sha384_len(PX_MD *h)
|
||||
{
|
||||
return SHA384_DIGEST_LENGTH;
|
||||
return PG_SHA384_DIGEST_LENGTH;
|
||||
}
|
||||
|
||||
static unsigned
|
||||
int_sha384_block_len(PX_MD *h)
|
||||
{
|
||||
return SHA384_BLOCK_LENGTH;
|
||||
return PG_SHA384_BLOCK_LENGTH;
|
||||
}
|
||||
|
||||
static void
|
||||
int_sha384_update(PX_MD *h, const uint8 *data, unsigned dlen)
|
||||
{
|
||||
SHA384_CTX *ctx = (SHA384_CTX *) h->p.ptr;
|
||||
pg_sha384_ctx *ctx = (pg_sha384_ctx *) h->p.ptr;
|
||||
|
||||
SHA384_Update(ctx, data, dlen);
|
||||
pg_sha384_update(ctx, data, dlen);
|
||||
}
|
||||
|
||||
static void
|
||||
int_sha384_reset(PX_MD *h)
|
||||
{
|
||||
SHA384_CTX *ctx = (SHA384_CTX *) h->p.ptr;
|
||||
pg_sha384_ctx *ctx = (pg_sha384_ctx *) h->p.ptr;
|
||||
|
||||
SHA384_Init(ctx);
|
||||
pg_sha384_init(ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
int_sha384_finish(PX_MD *h, uint8 *dst)
|
||||
{
|
||||
SHA384_CTX *ctx = (SHA384_CTX *) h->p.ptr;
|
||||
pg_sha384_ctx *ctx = (pg_sha384_ctx *) h->p.ptr;
|
||||
|
||||
SHA384_Final(dst, ctx);
|
||||
pg_sha384_final(ctx, dst);
|
||||
}
|
||||
|
||||
static void
|
||||
int_sha384_free(PX_MD *h)
|
||||
{
|
||||
SHA384_CTX *ctx = (SHA384_CTX *) h->p.ptr;
|
||||
pg_sha384_ctx *ctx = (pg_sha384_ctx *) h->p.ptr;
|
||||
|
||||
px_memset(ctx, 0, sizeof(*ctx));
|
||||
px_free(ctx);
|
||||
@@ -190,43 +190,43 @@ int_sha384_free(PX_MD *h)
|
||||
static unsigned
|
||||
int_sha512_len(PX_MD *h)
|
||||
{
|
||||
return SHA512_DIGEST_LENGTH;
|
||||
return PG_SHA512_DIGEST_LENGTH;
|
||||
}
|
||||
|
||||
static unsigned
|
||||
int_sha512_block_len(PX_MD *h)
|
||||
{
|
||||
return SHA512_BLOCK_LENGTH;
|
||||
return PG_SHA512_BLOCK_LENGTH;
|
||||
}
|
||||
|
||||
static void
|
||||
int_sha512_update(PX_MD *h, const uint8 *data, unsigned dlen)
|
||||
{
|
||||
SHA512_CTX *ctx = (SHA512_CTX *) h->p.ptr;
|
||||
pg_sha512_ctx *ctx = (pg_sha512_ctx *) h->p.ptr;
|
||||
|
||||
SHA512_Update(ctx, data, dlen);
|
||||
pg_sha512_update(ctx, data, dlen);
|
||||
}
|
||||
|
||||
static void
|
||||
int_sha512_reset(PX_MD *h)
|
||||
{
|
||||
SHA512_CTX *ctx = (SHA512_CTX *) h->p.ptr;
|
||||
pg_sha512_ctx *ctx = (pg_sha512_ctx *) h->p.ptr;
|
||||
|
||||
SHA512_Init(ctx);
|
||||
pg_sha512_init(ctx);
|
||||
}
|
||||
|
||||
static void
|
||||
int_sha512_finish(PX_MD *h, uint8 *dst)
|
||||
{
|
||||
SHA512_CTX *ctx = (SHA512_CTX *) h->p.ptr;
|
||||
pg_sha512_ctx *ctx = (pg_sha512_ctx *) h->p.ptr;
|
||||
|
||||
SHA512_Final(dst, ctx);
|
||||
pg_sha512_final(ctx, dst);
|
||||
}
|
||||
|
||||
static void
|
||||
int_sha512_free(PX_MD *h)
|
||||
{
|
||||
SHA512_CTX *ctx = (SHA512_CTX *) h->p.ptr;
|
||||
pg_sha512_ctx *ctx = (pg_sha512_ctx *) h->p.ptr;
|
||||
|
||||
px_memset(ctx, 0, sizeof(*ctx));
|
||||
px_free(ctx);
|
||||
@@ -238,7 +238,7 @@ int_sha512_free(PX_MD *h)
|
||||
void
|
||||
init_sha224(PX_MD *md)
|
||||
{
|
||||
SHA224_CTX *ctx;
|
||||
pg_sha224_ctx *ctx;
|
||||
|
||||
ctx = px_alloc(sizeof(*ctx));
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
@@ -258,7 +258,7 @@ init_sha224(PX_MD *md)
|
||||
void
|
||||
init_sha256(PX_MD *md)
|
||||
{
|
||||
SHA256_CTX *ctx;
|
||||
pg_sha256_ctx *ctx;
|
||||
|
||||
ctx = px_alloc(sizeof(*ctx));
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
@@ -278,7 +278,7 @@ init_sha256(PX_MD *md)
|
||||
void
|
||||
init_sha384(PX_MD *md)
|
||||
{
|
||||
SHA384_CTX *ctx;
|
||||
pg_sha384_ctx *ctx;
|
||||
|
||||
ctx = px_alloc(sizeof(*ctx));
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
@@ -298,7 +298,7 @@ init_sha384(PX_MD *md)
|
||||
void
|
||||
init_sha512(PX_MD *md)
|
||||
{
|
||||
SHA512_CTX *ctx;
|
||||
pg_sha512_ctx *ctx;
|
||||
|
||||
ctx = px_alloc(sizeof(*ctx));
|
||||
memset(ctx, 0, sizeof(*ctx));
|
||||
|
||||
Reference in New Issue
Block a user