diff options
author | Tomas Mraz <tomas@openssl.org> | 2021-07-07 17:47:06 +0200 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2021-07-15 09:33:04 +0200 |
commit | 52f7e44ec88a4d803dc9783cd7c71f87014ae3ee (patch) | |
tree | b49310dc3808ba0e9130e6c148ae85d3479a9856 /crypto | |
parent | 8e94c51b3279f7faae9161df5112414f915cd9f3 (diff) |
Split bignum code out of the sparcv9cap.c
Fixes #15978
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/16019)
Diffstat (limited to 'crypto')
-rwxr-xr-x | crypto/aes/asm/aes-sparcv9.pl | 5 | ||||
-rw-r--r-- | crypto/aes/asm/aesfx-sparcv9.pl | 5 | ||||
-rw-r--r-- | crypto/aes/asm/aest4-sparcv9.pl | 5 | ||||
-rwxr-xr-x | crypto/bn/asm/sparct4-mont.pl | 5 | ||||
-rw-r--r-- | crypto/bn/asm/sparcv9-gf2m.pl | 5 | ||||
-rw-r--r-- | crypto/bn/asm/sparcv9-mont.pl | 5 | ||||
-rwxr-xr-x | crypto/bn/asm/sparcv9a-mont.pl | 5 | ||||
-rw-r--r-- | crypto/bn/asm/vis3-mont.pl | 5 | ||||
-rw-r--r-- | crypto/bn/bn_exp.c | 3 | ||||
-rw-r--r-- | crypto/bn/bn_sparc.c | 77 | ||||
-rw-r--r-- | crypto/bn/build.info | 2 | ||||
-rw-r--r-- | crypto/camellia/asm/cmllt4-sparcv9.pl | 5 | ||||
-rw-r--r-- | crypto/des/asm/dest4-sparcv9.pl | 5 | ||||
-rwxr-xr-x | crypto/ec/asm/ecp_nistz256-sparcv9.pl | 5 | ||||
-rw-r--r-- | crypto/evp/e_camellia.c | 3 | ||||
-rw-r--r-- | crypto/evp/e_des.c | 4 | ||||
-rw-r--r-- | crypto/evp/e_des3.c | 4 | ||||
-rw-r--r-- | crypto/md5/asm/md5-sparcv9.pl | 5 | ||||
-rw-r--r-- | crypto/modes/asm/ghash-sparcv9.pl | 5 | ||||
-rw-r--r-- | crypto/modes/gcm128.c | 3 | ||||
-rwxr-xr-x | crypto/poly1305/asm/poly1305-sparcv9.pl | 5 | ||||
-rw-r--r-- | crypto/sha/asm/sha1-sparcv9.pl | 5 | ||||
-rw-r--r-- | crypto/sha/asm/sha512-sparcv9.pl | 5 | ||||
-rw-r--r-- | crypto/sparc_arch.h | 118 | ||||
-rw-r--r-- | crypto/sparcv9cap.c | 67 |
25 files changed, 148 insertions, 213 deletions
diff --git a/crypto/aes/asm/aes-sparcv9.pl b/crypto/aes/asm/aes-sparcv9.pl index 9b9a795dbf..cb17a75f24 100755 --- a/crypto/aes/asm/aes-sparcv9.pl +++ b/crypto/aes/asm/aes-sparcv9.pl @@ -82,7 +82,10 @@ sub _data_word() } $code.=<<___; -#include "sparc_arch.h" +#ifndef __ASSEMBLER__ +# define __ASSEMBLER__ 1 +#endif +#include "crypto/sparc_arch.h" #ifdef __arch64__ .register %g2,#scratch diff --git a/crypto/aes/asm/aesfx-sparcv9.pl b/crypto/aes/asm/aesfx-sparcv9.pl index b40f3919b4..86f2c442ed 100644 --- a/crypto/aes/asm/aesfx-sparcv9.pl +++ b/crypto/aes/asm/aesfx-sparcv9.pl @@ -39,7 +39,10 @@ $output = pop and open STDOUT,">$output"; my ($inp,$out,$key,$rounds,$tmp,$mask) = map("%o$_",(0..5)); $code.=<<___; -#include "sparc_arch.h" +#ifndef __ASSEMBLER__ +# define __ASSEMBLER__ 1 +#endif +#include "crypto/sparc_arch.h" #define LOCALS (STACK_BIAS+STACK_FRAME) diff --git a/crypto/aes/asm/aest4-sparcv9.pl b/crypto/aes/asm/aest4-sparcv9.pl index 6b7a6eb403..bb73f24915 100644 --- a/crypto/aes/asm/aest4-sparcv9.pl +++ b/crypto/aes/asm/aest4-sparcv9.pl @@ -91,7 +91,10 @@ $::evp=1; # if $evp is set to 0, script generates module with my ($inp,$out,$key,$rounds,$tmp,$mask)=map("%o$_",(0..5)); $code.=<<___; -#include "sparc_arch.h" +#ifndef __ASSEMBLER__ +# define __ASSEMBLER__ 1 +#endif +#include "crypto/sparc_arch.h" #ifdef __arch64__ .register %g2,#scratch diff --git a/crypto/bn/asm/sparct4-mont.pl b/crypto/bn/asm/sparct4-mont.pl index 2df872b4a8..6bc98530ce 100755 --- a/crypto/bn/asm/sparct4-mont.pl +++ b/crypto/bn/asm/sparct4-mont.pl @@ -86,7 +86,10 @@ require "sparcv9_modes.pl"; $output = pop and open STDOUT,">$output"; $code.=<<___; -#include "sparc_arch.h" +#ifndef __ASSEMBLER__ +# define __ASSEMBLER__ 1 +#endif +#include "crypto/sparc_arch.h" #ifdef __arch64__ .register %g2,#scratch diff --git a/crypto/bn/asm/sparcv9-gf2m.pl b/crypto/bn/asm/sparcv9-gf2m.pl index 41ab8039cc..28d1ed7426 100644 --- a/crypto/bn/asm/sparcv9-gf2m.pl +++ b/crypto/bn/asm/sparcv9-gf2m.pl @@ -38,7 +38,10 @@ $tab="%l0"; ($lo,$hi,$b)=("%g1",$a8,"%o7"); $a=$lo; $code.=<<___; -#include <sparc_arch.h> +#ifndef __ASSEMBLER__ +# define __ASSEMBLER__ 1 +#endif +#include "crypto/sparc_arch.h" #ifdef __arch64__ .register %g2,#scratch diff --git a/crypto/bn/asm/sparcv9-mont.pl b/crypto/bn/asm/sparcv9-mont.pl index 6005334790..ac93ef9ee6 100644 --- a/crypto/bn/asm/sparcv9-mont.pl +++ b/crypto/bn/asm/sparcv9-mont.pl @@ -83,7 +83,10 @@ $tpj="%l7"; $fname="bn_mul_mont_int"; $code=<<___; -#include "sparc_arch.h" +#ifndef __ASSEMBLER__ +# define __ASSEMBLER__ 1 +#endif +#include "crypto/sparc_arch.h" .section ".text",#alloc,#execinstr diff --git a/crypto/bn/asm/sparcv9a-mont.pl b/crypto/bn/asm/sparcv9a-mont.pl index 2a4255ed69..062a017072 100755 --- a/crypto/bn/asm/sparcv9a-mont.pl +++ b/crypto/bn/asm/sparcv9a-mont.pl @@ -126,7 +126,10 @@ $nhia="%f56"; $nhib="%f58"; $nhic="%f60"; $nhid="%f62"; $ASI_FL16_P=0xD2; # magic ASI value to engage 16-bit FP load $code=<<___; -#include "sparc_arch.h" +#ifndef __ASSEMBLER__ +# define __ASSEMBLER__ 1 +#endif +#include "crypto/sparc_arch.h" .section ".text",#alloc,#execinstr diff --git a/crypto/bn/asm/vis3-mont.pl b/crypto/bn/asm/vis3-mont.pl index 6ee64e28f6..6649c34727 100644 --- a/crypto/bn/asm/vis3-mont.pl +++ b/crypto/bn/asm/vis3-mont.pl @@ -31,7 +31,10 @@ $frame = "STACK_FRAME"; $bias = "STACK_BIAS"; $code.=<<___; -#include "sparc_arch.h" +#ifndef __ASSEMBLER__ +# define __ASSEMBLER__ 1 +#endif +#include "crypto/sparc_arch.h" #ifdef __arch64__ .register %g2,#scratch diff --git a/crypto/bn/bn_exp.c b/crypto/bn/bn_exp.c index 2ee85aa0cf..5329cd12a9 100644 --- a/crypto/bn/bn_exp.c +++ b/crypto/bn/bn_exp.c @@ -29,8 +29,7 @@ #undef SPARC_T4_MONT #if defined(OPENSSL_BN_ASM_MONT) && (defined(__sparc__) || defined(__sparc)) -# include "sparc_arch.h" -extern unsigned int OPENSSL_sparcv9cap_P[]; +# include "crypto/sparc_arch.h" # define SPARC_T4_MONT #endif diff --git a/crypto/bn/bn_sparc.c b/crypto/bn/bn_sparc.c new file mode 100644 index 0000000000..a810c3b1fa --- /dev/null +++ b/crypto/bn/bn_sparc.c @@ -0,0 +1,77 @@ +/* + * Copyright 2005-2021 The OpenSSL Project Authors. All Rights Reserved. + * + * Licensed under the Apache License 2.0 (the "License"). You may not use + * this file except in compliance with the License. You can obtain a copy + * in the file LICENSE in the source distribution or at + * https://www.openssl.org/source/license.html + */ + +#include <stdlib.h> +#include <openssl/bn.h> +#include "internal/cryptlib.h" +#include "crypto/sparc_arch.h" +#include "bn_local.h" /* for definition of bn_mul_mont */ + +int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, + const BN_ULONG *np, const BN_ULONG *n0, int num) +{ + int bn_mul_mont_vis3(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, + const BN_ULONG *np, const BN_ULONG *n0, int num); + int bn_mul_mont_fpu(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, + const BN_ULONG *np, const BN_ULONG *n0, int num); + int bn_mul_mont_int(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, + const BN_ULONG *np, const BN_ULONG *n0, int num); + + if (!(num & 1) && num >= 6) { + if ((num & 15) == 0 && num <= 64 && + (OPENSSL_sparcv9cap_P[1] & (CFR_MONTMUL | CFR_MONTSQR)) == + (CFR_MONTMUL | CFR_MONTSQR)) { + typedef int (*bn_mul_mont_f) (BN_ULONG *rp, const BN_ULONG *ap, + const BN_ULONG *bp, + const BN_ULONG *np, + const BN_ULONG *n0); + int bn_mul_mont_t4_8(BN_ULONG *rp, const BN_ULONG *ap, + const BN_ULONG *bp, const BN_ULONG *np, + const BN_ULONG *n0); + int bn_mul_mont_t4_16(BN_ULONG *rp, const BN_ULONG *ap, + const BN_ULONG *bp, const BN_ULONG *np, + const BN_ULONG *n0); + int bn_mul_mont_t4_24(BN_ULONG *rp, const BN_ULONG *ap, + const BN_ULONG *bp, const BN_ULONG *np, + const BN_ULONG *n0); + int bn_mul_mont_t4_32(BN_ULONG *rp, const BN_ULONG *ap, + const BN_ULONG *bp, const BN_ULONG *np, + const BN_ULONG *n0); + static const bn_mul_mont_f funcs[4] = { + bn_mul_mont_t4_8, bn_mul_mont_t4_16, + bn_mul_mont_t4_24, bn_mul_mont_t4_32 + }; + bn_mul_mont_f worker = funcs[num / 16 - 1]; + + if ((*worker) (rp, ap, bp, np, n0)) + return 1; + /* retry once and fall back */ + if ((*worker) (rp, ap, bp, np, n0)) + return 1; + return bn_mul_mont_vis3(rp, ap, bp, np, n0, num); + } + if ((OPENSSL_sparcv9cap_P[0] & SPARCV9_VIS3)) + return bn_mul_mont_vis3(rp, ap, bp, np, n0, num); + else if (num >= 8 && + /* + * bn_mul_mont_fpu doesn't use FMADD, we just use the + * flag to detect when FPU path is preferable in cases + * when current heuristics is unreliable. [it works + * out because FMADD-capable processors where FPU + * code path is undesirable are also VIS3-capable and + * VIS3 code path takes precedence.] + */ + ( (OPENSSL_sparcv9cap_P[0] & SPARCV9_FMADD) || + (OPENSSL_sparcv9cap_P[0] & + (SPARCV9_PREFER_FPU | SPARCV9_VIS1)) == + (SPARCV9_PREFER_FPU | SPARCV9_VIS1) )) + return bn_mul_mont_fpu(rp, ap, bp, np, n0, num); + } + return bn_mul_mont_int(rp, ap, bp, np, n0, num); +} diff --git a/crypto/bn/build.info b/crypto/bn/build.info index 40d7db9f50..9330274aef 100644 --- a/crypto/bn/build.info +++ b/crypto/bn/build.info @@ -40,7 +40,7 @@ IF[{- !$disabled{asm} -}] ENDIF $BNASM_sparcv9=asm/sparcv8plus.S sparcv9-mont.S sparcv9a-mont.S vis3-mont.S \ - sparct4-mont.S + sparct4-mont.S bn_sparc.c $BNDEF_sparcv9=OPENSSL_BN_ASM_MONT $BNASM_sparcv9_ec2m=sparcv9-gf2m.S $BNDEF_sparcv9_ec2m=OPENSSL_BN_ASM_GF2m diff --git a/crypto/camellia/asm/cmllt4-sparcv9.pl b/crypto/camellia/asm/cmllt4-sparcv9.pl index cbb626f00b..3f71e4c2fc 100644 --- a/crypto/camellia/asm/cmllt4-sparcv9.pl +++ b/crypto/camellia/asm/cmllt4-sparcv9.pl @@ -66,7 +66,10 @@ $::evp=1; # if $evp is set to 0, script generates module with my ($inp,$out,$key,$rounds,$tmp,$mask)=map("%o$_",(0..5)); $code=<<___; -#include "sparc_arch.h" +#ifndef __ASSEMBLER__ +# define __ASSEMBLER__ 1 +#endif +#include "crypto/sparc_arch.h" .text diff --git a/crypto/des/asm/dest4-sparcv9.pl b/crypto/des/asm/dest4-sparcv9.pl index eec9716074..09298583e4 100644 --- a/crypto/des/asm/dest4-sparcv9.pl +++ b/crypto/des/asm/dest4-sparcv9.pl @@ -37,7 +37,10 @@ require "sparcv9_modes.pl"; $output=pop and open STDOUT,">$output"; $code.=<<___; -#include "sparc_arch.h" +#ifndef __ASSEMBLER__ +# define __ASSEMBLER__ 1 +#endif +#include "crypto/sparc_arch.h" #ifdef __arch64__ .register %g2,#scratch diff --git a/crypto/ec/asm/ecp_nistz256-sparcv9.pl b/crypto/ec/asm/ecp_nistz256-sparcv9.pl index 5815896fa8..19821cdc85 100755 --- a/crypto/ec/asm/ecp_nistz256-sparcv9.pl +++ b/crypto/ec/asm/ecp_nistz256-sparcv9.pl @@ -34,7 +34,10 @@ $output = pop and open STDOUT,">$output"; $code.=<<___; -#include "sparc_arch.h" +#ifndef __ASSEMBLER__ +# define __ASSEMBLER__ 1 +#endif +#include "crypto/sparc_arch.h" #define LOCALS (STACK_BIAS+STACK_FRAME) #ifdef __arch64__ diff --git a/crypto/evp/e_camellia.c b/crypto/evp/e_camellia.c index b2f59847d4..4f1f4822dc 100644 --- a/crypto/evp/e_camellia.c +++ b/crypto/evp/e_camellia.c @@ -46,8 +46,7 @@ typedef struct { #if defined(AES_ASM) && (defined(__sparc) || defined(__sparc__)) /* ---------^^^ this is not a typo, just a way to detect that * assembler support was in general requested... */ -# include "sparc_arch.h" - +# include "crypto/sparc_arch.h" static int cmll_t4_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc) diff --git a/crypto/evp/e_des.c b/crypto/evp/e_des.c index 51a2f9d353..cd6e5af8d0 100644 --- a/crypto/evp/e_des.c +++ b/crypto/evp/e_des.c @@ -37,9 +37,7 @@ typedef struct { # if defined(AES_ASM) && (defined(__sparc) || defined(__sparc__)) /* ----------^^^ this is not a typo, just a way to detect that * assembler support was in general requested... */ -# include "sparc_arch.h" - -extern unsigned int OPENSSL_sparcv9cap_P[]; +# include "crypto/sparc_arch.h" # define SPARC_DES_CAPABLE (OPENSSL_sparcv9cap_P[1] & CFR_DES) diff --git a/crypto/evp/e_des3.c b/crypto/evp/e_des3.c index 746709fa41..1e15918344 100644 --- a/crypto/evp/e_des3.c +++ b/crypto/evp/e_des3.c @@ -40,9 +40,7 @@ typedef struct { # if defined(AES_ASM) && (defined(__sparc) || defined(__sparc__)) /* ---------^^^ this is not a typo, just a way to detect that * assembler support was in general requested... */ -# include "sparc_arch.h" - -extern unsigned int OPENSSL_sparcv9cap_P[]; +# include "crypto/sparc_arch.h" # define SPARC_DES_CAPABLE (OPENSSL_sparcv9cap_P[1] & CFR_DES) diff --git a/crypto/md5/asm/md5-sparcv9.pl b/crypto/md5/asm/md5-sparcv9.pl index 64e53a003f..a17d0b6bf5 100644 --- a/crypto/md5/asm/md5-sparcv9.pl +++ b/crypto/md5/asm/md5-sparcv9.pl @@ -203,7 +203,10 @@ ___ } $code.=<<___; -#include "sparc_arch.h" +#ifndef __ASSEMBLER__ +# define __ASSEMBLER__ 1 +#endif +#include "crypto/sparc_arch.h" #ifdef __arch64__ .register %g2,#scratch diff --git a/crypto/modes/asm/ghash-sparcv9.pl b/crypto/modes/asm/ghash-sparcv9.pl index c844235c0a..d3fa2a68fe 100644 --- a/crypto/modes/asm/ghash-sparcv9.pl +++ b/crypto/modes/asm/ghash-sparcv9.pl @@ -80,7 +80,10 @@ $inp="%i2"; $len="%i3"; $code.=<<___; -#include "sparc_arch.h" +#ifndef __ASSEMBLER__ +# define __ASSEMBLER__ 1 +#endif +#include "crypto/sparc_arch.h" #ifdef __arch64__ .register %g2,#scratch diff --git a/crypto/modes/gcm128.c b/crypto/modes/gcm128.c index 8317fd48e4..e7e719fc0e 100644 --- a/crypto/modes/gcm128.c +++ b/crypto/modes/gcm128.c @@ -674,10 +674,9 @@ void gcm_ghash_v8(u64 Xi[2], const u128 Htable[16], const u8 *inp, size_t len); # endif # elif defined(__sparc__) || defined(__sparc) -# include "sparc_arch.h" +# include "crypto/sparc_arch.h" # define GHASH_ASM_SPARC # define GCM_FUNCREF_4BIT -extern unsigned int OPENSSL_sparcv9cap_P[]; void gcm_init_vis3(u128 Htable[16], const u64 Xi[2]); void gcm_gmult_vis3(u64 Xi[2], const u128 Htable[16]); void gcm_ghash_vis3(u64 Xi[2], const u128 Htable[16], const u8 *inp, diff --git a/crypto/poly1305/asm/poly1305-sparcv9.pl b/crypto/poly1305/asm/poly1305-sparcv9.pl index c9db450b48..b20517f57b 100755 --- a/crypto/poly1305/asm/poly1305-sparcv9.pl +++ b/crypto/poly1305/asm/poly1305-sparcv9.pl @@ -52,7 +52,10 @@ my ($h0,$h1,$h2,$h3, $t0,$t1,$t2) = map("%o$_",(0..5,7)); my ($d0,$d1,$d2,$d3) = map("%g$_",(1..4)); $code.=<<___; -#include "sparc_arch.h" +#ifndef __ASSEMBLER__ +# define __ASSEMBLER__ 1 +#endif +#include "crypto/sparc_arch.h" #ifdef __arch64__ .register %g2,#scratch diff --git a/crypto/sha/asm/sha1-sparcv9.pl b/crypto/sha/asm/sha1-sparcv9.pl index c3b82d0cfd..bbca9ed21a 100644 --- a/crypto/sha/asm/sha1-sparcv9.pl +++ b/crypto/sha/asm/sha1-sparcv9.pl @@ -187,7 +187,10 @@ ___ } $code.=<<___; -#include "sparc_arch.h" +#ifndef __ASSEMBLER__ +# define __ASSEMBLER__ 1 +#endif +#include "crypto/sparc_arch.h" #ifdef __arch64__ .register %g2,#scratch diff --git a/crypto/sha/asm/sha512-sparcv9.pl b/crypto/sha/asm/sha512-sparcv9.pl index 1619f14387..a77ae7bed7 100644 --- a/crypto/sha/asm/sha512-sparcv9.pl +++ b/crypto/sha/asm/sha512-sparcv9.pl @@ -394,7 +394,10 @@ ___ } if ($SZ==8); $code.=<<___; -#include "sparc_arch.h" +#ifndef __ASSEMBLER__ +# define __ASSEMBLER__ 1 +#endif +#include "crypto/sparc_arch.h" #ifdef __arch64__ .register %g2,#scratch diff --git a/crypto/sparc_arch.h b/crypto/sparc_arch.h deleted file mode 100644 index f57f0e145b..0000000000 --- a/crypto/sparc_arch.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright 2012-2016 The OpenSSL Project Authors. All Rights Reserved. - * - * Licensed under the Apache License 2.0 (the "License"). You may not use - * this file except in compliance with the License. You can obtain a copy - * in the file LICENSE in the source distribution or at - * https://www.openssl.org/source/license.html - */ - -#ifndef OSSL_CRYPTO_SPARC_ARCH_H -# define OSSL_CRYPTO_SPARC_ARCH_H - -# define SPARCV9_TICK_PRIVILEGED (1<<0) -# define SPARCV9_PREFER_FPU (1<<1) -# define SPARCV9_VIS1 (1<<2) -# define SPARCV9_VIS2 (1<<3)/* reserved */ -# define SPARCV9_FMADD (1<<4) -# define SPARCV9_BLK (1<<5)/* VIS1 block copy */ -# define SPARCV9_VIS3 (1<<6) -# define SPARCV9_RANDOM (1<<7) -# define SPARCV9_64BIT_STACK (1<<8) -# define SPARCV9_FJAESX (1<<9)/* Fujitsu SPARC64 X AES */ -# define SPARCV9_FJDESX (1<<10)/* Fujitsu SPARC64 X DES, reserved */ -# define SPARCV9_FJHPCACE (1<<11)/* Fujitsu HPC-ACE, reserved */ -# define SPARCV9_IMA (1<<13)/* reserved */ -# define SPARCV9_VIS4 (1<<14)/* reserved */ - -/* - * OPENSSL_sparcv9cap_P[1] is copy of Compatibility Feature Register, - * %asr26, SPARC-T4 and later. There is no SPARCV9_CFR bit in - * OPENSSL_sparcv9cap_P[0], as %cfr copy is sufficient... - */ -# define CFR_AES 0x00000001/* Supports AES opcodes */ -# define CFR_DES 0x00000002/* Supports DES opcodes */ -# define CFR_KASUMI 0x00000004/* Supports KASUMI opcodes */ -# define CFR_CAMELLIA 0x00000008/* Supports CAMELLIA opcodes */ -# define CFR_MD5 0x00000010/* Supports MD5 opcodes */ -# define CFR_SHA1 0x00000020/* Supports SHA1 opcodes */ -# define CFR_SHA256 0x00000040/* Supports SHA256 opcodes */ -# define CFR_SHA512 0x00000080/* Supports SHA512 opcodes */ -# define CFR_MPMUL 0x00000100/* Supports MPMUL opcodes */ -# define CFR_MONTMUL 0x00000200/* Supports MONTMUL opcodes */ -# define CFR_MONTSQR 0x00000400/* Supports MONTSQR opcodes */ -# define CFR_CRC32C 0x00000800/* Supports CRC32C opcodes */ -# define CFR_XMPMUL 0x00001000/* Supports XMPMUL opcodes */ -# define CFR_XMONTMUL 0x00002000/* Supports XMONTMUL opcodes */ -# define CFR_XMONTSQR 0x00004000/* Supports XMONTSQR opcodes */ - -# if defined(OPENSSL_PIC) && !defined(__PIC__) -# define __PIC__ -# endif - -# if defined(__SUNPRO_C) && defined(__sparcv9) && !defined(__arch64__) -# define __arch64__ -# endif - -# define SPARC_PIC_THUNK(reg) \ - .align 32; \ -.Lpic_thunk: \ - jmp %o7 + 8; \ - add %o7, reg, reg; - -# define SPARC_PIC_THUNK_CALL(reg) \ - sethi %hi(_GLOBAL_OFFSET_TABLE_-4), reg; \ - call .Lpic_thunk; \ - or reg, %lo(_GLOBAL_OFFSET_TABLE_+4), reg; - -# if 1 -# define SPARC_SETUP_GOT_REG(reg) SPARC_PIC_THUNK_CALL(reg) -# else -# define SPARC_SETUP_GOT_REG(reg) \ - sethi %hi(_GLOBAL_OFFSET_TABLE_-4), reg; \ - call .+8; \ - or reg,%lo(_GLOBAL_OFFSET_TABLE_+4), reg; \ - add %o7, reg, reg -# endif - -# if defined(__arch64__) - -# define SPARC_LOAD_ADDRESS(SYM, reg) \ - setx SYM, %o7, reg; -# define LDPTR ldx -# define SIZE_T_CC %xcc -# define STACK_FRAME 192 -# define STACK_BIAS 2047 -# define STACK_7thARG (STACK_BIAS+176) - -# else - -# define SPARC_LOAD_ADDRESS(SYM, reg) \ - set SYM, reg; -# define LDPTR ld -# define SIZE_T_CC %icc -# define STACK_FRAME 112 -# define STACK_BIAS 0 -# define STACK_7thARG 92 -# define SPARC_LOAD_ADDRESS_LEAF(SYM,reg,tmp) SPARC_LOAD_ADDRESS(SYM,reg) - -# endif - -# ifdef __PIC__ -# undef SPARC_LOAD_ADDRESS -# undef SPARC_LOAD_ADDRESS_LEAF -# define SPARC_LOAD_ADDRESS(SYM, reg) \ - SPARC_SETUP_GOT_REG(reg); \ - sethi %hi(SYM), %o7; \ - or %o7, %lo(SYM), %o7; \ - LDPTR [reg + %o7], reg; -# endif - -# ifndef SPARC_LOAD_ADDRESS_LEAF -# define SPARC_LOAD_ADDRESS_LEAF(SYM, reg, tmp) \ - mov %o7, tmp; \ - SPARC_LOAD_ADDRESS(SYM, reg) \ - mov tmp, %o7; -# endif - -#endif /* OSSL_CRYPTO_SPARC_ARCH_H */ diff --git a/crypto/sparcv9cap.c b/crypto/sparcv9cap.c index d93429f4c3..53c0c3e045 100644 --- a/crypto/sparcv9cap.c +++ b/crypto/sparcv9cap.c @@ -16,78 +16,13 @@ #include <unistd.h> #include <openssl/bn.h> #include "internal/cryptlib.h" -#include "bn/bn_local.h" /* for definition of bn_mul_mont */ - -#include "sparc_arch.h" +#include "crypto/sparc_arch.h" #if defined(__GNUC__) && defined(__linux) __attribute__ ((visibility("hidden"))) #endif unsigned int OPENSSL_sparcv9cap_P[2] = { SPARCV9_TICK_PRIVILEGED, 0 }; -int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, - const BN_ULONG *np, const BN_ULONG *n0, int num) -{ - int bn_mul_mont_vis3(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, - const BN_ULONG *np, const BN_ULONG *n0, int num); - int bn_mul_mont_fpu(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, - const BN_ULONG *np, const BN_ULONG *n0, int num); - int bn_mul_mont_int(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, - const BN_ULONG *np, const BN_ULONG *n0, int num); - - if (!(num & 1) && num >= 6) { - if ((num & 15) == 0 && num <= 64 && - (OPENSSL_sparcv9cap_P[1] & (CFR_MONTMUL | CFR_MONTSQR)) == - (CFR_MONTMUL | CFR_MONTSQR)) { - typedef int (*bn_mul_mont_f) (BN_ULONG *rp, const BN_ULONG *ap, - const BN_ULONG *bp, - const BN_ULONG *np, - const BN_ULONG *n0); - int bn_mul_mont_t4_8(BN_ULONG *rp, const BN_ULONG *ap, - const BN_ULONG *bp, const BN_ULONG *np, - const BN_ULONG *n0); - int bn_mul_mont_t4_16(BN_ULONG *rp, const BN_ULONG *ap, - const BN_ULONG *bp, const BN_ULONG *np, - const BN_ULONG *n0); - int bn_mul_mont_t4_24(BN_ULONG *rp, const BN_ULONG *ap, - const BN_ULONG *bp, const BN_ULONG *np, - const BN_ULONG *n0); - int bn_mul_mont_t4_32(BN_ULONG *rp, const BN_ULONG *ap, - const BN_ULONG *bp, const BN_ULONG *np, - const BN_ULONG *n0); - static const bn_mul_mont_f funcs[4] = { - bn_mul_mont_t4_8, bn_mul_mont_t4_16, - bn_mul_mont_t4_24, bn_mul_mont_t4_32 - }; - bn_mul_mont_f worker = funcs[num / 16 - 1]; - - if ((*worker) (rp, ap, bp, np, n0)) - return 1; - /* retry once and fall back */ - if ((*worker) (rp, ap, bp, np, n0)) - return 1; - return bn_mul_mont_vis3(rp, ap, bp, np, n0, num); - } - if ((OPENSSL_sparcv9cap_P[0] & SPARCV9_VIS3)) - return bn_mul_mont_vis3(rp, ap, bp, np, n0, num); - else if (num >= 8 && - /* - * bn_mul_mont_fpu doesn't use FMADD, we just use the - * flag to detect when FPU path is preferable in cases - * when current heuristics is unreliable. [it works - * out because FMADD-capable processors where FPU - * code path is undesirable are also VIS3-capable and - * VIS3 code path takes precedence.] - */ - ( (OPENSSL_sparcv9cap_P[0] & SPARCV9_FMADD) || - (OPENSSL_sparcv9cap_P[0] & - (SPARCV9_PREFER_FPU | SPARCV9_VIS1)) == - (SPARCV9_PREFER_FPU | SPARCV9_VIS1) )) - return bn_mul_mont_fpu(rp, ap, bp, np, n0, num); - } - return bn_mul_mont_int(rp, ap, bp, np, n0, num); -} - unsigned long _sparcv9_rdtick(void); void _sparcv9_vis1_probe(void); unsigned long _sparcv9_vis1_instrument(void); |