int px_find_combo(const char *name, PX_Combo **res) { int err; char *buf, *s_cipher, *s_pad; PX_Combo *cx; cx = px_alloc(sizeof(*cx)); memset(cx, 0, sizeof(*cx)); buf = px_alloc(strlen(name) + 1); strcpy(buf, name); err = parse_cipher_name(buf, &s_cipher, &s_pad); if (err) { px_free(buf); px_free(cx); return err; } err = px_find_cipher(s_cipher, &cx->cipher); if (err) goto err1; if (s_pad != NULL) { if (strcmp(s_pad, "pkcs") == 0) cx->padding = 1; else if (strcmp(s_pad, "none") == 0) cx->padding = 0; else goto err1; } else cx->padding = 1; cx->init = combo_init; cx->encrypt = combo_encrypt; cx->decrypt = combo_decrypt; cx->encrypt_len = combo_encrypt_len; cx->decrypt_len = combo_decrypt_len; cx->free = combo_free; px_free(buf); *res = cx; return 0; err1: if (cx->cipher) px_cipher_free(cx->cipher); px_free(cx); px_free(buf); return PXE_NO_CIPHER; }
void pgp_cfb_free(PGP_CFB *ctx) { px_cipher_free(ctx->ciph); px_memset(ctx, 0, sizeof(*ctx)); px_free(ctx); }
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 void combo_free(PX_Combo *cx) { if (cx->cipher) px_cipher_free(cx->cipher); px_memset(cx, 0, sizeof(*cx)); px_free(cx); }