PostgreSQL Source Code: src/common/hmac.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#ifndef FRONTEND
19#else
21#endif
22
28
29
30
31
32
33#ifndef FRONTEND
34#define ALLOC(size) palloc(size)
35#define FREE(ptr) pfree(ptr)
36#else
37#define ALLOC(size) malloc(size)
38#define FREE(ptr) free(ptr)
39#endif
40
41
43{
48
49
51{
58
59
60
61
62
65};
66
67#define HMAC_IPAD 0x36
68#define HMAC_OPAD 0x5C
69
70
71
72
73
74
75
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}
131
132
133
134
135
136
137int
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}
216
217
218
219
220
221
222int
224{
225 if (ctx == NULL)
226 return -1;
227
229 {
232 return -1;
233 }
234
235 return 0;
236}
237
238
239
240
241
242
243int
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}
282
283
284
285
286
287
288void
290{
291 if (ctx == NULL)
292 return;
293
297}
298
299
300
301
302
303
304
305const char *
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}
const char * pg_cryptohash_error(pg_cryptohash_ctx *ctx)
int pg_cryptohash_update(pg_cryptohash_ctx *ctx, const uint8 *data, size_t len)
pg_cryptohash_ctx * pg_cryptohash_create(pg_cryptohash_type type)
int pg_cryptohash_init(pg_cryptohash_ctx *ctx)
void pg_cryptohash_free(pg_cryptohash_ctx *ctx)
int pg_cryptohash_final(pg_cryptohash_ctx *ctx, uint8 *dest, size_t len)
Assert(PointerIsAligned(start, uint64))
pg_hmac_ctx * pg_hmac_create(pg_cryptohash_type type)
void pg_hmac_free(pg_hmac_ctx *ctx)
const char * pg_hmac_error(pg_hmac_ctx *ctx)
int pg_hmac_update(pg_hmac_ctx *ctx, const uint8 *data, size_t len)
int pg_hmac_init(pg_hmac_ctx *ctx, const uint8 *key, size_t len)
int pg_hmac_final(pg_hmac_ctx *ctx, uint8 *dest, size_t len)
#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
uint8 k_opad[PG_SHA512_BLOCK_LENGTH]
uint8 k_ipad[PG_SHA512_BLOCK_LENGTH]