mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-30 18:57:27 +02:00
Pass in and check output length in SetCurve.
This commit is contained in:
@ -13288,7 +13288,7 @@ word32 SetExplicit(byte number, word32 len, byte* output)
|
|||||||
|
|
||||||
#if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT)
|
#if defined(HAVE_ECC) && defined(HAVE_ECC_KEY_EXPORT)
|
||||||
|
|
||||||
static int SetCurve(ecc_key* key, byte* output)
|
static int SetCurve(ecc_key* key, byte* output, size_t outSz)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_OID_ENCODING
|
#ifdef HAVE_OID_ENCODING
|
||||||
int ret;
|
int ret;
|
||||||
@ -13323,6 +13323,8 @@ static int SetCurve(ecc_key* key, byte* output)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
if (oidSz > outSz)
|
||||||
|
return BUFFER_E;
|
||||||
XMEMCPY(output+idx, key->dp->oid, oidSz);
|
XMEMCPY(output+idx, key->dp->oid, oidSz);
|
||||||
#endif
|
#endif
|
||||||
idx += oidSz;
|
idx += oidSz;
|
||||||
@ -22108,7 +22110,7 @@ static int SetEccPublicKey(byte* output, ecc_key* key, int outLen,
|
|||||||
|
|
||||||
/* headers */
|
/* headers */
|
||||||
if (with_header) {
|
if (with_header) {
|
||||||
curveSz = SetCurve(key, NULL);
|
curveSz = SetCurve(key, NULL, 0);
|
||||||
if (curveSz <= 0) {
|
if (curveSz <= 0) {
|
||||||
return curveSz;
|
return curveSz;
|
||||||
}
|
}
|
||||||
@ -22131,7 +22133,7 @@ static int SetEccPublicKey(byte* output, ecc_key* key, int outLen,
|
|||||||
idx += algoSz;
|
idx += algoSz;
|
||||||
/* curve */
|
/* curve */
|
||||||
if (output)
|
if (output)
|
||||||
(void)SetCurve(key, output + idx);
|
(void)SetCurve(key, output + idx, outLen - idx);
|
||||||
idx += curveSz;
|
idx += curveSz;
|
||||||
/* bit string */
|
/* bit string */
|
||||||
if (output)
|
if (output)
|
||||||
@ -22180,7 +22182,7 @@ static int SetEccPublicKey(byte* output, ecc_key* key, int outLen,
|
|||||||
CALLOC_ASNSETDATA(dataASN, eccPublicKeyASN_Length, ret, key->heap);
|
CALLOC_ASNSETDATA(dataASN, eccPublicKeyASN_Length, ret, key->heap);
|
||||||
|
|
||||||
/* Get the length of the named curve OID to put into the encoding. */
|
/* Get the length of the named curve OID to put into the encoding. */
|
||||||
curveIdSz = SetCurve(key, NULL);
|
curveIdSz = SetCurve(key, NULL, 0);
|
||||||
if (curveIdSz < 0) {
|
if (curveIdSz < 0) {
|
||||||
ret = curveIdSz;
|
ret = curveIdSz;
|
||||||
}
|
}
|
||||||
@ -22228,7 +22230,7 @@ static int SetEccPublicKey(byte* output, ecc_key* key, int outLen,
|
|||||||
|
|
||||||
if ((ret == 0) && (output != NULL)) {
|
if ((ret == 0) && (output != NULL)) {
|
||||||
/* Put named curve OID data into encoding. */
|
/* Put named curve OID data into encoding. */
|
||||||
curveIdSz = SetCurve(key, curveOid);
|
curveIdSz = SetCurve(key, curveOid, curveIdSz);
|
||||||
if (curveIdSz < 0) {
|
if (curveIdSz < 0) {
|
||||||
ret = curveIdSz;
|
ret = curveIdSz;
|
||||||
}
|
}
|
||||||
@ -29154,7 +29156,7 @@ static int wc_BuildEccKeyDer(ecc_key* key, byte* output, word32 *inLen,
|
|||||||
/* curve */
|
/* curve */
|
||||||
curve[curveidx++] = ECC_PREFIX_0;
|
curve[curveidx++] = ECC_PREFIX_0;
|
||||||
curveidx++ /* to put the size after computation */;
|
curveidx++ /* to put the size after computation */;
|
||||||
curveSz = SetCurve(key, curve+curveidx);
|
curveSz = SetCurve(key, curve+curveidx, MAX_ALGO_SZ);
|
||||||
if (curveSz < 0)
|
if (curveSz < 0)
|
||||||
return curveSz;
|
return curveSz;
|
||||||
/* set computed size */
|
/* set computed size */
|
||||||
@ -29337,7 +29339,7 @@ static int wc_BuildEccKeyDer(ecc_key* key, byte* output, word32 *inLen,
|
|||||||
SetASN_Buffer(&dataASN[ECCKEYASN_IDX_PKEY], NULL, privSz);
|
SetASN_Buffer(&dataASN[ECCKEYASN_IDX_PKEY], NULL, privSz);
|
||||||
if (curveIn) {
|
if (curveIn) {
|
||||||
/* Get length of the named curve OID to put into the encoding. */
|
/* Get length of the named curve OID to put into the encoding. */
|
||||||
curveIdSz = SetCurve(key, NULL);
|
curveIdSz = SetCurve(key, NULL, 0);
|
||||||
if (curveIdSz < 0) {
|
if (curveIdSz < 0) {
|
||||||
ret = curveIdSz;
|
ret = curveIdSz;
|
||||||
}
|
}
|
||||||
@ -29381,7 +29383,8 @@ static int wc_BuildEccKeyDer(ecc_key* key, byte* output, word32 *inLen,
|
|||||||
if (curveIn) {
|
if (curveIn) {
|
||||||
/* Put named curve OID data into encoding. */
|
/* Put named curve OID data into encoding. */
|
||||||
curveIdSz = SetCurve(key,
|
curveIdSz = SetCurve(key,
|
||||||
(byte*)dataASN[ECCKEYASN_IDX_CURVEID].data.buffer.data);
|
(byte*)dataASN[ECCKEYASN_IDX_CURVEID].data.buffer.data,
|
||||||
|
curveIdSz);
|
||||||
if (curveIdSz < 0) {
|
if (curveIdSz < 0) {
|
||||||
ret = curveIdSz;
|
ret = curveIdSz;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user