* pg_hmac_create * * Allocate a hash context. Returns NULL on failure for an OOM. The * backend issues an error, without returning. */
| 68 | * backend issues an error, without returning. |
| 69 | */ |
| 70 | pg_hmac_ctx * |
| 71 | pg_hmac_create(pg_cryptohash_type type) |
| 72 | { |
| 73 | pg_hmac_ctx *ctx; |
| 74 | |
| 75 | ctx = ALLOC(sizeof(pg_hmac_ctx)); |
| 76 | if (ctx == NULL) |
| 77 | return NULL; |
| 78 | memset(ctx, 0, sizeof(pg_hmac_ctx)); |
| 79 | |
| 80 | ctx->type = type; |
| 81 | |
| 82 | /* |
| 83 | * Initialization takes care of assigning the correct type for OpenSSL. |
| 84 | */ |
| 85 | #ifdef HAVE_HMAC_CTX_NEW |
| 86 | #ifndef FRONTEND |
| 87 | ResourceOwnerEnlargeHMAC(CurrentResourceOwner); |
| 88 | #endif |
| 89 | ctx->hmacctx = HMAC_CTX_new(); |
| 90 | #else |
| 91 | ctx->hmacctx = ALLOC(sizeof(HMAC_CTX)); |
| 92 | #endif |
| 93 | |
| 94 | if (ctx->hmacctx == NULL) |
| 95 | { |
| 96 | explicit_bzero(ctx, sizeof(pg_hmac_ctx)); |
| 97 | FREE(ctx); |
| 98 | #ifndef FRONTEND |
| 99 | ereport(ERROR, |
| 100 | (errcode(ERRCODE_OUT_OF_MEMORY), |
| 101 | errmsg("out of memory"))); |
| 102 | #endif |
| 103 | return NULL; |
| 104 | } |
| 105 | |
| 106 | #ifdef HAVE_HMAC_CTX_NEW |
| 107 | #ifndef FRONTEND |
| 108 | ctx->resowner = CurrentResourceOwner; |
| 109 | ResourceOwnerRememberHMAC(CurrentResourceOwner, PointerGetDatum(ctx)); |
| 110 | #endif |
| 111 | #else |
| 112 | memset(ctx->hmacctx, 0, sizeof(HMAC_CTX)); |
| 113 | #endif /* HAVE_HMAC_CTX_NEW */ |
| 114 | |
| 115 | return ctx; |
| 116 | } |
| 117 | |
| 118 | /* |
| 119 | * pg_hmac_init |
nothing calls this directly
no test coverage detected