]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/ppccap.c
6 #include <openssl/bn.h>
8 #define PPC_FPU64 (1<<0)
10 static int OPENSSL_ppccap_P
= 0;
12 static sigset_t all_masked
;
14 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
)
16 int bn_mul_mont_fpu64(BN_ULONG
*rp
, const BN_ULONG
*ap
, const BN_ULONG
*bp
, const BN_ULONG
*np
, const BN_ULONG
*n0
, int num
);
17 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
);
19 if (sizeof(size_t)==4)
21 #if (defined(__APPLE__) && defined(__MACH__))
22 if ((OPENSSL_ppccap_P
&PPC_FPU64
))
23 return bn_mul_mont_fpu64(rp
,ap
,bp
,np
,n0
,num
);
25 /* boundary of 32 was experimentally determined on
26 Linux 2.6.22, might have to be adjusted on AIX... */
27 if ((num
>=32) && (OPENSSL_ppccap_P
&PPC_FPU64
))
32 sigprocmask(SIG_SETMASK
,&all_masked
,&oset
);
33 ret
=bn_mul_mont_fpu64(rp
,ap
,bp
,np
,n0
,num
);
34 sigprocmask(SIG_SETMASK
,&oset
,NULL
);
40 else if ((OPENSSL_ppccap_P
&PPC_FPU64
))
41 /* this is a "must" on Power 6, but run-time detection
42 * is not implemented yet... */
43 return bn_mul_mont_fpu64(rp
,ap
,bp
,np
,n0
,num
);
45 return bn_mul_mont_int(rp
,ap
,bp
,np
,n0
,num
);
48 static sigjmp_buf ill_jmp
;
49 static void ill_handler (int sig
) { siglongjmp(ill_jmp
,sig
); }
51 void OPENSSL_cpuid_setup(void)
55 sigfillset(&all_masked
);
56 sigdelset(&all_masked
,SIGSEGV
);
57 sigdelset(&all_masked
,SIGILL
);
59 if ((e
=getenv("OPENSSL_ppccap")))
61 OPENSSL_ppccap_P
=strtoul(e
,NULL
,0);
65 if (sizeof(size_t)==4)
67 struct sigaction ill_oact
,ill_act
;
70 memset(&ill_act
,0,sizeof(ill_act
));
71 ill_act
.sa_handler
= ill_handler
;
72 sigfillset(&ill_act
.sa_mask
);
73 sigdelset(&ill_act
.sa_mask
,SIGILL
);
74 sigprocmask(SIG_SETMASK
,&ill_act
.sa_mask
,&oset
);
75 sigaction (SIGILL
,&ill_act
,&ill_oact
);
76 if (sigsetjmp(ill_jmp
,0) == 0)
78 OPENSSL_ppc64_probe();
79 OPENSSL_ppccap_P
|= PPC_FPU64
;
83 OPENSSL_ppccap_P
&= ~PPC_FPU64
;
85 sigaction (SIGILL
,&ill_oact
,NULL
);
86 sigprocmask(SIG_SETMASK
,&oset
,NULL
);