NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
lib/61073: libcrypto does not use the Poly1305 assembler, nor some of the aarch64 and riscv64 one
>Number: 61073
>Category: lib
>Synopsis: libcrypto does not use the Poly1305 assembler, nor some of the aarch64 and riscv64 one
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Nov 25 06:00:00 +0000 2026
>Originator: Showta Ishizaki
>Release: NetBSD 11.1
>Organization:
>Environment:
NetBSD techne.fml.org 11.1 NetBSD 11.1 (GENERIC) #0: Mon Nov 2 16:34:32 UTC 2026 mkrepro%mkrepro.NetBSD.org@localhost:/usr/src/sys/arch/amd64/compile/GENERIC amd64
>Description:
Comparing the openssl in pkgsrc with the one in base on 11.1/amd64,
chacha20-poly1305 in base is well under half the speed, while chacha20
and aes-gcm are about the same.
The arch poly1305.inc files add -DPOLY1305_ASM to POLY1305_CPPFLAGS, but
poly1305.inc reads POLY1305CPPFLAGS. The assembler is linked in and
never called. lib/59329 has POLY1305_ASM in its list of missing flags.
Going through the other arch files against what Configure picks for
3.5.7 turned up some more on aarch64 and riscv64.
On aarch64 "make regen" sends the output of sha512-armv8.pl to
/dev/stdout. That script chooses SHA-256 or SHA-512 by the name of its
output, so sha512-armv8.S has the SHA-256 code in it, and SHA512_ASM was
removed in October 2024 for want of the SHA-512 one. regen also passes
over md5-aarch64.pl, as it only looks for *arm*. BSAES_ASM,
OPENSSL_SM3_ASM and ECP_SM2P256_ASM are not defined although the
assembler is built, and the C half of the SM2 code is missing.
On riscv64 sm3-riscv64-zvksh.S is built, but not sm3_riscv.c, which
calls it, nor OPENSSL_SM3_ASM.
>How-To-Repeat:
On 11.1/amd64, base is 3.5.7 and pkgsrc 4.1.0:
$ /usr/bin/openssl speed -bytes 16384 -evp chacha20-poly1305
ChaCha20-Poly1305 726829.08k
$ /usr/pkg/bin/openssl speed -bytes 16384 -evp chacha20-poly1305
ChaCha20-Poly1305 2063429.17k
$ /usr/bin/openssl speed -bytes 16384 -evp chacha20
ChaCha20 3696410.03k
$ /usr/pkg/bin/openssl speed -bytes 16384 -evp chacha20
ChaCha20 3792185.30k
$ /usr/bin/openssl speed -bytes 16384 -evp aes-128-gcm
AES-128-GCM 4249309.75k
$ /usr/pkg/bin/openssl speed -bytes 16384 -evp aes-128-gcm
AES-128-GCM 4254140.98k
>Fix:
The diff below is against -current. It fixes the name and passes the
flag to all files, the way AESCPPFLAGS is since lib/59329, because
crypto/evp and the ciphers provider look at it too. powerpc and
powerpc64 also need poly1305_ppc.c, which is where poly1305_init() is.
The aarch64 regen is written the same way as in the amd64 Makefile.
I built libcrypto before and after and ran both with the same program:
the digests, the Poly1305 MAC, the AES, SM4 and ChaCha20-Poly1305 modes
and SM2 signatures. That was done on amd64, i386, aarch64, riscv64,
sparc64, mipsn64el, macppc and powerpc64, and the results are identical.
I also checked that the assembler is reached with the diff and not
without it. On sparc64 the library without it was the one in 11.1, and
there I could see the difference for ChaCha20-Poly1305 only. The macppc
was a G4 under qemu, so it was the floating point code that ran; on
powerpc64 I did not get to the VSX code. On amd64 and i386, where the
speed means something, Poly1305 went from about 680 to 1560 MB/s and
from 605 to 1370.
The .S files are not in the diff: with it applied, make regen in
arch/aarch64 writes sha256-armv8.S and md5-aarch64.S, rewrites
sha512-armv8.S, and leaves the others as they are.
--- crypto/external/apache2/openssl/lib/libcrypto/arch/aarch64/Makefile
+++ crypto/external/apache2/openssl/lib/libcrypto/arch/aarch64/Makefile
@@ -6,9 +6,15 @@ CRYPTODIST=${NETBSDSRCDIR}/crypto
.include "${NETBSDSRCDIR}/crypto/Makefile.openssl"
regen:
- for i in $$(find ${OPENSSLSRC} -name \*arm\*.pl); do \
+ for i in $$(find ${OPENSSLSRC} -name \*arm\*.pl) \
+ $$(find ${OPENSSLSRC} -name \*aarch64\*.pl); do \
case $$i in \
(*/charmap.pl|*/arm-xlate.pl|*/*v4*|*/bsaes-armv7.pl);; \
+ (*/sha512-armv8.pl) \
+ perl -I${OPENSSLSRC}/crypto/perlasm \
+ -I${OPENSSLSRC}/crypto/bn/asm $$i linux64 sha256-armv8.S; \
+ perl -I${OPENSSLSRC}/crypto/perlasm \
+ -I${OPENSSLSRC}/crypto/bn/asm $$i linux64 sha512-armv8.S;; \
(*) perl -I${OPENSSLSRC}/crypto/perlasm \
-I${OPENSSLSRC}/crypto/bn/asm $$i linux64 /dev/stdout \
> $$(basename $$i .pl).S;; \
--- crypto/external/apache2/openssl/lib/libcrypto/arch/aarch64/aes.inc
+++ crypto/external/apache2/openssl/lib/libcrypto/arch/aarch64/aes.inc
@@ -1,5 +1,5 @@
.PATH.S: ${.PARSEDIR}
-AESCPPFLAGS = -DVPAES_ASM
+AESCPPFLAGS = -DVPAES_ASM -DBSAES_ASM
AES_SRCS += aes_core.c aes_cbc.c vpaes-armv8.S aesv8-armx.S aes-gcm-armv8_64.S
AES_SRCS += aes-gcm-armv8-unroll8_64.S bsaes-armv8.S
--- crypto/external/apache2/openssl/lib/libcrypto/arch/aarch64/ec.inc
+++ crypto/external/apache2/openssl/lib/libcrypto/arch/aarch64/ec.inc
@@ -1,7 +1,8 @@
.PATH.S: ${.PARSEDIR}
-ECCPPFLAGS+=-DECP_NISTZ256_ASM
+ECCPPFLAGS+=-DECP_NISTZ256_ASM -DECP_SM2P256_ASM
EC_SRCS += ecp_nistz256-armv8.S ecp_sm2p256-armv8.S sm3-armv8.S sm4-armv8.S
EC_SRCS += vpsm4-armv8.S vpsm4_ex-armv8.S
+EC_SRCS += ecp_sm2p256.c ecp_sm2p256_table.c
ECNI = yes
.if ${MACHINE_ARCH} == "aarch64eb"
--- /dev/null
+++ crypto/external/apache2/openssl/lib/libcrypto/arch/aarch64/md5.inc
@@ -0,0 +1,4 @@
+.PATH.S: ${.PARSEDIR}
+MD5_SRCS = md5-aarch64.S
+MD5CPPFLAGS = -DMD5_ASM
+.include "../../md5.inc"
--- crypto/external/apache2/openssl/lib/libcrypto/arch/aarch64/poly1305.inc
+++ crypto/external/apache2/openssl/lib/libcrypto/arch/aarch64/poly1305.inc
@@ -1,6 +1,6 @@
.PATH.S: ${.PARSEDIR}
POLY1305_SRCS = poly1305-armv8.S
-POLY1305_CPPFLAGS+=-DPOLY1305_ASM
+POLY1305CPPFLAGS+=-DPOLY1305_ASM
.include "../../poly1305.inc"
--- crypto/external/apache2/openssl/lib/libcrypto/arch/aarch64/sha.inc
+++ crypto/external/apache2/openssl/lib/libcrypto/arch/aarch64/sha.inc
@@ -1,5 +1,5 @@
.PATH.S: ${.PARSEDIR}
-SHA_SRCS = sha1-armv8.S sha512-armv8.S keccak1600-armv8.S
-SHACPPFLAGS = -DSHA1_ASM -DSHA256_ASM -DKECCAK1600_ASM
+SHA_SRCS = sha1-armv8.S sha256-armv8.S sha512-armv8.S keccak1600-armv8.S
+SHACPPFLAGS = -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DKECCAK1600_ASM
KECCAKNI = yes
.include "../../sha.inc"
--- /dev/null
+++ crypto/external/apache2/openssl/lib/libcrypto/arch/aarch64/sm3.inc
@@ -0,0 +1,2 @@
+SM3CPPFLAGS = -DOPENSSL_SM3_ASM
+.include "../../sm3.inc"
--- crypto/external/apache2/openssl/lib/libcrypto/arch/i386/poly1305.inc
+++ crypto/external/apache2/openssl/lib/libcrypto/arch/i386/poly1305.inc
@@ -1,6 +1,6 @@
.PATH.S: ${.PARSEDIR}
POLY1305_SRCS = poly1305-x86.S
-POLY1305_CPPFLAGS+=-DPOLY1305_ASM
+POLY1305CPPFLAGS+=-DPOLY1305_ASM
.include "../../poly1305.inc"
--- crypto/external/apache2/openssl/lib/libcrypto/arch/mips/poly1305.inc
+++ crypto/external/apache2/openssl/lib/libcrypto/arch/mips/poly1305.inc
@@ -5,7 +5,7 @@
.PATH.S: ${.PARSEDIR}
POLY1305_SRCS = poly1305-mips64.S
-POLY1305_CPPFLAGS+=-DPOLY1305_ASM
+POLY1305CPPFLAGS+=-DPOLY1305_ASM
.endif
--- crypto/external/apache2/openssl/lib/libcrypto/arch/powerpc/poly1305.inc
+++ crypto/external/apache2/openssl/lib/libcrypto/arch/powerpc/poly1305.inc
@@ -1,6 +1,6 @@
.PATH.S: ${.PARSEDIR}
-POLY1305_SRCS = poly1305-ppc.S poly1305-ppcfp.S
-POLY1305_CPPFLAGS+=-DPOLY1305_ASM
+POLY1305_SRCS = poly1305_ppc.c poly1305-ppc.S poly1305-ppcfp.S
+POLY1305CPPFLAGS+=-DPOLY1305_ASM
.include "../../poly1305.inc"
--- crypto/external/apache2/openssl/lib/libcrypto/arch/powerpc64/poly1305.inc
+++ crypto/external/apache2/openssl/lib/libcrypto/arch/powerpc64/poly1305.inc
@@ -1,6 +1,6 @@
.PATH.S: ${.PARSEDIR}
-POLY1305_SRCS = poly1305-ppc.S poly1305-ppcfp.S
-POLY1305_CPPFLAGS+=-DPOLY1305_ASM
+POLY1305_SRCS = poly1305_ppc.c poly1305-ppc.S poly1305-ppcfp.S
+POLY1305CPPFLAGS+=-DPOLY1305_ASM
.include "../../poly1305.inc"
--- /dev/null
+++ crypto/external/apache2/openssl/lib/libcrypto/arch/riscv64/sm3.inc
@@ -0,0 +1,3 @@
+SM3_SRCS += sm3_riscv.c
+SM3CPPFLAGS = -DOPENSSL_SM3_ASM
+.include "../../sm3.inc"
--- crypto/external/apache2/openssl/lib/libcrypto/arch/sparc/poly1305.inc
+++ crypto/external/apache2/openssl/lib/libcrypto/arch/sparc/poly1305.inc
@@ -2,7 +2,7 @@
.PATH.S: ${.PARSEDIR}
POLY1305_SRCS = poly1305-sparcv9.S
-POLY1305_CPPFLAGS+=-DPOLY1305_ASM
+POLY1305CPPFLAGS+=-DPOLY1305_ASM
AFLAGS.poly1305-sparcv9.S+= -Wa,-Av9
.endif
--- crypto/external/apache2/openssl/lib/libcrypto/arch/sparc64/poly1305.inc
+++ crypto/external/apache2/openssl/lib/libcrypto/arch/sparc64/poly1305.inc
@@ -1,6 +1,6 @@
.PATH.S: ${.PARSEDIR}
POLY1305_SRCS = poly1305-sparcv9.S
-POLY1305_CPPFLAGS+=-DPOLY1305_ASM
+POLY1305CPPFLAGS+=-DPOLY1305_ASM
.include "../../poly1305.inc"
--- crypto/external/apache2/openssl/lib/libcrypto/arch/x86_64/poly1305.inc
+++ crypto/external/apache2/openssl/lib/libcrypto/arch/x86_64/poly1305.inc
@@ -1,6 +1,6 @@
.PATH.S: ${.PARSEDIR}
POLY1305_SRCS = poly1305-x86_64.S
-POLY1305_CPPFLAGS+=-DPOLY1305_ASM
+POLY1305CPPFLAGS+=-DPOLY1305_ASM
.include "../../poly1305.inc"
--- crypto/external/apache2/openssl/lib/libcrypto/poly1305.inc
+++ crypto/external/apache2/openssl/lib/libcrypto/poly1305.inc
@@ -7,6 +7,8 @@ poly1305.c \
SRCS += ${POLY1305_SRCS}
+CPPFLAGS+=${POLY1305CPPFLAGS}
+
.for cryptosrc in ${POLY1305_SRCS}
CPPFLAGS.${cryptosrc} += -I${OPENSSLSRC}/crypto/poly1305 ${POLY1305CPPFLAGS}
.endfor
Home |
Main Index |
Thread Index |
Old Index