/* Validate salt is an OCTET STRING choice */
if (pbkdf2_param->salt == NULL
|| pbkdf2_param->salt->type != V_ASN1_OCTET_STRING) {
- ERR_raise(ERR_LIB_PKCS12, PKCS12_R_PARSE_ERROR);
+ ERR_raise_data(ERR_LIB_PKCS12, PKCS12_R_PARSE_ERROR, "Invalid Salt");
goto err;
}
pbkdf2_salt = pbkdf2_param->salt->value.octet_string;
if (pbkdf2_param->keylength != NULL)
keylen = ASN1_INTEGER_get(pbkdf2_param->keylength);
if (keylen <= 0 || keylen > EVP_MAX_MD_SIZE) {
- ERR_raise(ERR_LIB_PKCS12, PKCS12_R_PARSE_ERROR);
+ ERR_raise_data(ERR_LIB_PKCS12, PKCS12_R_PARSE_ERROR, "Invalid Key length");
goto err;
}
{
int ret = 0;
EVP_MD *md;
- HMAC_CTX *hmac = NULL;
unsigned char key[EVP_MAX_MD_SIZE], *salt;
int saltlen, iter;
char md_name[80];
const ASN1_OBJECT *macoid;
OSSL_LIB_CTX *libctx;
const char *propq;
+ size_t md_sz, outlen;
if (!PKCS7_type_is_data(p12->authsafes)) {
ERR_raise(ERR_LIB_PKCS12, PKCS12_R_CONTENT_TYPE_NOT_DATA);
md_nid = EVP_MD_get_type(md);
if (keylen <= 0)
goto err;
+ md_sz = keylen;
/* For PBMAC1 we use a special keygen callback if not provided (e.g. on verification) */
if (pbmac1_md_nid != NID_undef && pkcs12_key_gen == NULL) {
}
}
}
- if ((hmac = HMAC_CTX_new()) == NULL
- || !HMAC_Init_ex(hmac, key, keylen, md, NULL)
- || !HMAC_Update(hmac, p12->authsafes->d.data->data,
- p12->authsafes->d.data->length)
- || !HMAC_Final(hmac, mac, maclen)) {
+ if (EVP_Q_mac(libctx, "HMAC", propq, md_name, NULL, key, keylen,
+ p12->authsafes->d.data->data, p12->authsafes->d.data->length,
+ mac, md_sz, &outlen)
+ == NULL)
goto err;
- }
+ if (outlen > UINT_MAX)
+ goto err;
+ *maclen = (unsigned int)outlen;
ret = 1;
-
err:
OPENSSL_cleanse(key, sizeof(key));
- HMAC_CTX_free(hmac);
EVP_MD_free(md);
return ret;
}