Skip to content

Commit 4693ee0

Browse files
committed
PPC64/PPC32 ASM: AES, SHA-2, SHA-3
PPC64: - Added AES-ECB/CBC/CTR/GCM/XTS using crypto instructions - Added SHA-256/512 using base scalar and crypto instructions - Added SHA-3 using base scalar and POWER8 VSX - Added SHA-3 x2/x3 but disabled compilation. - Added CPU id flags. - Changed the constant data format to be consistent with other platforms. PPC32: - Added AES-ECB/CBC/CTR/GCM/XTS using base scalar - Added SHA-256/512 using base scalar - Added SHA-3 using base scalar
1 parent dd6da70 commit 4693ee0

30 files changed

Lines changed: 86242 additions & 2449 deletions

.wolfssl_known_macro_extras

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ WOLFSSL_SECURE_RENEGOTIATION_ON_BY_DEFAULT
922922
WOLFSSL_SERVER_EXAMPLE
923923
WOLFSSL_SETTINGS_FILE
924924
WOLFSSL_SHA256_ALT_CH_MAJ
925+
WOLFSSL_SHA3_PPC64_BLOCKS_N
925926
WOLFSSL_SHA512_HASHTYPE
926927
WOLFSSL_SHUTDOWNONCE
927928
WOLFSSL_SILABS_TRNG

configure.ac

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3943,6 +3943,7 @@ then
39433943
done
39443944

39453945
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_PPC32_ASM"
3946+
AM_CCASFLAGS="$AM_CCASFLAGS -DEXTERNAL_OPTS_OPENVPN"
39463947
AC_MSG_NOTICE([32-bit PowerPC assembly for SHA-256])
39473948
ENABLED_PPC32_ASM=yes
39483949

@@ -3951,6 +3952,11 @@ then
39513952
else
39523953
AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_PPC32_ASM"
39533954
fi
3955+
if test "$ENABLED_PPC32_ASM_INLINE_REG" = "yes"; then
3956+
# The inline-register variant names GPRs (r0..r31) in inline assembly,
3957+
# which the PowerPC assembler only accepts with -mregnames.
3958+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_PPC32_ASM_INLINE_REG -Wa,-mregnames"
3959+
fi
39543960
if test "$ENABLED_PPC32_ASM_SMALL" = "yes"; then
39553961
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_PPC32_ASM_SMALL"
39563962
AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_PPC32_ASM_SMALL"
@@ -3986,8 +3992,14 @@ then
39863992
small)
39873993
ENABLED_PPC64_ASM_SMALL=yes
39883994
;;
3995+
crypto)
3996+
ENABLED_PPC64_ASM_CRYPTO=yes
3997+
;;
3998+
power8)
3999+
ENABLED_PPC64_ASM_POWER8=yes
4000+
;;
39894001
*)
3990-
AC_MSG_ERROR([Invalid RISC-V option [yes,inline,small]: $ENABLED_PPC64_ASM.])
4002+
AC_MSG_ERROR([Invalid PPC64 option [yes,inline,small,crypto,power8]: $ENABLED_PPC64_ASM.])
39914003
break
39924004
;;
39934005
esac
@@ -4007,6 +4019,20 @@ if test "$ENABLED_PPC64_ASM_SMALL" = "yes"; then
40074019
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_PPC64_ASM_SMALL"
40084020
AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_PPC64_ASM_SMALL"
40094021
fi
4022+
# POWER8 vector-crypto (vshasigmaw) SHA-256, selected at run time. The
4023+
# generated code marks the relevant function/section as POWER8 itself, so no
4024+
# global -mcpu=power8 is needed and the rest of the library stays portable.
4025+
if test "$ENABLED_PPC64_ASM_CRYPTO" = "yes"; then
4026+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_PPC64_ASM_CRYPTO"
4027+
AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_PPC64_ASM_CRYPTO"
4028+
fi
4029+
# POWER8 VSX (vrld) SHA-3, selected at run time. Like the crypto variant the
4030+
# generated code marks its own function/section as POWER8, so no global
4031+
# -mcpu=power8 is needed and the rest of the library stays portable.
4032+
if test "$ENABLED_PPC64_ASM_POWER8" = "yes"; then
4033+
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_PPC64_ASM_POWER8"
4034+
AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_PPC64_ASM_POWER8"
4035+
fi
40104036

40114037

40124038
# Xilinx hardened crypto
@@ -4691,6 +4717,9 @@ fi
46914717
if test "$ENABLED_SHA512" = "yes"
46924718
then
46934719
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SHA512"
4720+
# The SHA-512 transform is asm on some targets (PPC); the .S is guarded by
4721+
# WOLFSSL_SHA512/WOLFSSL_SHA384 so the assembler needs the macro too.
4722+
AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_SHA512"
46944723
fi
46954724

