summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoraoeu <aoeuh@yandex.ru>2021-03-16 15:19:33 +0000
committeraoeu <aoeuh@yandex.ru>2021-03-16 15:19:33 +0000
commitbb013624dddb99407661c35aaca5e64751b3da94 (patch)
tree624cd926ba220d995b492dcf24a008f9d316e796 /lib
parent0e243256eae5c41609f49f7c502c8ece4d002eba (diff)
downloadnss-hg-bb013624dddb99407661c35aaca5e64751b3da94.tar.gz
Bug 1698320 - replace __builtin_cpu_supports("vsx") with ppc_crypto_support() for clang. r=bbeurdouche
Differential Revision: https://phabricator.services.mozilla.com/D108354
Diffstat (limited to 'lib')
-rw-r--r--lib/freebl/Makefile4
-rw-r--r--lib/freebl/chacha20-ppc64le.S138
-rw-r--r--lib/freebl/chacha20poly1305.c10
-rw-r--r--lib/freebl/freebl.gyp8
4 files changed, 146 insertions, 14 deletions
diff --git a/lib/freebl/Makefile b/lib/freebl/Makefile
index 10654360c..ef93d075f 100644
--- a/lib/freebl/Makefile
+++ b/lib/freebl/Makefile
@@ -298,8 +298,10 @@ ifdef USE_64
PPC_ABI := $(shell $(CC) -dM -E - < /dev/null | awk '$$2 == "_CALL_ELF" {print $$3}')
ifeq ($(PPC_ABI),2)
ASFILES += sha512-p8.s
+ ifeq ($(OS_TEST),ppc64le)
EXTRA_SRCS += chacha20poly1305-ppc.c
ASFILES += chacha20-ppc64le.s
+ endif # ppc64le
endif
endif # USE_64
endif # ppc
@@ -764,7 +766,9 @@ $(OBJDIR)/$(PROG_PREFIX)gcm$(OBJ_SUFFIX): CFLAGS += -mcrypto -maltivec -mvsx
$(OBJDIR)/$(PROG_PREFIX)rijndael$(OBJ_SUFFIX): CFLAGS += -mcrypto -maltivec -mvsx
$(OBJDIR)/$(PROG_PREFIX)sha512$(OBJ_SUFFIX): CFLAGS += -mcrypto -maltivec -mvsx \
-funroll-loops -fpeel-loops
+ifeq ($(OS_TEST),ppc64le)
$(OBJDIR)/$(PROG_PREFIX)chacha20poly1305-ppc$(OBJ_SUFFIX): CFLAGS += -mcrypto -maltivec -mvsx
+endif # ppc64le
endif
endif
diff --git a/lib/freebl/chacha20-ppc64le.S b/lib/freebl/chacha20-ppc64le.S
index 241bef41f..487ff830a 100644
--- a/lib/freebl/chacha20-ppc64le.S
+++ b/lib/freebl/chacha20-ppc64le.S
@@ -11,14 +11,136 @@
# vs57 (v25) : increment for "converted" counter
# vs60 - vs63 (v28 - v31) : constants for rotate left or vpermxor
-#include <ppc-asm.h>
-
-.equ rSIZE, r3
-.equ rDST, r4
-.equ rSRC, r5
-.equ rKEY, r6
-.equ rNONCE, r7
-.equ rCNTR, r8
+#define r0 0
+#define sp 1
+#define r2 2
+#define rSIZE 3
+#define rDST 4
+#define rSRC 5
+#define rKEY 6
+#define rNONCE 7
+#define rCNTR 8
+#define r9 9
+#define r10 10
+#define r11 11
+#define r12 12
+#define r13 13
+#define r14 14
+#define r15 15
+#define r16 16
+#define r17 17
+#define r18 18
+#define r19 19
+#define r20 20
+#define r21 21
+#define r22 22
+#define r23 23
+#define r24 24
+#define r25 25
+#define r26 26
+#define r27 27
+#define r28 28
+#define r29 29
+#define r30 30
+#define r31 31
+
+#define v0 0
+#define v1 1
+#define v2 2
+#define v3 3
+#define v4 4
+#define v5 5
+#define v6 6
+#define v7 7
+#define v8 8
+#define v9 9
+#define v10 10
+#define v11 11
+#define v12 12
+#define v13 13
+#define v14 14
+#define v15 15
+#define v16 16
+#define v17 17
+#define v18 18
+#define v19 19
+#define v20 20
+#define v21 21
+#define v22 22
+#define v23 23
+#define v24 24
+#define v25 25
+#define v26 26
+#define v27 27
+#define v28 28
+#define v29 29
+#define v30 30
+#define v31 31
+
+#define vs0 0
+#define vs1 1
+#define vs2 2
+#define vs3 3
+#define vs4 4
+#define vs5 5
+#define vs6 6
+#define vs7 7
+#define vs8 8
+#define vs9 9
+#define vs10 10
+#define vs11 11
+#define vs12 12
+#define vs13 13
+#define vs14 14
+#define vs15 15
+#define vs16 16
+#define vs17 17
+#define vs18 18
+#define vs19 19
+#define vs20 20
+#define vs21 21
+#define vs22 22
+#define vs23 23
+#define vs24 24
+#define vs25 25
+#define vs26 26
+#define vs27 27
+#define vs28 28
+#define vs29 29
+#define vs30 30
+#define vs31 31
+#define vs32 32
+#define vs33 33
+#define vs34 34
+#define vs35 35
+#define vs36 36
+#define vs37 37
+#define vs38 38
+#define vs39 39
+#define vs40 40
+#define vs41 41
+#define vs42 42
+#define vs43 43
+#define vs44 44
+#define vs45 45
+#define vs46 46
+#define vs47 47
+#define vs48 48
+#define vs49 49
+#define vs50 50
+#define vs51 51
+#define vs52 52
+#define vs53 53
+#define vs54 54
+#define vs55 55
+#define vs56 56
+#define vs57 57
+#define vs58 58
+#define vs59 59
+#define vs60 60
+#define vs61 61
+#define vs62 62
+#define vs63 63
.abiversion 2
.section ".data"
diff --git a/lib/freebl/chacha20poly1305.c b/lib/freebl/chacha20poly1305.c
index da3d4c572..cfb56fca6 100644
--- a/lib/freebl/chacha20poly1305.c
+++ b/lib/freebl/chacha20poly1305.c
@@ -220,7 +220,7 @@ ChaCha20Xor(uint8_t *output, uint8_t *block, uint32_t len, uint8_t *k,
} else
#elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__) && \
!defined(NSS_DISABLE_ALTIVEC) && !defined(NSS_DISABLE_CRYPTO_VSX)
- if (__builtin_cpu_supports("vsx")) {
+ if (ppc_crypto_support()) {
chacha20vsx(len, output, block, k, nonce, ctr);
} else
#endif
@@ -293,7 +293,7 @@ ChaCha20Poly1305_Seal(const ChaCha20Poly1305Context *ctx, unsigned char *output,
} else
#elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__) && \
!defined(NSS_DISABLE_ALTIVEC) && !defined(NSS_DISABLE_CRYPTO_VSX)
- if (__builtin_cpu_supports("vsx")) {
+ if (ppc_crypto_support()) {
Chacha20Poly1305_vsx_aead_encrypt(
(uint8_t *)ctx->key, (uint8_t *)nonce, adLen, (uint8_t *)ad, inputLen,
(uint8_t *)input, output, output + inputLen);
@@ -362,7 +362,7 @@ ChaCha20Poly1305_Open(const ChaCha20Poly1305Context *ctx, unsigned char *output,
} else
#elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__) && \
!defined(NSS_DISABLE_ALTIVEC) && !defined(NSS_DISABLE_CRYPTO_VSX)
- if (__builtin_cpu_supports("vsx")) {
+ if (ppc_crypto_support()) {
res = Chacha20Poly1305_vsx_aead_decrypt(
(uint8_t *)ctx->key, (uint8_t *)nonce, adLen, (uint8_t *)ad, ciphertextLen,
(uint8_t *)output, (uint8_t *)input, (uint8_t *)input + ciphertextLen);
@@ -418,7 +418,7 @@ ChaCha20Poly1305_Encrypt(const ChaCha20Poly1305Context *ctx,
} else
#elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__) && \
!defined(NSS_DISABLE_ALTIVEC) && !defined(NSS_DISABLE_CRYPTO_VSX)
- if (__builtin_cpu_supports("vsx")) {
+ if (ppc_crypto_support()) {
Chacha20Poly1305_vsx_aead_encrypt(
(uint8_t *)ctx->key, (uint8_t *)nonce, adLen, (uint8_t *)ad, inputLen,
(uint8_t *)input, output, outTag);
@@ -472,7 +472,7 @@ ChaCha20Poly1305_Decrypt(const ChaCha20Poly1305Context *ctx,
} else
#elif defined(__powerpc64__) && defined(__LITTLE_ENDIAN__) && \
!defined(NSS_DISABLE_ALTIVEC) && !defined(NSS_DISABLE_CRYPTO_VSX)
- if (__builtin_cpu_supports("vsx")) {
+ if (ppc_crypto_support()) {
res = Chacha20Poly1305_vsx_aead_decrypt(
(uint8_t *)ctx->key, (uint8_t *)nonce, adLen, (uint8_t *)ad, ciphertextLen,
(uint8_t *)output, (uint8_t *)input, (uint8_t *)tagIn);
diff --git a/lib/freebl/freebl.gyp b/lib/freebl/freebl.gyp
index 19807e401..86f05aa33 100644
--- a/lib/freebl/freebl.gyp
+++ b/lib/freebl/freebl.gyp
@@ -414,7 +414,13 @@
'gcm-aes-aarch64_c_lib',
],
}],
- [ 'disable_altivec==0 and (target_arch=="ppc64" or target_arch=="ppc64le")', {
+ [ 'disable_altivec==0 and target_arch=="ppc64"', {
+ 'dependencies': [
+ 'gcm-aes-ppc_c_lib',
+ 'gcm-sha512-ppc_c_lib',
+ ],
+ }],
+ [ 'disable_altivec==0 and target_arch=="ppc64le"', {
'dependencies': [
'gcm-aes-ppc_c_lib',
'gcm-sha512-ppc_c_lib',