Skip to content

Commit 4b90afa

Browse files
committed
Provide way to disable ASN but have wc_RsaPublicKeyDecodeRaw, which doesn't need ASN.1 parsing.
1 parent 61dfbf5 commit 4b90afa

3 files changed

Lines changed: 69 additions & 60 deletions

File tree

configure.ac

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3990,7 +3990,7 @@ else
39903990
fi
39913991

39923992
if test "$ENABLED_RSA" = "yes" && test "$ENABLED_RSAVFY" = "no" && \
3993-
test "$ENABLED_ASN" = "no"
3993+
test "$ENABLED_ASN" = "no" && test "$ENABLED_LOWRESOURCE" = "no"
39943994
then
39953995
AC_MSG_ERROR([please disable rsa if disabling asn.])
39963996
fi
@@ -8457,7 +8457,7 @@ AM_CONDITIONAL([BUILD_SAKKE],[test "x$ENABLED_SAKKE" = "xyes" || test "x$ENABLED
84578457
AM_CONDITIONAL([BUILD_MEMORY],[test "x$ENABLED_MEMORY" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])
84588458
AM_CONDITIONAL([BUILD_RSA],[test "x$ENABLED_RSA" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])
84598459
AM_CONDITIONAL([BUILD_DH],[test "x$ENABLED_DH" != "xno" || test "x$ENABLED_USERSETTINGS" = "xyes"])
8460-
AM_CONDITIONAL([BUILD_ASN],[test "x$ENABLED_ASN" != "xno" || test "x$ENABLED_USERSETTINGS" = "xyes"])
8460+
AM_CONDITIONAL([BUILD_ASN],[test "x$ENABLED_ASN" != "xno" || test "x$ENABLED_RSA" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])
84618461
AM_CONDITIONAL([BUILD_AES],[test "x$ENABLED_AES" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])
84628462
AM_CONDITIONAL([BUILD_CODING],[test "x$ENABLED_CODING" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])
84638463
AM_CONDITIONAL([BUILD_RC4],[test "x$ENABLED_ARC4" = "xyes" || test "x$ENABLED_USERSETTINGS" = "xyes"])

wolfcrypt/src/asn.c

Lines changed: 65 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,20 @@ ASN Options:
9696
* WC_ASN_HASH_SHA256: Force use of SHA2-256 for the internal hash ID calcs.
9797
*/
9898

99+
#include <wolfssl/wolfcrypt/error-crypt.h>
100+
#ifndef NO_RSA
101+
#include <wolfssl/wolfcrypt/rsa.h>
102+
#if defined(WOLFSSL_XILINX_CRYPT) || defined(WOLFSSL_CRYPTOCELL)
103+
extern int wc_InitRsaHw(RsaKey* key);
104+
#endif
105+
#endif
106+
99107
#ifndef NO_ASN
108+
100109
#include <wolfssl/wolfcrypt/asn.h>
101110
#include <wolfssl/wolfcrypt/coding.h>
102111
#include <wolfssl/wolfcrypt/md2.h>
103112
#include <wolfssl/wolfcrypt/hmac.h>
104-
#include <wolfssl/wolfcrypt/error-crypt.h>
105113
#include <wolfssl/wolfcrypt/pwdbased.h>
106114
#include <wolfssl/wolfcrypt/des3.h>
107115
#include <wolfssl/wolfcrypt/aes.h>
@@ -168,13 +176,6 @@ ASN Options:
168176
#include <wolfssl/wolfcrypt/port/Renesas/renesas_cmn.h>
169177
#endif
170178

171-
#ifndef NO_RSA
172-
#include <wolfssl/wolfcrypt/rsa.h>
173-
#if defined(WOLFSSL_XILINX_CRYPT) || defined(WOLFSSL_CRYPTOCELL)
174-
extern int wc_InitRsaHw(RsaKey* key);
175-
#endif
176-
#endif
177-
178179
#ifndef NO_DSA
179180
#include <wolfssl/wolfcrypt/dsa.h>
180181
#else
@@ -9518,56 +9519,6 @@ int wc_RsaPublicKeyDecode(const byte* input, word32* inOutIdx, RsaKey* key,
95189519

95199520
return ret;
95209521
}
9521-
9522-
/* import RSA public key elements (n, e) into RsaKey structure (key) */
9523-
int wc_RsaPublicKeyDecodeRaw(const byte* n, word32 nSz, const byte* e,
9524-
word32 eSz, RsaKey* key)
9525-
{
9526-
if (n == NULL || e == NULL || key == NULL)
9527-
return BAD_FUNC_ARG;
9528-
9529-
key->type = RSA_PUBLIC;
9530-
9531-
if (mp_init(&key->n) != MP_OKAY)
9532-
return MP_INIT_E;
9533-
9534-
if (mp_read_unsigned_bin(&key->n, n, nSz) != 0) {
9535-
mp_clear(&key->n);
9536-
return ASN_GETINT_E;
9537-
}
9538-
#ifdef HAVE_WOLF_BIGINT
9539-
if ((int)nSz > 0 && wc_bigint_from_unsigned_bin(&key->n.raw, n, nSz) != 0) {
9540-
mp_clear(&key->n);
9541-
return ASN_GETINT_E;
9542-
}
9543-
#endif /* HAVE_WOLF_BIGINT */
9544-
9545-
if (mp_init(&key->e) != MP_OKAY) {
9546-
mp_clear(&key->n);
9547-
return MP_INIT_E;
9548-
}
9549-
9550-
if (mp_read_unsigned_bin(&key->e, e, eSz) != 0) {
9551-
mp_clear(&key->n);
9552-
mp_clear(&key->e);
9553-
return ASN_GETINT_E;
9554-
}
9555-
#ifdef HAVE_WOLF_BIGINT
9556-
if ((int)eSz > 0 && wc_bigint_from_unsigned_bin(&key->e.raw, e, eSz) != 0) {
9557-
mp_clear(&key->n);
9558-
mp_clear(&key->e);
9559-
return ASN_GETINT_E;
9560-
}
9561-
#endif /* HAVE_WOLF_BIGINT */
9562-
9563-
#ifdef WOLFSSL_XILINX_CRYPT
9564-
if (wc_InitRsaHw(key) != 0) {
9565-
return BAD_STATE_E;
9566-
}
9567-
#endif
9568-
9569-
return 0;
9570-
}
95719522
#endif /* HAVE_USER_RSA */
95729523
#endif /* !NO_RSA */
95739524

@@ -37022,6 +36973,62 @@ int wc_MIME_free_hdrs(MimeHdr* head)
3702236973

3702336974
#endif /* !NO_ASN */
3702436975

36976+
/* Functions that parse, but are not using ASN.1 */
36977+
#if !defined(NO_RSA) && !defined(HAVE_USER_RSA) && \
36978+
(!defined(NO_BIG_INT) || defined(WOLFSSL_SP_MATH))
36979+
/* import RSA public key elements (n, e) into RsaKey structure (key) */
36980+
/* this function does not use any ASN.1 parsing */
36981+
int wc_RsaPublicKeyDecodeRaw(const byte* n, word32 nSz, const byte* e,
36982+
word32 eSz, RsaKey* key)
36983+
{
36984+
if (n == NULL || e == NULL || key == NULL)
36985+
return BAD_FUNC_ARG;
36986+
36987+
key->type = RSA_PUBLIC;
36988+
36989+
if (mp_init(&key->n) != MP_OKAY)
36990+
return MP_INIT_E;
36991+
36992+
if (mp_read_unsigned_bin(&key->n, n, nSz) != 0) {
36993+
mp_clear(&key->n);
36994+
return ASN_GETINT_E;
36995+
}
36996+
#ifdef HAVE_WOLF_BIGINT
36997+
if ((int)nSz > 0 && wc_bigint_from_unsigned_bin(&key->n.raw, n, nSz) != 0) {
36998+
mp_clear(&key->n);
36999+
return ASN_GETINT_E;
37000+
}
37001+
#endif /* HAVE_WOLF_BIGINT */
37002+
37003+
if (mp_init(&key->e) != MP_OKAY) {
37004+
mp_clear(&key->n);
37005+
return MP_INIT_E;
37006+
}
37007+
37008+
if (mp_read_unsigned_bin(&key->e, e, eSz) != 0) {
37009+
mp_clear(&key->n);
37010+
mp_clear(&key->e);
37011+
return ASN_GETINT_E;
37012+
}
37013+
#ifdef HAVE_WOLF_BIGINT
37014+
if ((int)eSz > 0 && wc_bigint_from_unsigned_bin(&key->e.raw, e, eSz) != 0) {
37015+
mp_clear(&key->n);
37016+
mp_clear(&key->e);
37017+
return ASN_GETINT_E;
37018+
}
37019+
#endif /* HAVE_WOLF_BIGINT */
37020+
37021+
#ifdef WOLFSSL_XILINX_CRYPT
37022+
if (wc_InitRsaHw(key) != 0) {
37023+
return BAD_STATE_E;
37024+
}
37025+
#endif
37026+
37027+
return 0;
37028+
}
37029+
#endif /* !NO_RSA && !HAVE_USER_RSA && (!NO_BIG_INT || WOLFSSL_SP_MATH) */
37030+
37031+
3702537032
#ifdef WOLFSSL_SEP
3702637033

3702737034

wolfcrypt/test/test.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13301,7 +13301,9 @@ static int random_rng_test(void)
1330113301
if (rng == NULL)
1330213302
return WC_TEST_RET_ENC_ERRNO;
1330313303

13304+
#if defined(WOLFSSL_ASYNC_CRYPT) || defined(WOLF_CRYPTO_CB)
1330413305
rng->devId = devId;
13306+
#endif
1330513307
ret = _rng_test(rng, WC_TEST_RET_ENC_NC);
1330613308

1330713309
wc_rng_free(rng);

0 commit comments

Comments
 (0)