Skip to content

SP updates for SM2#6808

Merged
JacobBarthelmeh merged 1 commit intowolfSSL:masterfrom
SparkiDev:sp_sm2
Oct 13, 2023
Merged

SP updates for SM2#6808
JacobBarthelmeh merged 1 commit intowolfSSL:masterfrom
SparkiDev:sp_sm2

Conversation

@SparkiDev
Copy link
Copy Markdown
Contributor

Description

Allow wolfSSL to build with SP implementations of SM2.
Updates to SP implementation of other code.

Testing

How did you test?

Checklist

  • added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

Copy link
Copy Markdown
Contributor

@JacobBarthelmeh JacobBarthelmeh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple minor things. Very nice though!

Comparing ./configure --enable-all --enable-sp --enable-sp-asm --enable-sm2 --enable-sm3 && make

This PR with updated wolfsm :

------------------------------------------------------------------------------
 wolfSSL version 5.6.3
------------------------------------------------------------------------------
Math: 	Multi-Precision: Wolf(SP) word-size=64 bits=4096 sp_int.c
	Single Precision: ecc 256 384 521 rsa/dh 2048 3072 4096 asm sp_x86_64.c
wolfCrypt Benchmark (block bytes 1048576, min 1.0 sec each)
ECC   [      SM2P256V1]   256  key gen     80900 ops took 1.001 sec, avg 0.012 ms, 80855.681 ops/sec
ECDHE [      SM2P256V1]   256    agree     57000 ops took 1.001 sec, avg 0.018 ms, 56933.216 ops/sec
ECDSA [      SM2P256V1]   256     sign     56200 ops took 1.001 sec, avg 0.018 ms, 56125.185 ops/sec
ECDSA [      SM2P256V1]   256   verify     49800 ops took 1.001 sec, avg 0.020 ms, 49735.541 ops/sec
Benchmark complete

Vs current master:

------------------------------------------------------------------------------
 wolfSSL version 5.6.3
------------------------------------------------------------------------------
Math: 	Multi-Precision: Wolf(SP) word-size=64 bits=4096 sp_int.c
	Single Precision: ecc 256 384 521 rsa/dh 2048 3072 4096 asm sp_x86_64.c
wolfCrypt Benchmark (block bytes 1048576, min 1.0 sec each)
ECC   [      SM2P256V1]   256  key gen     20300 ops took 1.004 sec, avg 0.049 ms, 20228.069 ops/sec
ECDHE [      SM2P256V1]   256    agree     20800 ops took 1.002 sec, avg 0.048 ms, 20753.558 ops/sec
ECDSA [      SM2P256V1]   256     sign     16600 ops took 1.002 sec, avg 0.060 ms, 16573.829 ops/sec
ECDSA [      SM2P256V1]   256   verify     15800 ops took 1.002 sec, avg 0.063 ms, 15770.492 ops/sec
Benchmark complete

Comment thread wolfcrypt/src/sp_sm2_arm32.c Outdated
Comment thread configure.ac Outdated
@JacobBarthelmeh
Copy link
Copy Markdown
Contributor

JacobBarthelmeh commented Oct 11, 2023

In re-reviewing ./wolfcrypt/test/testwolfcrypt is failing for me:

cd wolfsm && ./install.sh && cd ..
cd wolfssl && ./configure --enable-all --enable-sp --enable-sp-asm --enable-sm2 --enable-sm3 && make

./wolfcrypt/test/testwolfcrypt
...
...
OPENSSL (PKEY1) passed!
OPENSSL (EVP Sign/Verify) passed!
SM2 Verify
ECC      test failed!
 error L=27600
 [fiducial line numbers: 7874 24284 35684 47863]
Exiting main with return code: -1

Env. details:

$ uname -a
Linux jak-virtual-machine 6.2.0-34-generic #34~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Sep  7 13:12:03 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

gcc version 11.4.0 (Ubuntu 11.4.0-1ubuntu1~22.04) 

Trying with clang gives the same unit test failure error. Also could see the error reported when removing the --enable-sp-asm flag.

EDIT: Another data point is that attempting this same build on master branches of wolfsm and wolfssl passes the unit tests.

@SparkiDev
Copy link
Copy Markdown
Contributor Author

The problem came from sm2.c where I was using the SP implementation even though it was a custom curve.
Fixed now.

@JacobBarthelmeh
Copy link
Copy Markdown
Contributor

That solved the ./wolfcrypt/test/testwolfcrypt report for me. Am seeing a unit test failure though when running 'make check' still though (same configure).

$ ./scripts/unit.test -225
starting unit tests...
 Begin API Tests
   225: test_wc_ecc_sm2_sign_hash_ex                        :
ERROR - tests/api.c line 23777 failed with:
    expected: wc_ecc_sm2_sign_hash_ex(hash, sizeof(hash), rng, key, smallR, s) == (-3)
    result:   -2 != -3

 failed (  0.00027)

ERROR - tests/api.c line 66708 failed with:
    expected: Test failed

    result:   ret 0


FAILURES:
   225: test_wc_ecc_sm2_sign_hash_ex

 End API Tests

Allow wolfSSL to build with SP implementations of SM2.
Updates to SP implementation of other code.
@SparkiDev
Copy link
Copy Markdown
Contributor Author

Fixed

@JacobBarthelmeh JacobBarthelmeh merged commit 79a6e1e into wolfSSL:master Oct 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants