mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-07-31 19:24:42 +02:00
Merge pull request #3357 from guidovranken/StoreECC_DSA_Sig-fix
Improve StoreECC_DSA_Sig bounds checking
This commit is contained in:
@@ -689,6 +689,8 @@ static int SetASNIntMP(mp_int* n, int maxSz, byte* output)
|
|||||||
|
|
||||||
leadingBit = mp_leading_bit(n);
|
leadingBit = mp_leading_bit(n);
|
||||||
length = mp_unsigned_bin_size(n);
|
length = mp_unsigned_bin_size(n);
|
||||||
|
if (maxSz >= 0 && (1 + length + (leadingBit ? 1 : 0)) > maxSz)
|
||||||
|
return BUFFER_E;
|
||||||
idx = SetASNInt(length, leadingBit ? 0x80 : 0x00, output);
|
idx = SetASNInt(length, leadingBit ? 0x80 : 0x00, output);
|
||||||
if (maxSz >= 0 && (idx + length) > maxSz)
|
if (maxSz >= 0 && (idx + length) > maxSz)
|
||||||
return BUFFER_E;
|
return BUFFER_E;
|
||||||
@@ -15408,13 +15410,13 @@ int StoreECC_DSA_Sig(byte* out, word32* outLen, mp_int* r, mp_int* s)
|
|||||||
idx = SetSequence(rLen + rLeadingZero + sLen+sLeadingZero + headerSz, out);
|
idx = SetSequence(rLen + rLeadingZero + sLen+sLeadingZero + headerSz, out);
|
||||||
|
|
||||||
/* store r */
|
/* store r */
|
||||||
rSz = SetASNIntMP(r, -1, &out[idx]);
|
rSz = SetASNIntMP(r, *outLen - idx, &out[idx]);
|
||||||
if (rSz < 0)
|
if (rSz < 0)
|
||||||
return rSz;
|
return rSz;
|
||||||
idx += rSz;
|
idx += rSz;
|
||||||
|
|
||||||
/* store s */
|
/* store s */
|
||||||
sSz = SetASNIntMP(s, -1, &out[idx]);
|
sSz = SetASNIntMP(s, *outLen - idx, &out[idx]);
|
||||||
if (sSz < 0)
|
if (sSz < 0)
|
||||||
return sSz;
|
return sSz;
|
||||||
idx += sSz;
|
idx += sSz;
|
||||||
|
Reference in New Issue
Block a user