Skip to content

Commit d58eea5

Browse files
committed
Address pr review: add braces, move scope of variables, add X9.63 comment
1 parent bf1013b commit d58eea5

2 files changed

Lines changed: 25 additions & 25 deletions

File tree

wolfcrypt/src/ecc.c

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9868,6 +9868,7 @@ static int _ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
98689868
if (key != NULL && out == NULL && outLen != NULL) {
98699869
/* if key hasn't been setup assume max bytes for size estimation */
98709870
numlen = key->dp ? (word32)key->dp->size : MAX_ECC_BYTES;
9871+
/* X9.63 uncompressed point: 0x04 header + x coord + y coord */
98719872
*outLen = 1 + 2 * numlen;
98729873
return WC_NO_ERR_TRACE(LENGTH_ONLY_E);
98739874
}
@@ -9961,6 +9962,7 @@ int wc_ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
99619962
/* return length needed only */
99629963
if (out == NULL) {
99639964
word32 numlen = key->dp ? (word32)key->dp->size : MAX_ECC_BYTES;
9965+
/* X9.63 uncompressed point: 0x04 header + x coord + y coord */
99649966
*outLen = 1 + 2 * numlen;
99659967
return WC_NO_ERR_TRACE(LENGTH_ONLY_E);
99669968
}
@@ -12263,28 +12265,28 @@ static int ecc_public_key_size(ecc_key* key, word32* sz)
1226312265
WOLFSSL_ABI
1226412266
int wc_ecc_size(ecc_key* key)
1226512267
{
12266-
#ifdef WOLF_CRYPTO_CB
12267-
int ret;
12268-
int keySz;
12269-
#endif
12270-
12271-
if (key == NULL)
12268+
if (key == NULL) {
1227212269
return 0;
12270+
}
1227312271

1227412272
#ifdef WOLF_CRYPTO_CB
1227512273
if (key->devId != INVALID_DEVID) {
12276-
keySz = 0;
12274+
int ret;
12275+
int keySz = 0;
12276+
1227712277
ret = wc_CryptoCb_EccGetSize(key, &keySz);
1227812278
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) {
12279-
if (ret != 0)
12279+
if (ret != 0) {
1228012280
return 0;
12281+
}
1228112282
return keySz;
1228212283
}
1228312284
}
1228412285
#endif
1228512286

12286-
if (key->dp == NULL)
12287+
if (key->dp == NULL) {
1228712288
return 0;
12289+
}
1228812290

1228912291
return key->dp->size;
1229012292
}
@@ -12313,28 +12315,29 @@ int wc_ecc_sig_size(const ecc_key* key)
1231312315
{
1231412316
int maxSigSz;
1231512317
int orderBits, keySz;
12316-
#ifdef WOLF_CRYPTO_CB
12317-
int ret;
12318-
int cbKeySz;
12319-
#endif
1232012318

12321-
if (key == NULL)
12319+
if (key == NULL) {
1232212320
return 0;
12321+
}
1232312322

1232412323
#ifdef WOLF_CRYPTO_CB
1232512324
if (key->devId != INVALID_DEVID) {
12326-
cbKeySz = 0;
12325+
int ret;
12326+
int cbKeySz = 0;
12327+
1232712328
ret = wc_CryptoCb_EccGetSigSize(key, &cbKeySz);
1232812329
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) {
12329-
if (ret != 0 || cbKeySz == 0)
12330+
if (ret != 0 || cbKeySz == 0) {
1233012331
return 0;
12332+
}
1233112333
return cbKeySz;
1233212334
}
1233312335
}
1233412336
#endif
1233512337

12336-
if (key->dp == NULL)
12338+
if (key->dp == NULL) {
1233712339
return 0;
12340+
}
1233812341

1233912342
/* the signature r and s will always be less than order */
1234012343
/* if the order MSB (top bit of byte) is set then ASN encoding needs

wolfcrypt/src/rsa.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4571,11 +4571,6 @@ static int _RsaFlattenPublicKey(const RsaKey* key, byte* e, word32* eSz,
45714571
int wc_RsaFlattenPublicKey(const RsaKey* key, byte* e, word32* eSz, byte* n,
45724572
word32* nSz)
45734573
{
4574-
#if defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_EXPORT_KEY)
4575-
int ret;
4576-
WC_DECLARE_VAR(tmpKey, RsaKey, 1, NULL);
4577-
#endif
4578-
45794574
if (key == NULL || e == NULL || eSz == NULL || n == NULL || nSz == NULL) {
45804575
return BAD_FUNC_ARG;
45814576
}
@@ -4585,6 +4580,9 @@ int wc_RsaFlattenPublicKey(const RsaKey* key, byte* e, word32* eSz, byte* n,
45854580
if (key->devId != INVALID_DEVID)
45864581
#endif
45874582
{
4583+
int ret;
4584+
WC_DECLARE_VAR(tmpKey, RsaKey, 1, NULL);
4585+
45884586
WC_ALLOC_VAR(tmpKey, RsaKey, 1, key->heap);
45894587
if (!WC_VAR_OK(tmpKey)) {
45904588
return MEMORY_E;
@@ -4695,9 +4693,6 @@ int wc_RsaExportKey(const RsaKey* key,
46954693
byte* q, word32* qSz)
46964694
{
46974695
int ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG);
4698-
#if defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_EXPORT_KEY)
4699-
WC_DECLARE_VAR(tmpKey, RsaKey, 1, NULL);
4700-
#endif
47014696

47024697
if (key && e && eSz && n && nSz && d && dSz && p && pSz && q && qSz) {
47034698
ret = 0;
@@ -4709,6 +4704,8 @@ int wc_RsaExportKey(const RsaKey* key,
47094704
if (key->devId != INVALID_DEVID)
47104705
#endif
47114706
{
4707+
WC_DECLARE_VAR(tmpKey, RsaKey, 1, NULL);
4708+
47124709
WC_ALLOC_VAR(tmpKey, RsaKey, 1, key->heap);
47134710
if (!WC_VAR_OK(tmpKey)) {
47144711
return MEMORY_E;

0 commit comments

Comments
 (0)