7 #if defined(__linux) || defined(_AIX)
8 # include <sys/utsname.h>
11 #include <openssl/bn.h>
15 unsigned int OPENSSL_ppccap_P = 0;
17 static sigset_t all_masked;
19 #ifdef OPENSSL_BN_ASM_MONT
20 int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
21 const BN_ULONG *np, const BN_ULONG *n0, int num)
23 int bn_mul_mont_fpu64(BN_ULONG *rp, const BN_ULONG *ap,
24 const BN_ULONG *bp, const BN_ULONG *np,
25 const BN_ULONG *n0, int num);
26 int bn_mul_mont_int(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
27 const BN_ULONG *np, const BN_ULONG *n0, int num);
29 if (sizeof(size_t) == 4) {
30 # if 1 || (defined(__APPLE__) && defined(__MACH__))
31 if (num >= 8 && (num & 3) == 0 && (OPENSSL_ppccap_P & PPC_FPU64))
32 return bn_mul_mont_fpu64(rp, ap, bp, np, n0, num);
35 * boundary of 32 was experimentally determined on Linux 2.6.22,
36 * might have to be adjusted on AIX...
38 if (num >= 32 && (num & 3) == 0 && (OPENSSL_ppccap_P & PPC_FPU64)) {
42 sigprocmask(SIG_SETMASK, &all_masked, &oset);
43 ret = bn_mul_mont_fpu64(rp, ap, bp, np, n0, num);
44 sigprocmask(SIG_SETMASK, &oset, NULL);
49 } else if ((OPENSSL_ppccap_P & PPC_FPU64))
51 * this is a "must" on POWER6, but run-time detection is not
54 return bn_mul_mont_fpu64(rp, ap, bp, np, n0, num);
56 return bn_mul_mont_int(rp, ap, bp, np, n0, num);
60 void sha256_block_p8(void *ctx, const void *inp, size_t len);
61 void sha256_block_ppc(void *ctx, const void *inp, size_t len);
62 void sha256_block_data_order(void *ctx, const void *inp, size_t len)
64 OPENSSL_ppccap_P & PPC_CRYPTO207 ? sha256_block_p8(ctx, inp, len) :
65 sha256_block_ppc(ctx, inp, len);
68 void sha512_block_p8(void *ctx, const void *inp, size_t len);
69 void sha512_block_ppc(void *ctx, const void *inp, size_t len);
70 void sha512_block_data_order(void *ctx, const void *inp, size_t len)
72 OPENSSL_ppccap_P & PPC_CRYPTO207 ? sha512_block_p8(ctx, inp, len) :
73 sha512_block_ppc(ctx, inp, len);
76 static sigjmp_buf ill_jmp;
77 static void ill_handler(int sig)
79 siglongjmp(ill_jmp, sig);
82 void OPENSSL_ppc64_probe(void);
83 void OPENSSL_altivec_probe(void);
84 void OPENSSL_crypto207_probe(void);
86 void OPENSSL_cpuid_setup(void)
89 struct sigaction ill_oact, ill_act;
91 static int trigger = 0;
97 sigfillset(&all_masked);
98 sigdelset(&all_masked, SIGILL);
99 sigdelset(&all_masked, SIGTRAP);
101 sigdelset(&all_masked, SIGEMT);
103 sigdelset(&all_masked, SIGFPE);
104 sigdelset(&all_masked, SIGBUS);
105 sigdelset(&all_masked, SIGSEGV);
107 if ((e = getenv("OPENSSL_ppccap"))) {
108 OPENSSL_ppccap_P = strtoul(e, NULL, 0);
112 OPENSSL_ppccap_P = 0;
115 if (sizeof(size_t) == 4) {
117 # if defined(_SC_AIX_KERNEL_BITMODE)
118 if (sysconf(_SC_AIX_KERNEL_BITMODE) != 64)
121 if (uname(&uts) != 0 || atoi(uts.version) < 6)
126 memset(&ill_act, 0, sizeof(ill_act));
127 ill_act.sa_handler = ill_handler;
128 ill_act.sa_mask = all_masked;
130 sigprocmask(SIG_SETMASK, &ill_act.sa_mask, &oset);
131 sigaction(SIGILL, &ill_act, &ill_oact);
133 if (sizeof(size_t) == 4) {
136 if (uname(&uts) == 0 && strcmp(uts.machine, "ppc64") == 0)
138 if (sigsetjmp(ill_jmp, 1) == 0) {
139 OPENSSL_ppc64_probe();
140 OPENSSL_ppccap_P |= PPC_FPU64;
144 * Wanted code detecting POWER6 CPU and setting PPC_FPU64
148 if (sigsetjmp(ill_jmp, 1) == 0) {
149 OPENSSL_altivec_probe();
150 OPENSSL_ppccap_P |= PPC_ALTIVEC;
151 if (sigsetjmp(ill_jmp, 1) == 0) {
152 OPENSSL_crypto207_probe();
153 OPENSSL_ppccap_P |= PPC_CRYPTO207;
157 sigaction(SIGILL, &ill_oact, NULL);
158 sigprocmask(SIG_SETMASK, &oset, NULL);