Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RISC-V 64: Add assembly code for SHA-512 #7833

Merged
merged 1 commit into from
Aug 6, 2024

Conversation

SparkiDev
Copy link
Contributor

Description

Implementation of SHA-512 using RISC-V 64 instructions.
Cleanup RISC-V 64 SHA-256 by removing unused rev_idx.

Testing

./configure '--disable-shared' '--enable-sha384' '--enable-sha512' 'LDFLAGS=--static' '--host=riscv64' 'CC=riscv64-linux-gnu-gcc' '--enable-riscv-asm'
./configure '--disable-shared' '--enable-sha384' '--enable-sha512' 'LDFLAGS=--static' '--host=riscv64' 'CC=riscv64-linux-gnu-gcc' '--enable-riscv-asm=zbb'
./configure '--disable-shared' '--enable-sha384' '--enable-sha512' 'LDFLAGS=--static' '--host=riscv64' 'CC=riscv64-linux-gnu-gcc' '--enable-riscv-asm=zbb,zbkb'
./configure '--disable-shared' '--enable-sha384' '--enable-sha512' 'LDFLAGS=--static' '--host=riscv64' 'CC=riscv64-linux-gnu-gcc' '--enable-riscv-asm=zkn,zbb'
./configure '--disable-shared' '--enable-sha384' '--enable-sha512' 'LDFLAGS=--static' '--host=riscv64' 'CC=riscv64-linux-gnu-gcc' '--enable-riscv-asm=zkn,zbb,zbkb'
./configure '--disable-shared' '--enable-sha384' '--enable-sha512' 'LDFLAGS=--static' '--host=riscv64' 'CC=riscv64-linux-gnu-gcc' '--enable-riscv-asm=zvbb'
./configure '--disable-shared' '--enable-sha384' '--enable-sha512' 'LDFLAGS=--static' '--host=riscv64' 'CC=riscv64-linux-gnu-gcc' '--enable-riscv-asm=zvbb,zbb'
./configure '--disable-shared' '--enable-sha384' '--enable-sha512' 'LDFLAGS=--static' '--host=riscv64' 'CC=riscv64-linux-gnu-gcc' '--enable-riscv-asm=zvkned,zvbb'

Checklist

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

@SparkiDev SparkiDev self-assigned this Aug 5, 2024
@dgarske dgarske self-assigned this Aug 5, 2024
@dgarske
Copy link
Contributor

dgarske commented Aug 5, 2024

I've rebased and force pushed to resolve the GitHub CI issues.

Testing results:

root@HiFiveU:~/wolfssl# ./wolfcrypt/benchmark/benchmark
------------------------------------------------------------------------------
 wolfSSL version 5.7.2
------------------------------------------------------------------------------
Math: 	Multi-Precision: Wolf(SP) word-size=64 bits=3072 sp_int.c
wolfCrypt Benchmark (block bytes 1048576, min 1.0 sec each)
RNG                         10 MiB took 1.060 seconds,    9.437 MiB/s
AES-128-CBC-enc             20 MiB took 1.080 seconds,   18.520 MiB/s
AES-128-CBC-dec             20 MiB took 1.093 seconds,   18.293 MiB/s
AES-192-CBC-enc             20 MiB took 1.247 seconds,   16.042 MiB/s
AES-192-CBC-dec             20 MiB took 1.248 seconds,   16.023 MiB/s
AES-256-CBC-enc             15 MiB took 1.060 seconds,   14.157 MiB/s
AES-256-CBC-dec             15 MiB took 1.049 seconds,   14.303 MiB/s
AES-128-GCM-enc             15 MiB took 1.310 seconds,   11.453 MiB/s
AES-128-GCM-dec             15 MiB took 1.309 seconds,   11.463 MiB/s
AES-192-GCM-enc             15 MiB took 1.433 seconds,   10.467 MiB/s
AES-192-GCM-dec             15 MiB took 1.434 seconds,   10.462 MiB/s
AES-256-GCM-enc             10 MiB took 1.036 seconds,    9.654 MiB/s
AES-256-GCM-dec             10 MiB took 1.038 seconds,    9.639 MiB/s
GMAC Table 4-bit            31 MiB took 1.003 seconds,   30.914 MiB/s
CHACHA                      40 MiB took 1.012 seconds,   39.538 MiB/s
CHA-POLY                    30 MiB took 1.105 seconds,   27.150 MiB/s
MD5                         75 MiB took 1.008 seconds,   74.370 MiB/s
POLY1305                    90 MiB took 1.041 seconds,   86.459 MiB/s
SHA                         35 MiB took 1.063 seconds,   32.924 MiB/s
SHA-256                     25 MiB took 1.166 seconds,   21.447 MiB/s
SHA-384                     35 MiB took 1.122 seconds,   31.190 MiB/s
SHA-512                     35 MiB took 1.124 seconds,   31.140 MiB/s
SHA-512/224                 35 MiB took 1.112 seconds,   31.482 MiB/s
SHA-512/256                 35 MiB took 1.129 seconds,   30.993 MiB/s
HMAC-MD5                    75 MiB took 1.009 seconds,   74.357 MiB/s
HMAC-SHA                    35 MiB took 1.062 seconds,   32.968 MiB/s
HMAC-SHA256                 25 MiB took 1.165 seconds,   21.453 MiB/s
HMAC-SHA384                 35 MiB took 1.112 seconds,   31.479 MiB/s
HMAC-SHA512                 35 MiB took 1.112 seconds,   31.480 MiB/s
PBKDF2                       3 KiB took 1.000 seconds,    2.655 KiB/s
RSA     2048   public      1500 ops took 1.051 sec, avg 0.701 ms, 1426.712 ops/sec
RSA     2048  private       100 ops took 4.394 sec, avg 43.937 ms, 22.760 ops/sec
DH      2048  key gen       115 ops took 1.003 sec, avg 8.722 ms, 114.656 ops/sec
DH      2048    agree       100 ops took 1.846 sec, avg 18.463 ms, 54.162 ops/sec
ECC   [      SECP256R1]   256  key gen       200 ops took 1.368 sec, avg 6.839 ms, 146.226 ops/sec
ECDHE [      SECP256R1]   256    agree       200 ops took 1.277 sec, avg 6.387 ms, 156.576 ops/sec
ECDSA [      SECP256R1]   256     sign       200 ops took 1.344 sec, avg 6.718 ms, 148.843 ops/sec
ECDSA [      SECP256R1]   256   verify       300 ops took 1.297 sec, avg 4.322 ms, 231.368 ops/sec
Benchmark complete

dgarske
dgarske previously approved these changes Aug 5, 2024
Copy link
Contributor

@dgarske dgarske left a comment

Choose a reason for hiding this comment

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

SHA2-512 is 42% faster. Nice work! SHA2-256 is basically the same.

@SparkiDev SparkiDev force-pushed the riscv-sha512-asm branch 2 times, most recently from ed32ec7 to 05a5dd2 Compare August 6, 2024 00:12
Cleanup RISC-V 64 SHA-256 by removing unused rev_idx.
@SparkiDev
Copy link
Contributor Author

Changed loading of W which should have improved things slightly.
If improved merge thanks!

@dgarske
Copy link
Contributor

dgarske commented Aug 6, 2024

Latest benchmarks for SHA2-512 are about 1% faster:

root@HiFiveU:~/wolfssl# ./wolfcrypt/benchmark/benchmark
------------------------------------------------------------------------------
 wolfSSL version 5.7.2
------------------------------------------------------------------------------
Math: 	Multi-Precision: Wolf(SP) word-size=64 bits=3072 sp_int.c
wolfCrypt Benchmark (block bytes 1048576, min 1.0 sec each)
RNG                         10 MiB took 1.141 seconds,    8.767 MiB/s
AES-128-CBC-enc             20 MiB took 1.068 seconds,   18.726 MiB/s
AES-128-CBC-dec             20 MiB took 1.067 seconds,   18.740 MiB/s
AES-192-CBC-enc             20 MiB took 1.239 seconds,   16.147 MiB/s
AES-192-CBC-dec             20 MiB took 1.231 seconds,   16.250 MiB/s
AES-256-CBC-enc             15 MiB took 1.062 seconds,   14.123 MiB/s
AES-256-CBC-dec             15 MiB took 1.048 seconds,   14.312 MiB/s
AES-128-GCM-enc             15 MiB took 1.303 seconds,   11.508 MiB/s
AES-128-GCM-dec             15 MiB took 1.304 seconds,   11.505 MiB/s
AES-192-GCM-enc             15 MiB took 1.432 seconds,   10.475 MiB/s
AES-192-GCM-dec             15 MiB took 1.432 seconds,   10.477 MiB/s
AES-256-GCM-enc             10 MiB took 1.034 seconds,    9.670 MiB/s
AES-256-GCM-dec             10 MiB took 1.034 seconds,    9.667 MiB/s
GMAC Table 4-bit            31 MiB took 1.003 seconds,   30.902 MiB/s
CHACHA                      40 MiB took 1.011 seconds,   39.574 MiB/s
CHA-POLY                    30 MiB took 1.104 seconds,   27.166 MiB/s
MD5                         75 MiB took 1.010 seconds,   74.257 MiB/s
POLY1305                    90 MiB took 1.041 seconds,   86.465 MiB/s
SHA                         35 MiB took 1.063 seconds,   32.938 MiB/s
SHA-256                     25 MiB took 1.165 seconds,   21.457 MiB/s
SHA-384                     35 MiB took 1.113 seconds,   31.437 MiB/s
SHA-512                     35 MiB took 1.113 seconds,   31.445 MiB/s
SHA-512/224                 35 MiB took 1.113 seconds,   31.450 MiB/s
SHA-512/256                 35 MiB took 1.113 seconds,   31.448 MiB/s
HMAC-MD5                    75 MiB took 1.010 seconds,   74.266 MiB/s
HMAC-SHA                    30 MiB took 1.043 seconds,   28.764 MiB/s
HMAC-SHA256                 25 MiB took 1.165 seconds,   21.451 MiB/s
HMAC-SHA384                 35 MiB took 1.114 seconds,   31.427 MiB/s
HMAC-SHA512                 35 MiB took 1.113 seconds,   31.437 MiB/s
PBKDF2                       2 KiB took 1.001 seconds,    2.435 KiB/s
RSA     2048   public      1500 ops took 1.050 sec, avg 0.700 ms, 1429.109 ops/sec
RSA     2048  private       100 ops took 4.388 sec, avg 43.876 ms, 22.791 ops/sec
DH      2048  key gen       115 ops took 1.004 sec, avg 8.727 ms, 114.592 ops/sec
DH      2048    agree       100 ops took 1.844 sec, avg 18.442 ms, 54.224 ops/sec
ECC   [      SECP256R1]   256  key gen       200 ops took 1.399 sec, avg 6.996 ms, 142.935 ops/sec
ECDHE [      SECP256R1]   256    agree       200 ops took 1.278 sec, avg 6.391 ms, 156.472 ops/sec
ECDSA [      SECP256R1]   256     sign       200 ops took 1.311 sec, avg 6.556 ms, 152.543 ops/sec
ECDSA [      SECP256R1]   256   verify       300 ops took 1.335 sec, avg 4.451 ms, 224.677 ops/sec
Benchmark complete

I'll approve and merge. Thank you

@dgarske dgarske merged commit a30d9c9 into wolfSSL:master Aug 6, 2024
122 checks passed
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