Skip to content

Commit d2ce541

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

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
@@ -9869,6 +9869,7 @@ static int _ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
98699869
if (key != NULL && out == NULL && outLen != NULL) {
98709870
/* if key hasn't been setup assume max bytes for size estimation */
98719871
numlen = key->dp ? (word32)key->dp->size : MAX_ECC_BYTES;
9872+
/* X9.63 uncompressed point: 0x04 header + x coord + y coord */
98729873
*outLen = 1 + 2 * numlen;
98739874
return WC_NO_ERR_TRACE(LENGTH_ONLY_E);
98749875
}
@@ -9962,6 +9963,7 @@ int wc_ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
99629963
/* return length needed only */
99639964
if (out == NULL) {
99649965
word32 numlen = key->dp ? (word32)key->dp->size : MAX_ECC_BYTES;
9966+
/* X9.63 uncompressed point: 0x04 header + x coord + y coord */
99659967
*outLen = 1 + 2 * numlen;
99669968
return WC_NO_ERR_TRACE(LENGTH_ONLY_E);
99679969
}
@@ -12264,28 +12266,28 @@ static int ecc_public_key_size(ecc_key* key, word32* sz)
1226412266
WOLFSSL_ABI
1226512267
int wc_ecc_size(ecc_key* key)
1226612268
{
12267-
#ifdef WOLF_CRYPTO_CB
12268-
int ret;
12269-
int keySz;
12270-
#endif
12271-
12272-
if (key == NULL)
12269+
if (key == NULL) {
1227312270
return 0;
12271+
}
1227412272

1227512273
#ifdef WOLF_CRYPTO_CB
1227612274
if (key->devId != INVALID_DEVID) {
12277-
keySz = 0;
12275+
int ret;
12276+
int keySz = 0;
12277+
1227812278
ret = wc_CryptoCb_EccGetSize(key, &keySz);
1227912279
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) {
12280-
if (ret != 0)
12280+
if (ret != 0) {
1228112281
return 0;
12282+
}
1228212283
return keySz;
1228312284
}
1228412285
}
1228512286
#endif
1228612287

12287-
if (key->dp == NULL)
12288+
if (key->dp == NULL) {
1228812289
return 0;
12290+
}
1228912291

1229012292
return key->dp->size;
1229112293
}
@@ -12314,28 +12316,29 @@ int wc_ecc_sig_size(const ecc_key* key)
1231412316
{
1231512317
int maxSigSz;
1231612318
int orderBits, keySz;
12317-
#ifdef WOLF_CRYPTO_CB
12318-
int ret;
12319-
int cbKeySz;
12320-
#endif
1232112319

12322-
if (key == NULL)
12320+
if (key == NULL) {
1232312321
return 0;
12322+
}
1232412323

1232512324
#ifdef WOLF_CRYPTO_CB
1232612325
if (key->devId != INVALID_DEVID) {
12327-
cbKeySz = 0;
12326+
int ret;
12327+
int cbKeySz = 0;
12328+
1232812329
ret = wc_CryptoCb_EccGetSigSize(key, &cbKeySz);
1232912330
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) {
12330-
if (ret != 0 || cbKeySz == 0)
12331+
if (ret != 0 || cbKeySz == 0) {
1233112332
return 0;
12333+
}
1233212334
return cbKeySz;
1233312335
}
1233412336
}
1233512337
#endif
1233612338

12337-
if (key->dp == NULL)
12339+
if (key->dp == NULL) {
1233812340
return 0;
12341+
}
1233912342

1234012343
/* the signature r and s will always be less than order */
1234112344
/* 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
@@ -4506,11 +4506,6 @@ static int _RsaFlattenPublicKey(const RsaKey* key, byte* e, word32* eSz,
45064506
int wc_RsaFlattenPublicKey(const RsaKey* key, byte* e, word32* eSz, byte* n,
45074507
word32* nSz)
45084508
{
4509-
#if defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_EXPORT_KEY)
4510-
int ret;
4511-
WC_DECLARE_VAR(tmpKey, RsaKey, 1, NULL);
4512-
#endif
4513-
45144509
if (key == NULL || e == NULL || eSz == NULL || n == NULL || nSz == NULL) {
45154510
return BAD_FUNC_ARG;
45164511
}
@@ -4520,6 +4515,9 @@ int wc_RsaFlattenPublicKey(const RsaKey* key, byte* e, word32* eSz, byte* n,
45204515
if (key->devId != INVALID_DEVID)
45214516
#endif
45224517
{
4518+
int ret;
4519+
WC_DECLARE_VAR(tmpKey, RsaKey, 1, NULL);
4520+
45234521
WC_ALLOC_VAR(tmpKey, RsaKey, 1, key->heap);
45244522
if (!WC_VAR_OK(tmpKey)) {
45254523
return MEMORY_E;
@@ -4630,9 +4628,6 @@ int wc_RsaExportKey(const RsaKey* key,
46304628
byte* q, word32* qSz)
46314629
{
46324630
int ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG);
4633-
#if defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_EXPORT_KEY)
4634-
WC_DECLARE_VAR(tmpKey, RsaKey, 1, NULL);
4635-
#endif
46364631

46374632
if (key && e && eSz && n && nSz && d && dSz && p && pSz && q && qSz) {
46384633
ret = 0;
@@ -4644,6 +4639,8 @@ int wc_RsaExportKey(const RsaKey* key,
46444639
if (key->devId != INVALID_DEVID)
46454640
#endif
46464641
{
4642+
WC_DECLARE_VAR(tmpKey, RsaKey, 1, NULL);
4643+
46474644
WC_ALLOC_VAR(tmpKey, RsaKey, 1, key->heap);
46484645
if (!WC_VAR_OK(tmpKey)) {
46494646
return MEMORY_E;

0 commit comments

Comments
 (0)