Skip to content

Commit ff319fc

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

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
@@ -9875,6 +9875,7 @@ static int _ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
98759875
if (key != NULL && out == NULL && outLen != NULL) {
98769876
/* if key hasn't been setup assume max bytes for size estimation */
98779877
numlen = key->dp ? (word32)key->dp->size : MAX_ECC_BYTES;
9878+
/* X9.63 uncompressed point: 0x04 header + x coord + y coord */
98789879
*outLen = 1 + 2 * numlen;
98799880
return WC_NO_ERR_TRACE(LENGTH_ONLY_E);
98809881
}
@@ -9968,6 +9969,7 @@ int wc_ecc_export_x963(ecc_key* key, byte* out, word32* outLen)
99689969
/* return length needed only */
99699970
if (out == NULL) {
99709971
word32 numlen = key->dp ? (word32)key->dp->size : MAX_ECC_BYTES;
9972+
/* X9.63 uncompressed point: 0x04 header + x coord + y coord */
99719973
*outLen = 1 + 2 * numlen;
99729974
return WC_NO_ERR_TRACE(LENGTH_ONLY_E);
99739975
}
@@ -12243,28 +12245,28 @@ static int ecc_public_key_size(ecc_key* key, word32* sz)
1224312245
WOLFSSL_ABI
1224412246
int wc_ecc_size(ecc_key* key)
1224512247
{
12246-
#ifdef WOLF_CRYPTO_CB
12247-
int ret;
12248-
int keySz;
12249-
#endif
12250-
12251-
if (key == NULL)
12248+
if (key == NULL) {
1225212249
return 0;
12250+
}
1225312251

1225412252
#ifdef WOLF_CRYPTO_CB
1225512253
if (key->devId != INVALID_DEVID) {
12256-
keySz = 0;
12254+
int ret;
12255+
int keySz = 0;
12256+
1225712257
ret = wc_CryptoCb_EccGetSize(key, &keySz);
1225812258
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) {
12259-
if (ret != 0)
12259+
if (ret != 0) {
1226012260
return 0;
12261+
}
1226112262
return keySz;
1226212263
}
1226312264
}
1226412265
#endif
1226512266

12266-
if (key->dp == NULL)
12267+
if (key->dp == NULL) {
1226712268
return 0;
12269+
}
1226812270

1226912271
return key->dp->size;
1227012272
}
@@ -12293,28 +12295,29 @@ int wc_ecc_sig_size(const ecc_key* key)
1229312295
{
1229412296
int maxSigSz;
1229512297
int orderBits, keySz;
12296-
#ifdef WOLF_CRYPTO_CB
12297-
int ret;
12298-
int cbKeySz;
12299-
#endif
1230012298

12301-
if (key == NULL)
12299+
if (key == NULL) {
1230212300
return 0;
12301+
}
1230312302

1230412303
#ifdef WOLF_CRYPTO_CB
1230512304
if (key->devId != INVALID_DEVID) {
12306-
cbKeySz = 0;
12305+
int ret;
12306+
int cbKeySz = 0;
12307+
1230712308
ret = wc_CryptoCb_EccGetSigSize(key, &cbKeySz);
1230812309
if (ret != WC_NO_ERR_TRACE(CRYPTOCB_UNAVAILABLE)) {
12309-
if (ret != 0 || cbKeySz == 0)
12310+
if (ret != 0 || cbKeySz == 0) {
1231012311
return 0;
12312+
}
1231112313
return cbKeySz;
1231212314
}
1231312315
}
1231412316
#endif
1231512317

12316-
if (key->dp == NULL)
12318+
if (key->dp == NULL) {
1231712319
return 0;
12320+
}
1231812321

1231912322
/* the signature r and s will always be less than order */
1232012323
/* 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
@@ -4497,11 +4497,6 @@ static int _RsaFlattenPublicKey(const RsaKey* key, byte* e, word32* eSz,
44974497
int wc_RsaFlattenPublicKey(const RsaKey* key, byte* e, word32* eSz, byte* n,
44984498
word32* nSz)
44994499
{
4500-
#if defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_EXPORT_KEY)
4501-
int ret;
4502-
WC_DECLARE_VAR(tmpKey, RsaKey, 1, NULL);
4503-
#endif
4504-
45054500
if (key == NULL || e == NULL || eSz == NULL || n == NULL || nSz == NULL) {
45064501
return BAD_FUNC_ARG;
45074502
}
@@ -4511,6 +4506,9 @@ int wc_RsaFlattenPublicKey(const RsaKey* key, byte* e, word32* eSz, byte* n,
45114506
if (key->devId != INVALID_DEVID)
45124507
#endif
45134508
{
4509+
int ret;
4510+
WC_DECLARE_VAR(tmpKey, RsaKey, 1, NULL);
4511+
45144512
WC_ALLOC_VAR(tmpKey, RsaKey, 1, key->heap);
45154513
if (!WC_VAR_OK(tmpKey)) {
45164514
return MEMORY_E;
@@ -4621,9 +4619,6 @@ int wc_RsaExportKey(const RsaKey* key,
46214619
byte* q, word32* qSz)
46224620
{
46234621
int ret = WC_NO_ERR_TRACE(BAD_FUNC_ARG);
4624-
#if defined(WOLF_CRYPTO_CB) && defined(WOLF_CRYPTO_CB_EXPORT_KEY)
4625-
WC_DECLARE_VAR(tmpKey, RsaKey, 1, NULL);
4626-
#endif
46274622

46284623
if (key && e && eSz && n && nSz && d && dSz && p && pSz && q && qSz) {
46294624
ret = 0;
@@ -4635,6 +4630,8 @@ int wc_RsaExportKey(const RsaKey* key,
46354630
if (key->devId != INVALID_DEVID)
46364631
#endif
46374632
{
4633+
WC_DECLARE_VAR(tmpKey, RsaKey, 1, NULL);
4634+
46384635
WC_ALLOC_VAR(tmpKey, RsaKey, 1, key->heap);
46394636
if (!WC_VAR_OK(tmpKey)) {
46404637
return MEMORY_E;

0 commit comments

Comments
 (0)