Address pr review: add braces, move scope of variables, add X9.63 comment

This commit is contained in:
night1rider
2026-03-25 11:25:36 -06:00
committed by Zackery Backman
parent bf1013bfd4
commit d58eea5566
2 changed files with 25 additions and 25 deletions
+20 -17
View File
@@ -9868,6 +9868,7 @@ static int _ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
if (key != NULL && out == NULL && outLen != NULL) {
/* if key hasn't been setup assume max bytes for size estimation */
numlen = key->dp ? (word32)key->dp->size : MAX_ECC_BYTES;
/* X9.63 uncompressed point: 0x04 header + x coord + y coord */
*outLen = 1 + 2 * numlen;
return WC_NO_ERR_TRACE(LENGTH_ONLY_E);
}
@@ -9961,6 +9962,7 @@ int wc_ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
/* return length needed only */
if (out == NULL) {
word32 numlen = key->dp ? (word32)key->dp->size : MAX_ECC_BYTES;
/* X9.63 uncompressed point: 0x04 header + x coord + y coord */
*outLen = 1 + 2 * numlen;
return WC_NO_ERR_TRACE(LENGTH_ONLY_E);
}
@@ -12263,28 +12265,28 @@ static int ecc_public_key_size(ecc_key* key, word32* sz)
WOLFSSL_ABI
int wc_ecc_size(ecc_key* key)
{
#ifdef WOLF_CRYPTO_CB
int ret;
int keySz;
#endif
if (key == NULL)
if (key == NULL) {
return 0;
}
#ifdef WOLF_CRYPTO_CB
if (key->devId != INVALID_DEVID) {
keySz = 0;
int ret;
int keySz = 0;
ret = wc_CryptoCb_EccGetSize(key, &keySz);
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) {
if (ret != 0)
if (ret != 0) {
return 0;
}
return keySz;
}
}
#endif
if (key->dp == NULL)
if (key->dp == NULL) {
return 0;
}
return key->dp->size;
}
@@ -12313,28 +12315,29 @@ int wc_ecc_sig_size(const ecc_key* key)
{
int maxSigSz;
int orderBits, keySz;
#ifdef WOLF_CRYPTO_CB
int ret;
int cbKeySz;
#endif
if (key == NULL)
if (key == NULL) {
return 0;
}
#ifdef WOLF_CRYPTO_CB
if (key->devId != INVALID_DEVID) {
cbKeySz = 0;
int ret;
int cbKeySz = 0;
ret = wc_CryptoCb_EccGetSigSize(key, &cbKeySz);
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) {
if (ret != 0 || cbKeySz == 0)
if (ret != 0 || cbKeySz == 0) {
return 0;
}
return cbKeySz;
}
}
#endif
if (key->dp == NULL)
if (key->dp == NULL) {
return 0;
}
/* the signature r and s will always be less than order */
/* if the order MSB (top bit of byte) is set then ASN encoding needs
+5 -8
View File
@@ -4571,11 +4571,6 @@ static int _RsaFlattenPublicKey(const RsaKey* key, byte* e, word32* eSz,
int wc_RsaFlattenPublicKey(const RsaKey* key, byte* e, word32* eSz, byte* n,
word32* nSz)
{
#if defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_EXPORT_KEY)
int ret;
WC_DECLARE_VAR(tmpKey, RsaKey, 1, NULL);
#endif
if (key == NULL || e == NULL || eSz == NULL || n == NULL || nSz == NULL) {
return BAD_FUNC_ARG;
}
@@ -4585,6 +4580,9 @@ int wc_RsaFlattenPublicKey(const RsaKey* key, byte* e, word32* eSz, byte* n,
if (key->devId != INVALID_DEVID)
#endif
{
int ret;
WC_DECLARE_VAR(tmpKey, RsaKey, 1, NULL);
WC_ALLOC_VAR(tmpKey, RsaKey, 1, key->heap);
if (!WC_VAR_OK(tmpKey)) {
return MEMORY_E;
@@ -4695,9 +4693,6 @@ int wc_RsaExportKey(const RsaKey* key,
byte* q, word32* qSz)
{
int ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG);
#if defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_EXPORT_KEY)
WC_DECLARE_VAR(tmpKey, RsaKey, 1, NULL);
#endif
if (key && e && eSz && n && nSz && d && dSz && p && pSz && q && qSz) {
ret = 0;
@@ -4709,6 +4704,8 @@ int wc_RsaExportKey(const RsaKey* key,
if (key->devId != INVALID_DEVID)
#endif
{
WC_DECLARE_VAR(tmpKey, RsaKey, 1, NULL);
WC_ALLOC_VAR(tmpKey, RsaKey, 1, key->heap);
if (!WC_VAR_OK(tmpKey)) {
return MEMORY_E;