46964725
# SHA-256 Hash DRBG (SP 800-90A) -- sub-option of hashdrbg
@@ -4734,6 +4763,7 @@ fi
47344763
if test "$ENABLED_SHA384" = "yes"
47354764
then
47364765
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SHA384"
4766+
AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_SHA384"
47374767
fi
47384768

47394769

@@ -7431,6 +7461,9 @@ fi
74317461
if test "$ENABLED_SHA3" != "no"
74327462
then
74337463
AM_CFLAGS="$AM_CFLAGS -DWOLFSSL_SHA3"
7464+
# The SHA-3 block transform is asm on some targets (PPC); the .S is guarded
7465+
# by WOLFSSL_SHA3 so the assembler needs the macro too.
7466+
AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_SHA3"
74347467
fi
74357468
74367469
# Set SHAKE128 flags
@@ -11843,28 +11876,54 @@ then
1184311876
if test "$ENABLED_AESGCM" = "word32"
1184411877
then
1184511878
AM_CFLAGS="$AM_CFLAGS -DGCM_WORD32"
11879+
AM_CCASFLAGS="$AM_CCASFLAGS -DGCM_WORD32"
1184611880
ENABLED_AESGCM=yes
1184711881
fi
1184811882
1184911883
if test "$ENABLED_AESGCM" = "small" || test "$ENABLED_LOWRESOURCE" = "yes"
1185011884
then
1185111885
AM_CFLAGS="$AM_CFLAGS -DGCM_SMALL"
11886+
AM_CCASFLAGS="$AM_CCASFLAGS -DGCM_SMALL"
1185211887
ENABLED_AESGCM=yes
1185311888
fi
1185411889
1185511890
if test "$ENABLED_AESGCM" = "table"
1185611891
then
1185711892
AM_CFLAGS="$AM_CFLAGS -DGCM_TABLE"
11893+
AM_CCASFLAGS="$AM_CCASFLAGS -DGCM_TABLE"
1185811894
ENABLED_AESGCM=yes
1185911895
fi
1186011896
1186111897
if test "$ENABLED_AESGCM" = "4bit"
1186211898
then
1186311899
AM_CFLAGS="$AM_CFLAGS -DGCM_TABLE_4BIT"
11900+
AM_CCASFLAGS="$AM_CCASFLAGS -DGCM_TABLE_4BIT"
1186411901
ENABLED_AESGCM=yes
1186511902
fi
1186611903
11904+
# The GCM table layout macro must reach assembled (.S) sources too: the
11905+
# PPC asm GCM_gmult_len is a single file with both layouts guarded by
11906+
# GCM_TABLE / GCM_TABLE_4BIT. Default (no explicit table choice) is 4bit.
11907+
case " $AM_CCASFLAGS " in
11908+
*" -DGCM_TABLE "*|*" -DGCM_TABLE_4BIT "*|*" -DGCM_SMALL "*|*" -DGCM_WORD32 "*) ;;
11909+
*) AM_CCASFLAGS="$AM_CCASFLAGS -DGCM_TABLE_4BIT" ;;
11910+
esac
11911+
1186711912
AM_CFLAGS="$AM_CFLAGS -DHAVE_AESGCM"
11913+
AM_CCASFLAGS="$AM_CCASFLAGS -DHAVE_AESGCM"
11914+
fi
11915+
# AES-CTR may be turned on by many presets above; mirror the feature macro to
11916+
# the assembler flags so the AES_CTR_encrypt in the PPC asm is emitted.
11917+
if test "$ENABLED_AESCTR" = "yes"
11918+
then
11919+
AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_AES_COUNTER"
11920+
fi
11921+
# Asm sources include settings.h, which enforces that AES-XTS streaming
11922+
# requires AES-XTS. Mirror the base WOLFSSL_AES_XTS macro to the assembler
11923+
# flags so that check is satisfied (it is otherwise only set for C sources).
11924+
if test "$ENABLED_AESXTS" = "yes"
11925+
then
11926+
AM_CCASFLAGS="$AM_CCASFLAGS -DWOLFSSL_AES_XTS"
1186811927
fi
1186911928
if test "$ENABLED_AESGCM_STREAM" != "no"
1187011929
then
@@ -12993,6 +13052,10 @@ if test "$ENABLED_PPC64_ASM_INLINE_REG" = "yes"
1299313052
then
1299413053
ENABLED_PPC64_ASM="inline C Reg"
1299513054
fi
13055+
if test "$ENABLED_PPC64_ASM_CRYPTO" = "yes"
13056+
then
13057+
ENABLED_PPC64_ASM="$ENABLED_PPC64_ASM + crypto"
13058+
fi
1299613059
echo " * PPC64 ASM $ENABLED_PPC64_ASM"
1299713060
echo " * Write duplicate: $ENABLED_WRITEDUP"
1299813061
echo " * Xilinx Hardware Acc.: $ENABLED_XILINX"

0 commit comments

Comments
 (0)