Provide an implementation of bn_sqr() that calls s2n-bignum's bignum_sqr().
authorjsing <jsing@openbsd.org>
Sat, 21 Jan 2023 17:29:56 +0000 (17:29 +0000)
committerjsing <jsing@openbsd.org>
Sat, 21 Jan 2023 17:29:56 +0000 (17:29 +0000)
ok tb@

lib/libcrypto/Makefile
lib/libcrypto/arch/amd64/Makefile.inc
lib/libcrypto/bn/arch/amd64/bn_arch.c [new file with mode: 0644]

index 9f223f5..451a480 100644 (file)
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.92 2023/01/20 10:04:33 jsing Exp $
+# $OpenBSD: Makefile,v 1.93 2023/01/21 17:29:56 jsing Exp $
 
 LIB=   crypto
 LIBREBUILD=y
@@ -733,13 +733,14 @@ SRCS+= x509spki.c
 SRCS+= x509type.c
 SRCS+= x_all.c
 
-.PATH: ${.CURDIR}/arch/${MACHINE_CPU} \
+.PATH: ${LCRYPTO_SRC}/arch/${MACHINE_CPU} \
        ${LCRYPTO_SRC} \
        ${LCRYPTO_SRC}/aes \
        ${LCRYPTO_SRC}/asn1 \
        ${LCRYPTO_SRC}/bf \
        ${LCRYPTO_SRC}/bio \
        ${LCRYPTO_SRC}/bn \
+       ${LCRYPTO_SRC}/bn/arch/${MACHINE_CPU} \
        ${LCRYPTO_SRC}/bn/asm \
        ${LCRYPTO_SRC}/buffer \
        ${LCRYPTO_SRC}/bytestring \
index dc615ec..1fd9f68 100644 (file)
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.9 2023/01/14 15:45:43 jsing Exp $
+# $OpenBSD: Makefile.inc,v 1.10 2023/01/21 17:29:56 jsing Exp $
 
 # amd64-specific libcrypto build rules
 
@@ -26,6 +26,11 @@ CFLAGS+= -DOPENSSL_BN_ASM_MONT5
 SSLASM+= bn x86_64-mont5
 CFLAGS+= -DOPENSSL_BN_ASM_GF2m
 SSLASM+= bn x86_64-gf2m
+
+# bn s2n-bignum
+SRCS += bn_arch.c
+SRCS += bignum_sqr.S
+
 # camellia
 SRCS+= cmll_misc.c
 SSLASM+= camellia cmll-x86_64
diff --git a/lib/libcrypto/bn/arch/amd64/bn_arch.c b/lib/libcrypto/bn/arch/amd64/bn_arch.c
new file mode 100644 (file)
index 0000000..2405759
--- /dev/null
@@ -0,0 +1,32 @@
+/*     $OpenBSD: bn_arch.c,v 1.1 2023/01/21 17:29:56 jsing Exp $ */
+/*
+ * Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <openssl/bn.h>
+
+#include "bn_arch.h"
+#include "bn_local.h"
+#include "s2n_bignum.h"
+
+#ifdef HAVE_BN_SQR
+int
+bn_sqr(BIGNUM *r, const BIGNUM *a, int rn, BN_CTX *ctx)
+{
+       bignum_sqr(rn, (uint64_t *)r->d, a->top, (uint64_t *)a->d);
+
+       return 1;
+}
+#endif