PostgreSQL Source Code: src/common/hmac.c File Reference (original) (raw)
Go to the source code of this file.
Macros | |
---|---|
#define | ALLOC(size) palloc(size) |
#define | FREE(ptr) pfree(ptr) |
#define | HMAC_IPAD 0x36 |
#define | HMAC_OPAD 0x5C |
Functions | |
---|---|
pg_hmac_ctx * | pg_hmac_create (pg_cryptohash_type type) |
int | pg_hmac_init (pg_hmac_ctx *ctx, const uint8 *key, size_t len) |
int | pg_hmac_update (pg_hmac_ctx *ctx, const uint8 *data, size_t len) |
int | pg_hmac_final (pg_hmac_ctx *ctx, uint8 *dest, size_t len) |
void | pg_hmac_free (pg_hmac_ctx *ctx) |
const char * | pg_hmac_error (pg_hmac_ctx *ctx) |
◆ ALLOC
| #define ALLOC | ( | | size | ) | palloc(size) | | ------------- | - | | ---- | - | ------------------------------------------------------------------ |
Definition at line 34 of file hmac.c.
◆ FREE
| #define FREE | ( | | ptr | ) | pfree(ptr) | | ------------ | - | | --- | - | ---------------------------------------------------------------- |
Definition at line 35 of file hmac.c.
◆ HMAC_IPAD
◆ HMAC_OPAD
◆ pg_hmac_errno
◆ pg_hmac_errno
Enumerator |
---|
PG_HMAC_ERROR_NONE |
PG_HMAC_ERROR_OOM |
PG_HMAC_ERROR_INTERNAL |
PG_HMAC_ERROR_NONE |
PG_HMAC_ERROR_DEST_LEN |
PG_HMAC_ERROR_OPENSSL |
Definition at line 42 of file hmac.c.
◆ pg_hmac_create()
Definition at line 77 of file hmac.c.
78{
80
82 if (ctx == NULL)
83 return NULL;
88
89
90
91
92
94 {
98 break;
102 break;
106 break;
110 break;
114 break;
118 break;
119 }
120
122 if (ctx->hash == NULL)
123 {
126 return NULL;
127 }
128
129 return ctx;
130}
pg_cryptohash_ctx * pg_cryptohash_create(pg_cryptohash_type type)
#define MD5_DIGEST_LENGTH
void explicit_bzero(void *buf, size_t len)
#define SHA1_DIGEST_LENGTH
#define PG_SHA256_DIGEST_LENGTH
#define PG_SHA384_BLOCK_LENGTH
#define PG_SHA384_DIGEST_LENGTH
#define PG_SHA512_DIGEST_LENGTH
#define PG_SHA256_BLOCK_LENGTH
#define PG_SHA512_BLOCK_LENGTH
#define PG_SHA224_BLOCK_LENGTH
#define PG_SHA224_DIGEST_LENGTH
References ALLOC, pg_hmac_ctx::block_size, pg_hmac_ctx::digest_size, pg_hmac_ctx::error, pg_hmac_ctx::errreason, explicit_bzero(), FREE, pg_hmac_ctx::hash, MD5_BLOCK_SIZE, MD5_DIGEST_LENGTH, pg_cryptohash_create(), PG_HMAC_ERROR_NONE, PG_MD5, PG_SHA1, PG_SHA224, PG_SHA224_BLOCK_LENGTH, PG_SHA224_DIGEST_LENGTH, PG_SHA256, PG_SHA256_BLOCK_LENGTH, PG_SHA256_DIGEST_LENGTH, PG_SHA384, PG_SHA384_BLOCK_LENGTH, PG_SHA384_DIGEST_LENGTH, PG_SHA512, PG_SHA512_BLOCK_LENGTH, PG_SHA512_DIGEST_LENGTH, SHA1_BLOCK_SIZE, SHA1_DIGEST_LENGTH, type, and pg_hmac_ctx::type.
Referenced by build_server_final_message(), calculate_client_proof(), scram_ClientKey(), scram_SaltedPassword(), scram_ServerKey(), verify_client_proof(), and verify_server_signature().
◆ pg_hmac_error()
Definition at line 306 of file hmac.c.
307{
308 if (ctx == NULL)
309 return _("out of memory");
310
311
312
313
314
317
318 switch (ctx->error)
319 {
321 return _("success");
323 return _("internal error");
325 return _("out of memory");
326 }
327
328 Assert(false);
329 return _("success");
330}
Assert(PointerIsAligned(start, uint64))
References _, Assert(), pg_hmac_ctx::error, pg_hmac_ctx::errreason, PG_HMAC_ERROR_INTERNAL, PG_HMAC_ERROR_NONE, and PG_HMAC_ERROR_OOM.
Referenced by build_server_final_message(), calculate_client_proof(), scram_ClientKey(), scram_SaltedPassword(), scram_ServerKey(), verify_client_proof(), and verify_server_signature().
◆ pg_hmac_final()
Definition at line 244 of file hmac.c.
245{
247
248 if (ctx == NULL)
249 return -1;
250
252 if (h == NULL)
253 {
255 return -1;
256 }
258
260 {
264 return -1;
265 }
266
267
272 {
276 return -1;
277 }
278
280 return 0;
281}
const char * pg_cryptohash_error(pg_cryptohash_ctx *ctx)
int pg_cryptohash_update(pg_cryptohash_ctx *ctx, const uint8 *data, size_t len)
int pg_cryptohash_init(pg_cryptohash_ctx *ctx)
int pg_cryptohash_final(pg_cryptohash_ctx *ctx, uint8 *dest, size_t len)
uint8 k_opad[PG_SHA512_BLOCK_LENGTH]
References ALLOC, pg_hmac_ctx::block_size, generate_unaccent_rules::dest, pg_hmac_ctx::digest_size, pg_hmac_ctx::error, pg_hmac_ctx::errreason, FREE, pg_hmac_ctx::hash, pg_hmac_ctx::k_opad, len, pg_cryptohash_error(), pg_cryptohash_final(), pg_cryptohash_init(), pg_cryptohash_update(), PG_HMAC_ERROR_INTERNAL, and PG_HMAC_ERROR_OOM.
Referenced by build_server_final_message(), calculate_client_proof(), scram_ClientKey(), scram_SaltedPassword(), scram_ServerKey(), verify_client_proof(), and verify_server_signature().
◆ pg_hmac_free()
◆ pg_hmac_init()
Definition at line 138 of file hmac.c.
139{
140 int i;
141 int digest_size;
143 uint8 *shrinkbuf = NULL;
144
145 if (ctx == NULL)
146 return -1;
147
150
153
154
155
156
157
159 {
161
162
163 shrinkbuf = ALLOC(digest_size);
164 if (shrinkbuf == NULL)
165 {
167 return -1;
168 }
169 memset(shrinkbuf, 0, digest_size);
170
172 if (hash_ctx == NULL)
173 {
175 FREE(shrinkbuf);
176 return -1;
177 }
178
182 {
186 FREE(shrinkbuf);
187 return -1;
188 }
189
190 key = shrinkbuf;
191 len = digest_size;
193 }
194
196 {
199 }
200
201
204 {
207 if (shrinkbuf)
208 FREE(shrinkbuf);
209 return -1;
210 }
211
212 if (shrinkbuf)
213 FREE(shrinkbuf);
214 return 0;
215}
uint8 k_ipad[PG_SHA512_BLOCK_LENGTH]
References ALLOC, block_size, pg_hmac_ctx::block_size, pg_hmac_ctx::digest_size, pg_hmac_ctx::error, pg_hmac_ctx::errreason, FREE, pg_hmac_ctx::hash, HMAC_IPAD, HMAC_OPAD, i, pg_hmac_ctx::k_ipad, pg_hmac_ctx::k_opad, sort-test::key, len, pg_cryptohash_create(), pg_cryptohash_error(), pg_cryptohash_final(), pg_cryptohash_free(), pg_cryptohash_init(), pg_cryptohash_update(), PG_HMAC_ERROR_INTERNAL, PG_HMAC_ERROR_OOM, and pg_hmac_ctx::type.
Referenced by build_server_final_message(), calculate_client_proof(), scram_ClientKey(), scram_SaltedPassword(), scram_ServerKey(), verify_client_proof(), and verify_server_signature().
◆ pg_hmac_update()
Definition at line 223 of file hmac.c.
224{
225 if (ctx == NULL)
226 return -1;
227
229 {
232 return -1;
233 }
234
235 return 0;
236}
References data, pg_hmac_ctx::error, pg_hmac_ctx::errreason, pg_hmac_ctx::hash, len, pg_cryptohash_error(), pg_cryptohash_update(), and PG_HMAC_ERROR_INTERNAL.
Referenced by build_server_final_message(), calculate_client_proof(), scram_ClientKey(), scram_SaltedPassword(), scram_ServerKey(), verify_client_proof(), and verify_server_signature().