Latest update.
This commit is contained in:
@@ -1989,7 +1989,7 @@ $code.=<<___;
|
||||
|
||||
.Lxts_enc_done:
|
||||
stg $sp,$tweak+0($sp) # wipe tweak
|
||||
stg $sp,$twesk+8($sp)
|
||||
stg $sp,$tweak+8($sp)
|
||||
lm${g} %r6,$ra,6*$SIZE_T($sp)
|
||||
br $ra
|
||||
.size AES_xts_encrypt,.-AES_xts_encrypt
|
||||
@@ -2269,7 +2269,7 @@ $code.=<<___;
|
||||
stg $sp,$tweak-16+8($sp)
|
||||
.Lxts_dec_done:
|
||||
stg $sp,$tweak+0($sp) # wipe tweak
|
||||
stg $sp,$twesk+8($sp)
|
||||
stg $sp,$tweak+8($sp)
|
||||
lm${g} %r6,$ra,6*$SIZE_T($sp)
|
||||
br $ra
|
||||
.size AES_xts_decrypt,.-AES_xts_decrypt
|
||||
|
||||
+120
-17
@@ -20,6 +20,8 @@
|
||||
|
||||
/* CMS EnvelopedData Utilities */
|
||||
|
||||
static void cms_env_set_version(CMS_EnvelopedData *env);
|
||||
|
||||
CMS_EnvelopedData *cms_get0_enveloped(CMS_ContentInfo *cms)
|
||||
{
|
||||
if (OBJ_obj2nid(cms->contentType) != NID_pkcs7_enveloped) {
|
||||
@@ -122,6 +124,47 @@ CMS_ContentInfo *CMS_EnvelopedData_create(const EVP_CIPHER *cipher)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int cms_EnvelopedData_final(CMS_ContentInfo *cms, BIO *chain)
|
||||
{
|
||||
CMS_EnvelopedData *env = NULL;
|
||||
EVP_CIPHER_CTX *ctx = NULL;
|
||||
BIO *mbio = BIO_find_type(chain, BIO_TYPE_CIPHER);
|
||||
|
||||
env = cms_get0_enveloped(cms);
|
||||
if (env == NULL)
|
||||
return 0;
|
||||
|
||||
if (mbio == NULL) {
|
||||
CMSerr(CMS_F_CMS_ENVELOPEDDATA_FINAL, CMS_R_CONTENT_NOT_FOUND);
|
||||
return 0;
|
||||
}
|
||||
|
||||
BIO_get_cipher_ctx(mbio, &ctx);
|
||||
|
||||
/*
|
||||
* If the selected cipher supports unprotected attributes,
|
||||
* deal with it using special ctrl function
|
||||
*/
|
||||
if (EVP_CIPHER_flags(EVP_CIPHER_CTX_cipher(ctx)) & EVP_CIPH_FLAG_CIPHER_WITH_MAC) {
|
||||
if (cms->d.envelopedData->unprotectedAttrs == NULL)
|
||||
cms->d.envelopedData->unprotectedAttrs = sk_X509_ATTRIBUTE_new_null();
|
||||
|
||||
if (cms->d.envelopedData->unprotectedAttrs == NULL) {
|
||||
CMSerr(CMS_F_CMS_ENVELOPEDDATA_FINAL, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_PROCESS_UNPROTECTED,
|
||||
1, env->unprotectedAttrs) <= 0) {
|
||||
CMSerr(CMS_F_CMS_ENVELOPEDDATA_FINAL, CMS_R_CTRL_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
cms_env_set_version(cms->d.envelopedData);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Key Transport Recipient Info (KTRI) routines */
|
||||
|
||||
/* Initialise a ktri based on passed certificate and key */
|
||||
@@ -176,8 +219,9 @@ static int cms_RecipientInfo_ktri_init(CMS_RecipientInfo *ri, X509 *recip,
|
||||
* Add a recipient certificate using appropriate type of RecipientInfo
|
||||
*/
|
||||
|
||||
CMS_RecipientInfo *CMS_add1_recipient_cert(CMS_ContentInfo *cms,
|
||||
X509 *recip, unsigned int flags)
|
||||
CMS_RecipientInfo *CMS_add1_recipient(CMS_ContentInfo *cms, X509 *recip,
|
||||
EVP_PKEY *originatorPrivKey,
|
||||
X509 *originator, unsigned int flags)
|
||||
{
|
||||
CMS_RecipientInfo *ri = NULL;
|
||||
CMS_EnvelopedData *env;
|
||||
@@ -193,7 +237,7 @@ CMS_RecipientInfo *CMS_add1_recipient_cert(CMS_ContentInfo *cms,
|
||||
|
||||
pk = X509_get0_pubkey(recip);
|
||||
if (pk == NULL) {
|
||||
CMSerr(CMS_F_CMS_ADD1_RECIPIENT_CERT, CMS_R_ERROR_GETTING_PUBLIC_KEY);
|
||||
CMSerr(CMS_F_CMS_ADD1_RECIPIENT, CMS_R_ERROR_GETTING_PUBLIC_KEY);
|
||||
goto err;
|
||||
}
|
||||
|
||||
@@ -205,12 +249,12 @@ CMS_RecipientInfo *CMS_add1_recipient_cert(CMS_ContentInfo *cms,
|
||||
break;
|
||||
|
||||
case CMS_RECIPINFO_AGREE:
|
||||
if (!cms_RecipientInfo_kari_init(ri, recip, pk, flags))
|
||||
if (!cms_RecipientInfo_kari_init(ri, recip, pk, originator, originatorPrivKey, flags))
|
||||
goto err;
|
||||
break;
|
||||
|
||||
default:
|
||||
CMSerr(CMS_F_CMS_ADD1_RECIPIENT_CERT,
|
||||
CMSerr(CMS_F_CMS_ADD1_RECIPIENT,
|
||||
CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
|
||||
goto err;
|
||||
|
||||
@@ -222,13 +266,19 @@ CMS_RecipientInfo *CMS_add1_recipient_cert(CMS_ContentInfo *cms,
|
||||
return ri;
|
||||
|
||||
merr:
|
||||
CMSerr(CMS_F_CMS_ADD1_RECIPIENT_CERT, ERR_R_MALLOC_FAILURE);
|
||||
CMSerr(CMS_F_CMS_ADD1_RECIPIENT, ERR_R_MALLOC_FAILURE);
|
||||
err:
|
||||
M_ASN1_free_of(ri, CMS_RecipientInfo);
|
||||
return NULL;
|
||||
|
||||
}
|
||||
|
||||
CMS_RecipientInfo *CMS_add1_recipient_cert(CMS_ContentInfo *cms,
|
||||
X509 *recip, unsigned int flags)
|
||||
{
|
||||
return CMS_add1_recipient(cms, recip, NULL, NULL, flags);
|
||||
}
|
||||
|
||||
int CMS_RecipientInfo_ktri_get0_algs(CMS_RecipientInfo *ri,
|
||||
EVP_PKEY **pk, X509 **recip,
|
||||
X509_ALGOR **palg)
|
||||
@@ -894,7 +944,34 @@ static void cms_env_set_version(CMS_EnvelopedData *env)
|
||||
env->version = 0;
|
||||
}
|
||||
|
||||
BIO *cms_EnvelopedData_init_bio(const CMS_ContentInfo *cms)
|
||||
static BIO *cms_EnvelopedData_Decryption_init_bio(CMS_ContentInfo *cms)
|
||||
{
|
||||
CMS_EncryptedContentInfo *ec = cms->d.envelopedData->encryptedContentInfo;
|
||||
BIO *contentBio = cms_EncryptedContent_init_bio(ec);
|
||||
EVP_CIPHER_CTX *ctx = NULL;
|
||||
|
||||
if (contentBio == NULL)
|
||||
return NULL;
|
||||
|
||||
BIO_get_cipher_ctx(contentBio, &ctx);
|
||||
if (ctx == NULL) {
|
||||
BIO_free(contentBio);
|
||||
return NULL;
|
||||
}
|
||||
/*
|
||||
* If the selected cipher supports unprotected attributes,
|
||||
* deal with it using special ctrl function
|
||||
*/
|
||||
if ((EVP_CIPHER_flags(EVP_CIPHER_CTX_cipher(ctx)) & EVP_CIPH_FLAG_CIPHER_WITH_MAC)
|
||||
&& EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_PROCESS_UNPROTECTED, 0,
|
||||
cms->d.envelopedData->unprotectedAttrs) <= 0) {
|
||||
BIO_free(contentBio);
|
||||
return NULL;
|
||||
}
|
||||
return contentBio;
|
||||
}
|
||||
|
||||
static BIO *cms_EnvelopedData_Encryption_init_bio(CMS_ContentInfo *cms)
|
||||
{
|
||||
CMS_EncryptedContentInfo *ec;
|
||||
STACK_OF(CMS_RecipientInfo) *rinfos;
|
||||
@@ -907,22 +984,19 @@ BIO *cms_EnvelopedData_init_bio(const CMS_ContentInfo *cms)
|
||||
ec = cms->d.envelopedData->encryptedContentInfo;
|
||||
ret = cms_EncryptedContent_init_bio(ec);
|
||||
|
||||
/* If error or no cipher end of processing */
|
||||
|
||||
if (!ret || !ec->cipher)
|
||||
/* If error end of processing */
|
||||
if (!ret)
|
||||
return ret;
|
||||
|
||||
/* Now encrypt content key according to each RecipientInfo type */
|
||||
|
||||
rinfos = cms->d.envelopedData->recipientInfos;
|
||||
|
||||
for (i = 0; i < sk_CMS_RecipientInfo_num(rinfos); i++) {
|
||||
ri = sk_CMS_RecipientInfo_value(rinfos, i);
|
||||
if (CMS_RecipientInfo_encrypt(cms, ri) <= 0) {
|
||||
CMSerr(CMS_F_CMS_ENVELOPEDDATA_INIT_BIO,
|
||||
CMS_R_ERROR_SETTING_RECIPIENTINFO);
|
||||
goto err;
|
||||
}
|
||||
ri = sk_CMS_RecipientInfo_value(rinfos, i);
|
||||
if (CMS_RecipientInfo_encrypt(cms, ri) <= 0) {
|
||||
CMSerr(0, CMS_R_ERROR_SETTING_RECIPIENTINFO);
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
cms_env_set_version(cms->d.envelopedData);
|
||||
|
||||
@@ -937,7 +1011,17 @@ BIO *cms_EnvelopedData_init_bio(const CMS_ContentInfo *cms)
|
||||
return ret;
|
||||
BIO_free(ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
BIO *cms_EnvelopedData_init_bio(CMS_ContentInfo *cms)
|
||||
{
|
||||
if (cms->d.envelopedData->encryptedContentInfo->cipher != NULL) {
|
||||
/* If cipher is set it's encryption */
|
||||
return cms_EnvelopedData_Encryption_init_bio(cms);
|
||||
}
|
||||
|
||||
/* If cipher is not set it's decryption */
|
||||
return cms_EnvelopedData_Decryption_init_bio(cms);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -955,3 +1039,22 @@ int cms_pkey_get_ri_type(EVP_PKEY *pk)
|
||||
}
|
||||
return CMS_RECIPINFO_TRANS;
|
||||
}
|
||||
|
||||
int cms_pkey_is_ri_type_supported(EVP_PKEY *pk, int ri_type)
|
||||
{
|
||||
int supportedRiType;
|
||||
|
||||
if (pk->ameth != NULL && pk->ameth->pkey_ctrl != NULL) {
|
||||
int i, r;
|
||||
|
||||
i = pk->ameth->pkey_ctrl(pk, ASN1_PKEY_CTRL_CMS_IS_RI_TYPE_SUPPORTED, ri_type, &r);
|
||||
if (i > 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
supportedRiType = cms_pkey_get_ri_type(pk);
|
||||
if (supportedRiType < 0)
|
||||
return 0;
|
||||
|
||||
return (supportedRiType == ri_type);
|
||||
}
|
||||
+83
-10
@@ -152,7 +152,7 @@ int CMS_RecipientEncryptedKey_cert_cmp(CMS_RecipientEncryptedKey *rek,
|
||||
return -1;
|
||||
}
|
||||
|
||||
int CMS_RecipientInfo_kari_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pk)
|
||||
int CMS_RecipientInfo_kari_set0_pkey_and_peer(CMS_RecipientInfo *ri, EVP_PKEY *pk, X509 *peer)
|
||||
{
|
||||
EVP_PKEY_CTX *pctx;
|
||||
CMS_KeyAgreeRecipientInfo *kari = ri->d.kari;
|
||||
@@ -161,9 +161,18 @@ int CMS_RecipientInfo_kari_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pk)
|
||||
kari->pctx = NULL;
|
||||
if (pk == NULL)
|
||||
return 1;
|
||||
|
||||
pctx = EVP_PKEY_CTX_new(pk, NULL);
|
||||
if (pctx == NULL || EVP_PKEY_derive_init(pctx) <= 0)
|
||||
goto err;
|
||||
|
||||
if (peer != NULL) {
|
||||
EVP_PKEY *pub_pkey = X509_get0_pubkey(peer);
|
||||
|
||||
if (EVP_PKEY_derive_set_peer(pctx, pub_pkey) <= 0)
|
||||
goto err;
|
||||
}
|
||||
|
||||
kari->pctx = pctx;
|
||||
return 1;
|
||||
err:
|
||||
@@ -171,6 +180,11 @@ int CMS_RecipientInfo_kari_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pk)
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CMS_RecipientInfo_kari_set0_pkey(CMS_RecipientInfo *ri, EVP_PKEY *pk)
|
||||
{
|
||||
return CMS_RecipientInfo_kari_set0_pkey_and_peer(ri, pk, NULL);
|
||||
}
|
||||
|
||||
EVP_CIPHER_CTX *CMS_RecipientInfo_kari_get0_ctx(CMS_RecipientInfo *ri)
|
||||
{
|
||||
if (ri->type == CMS_RECIPINFO_AGREE)
|
||||
@@ -283,10 +297,29 @@ static int cms_kari_create_ephemeral_key(CMS_KeyAgreeRecipientInfo *kari,
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* Set originator private key and initialise context based on it */
|
||||
static int cms_kari_set_originator_private_key(CMS_KeyAgreeRecipientInfo *kari, EVP_PKEY *originatorPrivKey )
|
||||
{
|
||||
EVP_PKEY_CTX *pctx = NULL;
|
||||
int rv = 0;
|
||||
|
||||
pctx = EVP_PKEY_CTX_new(originatorPrivKey, NULL);
|
||||
if (pctx == NULL)
|
||||
goto err;
|
||||
if (EVP_PKEY_derive_init(pctx) <= 0)
|
||||
goto err;
|
||||
|
||||
kari->pctx = pctx;
|
||||
rv = 1;
|
||||
err:
|
||||
if (rv == 0)
|
||||
EVP_PKEY_CTX_free(pctx);
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* Initialise a kari based on passed certificate and key */
|
||||
|
||||
int cms_RecipientInfo_kari_init(CMS_RecipientInfo *ri, X509 *recip,
|
||||
EVP_PKEY *pk, unsigned int flags)
|
||||
int cms_RecipientInfo_kari_init(CMS_RecipientInfo *ri, X509 *recip, EVP_PKEY *recipPubKey, X509 * originator, EVP_PKEY *originatorPrivKey, unsigned int flags)
|
||||
{
|
||||
CMS_KeyAgreeRecipientInfo *kari;
|
||||
CMS_RecipientEncryptedKey *rek = NULL;
|
||||
@@ -321,12 +354,36 @@ int cms_RecipientInfo_kari_init(CMS_RecipientInfo *ri, X509 *recip,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Create ephemeral key */
|
||||
if (!cms_kari_create_ephemeral_key(kari, pk))
|
||||
return 0;
|
||||
if (originatorPrivKey == NULL && originator == NULL) {
|
||||
/* Create ephemeral key */
|
||||
if (!cms_kari_create_ephemeral_key(kari, recipPubKey))
|
||||
return 0;
|
||||
} else {
|
||||
/* Use originator key */
|
||||
CMS_OriginatorIdentifierOrKey *oik = ri->d.kari->originator;
|
||||
|
||||
EVP_PKEY_up_ref(pk);
|
||||
rek->pkey = pk;
|
||||
if (originatorPrivKey == NULL && originator == NULL)
|
||||
return 0;
|
||||
|
||||
if (flags & CMS_USE_ORIGINATOR_KEYID) {
|
||||
oik->type = CMS_OIK_KEYIDENTIFIER;
|
||||
oik->d.subjectKeyIdentifier = ASN1_OCTET_STRING_new();
|
||||
if (oik->d.subjectKeyIdentifier == NULL)
|
||||
return 0;
|
||||
if (!cms_set1_keyid(&oik->d.subjectKeyIdentifier, originator))
|
||||
return 0;
|
||||
} else {
|
||||
oik->type = CMS_REK_ISSUER_SERIAL;
|
||||
if (!cms_set1_ias(&oik->d.issuerAndSerialNumber, originator))
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!cms_kari_set_originator_private_key(kari, originatorPrivKey))
|
||||
return 0;
|
||||
}
|
||||
|
||||
EVP_PKEY_up_ref(recipPubKey);
|
||||
rek->pkey = recipPubKey;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -336,14 +393,30 @@ static int cms_wrap_init(CMS_KeyAgreeRecipientInfo *kari,
|
||||
EVP_CIPHER_CTX *ctx = kari->ctx;
|
||||
const EVP_CIPHER *kekcipher;
|
||||
int keylen = EVP_CIPHER_key_length(cipher);
|
||||
int ret;
|
||||
|
||||
/* If a suitable wrap algorithm is already set nothing to do */
|
||||
kekcipher = EVP_CIPHER_CTX_cipher(ctx);
|
||||
|
||||
if (kekcipher) {
|
||||
if (kekcipher != NULL) {
|
||||
if (EVP_CIPHER_CTX_mode(ctx) != EVP_CIPH_WRAP_MODE)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
else if (cipher != NULL
|
||||
&& (EVP_CIPHER_flags(cipher) & EVP_CIPH_FLAG_GET_WRAP_CIPHER)) {
|
||||
ret = EVP_CIPHER_meth_get_ctrl(cipher)(NULL, EVP_CTRL_GET_WRAP_CIPHER,
|
||||
0, &kekcipher);
|
||||
if (ret <= 0)
|
||||
return 0;
|
||||
|
||||
if (kekcipher != NULL) {
|
||||
if (EVP_CIPHER_mode(kekcipher) != EVP_CIPH_WRAP_MODE)
|
||||
return 0;
|
||||
|
||||
return EVP_EncryptInit_ex(ctx, kekcipher, NULL, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Pick a cipher based on content encryption cipher. If it is DES3 use
|
||||
* DES3 wrap otherwise use AES wrap similar to key size.
|
||||
|
||||
@@ -133,12 +133,14 @@ int CMS_dataFinal(CMS_ContentInfo *cms, BIO *cmsbio)
|
||||
switch (OBJ_obj2nid(cms->contentType)) {
|
||||
|
||||
case NID_pkcs7_data:
|
||||
case NID_pkcs7_enveloped:
|
||||
case NID_pkcs7_encrypted:
|
||||
case NID_id_smime_ct_compressedData:
|
||||
/* Nothing to do */
|
||||
return 1;
|
||||
|
||||
case NID_pkcs7_enveloped:
|
||||
return cms_EnvelopedData_final(cms, cmsbio);
|
||||
|
||||
case NID_pkcs7_signed:
|
||||
return cms_SignedData_final(cms, cmsbio);
|
||||
|
||||
|
||||
@@ -402,13 +402,16 @@ int cms_Receipt_verify(CMS_ContentInfo *cms, CMS_ContentInfo *req_cms);
|
||||
int cms_msgSigDigest_add1(CMS_SignerInfo *dest, CMS_SignerInfo *src);
|
||||
ASN1_OCTET_STRING *cms_encode_Receipt(CMS_SignerInfo *si);
|
||||
|
||||
BIO *cms_EnvelopedData_init_bio(const CMS_ContentInfo *cms);
|
||||
BIO *cms_EnvelopedData_init_bio(CMS_ContentInfo *cms);
|
||||
int cms_EnvelopedData_final(CMS_ContentInfo *cms, BIO *chain);
|
||||
CMS_EnvelopedData *cms_get0_enveloped(CMS_ContentInfo *cms);
|
||||
int cms_env_asn1_ctrl(CMS_RecipientInfo *ri, int cmd);
|
||||
int cms_pkey_get_ri_type(EVP_PKEY *pk);
|
||||
int cms_pkey_is_ri_type_supported(EVP_PKEY *pk, int ri_type);
|
||||
/* KARI routines */
|
||||
int cms_RecipientInfo_kari_init(CMS_RecipientInfo *ri, X509 *recip,
|
||||
EVP_PKEY *pk, unsigned int flags);
|
||||
EVP_PKEY *recipPubKey, X509 *originator,
|
||||
EVP_PKEY *originatorPrivKey, unsigned int flags);
|
||||
int cms_RecipientInfo_kari_encrypt(const CMS_ContentInfo *cms,
|
||||
CMS_RecipientInfo *ri);
|
||||
|
||||
|
||||
+25
-15
@@ -576,19 +576,20 @@ CMS_ContentInfo *CMS_encrypt(STACK_OF(X509) *certs, BIO *data,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int cms_kari_set1_pkey(CMS_ContentInfo *cms, CMS_RecipientInfo *ri,
|
||||
EVP_PKEY *pk, X509 *cert)
|
||||
static int cms_kari_set1_pkey_and_peer(CMS_ContentInfo *cms, CMS_RecipientInfo *ri,
|
||||
EVP_PKEY *pk, X509 *cert, X509 *peer)
|
||||
{
|
||||
int i;
|
||||
STACK_OF(CMS_RecipientEncryptedKey) *reks;
|
||||
CMS_RecipientEncryptedKey *rek;
|
||||
|
||||
reks = CMS_RecipientInfo_kari_get0_reks(ri);
|
||||
for (i = 0; i < sk_CMS_RecipientEncryptedKey_num(reks); i++) {
|
||||
int rv;
|
||||
rek = sk_CMS_RecipientEncryptedKey_value(reks, i);
|
||||
if (cert != NULL && CMS_RecipientEncryptedKey_cert_cmp(rek, cert))
|
||||
continue;
|
||||
CMS_RecipientInfo_kari_set0_pkey(ri, pk);
|
||||
CMS_RecipientInfo_kari_set0_pkey_and_peer(ri, pk, peer);
|
||||
rv = CMS_RecipientInfo_kari_decrypt(cms, ri, rek);
|
||||
CMS_RecipientInfo_kari_set0_pkey(ri, NULL);
|
||||
if (rv > 0)
|
||||
@@ -599,28 +600,37 @@ static int cms_kari_set1_pkey(CMS_ContentInfo *cms, CMS_RecipientInfo *ri,
|
||||
}
|
||||
|
||||
int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert)
|
||||
{
|
||||
return CMS_decrypt_set1_pkey_and_peer(cms, pk, cert, NULL);
|
||||
}
|
||||
|
||||
int CMS_decrypt_set1_pkey_and_peer(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert, X509 *peer)
|
||||
{
|
||||
STACK_OF(CMS_RecipientInfo) *ris;
|
||||
CMS_RecipientInfo *ri;
|
||||
int i, r, ri_type;
|
||||
int i, r, cms_pkey_ri_type;
|
||||
int debug = 0, match_ri = 0;
|
||||
ris = CMS_get0_RecipientInfos(cms);
|
||||
if (ris)
|
||||
debug = cms->d.envelopedData->encryptedContentInfo->debug;
|
||||
ri_type = cms_pkey_get_ri_type(pk);
|
||||
if (ri_type == CMS_RECIPINFO_NONE) {
|
||||
CMSerr(CMS_F_CMS_DECRYPT_SET1_PKEY,
|
||||
CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
|
||||
return 0;
|
||||
|
||||
cms_pkey_ri_type = cms_pkey_get_ri_type(pk);
|
||||
if (cms_pkey_ri_type == CMS_RECIPINFO_NONE) {
|
||||
CMSerr(CMS_F_CMS_DECRYPT_SET1_PKEY_AND_PEER,
|
||||
CMS_R_NOT_SUPPORTED_FOR_THIS_KEY_TYPE);
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < sk_CMS_RecipientInfo_num(ris); i++) {
|
||||
int ri_type;
|
||||
|
||||
ri = sk_CMS_RecipientInfo_value(ris, i);
|
||||
if (CMS_RecipientInfo_type(ri) != ri_type)
|
||||
ri_type = CMS_RecipientInfo_type(ri);
|
||||
if (!cms_pkey_is_ri_type_supported(pk, ri_type))
|
||||
continue;
|
||||
match_ri = 1;
|
||||
if (ri_type == CMS_RECIPINFO_AGREE) {
|
||||
r = cms_kari_set1_pkey(cms, ri, pk, cert);
|
||||
r = cms_kari_set1_pkey_and_peer(cms, ri, pk, cert, peer);
|
||||
if (r > 0)
|
||||
return 1;
|
||||
if (r < 0)
|
||||
@@ -646,7 +656,7 @@ int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert)
|
||||
}
|
||||
if (r > 0)
|
||||
return 1;
|
||||
CMSerr(CMS_F_CMS_DECRYPT_SET1_PKEY, CMS_R_DECRYPT_ERROR);
|
||||
CMSerr(CMS_F_CMS_DECRYPT_SET1_PKEY_AND_PEER, CMS_R_DECRYPT_ERROR);
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
@@ -654,17 +664,17 @@ int CMS_decrypt_set1_pkey(CMS_ContentInfo *cms, EVP_PKEY *pk, X509 *cert)
|
||||
* successful decrypt. Always attempt to decrypt all recipients
|
||||
* to avoid leaking timing of a successful decrypt.
|
||||
*/
|
||||
else if (r > 0 && debug)
|
||||
else if (r > 0 && (debug || cms_pkey_ri_type != CMS_RECIPINFO_TRANS))
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
/* If no cert, key transport and not debugging always return success */
|
||||
if (cert == NULL && ri_type == CMS_RECIPINFO_TRANS && match_ri && !debug) {
|
||||
if (cert == NULL && cms_pkey_ri_type == CMS_RECIPINFO_TRANS && match_ri && !debug) {
|
||||
ERR_clear_error();
|
||||
return 1;
|
||||
}
|
||||
|
||||
CMSerr(CMS_F_CMS_DECRYPT_SET1_PKEY, CMS_R_NO_MATCHING_RECIPIENT);
|
||||
CMSerr(CMS_F_CMS_DECRYPT_SET1_PKEY_AND_PEER, CMS_R_NO_MATCHING_RECIPIENT);
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
LIBS=../../libcrypto
|
||||
|
||||
$COMMON=dh_lib.c dh_key.c dh_group_params.c
|
||||
$COMMON=dh_lib.c dh_key.c dh_group_params.c dh_check.c
|
||||
|
||||
SOURCE[../../libcrypto]=$COMMON\
|
||||
dh_asn1.c dh_gen.c dh_check.c dh_err.c dh_depr.c \
|
||||
dh_asn1.c dh_gen.c dh_err.c dh_depr.c \
|
||||
dh_ameth.c dh_pmeth.c dh_prn.c dh_rfc5114.c dh_kdf.c dh_meth.c
|
||||
|
||||
SOURCE[../../providers/libfips.a]=$COMMON
|
||||
+74
-68
@@ -22,6 +22,33 @@
|
||||
#include <openssl/objects.h>
|
||||
#include "crypto/bn_dh.h"
|
||||
#include "crypto/dh.h"
|
||||
#include "crypto/security_bits.h"
|
||||
|
||||
|
||||
#define FFDHE(sz) { NID_ffdhe##sz, sz, &_bignum_ffdhe##sz##_p }
|
||||
#define MODP(sz) { NID_modp_##sz, sz, &_bignum_modp_##sz##_p }
|
||||
|
||||
typedef struct safe_prime_group_st {
|
||||
int nid;
|
||||
int32_t nbits;
|
||||
const BIGNUM *p;
|
||||
} SP_GROUP;
|
||||
|
||||
static const SP_GROUP sp_groups[] = {
|
||||
FFDHE(2048),
|
||||
FFDHE(3072),
|
||||
FFDHE(4096),
|
||||
FFDHE(6144),
|
||||
FFDHE(8192),
|
||||
#ifndef FIPS_MODE
|
||||
MODP(1536),
|
||||
#endif
|
||||
MODP(2048),
|
||||
MODP(3072),
|
||||
MODP(4096),
|
||||
MODP(6144),
|
||||
MODP(8192),
|
||||
};
|
||||
|
||||
#ifndef FIPS_MODE
|
||||
static DH *dh_new_by_nid_with_ctx(OPENSSL_CTX *libctx, int nid);
|
||||
@@ -54,40 +81,24 @@ static DH *dh_param_init(OPENSSL_CTX *libctx, int nid, const BIGNUM *p,
|
||||
|
||||
static DH *dh_new_by_nid_with_ctx(OPENSSL_CTX *libctx, int nid)
|
||||
{
|
||||
/*
|
||||
* The last parameter specified in these fields is
|
||||
* 2 * max_target_security_strength.
|
||||
* See SP800-56Ar3 Table(s) 25 & 26.
|
||||
*/
|
||||
switch (nid) {
|
||||
case NID_ffdhe2048:
|
||||
return dh_param_init(libctx, nid, &_bignum_ffdhe2048_p, 225);
|
||||
case NID_ffdhe3072:
|
||||
return dh_param_init(libctx, nid, &_bignum_ffdhe3072_p, 275);
|
||||
case NID_ffdhe4096:
|
||||
return dh_param_init(libctx, nid, &_bignum_ffdhe4096_p, 325);
|
||||
case NID_ffdhe6144:
|
||||
return dh_param_init(libctx, nid, &_bignum_ffdhe6144_p, 375);
|
||||
case NID_ffdhe8192:
|
||||
return dh_param_init(libctx, nid, &_bignum_ffdhe8192_p, 400);
|
||||
#ifndef FIPS_MODE
|
||||
case NID_modp_1536:
|
||||
return dh_param_init(libctx, nid, &_bignum_modp_1536_p, 190);
|
||||
#endif
|
||||
case NID_modp_2048:
|
||||
return dh_param_init(libctx, nid, &_bignum_modp_2048_p, 225);
|
||||
case NID_modp_3072:
|
||||
return dh_param_init(libctx, nid, &_bignum_modp_3072_p, 275);
|
||||
case NID_modp_4096:
|
||||
return dh_param_init(libctx, nid, &_bignum_modp_4096_p, 325);
|
||||
case NID_modp_6144:
|
||||
return dh_param_init(libctx, nid, &_bignum_modp_6144_p, 375);
|
||||
case NID_modp_8192:
|
||||
return dh_param_init(libctx, nid, &_bignum_modp_8192_p, 400);
|
||||
default:
|
||||
DHerr(0, DH_R_INVALID_PARAMETER_NID);
|
||||
return NULL;
|
||||
int i;
|
||||
|
||||
for (i = 0; i < (int)OSSL_NELEM(sp_groups); ++i) {
|
||||
if (sp_groups[i].nid == nid) {
|
||||
int max_target_security_strength =
|
||||
ifc_ffc_compute_security_bits(sp_groups[i].nbits);
|
||||
|
||||
/*
|
||||
* The last parameter specified here is
|
||||
* 2 * max_target_security_strength.
|
||||
* See SP800-56Ar3 Table(s) 25 & 26.
|
||||
*/
|
||||
return dh_param_init(libctx, nid, sp_groups[i].p,
|
||||
2 * max_target_security_strength);
|
||||
}
|
||||
}
|
||||
DHerr(0, DH_R_INVALID_PARAMETER_NID);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DH *DH_new_by_nid(int nid)
|
||||
@@ -98,49 +109,44 @@ DH *DH_new_by_nid(int nid)
|
||||
|
||||
int DH_get_nid(DH *dh)
|
||||
{
|
||||
int nid = dh->params.nid;
|
||||
BIGNUM *q = NULL;
|
||||
int i, nid;
|
||||
|
||||
if (dh == NULL)
|
||||
return NID_undef;
|
||||
|
||||
nid = dh->params.nid;
|
||||
/* Just return if it is already cached */
|
||||
if (nid != NID_undef)
|
||||
return nid;
|
||||
|
||||
if (BN_get_word(dh->params.g) != 2)
|
||||
return NID_undef;
|
||||
if (!BN_cmp(dh->params.p, &_bignum_ffdhe2048_p))
|
||||
nid = NID_ffdhe2048;
|
||||
else if (!BN_cmp(dh->params.p, &_bignum_ffdhe3072_p))
|
||||
nid = NID_ffdhe3072;
|
||||
else if (!BN_cmp(dh->params.p, &_bignum_ffdhe4096_p))
|
||||
nid = NID_ffdhe4096;
|
||||
else if (!BN_cmp(dh->params.p, &_bignum_ffdhe6144_p))
|
||||
nid = NID_ffdhe6144;
|
||||
else if (!BN_cmp(dh->params.p, &_bignum_ffdhe8192_p))
|
||||
nid = NID_ffdhe8192;
|
||||
#ifndef FIPS_MODE
|
||||
else if (!BN_cmp(dh->params.p, &_bignum_modp_1536_p))
|
||||
nid = NID_modp_1536;
|
||||
#endif
|
||||
else if (!BN_cmp(dh->params.p, &_bignum_modp_2048_p))
|
||||
nid = NID_modp_2048;
|
||||
else if (!BN_cmp(dh->params.p, &_bignum_modp_3072_p))
|
||||
nid = NID_modp_3072;
|
||||
else if (!BN_cmp(dh->params.p, &_bignum_modp_4096_p))
|
||||
nid = NID_modp_4096;
|
||||
else if (!BN_cmp(dh->params.p, &_bignum_modp_6144_p))
|
||||
nid = NID_modp_6144;
|
||||
else if (!BN_cmp(dh->params.p, &_bignum_modp_8192_p))
|
||||
nid = NID_modp_8192;
|
||||
else
|
||||
return NID_undef;
|
||||
|
||||
/* Verify q is correct if it exists - reset the nid if it is not correct */
|
||||
if (dh->params.q != NULL) {
|
||||
BIGNUM *q = BN_dup(dh->params.p);
|
||||
for (i = 0; i < (int)OSSL_NELEM(sp_groups); ++i) {
|
||||
/* If a matching p is found then we will break out of the loop */
|
||||
if (!BN_cmp(dh->params.p, sp_groups[i].p)) {
|
||||
/* Set q = (p - 1) / 2 (p is known to be odd so just shift right ) */
|
||||
q = BN_dup(dh->params.p);
|
||||
|
||||
/* Check q = p * 2 + 1 we already know q is odd, so just shift right */
|
||||
if (q == NULL || !BN_rshift1(q, q) || (BN_cmp(dh->params.q, q) != 0))
|
||||
nid = NID_undef;
|
||||
BN_free(q);
|
||||
if (q == NULL || !BN_rshift1(q, q))
|
||||
break; /* returns nid = NID_undef on failure */
|
||||
|
||||
/* Verify q is correct if it exists */
|
||||
if (dh->params.q != NULL) {
|
||||
if (BN_cmp(dh->params.q, q) != 0)
|
||||
break; /* returns nid = NID_undef if q does not match */
|
||||
} else {
|
||||
/* assign the calculated q */
|
||||
dh->params.q = q;
|
||||
q = NULL; /* set to NULL so it is not freed */
|
||||
}
|
||||
dh->params.nid = sp_groups[i].nid; /* cache the nid */
|
||||
dh->length = 2 * ifc_ffc_compute_security_bits(sp_groups[i].nbits);
|
||||
dh->dirty_cnt++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
dh->params.nid = nid; /* cache the nid */
|
||||
BN_free(q);
|
||||
return nid;
|
||||
}
|
||||
+1
-2
@@ -251,8 +251,7 @@ static int generate_key(DH *dh)
|
||||
* (where s = max security strength supported).
|
||||
* N = dh->length (N = maximum bit length of private key)
|
||||
*/
|
||||
if (dh->length == 0
|
||||
|| dh->params.q == NULL
|
||||
if (dh->params.q == NULL
|
||||
|| dh->length > BN_num_bits(dh->params.q))
|
||||
goto err;
|
||||
if (!ffc_generate_private_key(ctx, &dh->params, dh->length,
|
||||
|
||||
+10
-5
@@ -211,11 +211,16 @@ int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g)
|
||||
|
||||
ffc_params_set0_pqg(&dh->params, p, q, g);
|
||||
dh->params.nid = NID_undef;
|
||||
DH_get_nid(dh); /* Check if this is a named group and cache it */
|
||||
|
||||
if (q != NULL)
|
||||
dh->length = BN_num_bits(q);
|
||||
|
||||
/*
|
||||
* Check if this is a named group. If it finds a named group then the
|
||||
* 'q' and 'length' value are either already set or are set by the
|
||||
* call.
|
||||
*/
|
||||
if (DH_get_nid(dh) == NID_undef) {
|
||||
/* If its not a named group then set the 'length' if q is not NULL */
|
||||
if (q != NULL)
|
||||
dh->length = BN_num_bits(q);
|
||||
}
|
||||
dh->dirty_cnt++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
LIBS=../../libcrypto
|
||||
|
||||
$COMMON=dsa_sign.c dsa_vrf.c dsa_lib.c dsa_ossl.c dsa_aid.c
|
||||
$COMMON=dsa_sign.c dsa_vrf.c dsa_lib.c dsa_ossl.c dsa_aid.c dsa_check.c \
|
||||
dsa_key.c
|
||||
|
||||
SOURCE[../../libcrypto]=$COMMON\
|
||||
dsa_gen.c dsa_key.c dsa_asn1.c \
|
||||
dsa_gen.c dsa_asn1.c \
|
||||
dsa_err.c dsa_depr.c dsa_ameth.c dsa_pmeth.c dsa_prn.c \
|
||||
dsa_meth.c
|
||||
SOURCE[../../providers/libfips.a]=$COMMON
|
||||
@@ -15,7 +15,6 @@
|
||||
|
||||
int dsa_check_params(const DSA *dsa, int *ret)
|
||||
{
|
||||
int nid;
|
||||
/*
|
||||
* (2b) FFC domain params conform to FIPS-186-4 explicit domain param
|
||||
* validity tests.
|
||||
|
||||
@@ -58,7 +58,12 @@ static c448_error_t hash_init_with_dom(OPENSSL_CTX *ctx, EVP_MD_CTX *hashctx,
|
||||
const uint8_t *context,
|
||||
size_t context_len)
|
||||
{
|
||||
const char *dom_s = "SigEd448";
|
||||
#ifdef CHARSET_EBCDIC
|
||||
const char dom_s[] = {0x53, 0x69, 0x67, 0x45,
|
||||
0x64, 0x34, 0x34, 0x38, 0x00};
|
||||
#else
|
||||
const char dom_s[] = "SigEd448";
|
||||
#endif
|
||||
uint8_t dom[2];
|
||||
EVP_MD *shake256 = NULL;
|
||||
|
||||
|
||||
@@ -243,6 +243,7 @@ CMS_F_CMS_ADD0_CERT:164:CMS_add0_cert
|
||||
CMS_F_CMS_ADD0_RECIPIENT_KEY:100:CMS_add0_recipient_key
|
||||
CMS_F_CMS_ADD0_RECIPIENT_PASSWORD:165:CMS_add0_recipient_password
|
||||
CMS_F_CMS_ADD1_RECEIPTREQUEST:158:CMS_add1_ReceiptRequest
|
||||
CMS_F_CMS_ADD1_RECIPIENT:184:
|
||||
CMS_F_CMS_ADD1_RECIPIENT_CERT:101:CMS_add1_recipient_cert
|
||||
CMS_F_CMS_ADD1_SIGNER:102:CMS_add1_signer
|
||||
CMS_F_CMS_ADD1_SIGNINGTIME:103:cms_add1_signingTime
|
||||
@@ -260,6 +261,7 @@ CMS_F_CMS_DECRYPT:112:CMS_decrypt
|
||||
CMS_F_CMS_DECRYPT_SET1_KEY:113:CMS_decrypt_set1_key
|
||||
CMS_F_CMS_DECRYPT_SET1_PASSWORD:166:CMS_decrypt_set1_password
|
||||
CMS_F_CMS_DECRYPT_SET1_PKEY:114:CMS_decrypt_set1_pkey
|
||||
CMS_F_CMS_DECRYPT_SET1_PKEY_AND_PEER:185:
|
||||
CMS_F_CMS_DIGESTALGORITHM_FIND_CTX:115:cms_DigestAlgorithm_find_ctx
|
||||
CMS_F_CMS_DIGESTALGORITHM_INIT_BIO:116:cms_DigestAlgorithm_init_bio
|
||||
CMS_F_CMS_DIGESTEDDATA_DO_FINAL:117:cms_DigestedData_do_final
|
||||
@@ -272,6 +274,8 @@ CMS_F_CMS_ENCRYPTEDDATA_DECRYPT:121:CMS_EncryptedData_decrypt
|
||||
CMS_F_CMS_ENCRYPTEDDATA_ENCRYPT:122:CMS_EncryptedData_encrypt
|
||||
CMS_F_CMS_ENCRYPTEDDATA_SET1_KEY:123:CMS_EncryptedData_set1_key
|
||||
CMS_F_CMS_ENVELOPEDDATA_CREATE:124:CMS_EnvelopedData_create
|
||||
CMS_F_CMS_ENVELOPEDDATA_ENCRYPTION_INIT_BIO:186:
|
||||
CMS_F_CMS_ENVELOPEDDATA_FINAL:187:
|
||||
CMS_F_CMS_ENVELOPEDDATA_INIT_BIO:125:cms_EnvelopedData_init_bio
|
||||
CMS_F_CMS_ENVELOPED_DATA_INIT:126:cms_enveloped_data_init
|
||||
CMS_F_CMS_ENV_ASN1_CTRL:171:cms_env_asn1_ctrl
|
||||
|
||||
@@ -243,6 +243,7 @@ CMS_F_CMS_ADD0_CERT:164:CMS_add0_cert
|
||||
CMS_F_CMS_ADD0_RECIPIENT_KEY:100:CMS_add0_recipient_key
|
||||
CMS_F_CMS_ADD0_RECIPIENT_PASSWORD:165:CMS_add0_recipient_password
|
||||
CMS_F_CMS_ADD1_RECEIPTREQUEST:158:CMS_add1_ReceiptRequest
|
||||
CMS_F_CMS_ADD1_RECIPIENT:184:
|
||||
CMS_F_CMS_ADD1_RECIPIENT_CERT:101:CMS_add1_recipient_cert
|
||||
CMS_F_CMS_ADD1_SIGNER:102:CMS_add1_signer
|
||||
CMS_F_CMS_ADD1_SIGNINGTIME:103:cms_add1_signingTime
|
||||
@@ -260,6 +261,7 @@ CMS_F_CMS_DECRYPT:112:CMS_decrypt
|
||||
CMS_F_CMS_DECRYPT_SET1_KEY:113:CMS_decrypt_set1_key
|
||||
CMS_F_CMS_DECRYPT_SET1_PASSWORD:166:CMS_decrypt_set1_password
|
||||
CMS_F_CMS_DECRYPT_SET1_PKEY:114:CMS_decrypt_set1_pkey
|
||||
CMS_F_CMS_DECRYPT_SET1_PKEY_AND_PEER:185:
|
||||
CMS_F_CMS_DIGESTALGORITHM_FIND_CTX:115:cms_DigestAlgorithm_find_ctx
|
||||
CMS_F_CMS_DIGESTALGORITHM_INIT_BIO:116:cms_DigestAlgorithm_init_bio
|
||||
CMS_F_CMS_DIGESTEDDATA_DO_FINAL:117:cms_DigestedData_do_final
|
||||
@@ -272,6 +274,8 @@ CMS_F_CMS_ENCRYPTEDDATA_DECRYPT:121:CMS_EncryptedData_decrypt
|
||||
CMS_F_CMS_ENCRYPTEDDATA_ENCRYPT:122:CMS_EncryptedData_encrypt
|
||||
CMS_F_CMS_ENCRYPTEDDATA_SET1_KEY:123:CMS_EncryptedData_set1_key
|
||||
CMS_F_CMS_ENVELOPEDDATA_CREATE:124:CMS_EnvelopedData_create
|
||||
CMS_F_CMS_ENVELOPEDDATA_ENCRYPTION_INIT_BIO:186:
|
||||
CMS_F_CMS_ENVELOPEDDATA_FINAL:187:
|
||||
CMS_F_CMS_ENVELOPEDDATA_INIT_BIO:125:cms_EnvelopedData_init_bio
|
||||
CMS_F_CMS_ENVELOPED_DATA_INIT:126:cms_enveloped_data_init
|
||||
CMS_F_CMS_ENV_ASN1_CTRL:171:cms_env_asn1_ctrl
|
||||
|
||||
@@ -230,7 +230,7 @@ int EVP_PKEY_fromdata(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey, OSSL_PARAM params[])
|
||||
if (ctx->operation == EVP_PKEY_OP_PARAMFROMDATA)
|
||||
selection = OSSL_KEYMGMT_SELECT_ALL_PARAMETERS;
|
||||
else
|
||||
selection = OSSL_KEYMGMT_SELECT_KEYPAIR;
|
||||
selection = OSSL_KEYMGMT_SELECT_ALL;
|
||||
keydata = evp_keymgmt_util_fromdata(*ppkey, ctx->keymgmt, selection,
|
||||
params);
|
||||
|
||||
@@ -261,6 +261,6 @@ const OSSL_PARAM *EVP_PKEY_key_fromdata_settable(EVP_PKEY_CTX *ctx)
|
||||
/* We call fromdata_init to get ctx->keymgmt populated */
|
||||
if (fromdata_init(ctx, EVP_PKEY_OP_UNDEFINED))
|
||||
return evp_keymgmt_import_types(ctx->keymgmt,
|
||||
OSSL_KEYMGMT_SELECT_KEYPAIR);
|
||||
OSSL_KEYMGMT_SELECT_ALL);
|
||||
return NULL;
|
||||
}
|
||||
@@ -774,6 +774,13 @@ int EVP_PKEY_CTX_set_signature_md(EVP_PKEY_CTX *ctx, const EVP_MD *md)
|
||||
static int legacy_ctrl_to_param(EVP_PKEY_CTX *ctx, int keytype, int optype,
|
||||
int cmd, int p1, void *p2)
|
||||
{
|
||||
/*
|
||||
* GOST CMS format is different for different cipher algorithms.
|
||||
* Most of other algorithms don't have such a difference
|
||||
* so this ctrl is just ignored.
|
||||
*/
|
||||
if (cmd == EVP_PKEY_CTRL_CIPHER)
|
||||
return -2;
|
||||
# ifndef OPENSSL_NO_DH
|
||||
if (keytype == EVP_PKEY_DH) {
|
||||
switch (cmd) {
|
||||
@@ -931,7 +938,7 @@ static int legacy_ctrl_str_to_param(EVP_PKEY_CTX *ctx, const char *name,
|
||||
else if (strcmp(name, "ecdh_cofactor_mode") == 0)
|
||||
name = OSSL_EXCHANGE_PARAM_EC_ECDH_COFACTOR_MODE;
|
||||
else if (strcmp(name, "ecdh_kdf_md") == 0)
|
||||
name = OSSL_EXCHANGE_PARAM_KDF_TYPE;
|
||||
name = OSSL_EXCHANGE_PARAM_KDF_DIGEST;
|
||||
# endif
|
||||
|
||||
{
|
||||
|
||||
@@ -36,13 +36,19 @@ int ffc_generate_private_key(BN_CTX *ctx, const FFC_PARAMS *params,
|
||||
int ffc_generate_private_key_fips(BN_CTX *ctx, const FFC_PARAMS *params,
|
||||
int N, int s, BIGNUM *priv)
|
||||
{
|
||||
int ret = 0;
|
||||
int ret = 0, qbits = BN_num_bits(params->q);
|
||||
BIGNUM *m, *two_powN = NULL;
|
||||
|
||||
/* Step (2) : check range of N */
|
||||
if (N < 2 * s || N > BN_num_bits(params->q))
|
||||
if (N < 2 * s || N > qbits)
|
||||
return 0;
|
||||
|
||||
/* Deal with the edge case where the value of N is not set */
|
||||
if (N == 0) {
|
||||
N = qbits;
|
||||
s = N / 2;
|
||||
}
|
||||
|
||||
two_powN = BN_new();
|
||||
/* 2^N */
|
||||
if (two_powN == NULL || !BN_lshift(two_powN, BN_value_one(), N))
|
||||
@@ -50,6 +56,7 @@ int ffc_generate_private_key_fips(BN_CTX *ctx, const FFC_PARAMS *params,
|
||||
|
||||
/* Step (5) : M = min(2 ^ N, q) */
|
||||
m = (BN_cmp(two_powN, params->q) > 0) ? params->q : two_powN;
|
||||
|
||||
do {
|
||||
/* Steps (3, 4 & 7) : c + 1 = 1 + random[0..2^N - 1] */
|
||||
if (!BN_priv_rand_range_ex(priv, two_powN, ctx)
|
||||
|
||||
+39
-3
@@ -10,6 +10,7 @@
|
||||
#include <openssl/core.h>
|
||||
#include <openssl/core_numbers.h>
|
||||
#include <openssl/core_names.h>
|
||||
#include <openssl/provider.h>
|
||||
#include <openssl/params.h>
|
||||
#include <openssl/opensslv.h>
|
||||
#include "crypto/cryptlib.h"
|
||||
@@ -92,6 +93,7 @@ static int ossl_provider_cmp(const OSSL_PROVIDER * const *a,
|
||||
struct provider_store_st {
|
||||
STACK_OF(OSSL_PROVIDER) *providers;
|
||||
CRYPTO_RWLOCK *lock;
|
||||
char *default_path;
|
||||
unsigned int use_fallbacks:1;
|
||||
};
|
||||
|
||||
@@ -101,6 +103,7 @@ static void provider_store_free(void *vstore)
|
||||
|
||||
if (store == NULL)
|
||||
return;
|
||||
OPENSSL_free(store->default_path);
|
||||
sk_OSSL_PROVIDER_pop_free(store->providers, ossl_provider_free);
|
||||
CRYPTO_THREAD_lock_free(store->lock);
|
||||
OPENSSL_free(store);
|
||||
@@ -384,6 +387,29 @@ int ossl_provider_add_parameter(OSSL_PROVIDER *prov,
|
||||
*/
|
||||
static const OSSL_DISPATCH *core_dispatch; /* Define further down */
|
||||
|
||||
int OSSL_PROVIDER_set_default_search_path(OPENSSL_CTX *libctx, const char *path)
|
||||
{
|
||||
struct provider_store_st *store;
|
||||
char *p = NULL;
|
||||
|
||||
if (path != NULL) {
|
||||
p = OPENSSL_strdup(path);
|
||||
if (p == NULL) {
|
||||
CRYPTOerr(0, ERR_R_MALLOC_FAILURE);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
if ((store = get_provider_store(libctx)) != NULL
|
||||
&& CRYPTO_THREAD_write_lock(store->lock)) {
|
||||
OPENSSL_free(store->default_path);
|
||||
store->default_path = p;
|
||||
CRYPTO_THREAD_unlock(store->lock);
|
||||
return 1;
|
||||
}
|
||||
OPENSSL_free(p);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Internal version that doesn't affect the store flags, and thereby avoid
|
||||
* locking. Direct callers must remember to set the store flags when
|
||||
@@ -413,15 +439,24 @@ static int provider_activate(OSSL_PROVIDER *prov)
|
||||
char *allocated_path = NULL;
|
||||
const char *module_path = NULL;
|
||||
char *merged_path = NULL;
|
||||
const char *load_dir = ossl_safe_getenv("OPENSSL_MODULES");
|
||||
const char *load_dir = NULL;
|
||||
struct provider_store_st *store;
|
||||
|
||||
if ((prov->module = DSO_new()) == NULL) {
|
||||
/* DSO_new() generates an error already */
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (load_dir == NULL)
|
||||
load_dir = MODULESDIR;
|
||||
if ((store = get_provider_store(prov->libctx)) == NULL
|
||||
|| !CRYPTO_THREAD_read_lock(store->lock))
|
||||
return 0;
|
||||
load_dir = store->default_path;
|
||||
|
||||
if (load_dir == NULL) {
|
||||
load_dir = ossl_safe_getenv("OPENSSL_MODULES");
|
||||
if (load_dir == NULL)
|
||||
load_dir = MODULESDIR;
|
||||
}
|
||||
|
||||
DSO_ctrl(prov->module, DSO_CTRL_SET_FLAGS,
|
||||
DSO_FLAG_NAME_TRANSLATION_EXT_ONLY, NULL);
|
||||
@@ -432,6 +467,7 @@ static int provider_activate(OSSL_PROVIDER *prov)
|
||||
DSO_convert_filename(prov->module, prov->name);
|
||||
if (module_path != NULL)
|
||||
merged_path = DSO_merge(prov->module, module_path, load_dir);
|
||||
CRYPTO_THREAD_unlock(store->lock);
|
||||
|
||||
if (merged_path == NULL
|
||||
|| (DSO_load(prov->module, merged_path, NULL, 0)) == NULL) {
|
||||
|
||||
+14
-2
@@ -17,6 +17,7 @@
|
||||
#include "crypto/bn.h"
|
||||
#include "crypto/evp.h"
|
||||
#include "crypto/rsa.h"
|
||||
#include "crypto/security_bits.h"
|
||||
#include "rsa_local.h"
|
||||
|
||||
static RSA *rsa_new_intern(ENGINE *engine, OPENSSL_CTX *libctx);
|
||||
@@ -275,11 +276,20 @@ static uint32_t ilog_e(uint64_t v)
|
||||
* NIST SP 800-56B rev 2 Appendix D: Maximum Security Strength Estimates for IFC
|
||||
* Modulus Lengths.
|
||||
*
|
||||
* Note that this formula is also referred to in SP800-56A rev3 Appendix D:
|
||||
* for FFC safe prime groups for modp and ffdhe.
|
||||
* After Table 25 and Table 26 it refers to
|
||||
* "The maximum security strength estimates were calculated using the formula in
|
||||
* Section 7.5 of the FIPS 140 IG and rounded to the nearest multiple of eight
|
||||
* bits".
|
||||
*
|
||||
* The formula is:
|
||||
*
|
||||
* E = \frac{1.923 \sqrt[3]{nBits \cdot log_e(2)}
|
||||
* \cdot(log_e(nBits \cdot log_e(2))^{2/3} - 4.69}{log_e(2)}
|
||||
* The two cube roots are merged together here.
|
||||
*/
|
||||
uint16_t rsa_compute_security_bits(int n)
|
||||
uint16_t ifc_ffc_compute_security_bits(int n)
|
||||
{
|
||||
uint64_t x;
|
||||
uint32_t lx;
|
||||
@@ -316,6 +326,8 @@ uint16_t rsa_compute_security_bits(int n)
|
||||
return (y + 4) & ~7;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int RSA_security_bits(const RSA *rsa)
|
||||
{
|
||||
int bits = BN_num_bits(rsa->n);
|
||||
@@ -329,7 +341,7 @@ int RSA_security_bits(const RSA *rsa)
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
return rsa_compute_security_bits(bits);
|
||||
return ifc_ffc_compute_security_bits(bits);
|
||||
}
|
||||
|
||||
int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d)
|
||||
|
||||
@@ -137,8 +137,6 @@ RSA_PRIME_INFO *rsa_multip_info_new(void);
|
||||
int rsa_multip_calc_product(RSA *rsa);
|
||||
int rsa_multip_cap(int bits);
|
||||
|
||||
uint16_t rsa_compute_security_bits(int n);
|
||||
|
||||
int rsa_sp800_56b_validate_strength(int nbits, int strength);
|
||||
int rsa_check_pminusq_diff(BIGNUM *diff, const BIGNUM *p, const BIGNUM *q,
|
||||
int nbits);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/bn.h>
|
||||
#include "crypto/bn.h"
|
||||
#include "crypto/security_bits.h"
|
||||
#include "rsa_local.h"
|
||||
|
||||
#define RSA_FIPS1864_MIN_KEYGEN_KEYSIZE 2048
|
||||
@@ -144,7 +145,7 @@ err:
|
||||
*/
|
||||
int rsa_sp800_56b_validate_strength(int nbits, int strength)
|
||||
{
|
||||
int s = (int)rsa_compute_security_bits(nbits);
|
||||
int s = (int)ifc_ffc_compute_security_bits(nbits);
|
||||
|
||||
if (s < RSA_FIPS1864_MIN_KEYGEN_STRENGTH
|
||||
|| s > RSA_FIPS1864_MAX_KEYGEN_STRENGTH) {
|
||||
|
||||
Reference in New Issue
Block a user