Skip to content

Commit 0cc21a4

Browse files
committed
SP updates for SM2
Allow wolfSSL to build with SP implementations of SM2. Updates to SP implementation of other code.
1 parent 1149522 commit 0cc21a4

35 files changed

Lines changed: 2768 additions & 2982 deletions

configure.ac

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3515,10 +3515,6 @@ AC_ARG_ENABLE([sm2],
35153515
[ ENABLED_SM2=no ]
35163516
)
35173517

3518-
if test "$ENABLED_SP_MATH" = "yes"
3519-
then
3520-
ENABLED_SM2="no"
3521-
fi
35223518
if test "$ENABLED_SM2" = "yes"
35233519
then
35243520
if test "$ENABLED_ECC" = "no"
@@ -7115,6 +7111,7 @@ ENABLED_SP_ECC=no
71157111
ENABLED_SP_EC_256=no
71167112
ENABLED_SP_EC_384=no
71177113
ENABLED_SP_EC_521=no
7114+
ENABLED_SP_SM2=$ENABLED_SM2
71187115
ENABLED_SP_SAKKE_1024=$ENABLED_SAKKE
71197116
ENABLED_SP_NO_MALLOC=no
71207117
ENABLED_SP_NONBLOCK=no
@@ -7206,6 +7203,15 @@ do
72067203
ENABLED_SP_ECC=yes
72077204
ENABLED_SP_SAKKE_1024=yes
72087205
;;
7206+
smallsm2)
7207+
ENABLED_SP_SMALL=yes
7208+
ENABLED_SP_ECC=yes
7209+
ENABLED_SP_SM2=yes
7210+
;;
7211+
sm2)
7212+
ENABLED_SP_ECC=yes
7213+
ENABLED_SP_SM2=yes
7214+
;;
72097215

72107216
small2048)
72117217
ENABLED_SP_SMALL=yes
@@ -7353,6 +7359,10 @@ if test "$ENABLED_ECC" != "no" && test "$ENABLED_SP_ECC" = "yes"; then
73537359
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SP_1024"
73547360
AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_SP_1024"
73557361
fi
7362+
if test "$ENABLED_SP_SM2" = "yes"; then
7363+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SP_SM2"
7364+
AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_SP_SM2"
7365+
fi
73567366
fi
73577367
if test "$ENABLED_SP_SMALL" = "yes"; then
73587368
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SP_SMALL"

examples/server/server.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,18 @@ static void SetKeyShare(WOLFSSL* ssl, int onlyKeyShare, int useX25519,
752752
else
753753
err_sys("unable to use curve secp256r1");
754754
} while (ret == WC_PENDING_E);
755+
#elif defined(WOLFSSL_SM2)
756+
do {
757+
ret = wolfSSL_UseKeyShare(ssl, WOLFSSL_ECC_SM2P256V1);
758+
if (ret == WOLFSSL_SUCCESS)
759+
groups[count++] = WOLFSSL_ECC_SM2P256V1;
760+
#ifdef WOLFSSL_ASYNC_CRYPT
761+
else if (ret == WC_PENDING_E)
762+
wolfSSL_AsyncPoll(ssl, WOLF_POLL_FLAG_CHECK_HW);
763+
#endif
764+
else
765+
err_sys("unable to use curve sm2p256r1");
766+
} while (ret == WC_PENDING_E);
755767
#endif
756768
#endif
757769
}

src/include.am

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,35 @@ endif !BUILD_FIPS_CURRENT
517517
if !BUILD_FIPS_CURRENT
518518
if BUILD_SM2
519519
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/sm2.c
520+
if BUILD_SP
521+
if BUILD_SP_C32
522+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/sp_sm2_c32.c
523+
endif
524+
if BUILD_SP_C64
525+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/sp_sm2_c64.c
526+
endif
527+
528+
if BUILD_SP_X86_64
529+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/sp_sm2_x86_64.c
530+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/sp_sm2_x86_64_asm.S
531+
endif
532+
if !BUILD_FIPS_V2
533+
if BUILD_SP_ARM32
534+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/sp_sm2_arm32.c
535+
endif
536+
endif
537+
if BUILD_SP_ARM_THUMB
538+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/sp_sm2_armthumb.c
539+
endif
540+
if !BUILD_FIPS_V2
541+
if BUILD_SP_ARM64
542+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/sp_sm2_arm64.c
543+
endif
544+
endif
545+
if BUILD_SP_ARM_CORTEX
546+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/sp_sm2_cortexm.c
547+
endif
548+
endif BUILD_SP
520549
endif BUILD_SM2
521550
endif !BUILD_FIPS_CURRENT
522551

tests/api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23770,8 +23770,8 @@ static int test_wc_ecc_sm2_sign_hash_ex(void)
2377023770
mp_int smallR[1];
2377123771
sp_init_size(smallR, 1);
2377223772
/* Force failure in _ecc_sm2_calc_r_s by r being too small. */
23773-
ExpectIntEQ(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key,
23774-
smallR, s), MP_VAL);
23773+
ExpectIntLT(wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key,
23774+
smallR, s), 0);
2377523775
}
2377623776
#endif
2377723777

0 commit comments

Comments
 (0)