Skip to content

Commit 79a6e1e

Browse files
Merge pull request #6808 from SparkiDev/sp_sm2
SP updates for SM2
2 parents f247e6b + 0cc21a4 commit 79a6e1e

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
@@ -3530,10 +3530,6 @@ AC_ARG_ENABLE([sm2],
35303530
[ ENABLED_SM2=no ]
35313531
)
35323532

3533-
if test "$ENABLED_SP_MATH" = "yes"
3534-
then
3535-
ENABLED_SM2="no"
3536-
fi
35373533
if test "$ENABLED_SM2" = "yes"
35383534
then
35393535
if test "$ENABLED_ECC" = "no"
@@ -7149,6 +7145,7 @@ ENABLED_SP_ECC=no
71497145
ENABLED_SP_EC_256=no
71507146
ENABLED_SP_EC_384=no
71517147
ENABLED_SP_EC_521=no
7148+
ENABLED_SP_SM2=$ENABLED_SM2
71527149
ENABLED_SP_SAKKE_1024=$ENABLED_SAKKE
71537150
ENABLED_SP_NO_MALLOC=no
71547151
ENABLED_SP_NONBLOCK=no
@@ -7240,6 +7237,15 @@ do
72407237
ENABLED_SP_ECC=yes
72417238
ENABLED_SP_SAKKE_1024=yes
72427239
;;
7240+
smallsm2)
7241+
ENABLED_SP_SMALL=yes
7242+
ENABLED_SP_ECC=yes
7243+
ENABLED_SP_SM2=yes
7244+
;;
7245+
sm2)
7246+
ENABLED_SP_ECC=yes
7247+
ENABLED_SP_SM2=yes
7248+
;;
72437249

72447250
small2048)
72457251
ENABLED_SP_SMALL=yes
@@ -7387,6 +7393,10 @@ if test "$ENABLED_ECC" != "no" && test "$ENABLED_SP_ECC" = "yes"; then
73877393
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SP_1024"
73887394
AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_SP_1024"
73897395
fi
7396+
if test "$ENABLED_SP_SM2" = "yes"; then
7397+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SP_SM2"
7398+
AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_SP_SM2"
7399+
fi
73907400
fi
73917401
if test "$ENABLED_SP_SMALL" = "yes"; then
73927402
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
@@ -519,6 +519,35 @@ endif !BUILD_FIPS_CURRENT
519519
if !BUILD_FIPS_CURRENT
520520
if BUILD_SM2
521521
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/sm2.c
522+
if BUILD_SP
523+
if BUILD_SP_C32
524+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/sp_sm2_c32.c
525+
endif
526+
if BUILD_SP_C64
527+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/sp_sm2_c64.c
528+
endif
529+
530+
if BUILD_SP_X86_64
531+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/sp_sm2_x86_64.c
532+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/sp_sm2_x86_64_asm.S
533+
endif
534+
if !BUILD_FIPS_V2
535+
if BUILD_SP_ARM32
536+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/sp_sm2_arm32.c
537+
endif
538+
endif
539+
if BUILD_SP_ARM_THUMB
540+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/sp_sm2_armthumb.c
541+
endif
542+
if !BUILD_FIPS_V2
543+
if BUILD_SP_ARM64
544+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/sp_sm2_arm64.c
545+
endif
546+
endif
547+
if BUILD_SP_ARM_CORTEX
548+
src_libwolfssl@LIBSUFFIX@_la_SOURCES += wolfcrypt/src/sp_sm2_cortexm.c
549+
endif
550+
endif BUILD_SP
522551
endif BUILD_SM2
523552
endif !BUILD_FIPS_CURRENT
524553

tests/api.c

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

0 commit comments

Comments
 (0)