mp_int
mp_int_alloc(void)
{
- mp_int out = px_alloc(sizeof(mpz_t));
+ mp_int out = palloc(sizeof(mpz_t));
if (out != NULL)
mp_int_init(out);
assert(z != NULL);
mp_int_clear(z);
- px_free(z); /* note: NOT s_free() */
+ pfree(z); /* note: NOT s_free() */
}
mp_result
static mp_digit *
s_alloc(mp_size num)
{
- mp_digit *out = px_alloc(num * sizeof(mp_digit));
+ mp_digit *out = palloc(num * sizeof(mp_digit));
assert(out != NULL);
new[ix] = fill;
memcpy(new, old, osize * sizeof(mp_digit));
#else
- mp_digit *new = px_realloc(old, nsize * sizeof(mp_digit));
+ mp_digit *new = repalloc(old, nsize * sizeof(mp_digit));
assert(new != NULL);
#endif
static void
s_free(void *ptr)
{
- px_free(ptr);
+ pfree(ptr);
}
static bool
pg_sha224_ctx *ctx = (pg_sha224_ctx *) h->p.ptr;
px_memset(ctx, 0, sizeof(*ctx));
- px_free(ctx);
- px_free(h);
+ pfree(ctx);
+ pfree(h);
}
/* SHA256 */
pg_sha256_ctx *ctx = (pg_sha256_ctx *) h->p.ptr;
px_memset(ctx, 0, sizeof(*ctx));
- px_free(ctx);
- px_free(h);
+ pfree(ctx);
+ pfree(h);
}
/* SHA384 */
pg_sha384_ctx *ctx = (pg_sha384_ctx *) h->p.ptr;
px_memset(ctx, 0, sizeof(*ctx));
- px_free(ctx);
- px_free(h);
+ pfree(ctx);
+ pfree(h);
}
/* SHA512 */
pg_sha512_ctx *ctx = (pg_sha512_ctx *) h->p.ptr;
px_memset(ctx, 0, sizeof(*ctx));
- px_free(ctx);
- px_free(h);
+ pfree(ctx);
+ pfree(h);
}
/* init functions */
{
pg_sha224_ctx *ctx;
- ctx = px_alloc(sizeof(*ctx));
- memset(ctx, 0, sizeof(*ctx));
+ ctx = palloc0(sizeof(*ctx));
md->p.ptr = ctx;
{
pg_sha256_ctx *ctx;
- ctx = px_alloc(sizeof(*ctx));
- memset(ctx, 0, sizeof(*ctx));
+ ctx = palloc0(sizeof(*ctx));
md->p.ptr = ctx;
{
pg_sha384_ctx *ctx;
- ctx = px_alloc(sizeof(*ctx));
- memset(ctx, 0, sizeof(*ctx));
+ ctx = palloc0(sizeof(*ctx));
md->p.ptr = ctx;
{
pg_sha512_ctx *ctx;
- ctx = px_alloc(sizeof(*ctx));
- memset(ctx, 0, sizeof(*ctx));
+ ctx = palloc0(sizeof(*ctx));
md->p.ptr = ctx;
MD5_CTX *ctx = (MD5_CTX *) h->p.ptr;
px_memset(ctx, 0, sizeof(*ctx));
- px_free(ctx);
- px_free(h);
+ pfree(ctx);
+ pfree(h);
}
/* SHA1 */
SHA1_CTX *ctx = (SHA1_CTX *) h->p.ptr;
px_memset(ctx, 0, sizeof(*ctx));
- px_free(ctx);
- px_free(h);
+ pfree(ctx);
+ pfree(h);
}
/* init functions */
{
MD5_CTX *ctx;
- ctx = px_alloc(sizeof(*ctx));
- memset(ctx, 0, sizeof(*ctx));
+ ctx = palloc0(sizeof(*ctx));
md->p.ptr = ctx;
{
SHA1_CTX *ctx;
- ctx = px_alloc(sizeof(*ctx));
- memset(ctx, 0, sizeof(*ctx));
+ ctx = palloc0(sizeof(*ctx));
md->p.ptr = ctx;
if (cx)
{
px_memset(cx, 0, sizeof *cx);
- px_free(cx);
+ pfree(cx);
}
- px_free(c);
+ pfree(c);
}
/*
PX_Cipher *c;
struct int_ctx *cx;
- c = px_alloc(sizeof *c);
- memset(c, 0, sizeof *c);
+ c = palloc0(sizeof *c);
c->block_size = rj_block_size;
c->key_size = rj_key_size;
c->decrypt = rj_decrypt;
c->free = intctx_free;
- cx = px_alloc(sizeof *cx);
- memset(cx, 0, sizeof *cx);
+ cx = palloc0(sizeof *cx);
cx->mode = mode;
c->ptr = cx;
PX_Cipher *c;
struct int_ctx *cx;
- c = px_alloc(sizeof *c);
- memset(c, 0, sizeof *c);
+ c = palloc0(sizeof *c);
c->block_size = bf_block_size;
c->key_size = bf_key_size;
c->decrypt = bf_decrypt;
c->free = intctx_free;
- cx = px_alloc(sizeof *cx);
- memset(cx, 0, sizeof *cx);
+ cx = palloc0(sizeof *cx);
cx->mode = mode;
c->ptr = cx;
return c;
for (p = int_digest_list; p->name; p++)
if (pg_strcasecmp(p->name, name) == 0)
{
- h = px_alloc(sizeof(*h));
+ h = palloc(sizeof(*h));
p->init(h);
*res = h;
if (mbuf->own_data)
{
px_memset(mbuf->data, 0, mbuf->buf_end - mbuf->data);
- px_free(mbuf->data);
+ pfree(mbuf->data);
}
- px_free(mbuf);
+ pfree(mbuf);
return 0;
}
newlen = (mbuf->buf_end - mbuf->data)
+ ((block_len + STEP + STEP - 1) & -STEP);
- newbuf = px_realloc(mbuf->data, newlen);
+ newbuf = repalloc(mbuf->data, newlen);
mbuf->buf_end = newbuf + newlen;
mbuf->data_end = newbuf + (mbuf->data_end - mbuf->data);
if (!len)
len = 8192;
- mbuf = px_alloc(sizeof *mbuf);
- mbuf->data = px_alloc(len);
+ mbuf = palloc(sizeof *mbuf);
+ mbuf->data = palloc(len);
mbuf->buf_end = mbuf->data + len;
mbuf->data_end = mbuf->data;
mbuf->read_pos = mbuf->data;
{
MBuf *mbuf;
- mbuf = px_alloc(sizeof *mbuf);
+ mbuf = palloc(sizeof *mbuf);
mbuf->data = (uint8 *) data;
mbuf->buf_end = mbuf->data + len;
mbuf->data_end = mbuf->data + len;
res = 0;
}
- pf = px_alloc(sizeof(*pf));
- memset(pf, 0, sizeof(*pf));
+ pf = palloc0(sizeof(*pf));
pf->buflen = res;
pf->op = op;
pf->priv = priv;
pf->src = src;
if (pf->buflen > 0)
{
- pf->buf = px_alloc(pf->buflen);
+ pf->buf = palloc(pf->buflen);
pf->pos = 0;
}
else
if (pf->buf)
{
px_memset(pf->buf, 0, pf->buflen);
- px_free(pf->buf);
+ pfree(pf->buf);
}
px_memset(pf, 0, sizeof(*pf));
- px_free(pf);
+ pfree(pf);
}
/* may return less data than asked, 0 means eof */
res = 0;
}
- mp = px_alloc(sizeof(*mp));
- memset(mp, 0, sizeof(*mp));
+ mp = palloc0(sizeof(*mp));
mp->block_size = res;
mp->op = op;
mp->priv = priv;
mp->next = next;
if (mp->block_size > 0)
{
- mp->buf = px_alloc(mp->block_size);
+ mp->buf = palloc(mp->block_size);
mp->pos = 0;
}
else
if (mp->buf)
{
px_memset(mp->buf, 0, mp->block_size);
- px_free(mp->buf);
+ pfree(mp->buf);
}
px_memset(mp, 0, sizeof(*mp));
- px_free(mp);
+ pfree(mp);
}
void
OSSLDigest *digest = (OSSLDigest *) h->p.ptr;
free_openssl_digest(digest);
- px_free(h);
+ pfree(h);
}
static int px_openssl_initialized = 0;
open_digests = digest;
/* The PX_MD object is allocated in the current memory context. */
- h = px_alloc(sizeof(*h));
+ h = palloc(sizeof(*h));
h->result_size = digest_result_size;
h->block_size = digest_block_size;
h->reset = digest_reset;
OSSLCipher *od = (OSSLCipher *) c->ptr;
free_openssl_cipher(od);
- px_free(c);
+ pfree(c);
}
static int
od->evp_ciph = i->ciph->cipher_func();
/* The PX_Cipher is allocated in current memory context */
- c = px_alloc(sizeof(*c));
+ c = palloc(sizeof(*c));
c->block_size = gen_ossl_block_size;
c->key_size = gen_ossl_key_size;
c->iv_size = gen_ossl_iv_size;
return res;
}
- ctx = px_alloc(sizeof(*ctx));
- memset(ctx, 0, sizeof(*ctx));
+ ctx = palloc0(sizeof(*ctx));
ctx->ciph = ciph;
ctx->block_size = px_cipher_block_size(ciph);
ctx->resync = resync;
{
px_cipher_free(ctx->ciph);
px_memset(ctx, 0, sizeof(*ctx));
- px_free(ctx);
+ pfree(ctx);
}
/*
static void *
z_alloc(void *priv, unsigned n_items, unsigned item_len)
{
- return px_alloc(n_items * item_len);
+ return palloc(n_items * item_len);
}
static void
z_free(void *priv, void *addr)
{
- px_free(addr);
+ pfree(addr);
}
static int
/*
* init
*/
- st = px_alloc(sizeof(*st));
- memset(st, 0, sizeof(*st));
+ st = palloc0(sizeof(*st));
st->buf_len = ZIP_OUT_BUF;
st->stream.zalloc = z_alloc;
st->stream.zfree = z_free;
res = deflateInit(&st->stream, ctx->compress_level);
if (res != Z_OK)
{
- px_free(st);
+ pfree(st);
return PXE_PGP_COMPRESSION_ERROR;
}
*priv_p = st;
deflateEnd(&st->stream);
px_memset(st, 0, sizeof(*st));
- px_free(st);
+ pfree(st);
}
static const PushFilterOps
&& ctx->compress_algo != PGP_COMPR_ZIP)
return PXE_PGP_UNSUPPORTED_COMPR;
- dec = px_alloc(sizeof(*dec));
- memset(dec, 0, sizeof(*dec));
+ dec = palloc0(sizeof(*dec));
dec->buf_len = ZIP_OUT_BUF;
*priv_p = dec;
res = inflateInit(&dec->stream);
if (res != Z_OK)
{
- px_free(dec);
+ pfree(dec);
px_debug("decompress_init: inflateInit error");
return PXE_PGP_COMPRESSION_ERROR;
}
inflateEnd(&dec->stream);
px_memset(dec, 0, sizeof(*dec));
- px_free(dec);
+ pfree(dec);
}
static const PullFilterOps
struct PktData *pkt = priv;
px_memset(pkt, 0, sizeof(*pkt));
- px_free(pkt);
+ pfree(pkt);
}
static struct PullFilterOps pktreader_filter = {
int pkttype, PGP_Context *ctx)
{
int res;
- struct PktData *pkt = px_alloc(sizeof(*pkt));
+ struct PktData *pkt = palloc(sizeof(*pkt));
pkt->type = pkttype;
pkt->len = len;
res = pullf_create(pf_p, &pktreader_filter, pkt, src);
if (res < 0)
- px_free(pkt);
+ pfree(pkt);
return res;
}
PGP_Context *ctx = arg;
struct MDCBufData *st;
- st = px_alloc(sizeof(*st));
- memset(st, 0, sizeof(*st));
+ st = palloc0(sizeof(*st));
st->buflen = sizeof(st->buf);
st->ctx = ctx;
*priv_p = st;
px_md_free(st->ctx->mdc_ctx);
st->ctx->mdc_ctx = NULL;
px_memset(st, 0, sizeof(*st));
- px_free(st);
+ pfree(st);
}
static struct PullFilterOps mdcbuf_filter = {
if (res < 0)
return res;
- st = px_alloc(sizeof(*st));
- memset(st, 0, sizeof(*st));
+ st = palloc0(sizeof(*st));
st->ciph = ciph;
*priv_p = st;
if (st->ciph)
pgp_cfb_free(st->ciph);
px_memset(st, 0, sizeof(*st));
- px_free(st);
+ pfree(st);
}
static const PushFilterOps encrypt_filter = {
{
struct PktStreamStat *st;
- st = px_alloc(sizeof(*st));
+ st = palloc(sizeof(*st));
st->final_done = 0;
st->pkt_block = 1 << STREAM_BLOCK_SHIFT;
*priv_p = st;
struct PktStreamStat *st = priv;
px_memset(st, 0, sizeof(*st));
- px_free(st);
+ pfree(st);
}
static const PushFilterOps pkt_stream_filter = {
int last_bits = bits & 7;
uint8 *buf;
- buf = px_alloc(bytes);
+ buf = palloc(bytes);
if (!pg_strong_random(buf, bytes))
{
- px_free(buf);
+ pfree(buf);
return PXE_NO_RANDOM;
}
mp_int_read_unsigned(res, buf, bytes);
- px_free(buf);
+ pfree(buf);
return 0;
}
px_debug("pgp_mpi_alloc: unreasonable request: bits=%d", bits);
return PXE_PGP_CORRUPT_DATA;
}
- n = px_alloc(sizeof(*n) + len);
+ n = palloc(sizeof(*n) + len);
n->bits = bits;
n->bytes = len;
n->data = (uint8 *) (n) + sizeof(*n);
if (mpi == NULL)
return 0;
px_memset(mpi, 0, sizeof(*mpi) + mpi->bytes);
- px_free(mpi);
+ pfree(mpi);
return 0;
}
if (pad_len < 8)
return PXE_BUG;
- buf = px_alloc(res_len);
+ buf = palloc(res_len);
buf[0] = 0x02;
if (!pg_strong_random(buf + 1, pad_len))
{
- px_free(buf);
+ pfree(buf);
return PXE_NO_RANDOM;
}
if (!pg_strong_random(p, 1))
{
px_memset(buf, 0, res_len);
- px_free(buf);
+ pfree(buf);
return PXE_NO_RANDOM;
}
}
/*
* create "secret message"
*/
- secmsg = px_alloc(klen + 3);
+ secmsg = palloc(klen + 3);
secmsg[0] = ctx->cipher_algo;
memcpy(secmsg + 1, ctx->sess_key, klen);
secmsg[klen + 1] = (cksum >> 8) & 0xFF;
if (padded)
{
px_memset(padded, 0, full_bytes);
- px_free(padded);
+ pfree(padded);
}
px_memset(secmsg, 0, klen + 3);
- px_free(secmsg);
+ pfree(secmsg);
if (res >= 0)
*msg_p = m;
{
PGP_PubKey *pk;
- pk = px_alloc(sizeof(*pk));
- memset(pk, 0, sizeof(*pk));
+ pk = palloc0(sizeof(*pk));
*pk_p = pk;
return 0;
}
break;
}
px_memset(pk, 0, sizeof(*pk));
- px_free(pk);
+ pfree(pk);
}
static int
{
PGP_Context *ctx;
- ctx = px_alloc(sizeof *ctx);
- memset(ctx, 0, sizeof *ctx);
+ ctx = palloc0(sizeof *ctx);
ctx->cipher_algo = def_cipher_algo;
ctx->s2k_cipher_algo = def_s2k_cipher_algo;
if (ctx->pub_key)
pgp_key_free(ctx->pub_key);
px_memset(ctx, 0, sizeof *ctx);
- px_free(ctx);
+ pfree(ctx);
return 0;
}
PX_MD *md = h->md;
bs = px_md_block_size(md);
- keybuf = px_alloc(bs);
- memset(keybuf, 0, bs);
+ keybuf = palloc0(bs);
if (klen > bs)
{
}
px_memset(keybuf, 0, bs);
- px_free(keybuf);
+ pfree(keybuf);
px_md_update(md, h->p.ipad, bs);
}
bs = px_md_block_size(md);
hlen = px_md_result_size(md);
- buf = px_alloc(hlen);
+ buf = palloc(hlen);
px_md_finish(md, buf);
px_md_finish(md, dst);
px_memset(buf, 0, hlen);
- px_free(buf);
+ pfree(buf);
}
static void
px_memset(h->p.ipad, 0, bs);
px_memset(h->p.opad, 0, bs);
- px_free(h->p.ipad);
- px_free(h->p.opad);
- px_free(h);
+ pfree(h->p.ipad);
+ pfree(h->p.opad);
+ pfree(h);
}
return PXE_HASH_UNUSABLE_FOR_HMAC;
}
- h = px_alloc(sizeof(*h));
- h->p.ipad = px_alloc(bs);
- h->p.opad = px_alloc(bs);
+ h = palloc(sizeof(*h));
+ h->p.ipad = palloc(bs);
+ h->p.opad = palloc(bs);
h->md = md;
h->result_size = hmac_result_size;
ivs = px_cipher_iv_size(c);
if (ivs > 0)
{
- ivbuf = px_alloc(ivs);
- memset(ivbuf, 0, ivs);
+ ivbuf = palloc0(ivs);
if (ivlen > ivs)
memcpy(ivbuf, iv, ivs);
else
if (klen > ks)
klen = ks;
- keybuf = px_alloc(ks);
+ keybuf = palloc0(ks);
memset(keybuf, 0, ks);
memcpy(keybuf, key, klen);
err = px_cipher_init(c, keybuf, klen, ivbuf);
if (ivbuf)
- px_free(ivbuf);
- px_free(keybuf);
+ pfree(ivbuf);
+ pfree(keybuf);
return err;
}
/* encrypt */
if (bs > 1)
{
- bbuf = px_alloc(bs * 4);
+ bbuf = palloc(bs * 4);
bpos = dlen % bs;
*rlen = dlen - bpos;
memcpy(bbuf, data + *rlen, bpos);
}
out:
if (bbuf)
- px_free(bbuf);
+ pfree(bbuf);
return err;
}
if (cx->cipher)
px_cipher_free(cx->cipher);
px_memset(cx, 0, sizeof(*cx));
- px_free(cx);
+ pfree(cx);
}
/* PARSER */
PX_Combo *cx;
- cx = px_alloc(sizeof(*cx));
- memset(cx, 0, sizeof(*cx));
-
- buf = px_alloc(strlen(name) + 1);
- strcpy(buf, name);
+ cx = palloc0(sizeof(*cx));
+ buf = pstrdup(name);
err = parse_cipher_name(buf, &s_cipher, &s_pad);
if (err)
{
- px_free(buf);
- px_free(cx);
+ pfree(buf);
+ pfree(cx);
return err;
}
cx->decrypt_len = combo_decrypt_len;
cx->free = combo_free;
- px_free(buf);
+ pfree(buf);
*res = cx;
err1:
if (cx->cipher)
px_cipher_free(cx->cipher);
- px_free(cx);
- px_free(buf);
+ pfree(cx);
+ pfree(buf);
return PXE_NO_CIPHER;
}
/* keep debug messages? */
#define PX_DEBUG
-/* a way to disable palloc
- * - useful if compiled into standalone
- */
-#ifndef PX_OWN_ALLOC
-#define px_alloc(s) palloc(s)
-#define px_realloc(p, s) repalloc(p, s)
-#define px_free(p) pfree(p)
-#else
-void *px_alloc(size_t s);
-void *px_realloc(void *p, size_t s);
-void px_free(void *p);
-#endif
-
/* max salt returned */
#define PX_MAX_SALT_LEN 128