mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-01 19:54:40 +02:00
Generating serial number - clear top bit
If the top bit is set then the encoding routine will drop a byte of the serial number. Better to ensure number is positive, top bit clear, and use as much of the serial number data as possible.
This commit is contained in:
@@ -11870,6 +11870,8 @@ static int EncodeCert(Cert* cert, DerCert* der, RsaKey* rsaKey, ecc_key* eccKey,
|
|||||||
ret = wc_RNG_GenerateBlock(rng, cert->serial, cert->serialSz);
|
ret = wc_RNG_GenerateBlock(rng, cert->serial, cert->serialSz);
|
||||||
if (ret != 0)
|
if (ret != 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
/* Clear the top bit to avoid a negative value */
|
||||||
|
cert->serial[0] &= 0x7f;
|
||||||
}
|
}
|
||||||
der->serialSz = SetSerialNumber(cert->serial, cert->serialSz, der->serial,
|
der->serialSz = SetSerialNumber(cert->serial, cert->serialSz, der->serial,
|
||||||
sizeof(der->serial), CTC_SERIAL_SIZE);
|
sizeof(der->serial), CTC_SERIAL_SIZE);
|
||||||
|
Reference in New Issue
Block a user