From 33fa82afac082822a8dea9e89460d16d19cfbf29 Mon Sep 17 00:00:00 2001 From: jsing Date: Mon, 23 Jan 2023 12:09:06 +0000 Subject: [PATCH] Move bn_sqr_words from bn_asm.c to bn_sqr.c. This is wrapped with #ifndef HAVE_BN_SQR_WORDS, which is then defined for architectures that provide their own assembly versions. --- lib/libcrypto/bn/arch/amd64/bn_arch.h | 3 +- lib/libcrypto/bn/arch/i386/bn_arch.h | 3 +- lib/libcrypto/bn/arch/mips64/bn_arch.h | 3 +- lib/libcrypto/bn/arch/powerpc/bn_arch.h | 3 +- lib/libcrypto/bn/arch/sparc/bn_arch.h | 3 +- lib/libcrypto/bn/bn_asm.c | 54 +--------------------- lib/libcrypto/bn/bn_sqr.c | 59 ++++++++++++++++++++++++- 7 files changed, 69 insertions(+), 59 deletions(-) diff --git a/lib/libcrypto/bn/arch/amd64/bn_arch.h b/lib/libcrypto/bn/arch/amd64/bn_arch.h index 2d11fbd7c22..e8c9986bb30 100644 --- a/lib/libcrypto/bn/arch/amd64/bn_arch.h +++ b/lib/libcrypto/bn/arch/amd64/bn_arch.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_arch.h,v 1.5 2023/01/23 12:02:48 jsing Exp $ */ +/* $OpenBSD: bn_arch.h,v 1.6 2023/01/23 12:09:06 jsing Exp $ */ /* * Copyright (c) 2023 Joel Sing * @@ -30,6 +30,7 @@ #define HAVE_BN_SQR #define HAVE_BN_SQR_COMBA4 #define HAVE_BN_SQR_COMBA8 +#define HAVE_BN_SQR_WORDS #define HAVE_BN_SUB_WORDS diff --git a/lib/libcrypto/bn/arch/i386/bn_arch.h b/lib/libcrypto/bn/arch/i386/bn_arch.h index 18d7e519ec6..eeb273583ae 100644 --- a/lib/libcrypto/bn/arch/i386/bn_arch.h +++ b/lib/libcrypto/bn/arch/i386/bn_arch.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_arch.h,v 1.4 2023/01/23 12:02:48 jsing Exp $ */ +/* $OpenBSD: bn_arch.h,v 1.5 2023/01/23 12:09:06 jsing Exp $ */ /* * Copyright (c) 2023 Joel Sing * @@ -29,6 +29,7 @@ #define HAVE_BN_SQR_COMBA4 #define HAVE_BN_SQR_COMBA8 +#define HAVE_BN_SQR_WORDS #define HAVE_BN_SUB_WORDS diff --git a/lib/libcrypto/bn/arch/mips64/bn_arch.h b/lib/libcrypto/bn/arch/mips64/bn_arch.h index f53c75472c1..f7676611d7a 100644 --- a/lib/libcrypto/bn/arch/mips64/bn_arch.h +++ b/lib/libcrypto/bn/arch/mips64/bn_arch.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_arch.h,v 1.5 2023/01/23 12:02:48 jsing Exp $ */ +/* $OpenBSD: bn_arch.h,v 1.6 2023/01/23 12:09:06 jsing Exp $ */ /* * Copyright (c) 2023 Joel Sing * @@ -30,6 +30,7 @@ #define HAVE_BN_SQR_COMBA4 #define HAVE_BN_SQR_COMBA8 +#define HAVE_BN_SQR_WORDS #define HAVE_BN_SUB_WORDS diff --git a/lib/libcrypto/bn/arch/powerpc/bn_arch.h b/lib/libcrypto/bn/arch/powerpc/bn_arch.h index 18d7e519ec6..eeb273583ae 100644 --- a/lib/libcrypto/bn/arch/powerpc/bn_arch.h +++ b/lib/libcrypto/bn/arch/powerpc/bn_arch.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_arch.h,v 1.4 2023/01/23 12:02:48 jsing Exp $ */ +/* $OpenBSD: bn_arch.h,v 1.5 2023/01/23 12:09:06 jsing Exp $ */ /* * Copyright (c) 2023 Joel Sing * @@ -29,6 +29,7 @@ #define HAVE_BN_SQR_COMBA4 #define HAVE_BN_SQR_COMBA8 +#define HAVE_BN_SQR_WORDS #define HAVE_BN_SUB_WORDS diff --git a/lib/libcrypto/bn/arch/sparc/bn_arch.h b/lib/libcrypto/bn/arch/sparc/bn_arch.h index 18d7e519ec6..eeb273583ae 100644 --- a/lib/libcrypto/bn/arch/sparc/bn_arch.h +++ b/lib/libcrypto/bn/arch/sparc/bn_arch.h @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_arch.h,v 1.4 2023/01/23 12:02:48 jsing Exp $ */ +/* $OpenBSD: bn_arch.h,v 1.5 2023/01/23 12:09:06 jsing Exp $ */ /* * Copyright (c) 2023 Joel Sing * @@ -29,6 +29,7 @@ #define HAVE_BN_SQR_COMBA4 #define HAVE_BN_SQR_COMBA8 +#define HAVE_BN_SQR_WORDS #define HAVE_BN_SUB_WORDS diff --git a/lib/libcrypto/bn/bn_asm.c b/lib/libcrypto/bn/bn_asm.c index a7f288fc1c8..143c9393670 100644 --- a/lib/libcrypto/bn/bn_asm.c +++ b/lib/libcrypto/bn/bn_asm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_asm.c,v 1.21 2023/01/23 12:02:48 jsing Exp $ */ +/* $OpenBSD: bn_asm.c,v 1.22 2023/01/23 12:09:06 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -124,32 +124,6 @@ bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w) return (c1); } -void -bn_sqr_words(BN_ULONG *r, const BN_ULONG *a, int n) -{ - assert(n >= 0); - if (n <= 0) - return; - -#ifndef OPENSSL_SMALL_FOOTPRINT - while (n & ~3) { - sqr(r[0], r[1], a[0]); - sqr(r[2], r[3], a[1]); - sqr(r[4], r[5], a[2]); - sqr(r[6], r[7], a[3]); - a += 4; - r += 8; - n -= 4; - } -#endif - while (n) { - sqr(r[0], r[1], a[0]); - a++; - r += 2; - n--; - } -} - #else /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */ BN_ULONG @@ -218,32 +192,6 @@ bn_mul_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w) return (carry); } -void -bn_sqr_words(BN_ULONG *r, const BN_ULONG *a, int n) -{ - assert(n >= 0); - if (n <= 0) - return; - -#ifndef OPENSSL_SMALL_FOOTPRINT - while (n & ~3) { - sqr64(r[0], r[1], a[0]); - sqr64(r[2], r[3], a[1]); - sqr64(r[4], r[5], a[2]); - sqr64(r[6], r[7], a[3]); - a += 4; - r += 8; - n -= 4; - } -#endif - while (n) { - sqr64(r[0], r[1], a[0]); - a++; - r += 2; - n--; - } -} - #endif /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */ #if defined(BN_MUL_COMBA) && !defined(OPENSSL_SMALL_FOOTPRINT) diff --git a/lib/libcrypto/bn/bn_sqr.c b/lib/libcrypto/bn/bn_sqr.c index ff254764e34..74d5eded947 100644 --- a/lib/libcrypto/bn/bn_sqr.c +++ b/lib/libcrypto/bn/bn_sqr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bn_sqr.c,v 1.21 2023/01/21 14:10:46 jsing Exp $ */ +/* $OpenBSD: bn_sqr.c,v 1.22 2023/01/23 12:09:06 jsing Exp $ */ /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) * All rights reserved. * @@ -56,6 +56,7 @@ * [including the GNU Public Licence.] */ +#include #include #include @@ -178,6 +179,62 @@ bn_sqr_comba8(BN_ULONG *r, const BN_ULONG *a) } #endif +#ifndef HAVE_BN_SQR_WORDS +#if defined(BN_LLONG) || defined(BN_UMULT_HIGH) +void +bn_sqr_words(BN_ULONG *r, const BN_ULONG *a, int n) +{ + assert(n >= 0); + if (n <= 0) + return; + +#ifndef OPENSSL_SMALL_FOOTPRINT + while (n & ~3) { + sqr(r[0], r[1], a[0]); + sqr(r[2], r[3], a[1]); + sqr(r[4], r[5], a[2]); + sqr(r[6], r[7], a[3]); + a += 4; + r += 8; + n -= 4; + } +#endif + while (n) { + sqr(r[0], r[1], a[0]); + a++; + r += 2; + n--; + } +} +#else /* !(defined(BN_LLONG) || defined(BN_UMULT_HIGH)) */ +void +bn_sqr_words(BN_ULONG *r, const BN_ULONG *a, int n) +{ + assert(n >= 0); + if (n <= 0) + return; + +#ifndef OPENSSL_SMALL_FOOTPRINT + while (n & ~3) { + sqr64(r[0], r[1], a[0]); + sqr64(r[2], r[3], a[1]); + sqr64(r[4], r[5], a[2]); + sqr64(r[6], r[7], a[3]); + a += 4; + r += 8; + n -= 4; + } +#endif + while (n) { + sqr64(r[0], r[1], a[0]); + a++; + r += 2; + n--; + } +} +#endif +#endif + /* tmp must have 2*n words */ void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp) -- 2.20.1