forked from wolfSSL/wolfssl
add trailing zero enum and correct call for export key size
This commit is contained in:
@@ -5883,7 +5883,7 @@ static int SetSerial(const byte* serial, byte* output)
|
|||||||
/* Write a public ECC key to output */
|
/* Write a public ECC key to output */
|
||||||
static int SetEccPublicKey(byte* output, ecc_key* key, int with_header)
|
static int SetEccPublicKey(byte* output, ecc_key* key, int with_header)
|
||||||
{
|
{
|
||||||
byte len[MAX_LENGTH_SZ + 1]; /* trailing 0 */
|
byte len[MAX_LENGTH_SZ + TRAILING_ZERO];
|
||||||
int algoSz;
|
int algoSz;
|
||||||
int curveSz;
|
int curveSz;
|
||||||
int lenSz;
|
int lenSz;
|
||||||
@@ -5941,7 +5941,7 @@ static int SetEccPublicKey(byte* output, ecc_key* key, int with_header)
|
|||||||
#endif
|
#endif
|
||||||
algoSz = SetAlgoID(ECDSAk, algo, oidKeyType, curveSz);
|
algoSz = SetAlgoID(ECDSAk, algo, oidKeyType, curveSz);
|
||||||
|
|
||||||
lenSz = SetLength(pubSz + 1, len);
|
lenSz = SetLength(pubSz + TRAILING_ZERO, len);
|
||||||
len[lenSz++] = 0; /* trailing 0 */
|
len[lenSz++] = 0; /* trailing 0 */
|
||||||
|
|
||||||
/* write, 1 is for ASN_BIT_STRING */
|
/* write, 1 is for ASN_BIT_STRING */
|
||||||
@@ -5985,24 +5985,30 @@ int wc_EccPublicKeyToDer(ecc_key* key, byte* output, word32 inLen,
|
|||||||
int with_AlgCurve)
|
int with_AlgCurve)
|
||||||
{
|
{
|
||||||
word32 infoSz = 0;
|
word32 infoSz = 0;
|
||||||
|
word32 keySz = 0;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (output == NULL || key == NULL) {
|
if (output == NULL || key == NULL) {
|
||||||
return BAD_FUNC_ARG;
|
return BAD_FUNC_ARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (with_AlgCurve) {
|
if (with_AlgCurve) {
|
||||||
int maxSetLength = 4; /* max buffer space needed for SetLength */
|
/* buffer space for algorithm/curve */
|
||||||
int asnBit = 1; /* buffer space needed for asn bit string macro */
|
infoSz += MAX_SEQ_SZ;
|
||||||
|
infoSz += 2 * MAX_ALGO_SZ;
|
||||||
|
|
||||||
infoSz += asnBit;
|
/* buffer space for public key sequence */
|
||||||
infoSz += maxSetLength + asnBit; /* SetSequence buffer needed */
|
infoSz += MAX_SEQ_SZ;
|
||||||
infoSz += 2 * MAX_ALGO_SZ; /* buffer space for algorithm/curve */
|
infoSz += TRAILING_ZERO;
|
||||||
infoSz += asnBit;
|
|
||||||
infoSz += maxSetLength;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inLen < wc_ecc_size(key) + infoSz) {
|
if ((ret = wc_ecc_export_x963(key, NULL, &keySz)) != LENGTH_ONLY_E) {
|
||||||
return BAD_FUNC_ARG;
|
WOLFSSL_MSG("Error in getting ECC public key size");
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (inLen < keySz + infoSz) {
|
||||||
|
return BUFFER_E;
|
||||||
}
|
}
|
||||||
|
|
||||||
return SetEccPublicKey(output, key, with_AlgCurve);
|
return SetEccPublicKey(output, key, with_AlgCurve);
|
||||||
|
@@ -195,7 +195,8 @@ enum Misc_ASN {
|
|||||||
EIGHTK_BUF = 8192, /* Tmp buffer size */
|
EIGHTK_BUF = 8192, /* Tmp buffer size */
|
||||||
MAX_PUBLIC_KEY_SZ = MAX_NTRU_ENC_SZ + MAX_ALGO_SZ + MAX_SEQ_SZ * 2,
|
MAX_PUBLIC_KEY_SZ = MAX_NTRU_ENC_SZ + MAX_ALGO_SZ + MAX_SEQ_SZ * 2,
|
||||||
/* use bigger NTRU size */
|
/* use bigger NTRU size */
|
||||||
HEADER_ENCRYPTED_KEY_SIZE = 88 /* Extra header size for encrypted key */
|
HEADER_ENCRYPTED_KEY_SIZE = 88,/* Extra header size for encrypted key */
|
||||||
|
TRAILING_ZERO = 1 /* Used for size of zero pad */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user