Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/crl.c
Original file line number Diff line number Diff line change
Expand Up @@ -2621,6 +2621,13 @@ int wolfSSL_X509_CRL_add_revoked(WOLFSSL_X509_CRL* crl,
}

{
/* The serial is the bare value octets - no DER tag or length. That is
* what wolfSSL_X509_CRL_get_REVOKED() and
* wolfSSL_X509_CRL_add_revoked_cert() produce, and the only layout
* this function has ever accepted, so it is read without consulting
* dataIsRaw. Reading a DER INTEGER here instead would misread a bare
* value that happens to form one: the serial 02 02 00 00, for
* instance, is a valid DER encoding of zero. */
const byte* serial = rev->serialNumber->data;
int serialSz = rev->serialNumber->length;
int i;
Expand Down Expand Up @@ -2764,6 +2771,8 @@ int wolfSSL_X509_CRL_add_revoked_cert(WOLFSSL_X509_CRL* crl,

XMEMCPY(serialInt->data, cert->serial, cert->serialSz);
serialInt->length = cert->serialSz;
/* The certificate's serial is the value, with no DER tag or length. */
serialInt->dataIsRaw = 1;

XMEMSET(&revoked, 0, sizeof(revoked));
revoked.serialNumber = serialInt;
Expand Down
3 changes: 3 additions & 0 deletions src/ocsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -2138,12 +2138,15 @@ int wolfSSL_OCSP_id_get0_info(WOLFSSL_ASN1_STRING **name,
XMEMCPY(&ser->data[i], cid->status->serial,
(size_t)cid->status->serialSz);
ser->length = cid->status->serialSz;
/* Qt and HAProxy read data/length as the value octets. */
ser->dataIsRaw = 1;
#else
ser->data[i++] = ASN_INTEGER;
i += SetLength(cid->status->serialSz, ser->data + i);
XMEMCPY(&ser->data[i], cid->status->serial,
(size_t)cid->status->serialSz);
ser->length = i + cid->status->serialSz;
ser->dataIsRaw = 0;
#endif

cid->status->serialInt = ser;
Expand Down
12 changes: 11 additions & 1 deletion src/pk.c
Original file line number Diff line number Diff line change
Expand Up @@ -7492,7 +7492,12 @@ int pkcs8_encrypt(WOLFSSL_EVP_PKEY* pkey,
}
else
#endif /* WOLFSSL_HAVE_MLDSA */
{
if ((pkey->pkey.ptr == NULL) || (pkey->pkey_sz <= 0) ||
(pkey->pkcs8HeaderSz >= pkey->pkey_sz)) {
/* The PKCS#8 header size must lie inside the DER encoding. */
ret = BAD_FUNC_ARG;
}
else {
/* Encrypt private into buffer. */
ret = TraditionalEnc(
(byte*)pkey->pkey.ptr + pkey->pkcs8HeaderSz,
Expand Down Expand Up @@ -7639,6 +7644,11 @@ int pkcs8_encode(WOLFSSL_EVP_PKEY* pkey, byte* key, word32* keySz)
ret = NOT_COMPILED_IN;
}

/* The PKCS#8 header size must lie inside the DER encoding. */
if ((ret >= 0) && ((pkey->pkey.ptr == NULL) || (pkey->pkey_sz <= 0) ||
(pkey->pkcs8HeaderSz >= pkey->pkey_sz))) {
ret = BAD_FUNC_ARG;
}
if (ret >= 0) {
/* Encode private key in PKCS#8 format. */
ret = wc_CreatePKCS8Key(key, keySz, (byte*)pkey->pkey.ptr +
Expand Down
42 changes: 38 additions & 4 deletions src/pk_ec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1858,11 +1858,14 @@ int wolfSSL_EC_POINT_is_on_curve(const WOLFSSL_EC_GROUP *group,

#if !defined(WOLFSSL_SP_MATH) && !defined(WOLF_CRYPTO_CB_ONLY_ECC)
/* Convert Jacobian ordinates to affine.
*
* Note the return convention: zero is success, the opposite of most functions
* here. Both callers treat a non-zero return as an error.
*
* @param [in] group EC group.
* @param [in] point EC point to get coordinates from.
* @return 1 on success.
* @return 0 on error.
* @param [in, out] point EC point to convert.
* @return 0 on success.
* @return 1 on error.
*/
int ec_point_convert_to_affine(const WOLFSSL_EC_GROUP *group,
WOLFSSL_EC_POINT *point)
Expand All @@ -1881,8 +1884,16 @@ int ec_point_convert_to_affine(const WOLFSSL_EC_GROUP *group,
mp_digit mp = 0;
WC_DECLARE_VAR(modulus, mp_int, 1, 0);

/* Curve parameters are only available for curves in ecc_sets. */
if ((group->curve_idx < 0) || (!wc_ecc_is_valid_idx(group->curve_idx))) {
WOLFSSL_MSG("ec_point_convert_to_affine curve index error");
err = 1;
}

/* Allocate memory for curve's prime modulus. */
WC_ALLOC_VAR_EX(modulus, mp_int, 1, NULL, DYNAMIC_TYPE_BIGINT, err=1);
if (!err) {
WC_ALLOC_VAR_EX(modulus, mp_int, 1, NULL, DYNAMIC_TYPE_BIGINT, err=1);
}
/* Initialize the MP integer. */
if ((!err) && (mp_init(modulus) != MP_OKAY)) {
WOLFSSL_MSG("mp_init failed");
Expand Down Expand Up @@ -2250,6 +2261,12 @@ int wolfSSL_EC_POINT_add(const WOLFSSL_EC_GROUP* group, WOLFSSL_EC_POINT* r,
WOLFSSL_MSG("wolfSSL_EC_POINT_add error");
ret = 0;
}
/* Curve parameters are only available for curves in ecc_sets. */
if ((ret == 1) && ((group->curve_idx < 0) ||
(!wc_ecc_is_valid_idx(group->curve_idx)))) {
WOLFSSL_MSG("wolfSSL_EC_POINT_add Bad group idx");
ret = 0;
Comment thread
SparkiDev marked this conversation as resolved.
Resolved
}

/* Ensure the internal objects of the EC points are setup. */
if ((ret == 1) && ((ec_point_setup(r) != 1) || (ec_point_setup(p1) != 1) ||
Expand Down Expand Up @@ -2515,6 +2532,12 @@ int wolfSSL_EC_POINT_mul(const WOLFSSL_EC_GROUP *group, WOLFSSL_EC_POINT *r,
WOLFSSL_MSG("wolfSSL_EC_POINT_mul NULL error");
ret = 0;
}
/* Curve parameters are only available for curves in ecc_sets. */
if ((ret == 1) && ((group->curve_idx < 0) ||
(!wc_ecc_is_valid_idx(group->curve_idx)))) {
WOLFSSL_MSG("wolfSSL_EC_POINT_mul Bad group idx");
ret = 0;
}

/* Ensure the internal representation of the EC point q is setup. */
if ((ret == 1) && (q != NULL) && (ec_point_setup(q) != 1)) {
Expand Down Expand Up @@ -2638,6 +2661,12 @@ int wolfSSL_EC_POINT_invert(const WOLFSSL_EC_GROUP *group,
if ((group == NULL) || (point == NULL) || (point->internal == NULL)) {
ret = 0;
}
/* Curve parameters are only available for curves in ecc_sets. */
if ((ret == 1) && ((group->curve_idx < 0) ||
(!wc_ecc_is_valid_idx(group->curve_idx)))) {
WOLFSSL_MSG("wolfSSL_EC_POINT_invert Bad group idx");
ret = 0;
}

/* Ensure internal representation of point is setup. */
if ((ret == 1) && (ec_point_setup(point) != 1)) {
Expand Down Expand Up @@ -2720,6 +2749,11 @@ static int ec_point_cmp_jacobian(const WOLFSSL_EC_GROUP* group,
(mod == NULL)) {
ret = WOLFSSL_FATAL_ERROR;
}
/* Curve parameters are only available for curves in ecc_sets. */
if ((ret == 0) && ((group->curve_idx < 0) ||
(!wc_ecc_is_valid_idx(group->curve_idx)))) {
ret = WOLFSSL_FATAL_ERROR;
}
/* Get the modulus for the curve. */
if ((ret == 0) &&
(BN_hex2bn(&mod, ecc_sets[group->curve_idx].prime) != 1)) {
Expand Down
Loading
Loading