7 #if defined(__linux) || defined(_AIX)
8 # include <sys/utsname.h>
10 #if defined(__APPLE__) && defined(__MACH__)
11 # include <sys/types.h>
12 # include <sys/sysctl.h>
14 #include <openssl/crypto.h>
15 #include <openssl/bn.h>
19 unsigned int OPENSSL_ppccap_P = 0;
21 static sigset_t all_masked;
23 #ifdef OPENSSL_BN_ASM_MONT
24 int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
25 const BN_ULONG *np, const BN_ULONG *n0, int num)
27 int bn_mul_mont_fpu64(BN_ULONG *rp, const BN_ULONG *ap,
28 const BN_ULONG *bp, const BN_ULONG *np,
29 const BN_ULONG *n0, int num);
30 int bn_mul_mont_int(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
31 const BN_ULONG *np, const BN_ULONG *n0, int num);
33 if (sizeof(size_t) == 4) {
34 # if 1 || (defined(__APPLE__) && defined(__MACH__))
35 if (num >= 8 && (num & 3) == 0 && (OPENSSL_ppccap_P & PPC_FPU64))
36 return bn_mul_mont_fpu64(rp, ap, bp, np, n0, num);
39 * boundary of 32 was experimentally determined on Linux 2.6.22,
40 * might have to be adjusted on AIX...
42 if (num >= 32 && (num & 3) == 0 && (OPENSSL_ppccap_P & PPC_FPU64)) {
46 sigprocmask(SIG_SETMASK, &all_masked, &oset);
47 ret = bn_mul_mont_fpu64(rp, ap, bp, np, n0, num);
48 sigprocmask(SIG_SETMASK, &oset, NULL);
53 } else if ((OPENSSL_ppccap_P & PPC_FPU64))
55 * this is a "must" on POWER6, but run-time detection is not
58 return bn_mul_mont_fpu64(rp, ap, bp, np, n0, num);
60 return bn_mul_mont_int(rp, ap, bp, np, n0, num);
64 void sha256_block_p8(void *ctx, const void *inp, size_t len);
65 void sha256_block_ppc(void *ctx, const void *inp, size_t len);
66 void sha256_block_data_order(void *ctx, const void *inp, size_t len)
68 OPENSSL_ppccap_P & PPC_CRYPTO207 ? sha256_block_p8(ctx, inp, len) :
69 sha256_block_ppc(ctx, inp, len);
72 void sha512_block_p8(void *ctx, const void *inp, size_t len);
73 void sha512_block_ppc(void *ctx, const void *inp, size_t len);
74 void sha512_block_data_order(void *ctx, const void *inp, size_t len)
76 OPENSSL_ppccap_P & PPC_CRYPTO207 ? sha512_block_p8(ctx, inp, len) :
77 sha512_block_ppc(ctx, inp, len);
80 static sigjmp_buf ill_jmp;
81 static void ill_handler(int sig)
83 siglongjmp(ill_jmp, sig);
86 void OPENSSL_ppc64_probe(void);
87 void OPENSSL_altivec_probe(void);
88 void OPENSSL_crypto207_probe(void);
90 void OPENSSL_cpuid_setup(void)
93 struct sigaction ill_oact, ill_act;
95 static int trigger = 0;
101 sigfillset(&all_masked);
102 sigdelset(&all_masked, SIGILL);
103 sigdelset(&all_masked, SIGTRAP);
105 sigdelset(&all_masked, SIGEMT);
107 sigdelset(&all_masked, SIGFPE);
108 sigdelset(&all_masked, SIGBUS);
109 sigdelset(&all_masked, SIGSEGV);
111 if ((e = getenv("OPENSSL_ppccap"))) {
112 OPENSSL_ppccap_P = strtoul(e, NULL, 0);
116 OPENSSL_ppccap_P = 0;
119 if (sizeof(size_t) == 4) {
121 # if defined(_SC_AIX_KERNEL_BITMODE)
122 if (sysconf(_SC_AIX_KERNEL_BITMODE) != 64)
125 if (uname(&uts) != 0 || atoi(uts.version) < 6)
130 #if defined(__APPLE__) && defined(__MACH__)
133 size_t len = sizeof(val);
135 if (sysctlbyname("hw.optional.64bitops", &val, &len, NULL, 0) == 0) {
137 OPENSSL_ppccap_P |= PPC_FPU64;
141 if (sysctlbyname("hw.optional.altivec", &val, &len, NULL, 0) == 0) {
143 OPENSSL_ppccap_P |= PPC_ALTIVEC;
150 memset(&ill_act, 0, sizeof(ill_act));
151 ill_act.sa_handler = ill_handler;
152 ill_act.sa_mask = all_masked;
154 sigprocmask(SIG_SETMASK, &ill_act.sa_mask, &oset);
155 sigaction(SIGILL, &ill_act, &ill_oact);
157 if (sizeof(size_t) == 4) {
160 if (uname(&uts) == 0 && strcmp(uts.machine, "ppc64") == 0)
162 if (sigsetjmp(ill_jmp, 1) == 0) {
163 OPENSSL_ppc64_probe();
164 OPENSSL_ppccap_P |= PPC_FPU64;
168 * Wanted code detecting POWER6 CPU and setting PPC_FPU64
172 if (sigsetjmp(ill_jmp, 1) == 0) {
173 OPENSSL_altivec_probe();
174 OPENSSL_ppccap_P |= PPC_ALTIVEC;
175 if (sigsetjmp(ill_jmp, 1) == 0) {
176 OPENSSL_crypto207_probe();
177 OPENSSL_ppccap_P |= PPC_CRYPTO207;
181 sigaction(SIGILL, &ill_oact, NULL);
182 sigprocmask(SIG_SETMASK, &oset, NULL);