Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,21 @@ The following files will be placed in wolfssl/wolfssl/wolfcrypt:

The following files will be placed in wolfssl/wolfcrypt/src:
* sm2.c
* sp_sm2_arm32.c (Assembly optimised SM2 for ARM 32-bit)
* sp_sm2_arm64.c (Assembly optimised SM2 for Aarch64)
* sp_sm2_armthumb.c (Assembly optimised SM2 for ARM Thumb)
* sp_sm2_c32.c (C only optimised SM2 for 32-bit CPUs)
* sp_sm2_c64.c (C only optimised SM2 for 64-bit CPUs)
* sp_sm2_cortexm.c (Assembly optimised SM2 for ARM Thumb2)
* sp_sm2_x86_64_asm.S (Assembly optimised SM2 for Intel x64)
* sp_sm2_x86_64.c (C calling assembly optimised SM2 for Intel x64)
* sm3.c
* sm3_asm.S
* sm3_asm.S (Assembly optimised SM2 for Intel x64)
* sm4.c

## Build wolfSSL

Now you can build SM algorithms into wolfSSL.
Once the files have been installed, you can build SM algorithms into wolfSSL.

Choose which algorithms you require on the configure line:
* --enable-sm3
Expand All @@ -79,6 +87,23 @@ make
sudo make install
```

### Optimised SM2

To use optimised implementations of SM2 you can either use C only code or C code
with the faster assembly code.

For C code only: --enable-sp
For C and assembly code: --enable-sp --enable-sp-asm

Optimised C code is available for 32 and 64 bit CPUs.

Assmembly code is available for the following platforms:
* Intel x64
* Aarch64
* ARM 32-bit
* ARM Thumb2
* ARM Thumb

## Testing Algorithms

To test that the SM ciphers are working use the following command:
Expand Down
8 changes: 8 additions & 0 deletions check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ check_file() {
echo "Diffing files with those in wolfssl ... "
check_file sm2.h wolfssl/wolfcrypt
check_file sm2.c wolfcrypt/src
check_file sp_sm2_c32.c wolfcrypt/src/
check_file sp_sm2_c64.c wolfcrypt/src/
check_file sp_sm2_x86_64.c wolfcrypt/src/
check_file sp_sm2_x86_64_asm.S wolfcrypt/src/
check_file sp_sm2_arm32.c wolfcrypt/src/
check_file sp_sm2_cortexm.c wolfcrypt/src/
check_file sp_sm2_armthumb.c wolfcrypt/src/
check_file sp_sm2_arm64.c wolfcrypt/src/
check_file sm3.h wolfssl/wolfcrypt
check_file sm3.c wolfcrypt/src
check_file sm3_asm.S wolfcrypt/src
Expand Down
4 changes: 4 additions & 0 deletions gen-asm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ fi
echo -n "Generating x86_64 assembly files ... "
ruby ./scripts/sm3/sm3.rb x86_64 sm3_asm
echo "Done"
echo "Generating SP files ... "
cd scripts
./gen-sp-sm2.sh
echo "Done"

8 changes: 8 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ fi
echo -n "Copying files into wolfssl ... "
cp sm2.h $WOLFSSL_DIR/wolfssl/wolfcrypt/
cp sm2.c $WOLFSSL_DIR/wolfcrypt/src/
cp sp_sm2_c32.c $WOLFSSL_DIR/wolfcrypt/src/
cp sp_sm2_c64.c $WOLFSSL_DIR/wolfcrypt/src/
cp sp_sm2_x86_64.c $WOLFSSL_DIR/wolfcrypt/src/
cp sp_sm2_x86_64_asm.S $WOLFSSL_DIR/wolfcrypt/src/
cp sp_sm2_arm32.c $WOLFSSL_DIR/wolfcrypt/src/
cp sp_sm2_cortexm.c $WOLFSSL_DIR/wolfcrypt/src/
cp sp_sm2_armthumb.c $WOLFSSL_DIR/wolfcrypt/src/
cp sp_sm2_arm64.c $WOLFSSL_DIR/wolfcrypt/src/
cp sm3.h $WOLFSSL_DIR/wolfssl/wolfcrypt/
cp sm3.c $WOLFSSL_DIR/wolfcrypt/src/
cp sm3_asm.S $WOLFSSL_DIR/wolfcrypt/src/
Expand Down
25 changes: 25 additions & 0 deletions scripts/gen-sp-sm2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/bin/sh

# Current directory is: wolfsm/scripts

OUT_DIR=..
if [ $# -eq 1 ]; then
OUT_DIR=$1
fi

echo "C32..."
ruby sp/sp_sm2.rb 32 >$OUT_DIR/sp_sm2_c32.c
echo "C64..."
ruby sp/sp_sm2.rb 64 >$OUT_DIR/sp_sm2_c64.c
echo "arm32..."
ruby sp/sp_sm2.rb ARM32 $OUT_DIR/sp_sm2_arm32
echo "arm thumb..."
ruby sp/sp_sm2.rb ARM_Thumb $OUT_DIR/sp_sm2_armthumb
echo "Cortex-M..."
ruby sp/sp_sm2.rb Thumb2 $OUT_DIR/sp_sm2_cortexm
echo "arm64..."
ruby sp/sp_sm2.rb ARM64 >$OUT_DIR/sp_sm2_arm64.c
echo "x86_64..."
ruby sp/sp_sm2.rb x86_64 $OUT_DIR/sp_sm2_x86_64_asm >$OUT_DIR/sp_sm2_x86_64.c
echo "Done"

2 changes: 1 addition & 1 deletion scripts/sm3/sm3.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# sm3.rb
#
# Copyright (C) 2006-2022 wolfSSL Inc.
# Copyright (C) 2006-2023 wolfSSL Inc.
#
# This file is part of wolfSSL.
#
Expand Down
2 changes: 1 addition & 1 deletion scripts/sm3/x86_64/sm3.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# sm3.rb
#
# Copyright (C) 2006-2020 wolfSSL Inc.
# Copyright (C) 2006-2023 wolfSSL Inc.
#
# This file is part of wolfSSL.
#
Expand Down
2 changes: 1 addition & 1 deletion scripts/sm3/x86_64/sm3_avx1.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# sm3_avx1.rb
#
# Copyright (C) 2006-2020 wolfSSL Inc.
# Copyright (C) 2006-2023 wolfSSL Inc.
#
# This file is part of wolfSSL.
#
Expand Down
2 changes: 1 addition & 1 deletion scripts/sm3/x86_64/sm3_avx1_rorx.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# sm3_avx1_rorx.rb
#
# Copyright (C) 2006-2020 wolfSSL Inc.
# Copyright (C) 2006-2023 wolfSSL Inc.
#
# This file is part of wolfSSL.
#
Expand Down
Loading