int pgp_cfb_create(PGP_CFB **ctx_p, int algo, const uint8 *key, int key_len, int resync, uint8 *iv) { int res; PX_Cipher *ciph; PGP_CFB *ctx; res = pgp_load_cipher(algo, &ciph); if (res < 0) return res; res = px_cipher_init(ciph, key, key_len, NULL); if (res < 0) { px_cipher_free(ciph); return res; } ctx = px_alloc(sizeof(*ctx)); memset(ctx, 0, sizeof(*ctx)); ctx->ciph = ciph; ctx->block_size = px_cipher_block_size(ciph); ctx->resync = resync; if (iv) memcpy(ctx->fr, iv, ctx->block_size); *ctx_p = ctx; return 0; }
static int combo_init(PX_Combo *cx, const uint8 *key, unsigned klen, const uint8 *iv, unsigned ivlen) { int err; unsigned bs, ks, ivs; PX_Cipher *c = cx->cipher; uint8 *ivbuf = NULL; uint8 *keybuf; bs = px_cipher_block_size(c); ks = px_cipher_key_size(c); ivs = px_cipher_iv_size(c); if (ivs > 0) { ivbuf = px_alloc(ivs); memset(ivbuf, 0, ivs); if (ivlen > ivs) memcpy(ivbuf, iv, ivs); else memcpy(ivbuf, iv, ivlen); } if (klen > ks) klen = ks; keybuf = px_alloc(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); return err; }