Changeset View
Changeset View
Standalone View
Standalone View
crypto/cms/cms_ec.c
/* | /* | ||||
* Copyright 2006-2022 The OpenSSL Project Authors. All Rights Reserved. | * Copyright 2006-2023 The OpenSSL Project Authors. All Rights Reserved. | ||||
* | * | ||||
* Licensed under the Apache License 2.0 (the "License"). You may not use | * Licensed under the Apache License 2.0 (the "License"). You may not use | ||||
* this file except in compliance with the License. You can obtain a copy | * this file except in compliance with the License. You can obtain a copy | ||||
Context not available. | |||||
*/ | */ | ||||
#include <assert.h> | #include <assert.h> | ||||
#include <limits.h> | |||||
#include <openssl/cms.h> | #include <openssl/cms.h> | ||||
#include <openssl/err.h> | #include <openssl/err.h> | ||||
#include <openssl/decoder.h> | #include <openssl/decoder.h> | ||||
Context not available. | |||||
ASN1_STRING *wrap_str; | ASN1_STRING *wrap_str; | ||||
ASN1_OCTET_STRING *ukm; | ASN1_OCTET_STRING *ukm; | ||||
unsigned char *penc = NULL; | unsigned char *penc = NULL; | ||||
size_t penclen; | int penclen; | ||||
int rv = 0; | int rv = 0; | ||||
int ecdh_nid, kdf_type, kdf_nid, wrap_nid; | int ecdh_nid, kdf_type, kdf_nid, wrap_nid; | ||||
const EVP_MD *kdf_md; | const EVP_MD *kdf_md; | ||||
Context not available. | |||||
/* Is everything uninitialised? */ | /* Is everything uninitialised? */ | ||||
if (aoid == OBJ_nid2obj(NID_undef)) { | if (aoid == OBJ_nid2obj(NID_undef)) { | ||||
/* Set the key */ | /* Set the key */ | ||||
size_t enckeylen; | |||||
penclen = EVP_PKEY_get1_encoded_public_key(pkey, &penc); | enckeylen = EVP_PKEY_get1_encoded_public_key(pkey, &penc); | ||||
ASN1_STRING_set0(pubkey, penc, penclen); | if (enckeylen > INT_MAX || enckeylen == 0) | ||||
goto err; | |||||
ASN1_STRING_set0(pubkey, penc, (int)enckeylen); | |||||
pubkey->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); | pubkey->flags &= ~(ASN1_STRING_FLAG_BITS_LEFT | 0x07); | ||||
pubkey->flags |= ASN1_STRING_FLAG_BITS_LEFT; | pubkey->flags |= ASN1_STRING_FLAG_BITS_LEFT; | ||||
penc = NULL; | penc = NULL; | ||||
X509_ALGOR_set0(talg, OBJ_nid2obj(NID_X9_62_id_ecPublicKey), | (void)X509_ALGOR_set0(talg, OBJ_nid2obj(NID_X9_62_id_ecPublicKey), | ||||
V_ASN1_UNDEF, NULL); | V_ASN1_UNDEF, NULL); /* cannot fail */ | ||||
} | } | ||||
/* See if custom parameters set */ | /* See if custom parameters set */ | ||||
Context not available. | |||||
penclen = CMS_SharedInfo_encode(&penc, wrap_alg, ukm, keylen); | penclen = CMS_SharedInfo_encode(&penc, wrap_alg, ukm, keylen); | ||||
if (penclen == 0) | if (penclen <= 0) | ||||
goto err; | goto err; | ||||
if (EVP_PKEY_CTX_set0_ecdh_kdf_ukm(pctx, penc, penclen) <= 0) | if (EVP_PKEY_CTX_set0_ecdh_kdf_ukm(pctx, penc, penclen) <= 0) | ||||
Context not available. | |||||
* of another AlgorithmIdentifier. | * of another AlgorithmIdentifier. | ||||
*/ | */ | ||||
penclen = i2d_X509_ALGOR(wrap_alg, &penc); | penclen = i2d_X509_ALGOR(wrap_alg, &penc); | ||||
if (penc == NULL || penclen == 0) | if (penclen <= 0) | ||||
goto err; | goto err; | ||||
wrap_str = ASN1_STRING_new(); | wrap_str = ASN1_STRING_new(); | ||||
if (wrap_str == NULL) | if (wrap_str == NULL) | ||||
Context not available. |