#include "postgres.h"
#include "px.h"
Go to the source code of this file.
Defines | |
#define | HMAC_IPAD 0x36 |
#define | HMAC_OPAD 0x5C |
Functions | |
static unsigned | hmac_result_size (PX_HMAC *h) |
static unsigned | hmac_block_size (PX_HMAC *h) |
static void | hmac_init (PX_HMAC *h, const uint8 *key, unsigned klen) |
static void | hmac_reset (PX_HMAC *h) |
static void | hmac_update (PX_HMAC *h, const uint8 *data, unsigned dlen) |
static void | hmac_finish (PX_HMAC *h, uint8 *dst) |
static void | hmac_free (PX_HMAC *h) |
int | px_find_hmac (const char *name, PX_HMAC **res) |
static unsigned hmac_block_size | ( | PX_HMAC * | h | ) | [static] |
Definition at line 46 of file px-hmac.c.
References px_hmac::md, and px_md_block_size.
{ return px_md_block_size(h->md); }
Definition at line 101 of file px-hmac.c.
References buf, px_hmac::md, px_hmac::opad, px_hmac::p, px_alloc, px_free, px_md_block_size, px_md_finish, px_md_reset, px_md_result_size, and px_md_update.
{ PX_MD *md = h->md; unsigned bs, hlen; uint8 *buf; bs = px_md_block_size(md); hlen = px_md_result_size(md); buf = px_alloc(hlen); px_md_finish(md, buf); px_md_reset(md); px_md_update(md, h->p.opad, bs); px_md_update(md, buf, hlen); px_md_finish(md, dst); memset(buf, 0, hlen); px_free(buf); }
static void hmac_free | ( | PX_HMAC * | h | ) | [static] |
Definition at line 125 of file px-hmac.c.
References px_hmac::ipad, px_hmac::md, px_hmac::opad, px_hmac::p, px_free, px_md_block_size, and px_md_free.
Definition at line 52 of file px-hmac.c.
References i, px_hmac::ipad, px_hmac::md, px_hmac::opad, px_hmac::p, px_alloc, px_free, px_md_block_size, px_md_finish, px_md_reset, and px_md_update.
{ unsigned bs, i; uint8 *keybuf; PX_MD *md = h->md; bs = px_md_block_size(md); keybuf = px_alloc(bs); memset(keybuf, 0, bs); if (klen > bs) { px_md_update(md, key, klen); px_md_finish(md, keybuf); px_md_reset(md); } else memcpy(keybuf, key, klen); for (i = 0; i < bs; i++) { h->p.ipad[i] = keybuf[i] ^ HMAC_IPAD; h->p.opad[i] = keybuf[i] ^ HMAC_OPAD; } memset(keybuf, 0, bs); px_free(keybuf); px_md_update(md, h->p.ipad, bs); }
static void hmac_reset | ( | PX_HMAC * | h | ) | [static] |
Definition at line 85 of file px-hmac.c.
References px_hmac::ipad, px_hmac::md, px_hmac::p, px_md_block_size, px_md_reset, and px_md_update.
{ PX_MD *md = h->md; unsigned bs = px_md_block_size(md); px_md_reset(md); px_md_update(md, h->p.ipad, bs); }
static unsigned hmac_result_size | ( | PX_HMAC * | h | ) | [static] |
Definition at line 40 of file px-hmac.c.
References px_hmac::md, and px_md_result_size.
{ return px_md_result_size(h->md); }
Definition at line 95 of file px-hmac.c.
References px_hmac::md, and px_md_update.
{ px_md_update(h->md, data, dlen); }
int px_find_hmac | ( | const char * | name, | |
PX_HMAC ** | res | |||
) |
Definition at line 143 of file px-hmac.c.
References px_hmac::block_size, px_hmac::finish, px_hmac::free, px_hmac::init, px_hmac::ipad, px_hmac::md, px_hmac::opad, px_hmac::p, px_alloc, px_find_digest(), px_md_block_size, px_md_free, px_hmac::reset, px_hmac::result_size, and px_hmac::update.
Referenced by pg_hmac().
{ int err; PX_MD *md; PX_HMAC *h; unsigned bs; err = px_find_digest(name, &md); if (err) return err; bs = px_md_block_size(md); if (bs < 2) { px_md_free(md); return PXE_HASH_UNUSABLE_FOR_HMAC; } h = px_alloc(sizeof(*h)); h->p.ipad = px_alloc(bs); h->p.opad = px_alloc(bs); h->md = md; h->result_size = hmac_result_size; h->block_size = hmac_block_size; h->reset = hmac_reset; h->update = hmac_update; h->finish = hmac_finish; h->free = hmac_free; h->init = hmac_init; *res = h; return 0; }