24 #include <openssl/err.h>
25 #include <openssl/evp.h>
42 #define ALLOC(size) MemoryContextAlloc(TopMemoryContext, size)
43 #define FREE(ptr) pfree(ptr)
45 #define ALLOC(size) malloc(size)
46 #define FREE(ptr) free(ptr)
82 .
name =
"OpenSSL cryptohash context",
112 return ERR_reason_error_string(ecode);
149 ctx->
evpctx = EVP_MD_CTX_create();
157 (
errcode(ERRCODE_OUT_OF_MEMORY),
158 errmsg(
"out of memory")));
188 status = EVP_DigestInit_ex(ctx->
evpctx, EVP_md5(), NULL);
191 status = EVP_DigestInit_ex(ctx->
evpctx, EVP_sha1(), NULL);
194 status = EVP_DigestInit_ex(ctx->
evpctx, EVP_sha224(), NULL);
197 status = EVP_DigestInit_ex(ctx->
evpctx, EVP_sha256(), NULL);
200 status = EVP_DigestInit_ex(ctx->
evpctx, EVP_sha384(), NULL);
203 status = EVP_DigestInit_ex(ctx->
evpctx, EVP_sha512(), NULL);
308 status = EVP_DigestFinal_ex(ctx->
evpctx,
dest, 0);
331 EVP_MD_CTX_destroy(ctx->
evpctx);
356 return _(
"out of memory");
370 return _(
"destination buffer too small");
372 return _(
"OpenSSL failure");
#define Assert(condition)
static void ResOwnerReleaseCryptoHash(Datum res)
int pg_cryptohash_update(pg_cryptohash_ctx *ctx, const uint8 *data, size_t len)
int pg_cryptohash_init(pg_cryptohash_ctx *ctx)
static const char * SSLerrmessage(unsigned long ecode)
static void ResourceOwnerForgetCryptoHash(ResourceOwner owner, pg_cryptohash_ctx *ctx)
static const ResourceOwnerDesc cryptohash_resowner_desc
@ PG_CRYPTOHASH_ERROR_DEST_LEN
@ PG_CRYPTOHASH_ERROR_NONE
@ PG_CRYPTOHASH_ERROR_OPENSSL
static void ResourceOwnerRememberCryptoHash(ResourceOwner owner, pg_cryptohash_ctx *ctx)
void pg_cryptohash_free(pg_cryptohash_ctx *ctx)
pg_cryptohash_ctx * pg_cryptohash_create(pg_cryptohash_type type)
int pg_cryptohash_final(pg_cryptohash_ctx *ctx, uint8 *dest, size_t len)
const char * pg_cryptohash_error(pg_cryptohash_ctx *ctx)
static void PGresult * res
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define MD5_DIGEST_LENGTH
void explicit_bzero(void *buf, size_t len)
static Datum PointerGetDatum(const void *X)
static Pointer DatumGetPointer(Datum X)
ResourceOwner CurrentResourceOwner
void ResourceOwnerForget(ResourceOwner owner, Datum value, const ResourceOwnerDesc *kind)
void ResourceOwnerRemember(ResourceOwner owner, Datum value, const ResourceOwnerDesc *kind)
void ResourceOwnerEnlarge(ResourceOwner owner)
@ RESOURCE_RELEASE_BEFORE_LOCKS
#define RELEASE_PRIO_CRYPTOHASH_CONTEXTS
#define SHA1_DIGEST_LENGTH
#define PG_SHA256_DIGEST_LENGTH
#define PG_SHA384_DIGEST_LENGTH
#define PG_SHA512_DIGEST_LENGTH
#define PG_SHA224_DIGEST_LENGTH
pg_cryptohash_errno error