Skip to content

Commit 9ee7c18

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

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
@@ -9876,6 +9876,7 @@ static int _ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
98769876
if (key != NULL && out == NULL && outLen != NULL) {
98779877
/* if key hasn't been setup assume max bytes for size estimation */
98789878
numlen = key->dp ? (word32)key->dp->size : MAX_ECC_BYTES;
9879+
/* X9.63 uncompressed point: 0x04 header + x coord + y coord */
98799880
*outLen = 1 + 2 * numlen;
98809881
return WC_NO_ERR_TRACE(LENGTH_ONLY_E);
98819882
}
@@ -9969,6 +9970,7 @@ int wc_ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
99699970
/* return length needed only */
99709971
if (out == NULL) {
99719972
word32 numlen = key->dp ? (word32)key->dp->size : MAX_ECC_BYTES;
9973+
/* X9.63 uncompressed point: 0x04 header + x coord + y coord */
99729974
*outLen = 1 + 2 * numlen;
99739975
return WC_NO_ERR_TRACE(LENGTH_ONLY_E);
99749976
}
@@ -12244,28 +12246,28 @@ static int ecc_public_key_size(ecc_key* key, word32* sz)
1224412246
WOLFSSL_ABI
1224512247
int wc_ecc_size(ecc_key* key)
1224612248
{
12247-
#ifdef WOLF_CRYPTO_CB
12248-
int ret;
12249-
int keySz;
12250-
#endif
12251-
12252-
if (key == NULL)
12249+
if (key == NULL) {
1225312250
return 0;
12251+
}
1225412252

1225512253
#ifdef WOLF_CRYPTO_CB
1225612254
if (key->devId != INVALID_DEVID) {
12257-
keySz = 0;
12255+
int ret;
12256+
int keySz = 0;
12257+
1225812258
ret = wc_CryptoCb_EccGetSize(key, &keySz);
1225912259
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) {
12260-
if (ret != 0)
12260+
if (ret != 0) {
1226112261
return 0;
12262+
}
1226212263
return keySz;
1226312264
}
1226412265
}
1226512266
#endif
1226612267

12267-
if (key->dp == NULL)
12268+
if (key->dp == NULL) {
1226812269
return 0;
12270+
}
1226912271

1227012272
return key->dp->size;
1227112273
}
@@ -12294,28 +12296,29 @@ int wc_ecc_sig_size(const ecc_key* key)
1229412296
{
1229512297
int maxSigSz;
1229612298
int orderBits, keySz;
12297-
#ifdef WOLF_CRYPTO_CB
12298-
int ret;
12299-
int cbKeySz;
12300-
#endif
1230112299

12302-
if (key == NULL)
12300+
if (key == NULL) {
1230312301
return 0;
12302+
}
1230412303

1230512304
#ifdef WOLF_CRYPTO_CB
1230612305
if (key->devId != INVALID_DEVID) {
12307-
cbKeySz = 0;
12306+
int ret;
12307+
int cbKeySz = 0;
12308+
1230812309
ret = wc_CryptoCb_EccGetSigSize(key, &cbKeySz);
1230912310
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) {
12310-
if (ret != 0 || cbKeySz == 0)
12311+
if (ret != 0 || cbKeySz == 0) {
1231112312
return 0;
12313+
}
1231212314
return cbKeySz;
1231312315
}
1231412316
}
1231512317
#endif
1231612318

12317-
if (key->dp == NULL)
12319+
if (key->dp == NULL) {
1231812320
return 0;
12321+
}
1231912322

1232012323
/* the signature r and s will always be less than order */
1232112324
/* 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)