18 DISABLE_GCC_WARNING(
"-Wstrict-prototypes")
21 ENABLE_GCC_WARNING(
"-Wstrict-prototypes")
24 aes_new_cipher(const uint8_t *key, const uint8_t *iv,
27 const CK_MECHANISM_TYPE ckm = CKM_AES_CTR;
28 SECItem keyItem = { .type = siBuffer,
29 .data = (
unsigned char *)key,
30 .len = (key_bits / 8) };
31 CK_AES_CTR_PARAMS params;
32 params.ulCounterBits = 128;
33 memcpy(params.cb, iv, 16);
34 SECItem ivItem = { .type = siBuffer,
35 .data = (
unsigned char *)¶ms,
36 .len =
sizeof(params) };
37 PK11SlotInfo *slot = NULL;
38 PK11SymKey *keyObj = NULL;
39 SECItem *ivObj = NULL;
40 PK11Context *result = NULL;
42 slot = PK11_GetBestSlot(ckm, NULL);
46 keyObj = PK11_ImportSymKey(slot, ckm, PK11_OriginUnwrap,
47 CKA_ENCRYPT, &keyItem, NULL);
51 ivObj = PK11_ParamFromIV(ckm, &ivItem);
55 PORT_SetError(SEC_ERROR_IO);
56 result = PK11_CreateContextBySymKey(ckm, CKA_ENCRYPT, keyObj, ivObj);
59 memwipe(¶ms, 0,
sizeof(params));
61 SECITEM_FreeItem(ivObj, PR_TRUE);
63 PK11_FreeSymKey(keyObj);
68 return (aes_cnt_cipher_t *)result;
72 aes_cipher_free_(aes_cnt_cipher_t *cipher)
76 PK11_DestroyContext((PK11Context*) cipher, PR_TRUE);
80 aes_crypt_inplace(aes_cnt_cipher_t *cipher,
char *data_,
size_t len_)
85 PK11Context *ctx = (PK11Context*)cipher;
86 unsigned char *data = (
unsigned char *)data_;
90 s = PK11_CipherOp(ctx, data, &result_len, len, data, len);
96 evaluate_evp_for_aes(
int force_value)
103 evaluate_ctr_for_aes(
void)
Headers for crypto_nss_mgt.c.
void memwipe(void *mem, uint8_t byte, size_t sz)
Common functions for cryptographic routines.
Macros to manage assertions, fatal and non-fatal.