14ec2eca9Schristos /* 292d83a12Schristos * Copyright 2009-2019 The OpenSSL Project Authors. All Rights Reserved. 34ec2eca9Schristos * 44ec2eca9Schristos * Licensed under the OpenSSL license (the "License"). You may not use 54ec2eca9Schristos * this file except in compliance with the License. You can obtain a copy 64ec2eca9Schristos * in the file LICENSE in the source distribution or at 74ec2eca9Schristos * https://www.openssl.org/source/license.html 84ec2eca9Schristos */ 94ec2eca9Schristos 1013ce5681Schristos #include <stdio.h> 1113ce5681Schristos #include <stdlib.h> 1213ce5681Schristos #include <string.h> 1313ce5681Schristos #include <setjmp.h> 1413ce5681Schristos #include <signal.h> 1521bfa713Schristos #include <unistd.h> 167fa80bafSspz #if defined(__linux) || defined(_AIX) 177fa80bafSspz # include <sys/utsname.h> 187fa80bafSspz #endif 194ec2eca9Schristos #if defined(_AIX53) /* defined even on post-5.3 */ 204ec2eca9Schristos # include <sys/systemcfg.h> 214ec2eca9Schristos # if !defined(__power_set) 224ec2eca9Schristos # define __power_set(a) (_system_configuration.implementation & (a)) 234ec2eca9Schristos # endif 244ec2eca9Schristos #endif 254ec2eca9Schristos #if defined(__APPLE__) && defined(__MACH__) 264ec2eca9Schristos # include <sys/types.h> 274ec2eca9Schristos # include <sys/sysctl.h> 284ec2eca9Schristos #endif 29*d4503398Srin #if defined(__NetBSD__) 30*d4503398Srin # include <sys/param.h> 31*d4503398Srin # include <sys/sysctl.h> 32*d4503398Srin #endif 337fa80bafSspz #include <openssl/crypto.h> 3413ce5681Schristos #include <openssl/bn.h> 35e7ccb6d1Schristos #include <internal/cryptlib.h> 36cb006352Schristos #include <crypto/chacha.h> 37cb006352Schristos #include "bn/bn_local.h" 3813ce5681Schristos 397fa80bafSspz #include "ppc_arch.h" 4013ce5681Schristos 417fa80bafSspz unsigned int OPENSSL_ppccap_P = 0; 4213ce5681Schristos 4313ce5681Schristos static sigset_t all_masked; 4413ce5681Schristos 4513ce5681Schristos #ifdef OPENSSL_BN_ASM_MONT 46d572d25fSspz int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, 47d572d25fSspz const BN_ULONG *np, const BN_ULONG *n0, int num) 4813ce5681Schristos { 49d572d25fSspz int bn_mul_mont_int(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, 50d572d25fSspz const BN_ULONG *np, const BN_ULONG *n0, int num); 51e7ccb6d1Schristos int bn_mul4x_mont_int(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, 52e7ccb6d1Schristos const BN_ULONG *np, const BN_ULONG *n0, int num); 5313ce5681Schristos 54e7ccb6d1Schristos if (num < 4) 55e7ccb6d1Schristos return 0; 56e7ccb6d1Schristos 57e7ccb6d1Schristos if ((num & 3) == 0) 58e7ccb6d1Schristos return bn_mul4x_mont_int(rp, ap, bp, np, n0, num); 59e7ccb6d1Schristos 60d572d25fSspz /* 61e7ccb6d1Schristos * There used to be [optional] call to bn_mul_mont_fpu64 here, 62e7ccb6d1Schristos * but above subroutine is faster on contemporary processors. 63e7ccb6d1Schristos * Formulation means that there might be old processors where 64e7ccb6d1Schristos * FPU code path would be faster, POWER6 perhaps, but there was 65e7ccb6d1Schristos * no opportunity to figure it out... 66d572d25fSspz */ 6713ce5681Schristos 6813ce5681Schristos return bn_mul_mont_int(rp, ap, bp, np, n0, num); 6913ce5681Schristos } 7013ce5681Schristos #endif 7113ce5681Schristos 727fa80bafSspz #ifdef DONT_USE_SHA256_FROM_LIBC 737fa80bafSspz void sha256_block_p8(void *ctx, const void *inp, size_t len); 747fa80bafSspz void sha256_block_ppc(void *ctx, const void *inp, size_t len); 75e7ccb6d1Schristos void sha256_block_data_order(void *ctx, const void *inp, size_t len); 767fa80bafSspz void sha256_block_data_order(void *ctx, const void *inp, size_t len) 777fa80bafSspz { 787fa80bafSspz OPENSSL_ppccap_P & PPC_CRYPTO207 ? sha256_block_p8(ctx, inp, len) : 797fa80bafSspz sha256_block_ppc(ctx, inp, len); 807fa80bafSspz } 817fa80bafSspz #endif 827fa80bafSspz 837fa80bafSspz #ifdef DONT_USE_SHA512_FROM_LIBC 847fa80bafSspz void sha512_block_p8(void *ctx, const void *inp, size_t len); 857fa80bafSspz void sha512_block_ppc(void *ctx, const void *inp, size_t len); 86e7ccb6d1Schristos void sha512_block_data_order(void *ctx, const void *inp, size_t len); 877fa80bafSspz void sha512_block_data_order(void *ctx, const void *inp, size_t len) 887fa80bafSspz { 897fa80bafSspz OPENSSL_ppccap_P & PPC_CRYPTO207 ? sha512_block_p8(ctx, inp, len) : 907fa80bafSspz sha512_block_ppc(ctx, inp, len); 917fa80bafSspz } 927fa80bafSspz #endif 937fa80bafSspz 944ec2eca9Schristos #ifndef OPENSSL_NO_CHACHA 954ec2eca9Schristos void ChaCha20_ctr32_int(unsigned char *out, const unsigned char *inp, 964ec2eca9Schristos size_t len, const unsigned int key[8], 974ec2eca9Schristos const unsigned int counter[4]); 984ec2eca9Schristos void ChaCha20_ctr32_vmx(unsigned char *out, const unsigned char *inp, 994ec2eca9Schristos size_t len, const unsigned int key[8], 1004ec2eca9Schristos const unsigned int counter[4]); 101e7ccb6d1Schristos void ChaCha20_ctr32_vsx(unsigned char *out, const unsigned char *inp, 102e7ccb6d1Schristos size_t len, const unsigned int key[8], 103e7ccb6d1Schristos const unsigned int counter[4]); 1044ec2eca9Schristos void ChaCha20_ctr32(unsigned char *out, const unsigned char *inp, 1054ec2eca9Schristos size_t len, const unsigned int key[8], 1064ec2eca9Schristos const unsigned int counter[4]) 1074ec2eca9Schristos { 108e7ccb6d1Schristos OPENSSL_ppccap_P & PPC_CRYPTO207 109e7ccb6d1Schristos ? ChaCha20_ctr32_vsx(out, inp, len, key, counter) 110e7ccb6d1Schristos : OPENSSL_ppccap_P & PPC_ALTIVEC 1114ec2eca9Schristos ? ChaCha20_ctr32_vmx(out, inp, len, key, counter) 1124ec2eca9Schristos : ChaCha20_ctr32_int(out, inp, len, key, counter); 1134ec2eca9Schristos } 1144ec2eca9Schristos #endif 1154ec2eca9Schristos 1164ec2eca9Schristos #ifndef OPENSSL_NO_POLY1305 1174ec2eca9Schristos void poly1305_init_int(void *ctx, const unsigned char key[16]); 1184ec2eca9Schristos void poly1305_blocks(void *ctx, const unsigned char *inp, size_t len, 1194ec2eca9Schristos unsigned int padbit); 1204ec2eca9Schristos void poly1305_emit(void *ctx, unsigned char mac[16], 1214ec2eca9Schristos const unsigned int nonce[4]); 1224ec2eca9Schristos void poly1305_init_fpu(void *ctx, const unsigned char key[16]); 1234ec2eca9Schristos void poly1305_blocks_fpu(void *ctx, const unsigned char *inp, size_t len, 1244ec2eca9Schristos unsigned int padbit); 1254ec2eca9Schristos void poly1305_emit_fpu(void *ctx, unsigned char mac[16], 1264ec2eca9Schristos const unsigned int nonce[4]); 127e7ccb6d1Schristos int poly1305_init(void *ctx, const unsigned char key[16], void *func[2]); 1284ec2eca9Schristos int poly1305_init(void *ctx, const unsigned char key[16], void *func[2]) 1294ec2eca9Schristos { 1304ec2eca9Schristos if (sizeof(size_t) == 4 && (OPENSSL_ppccap_P & PPC_FPU)) { 1314ec2eca9Schristos poly1305_init_fpu(ctx, key); 132e7ccb6d1Schristos func[0] = (void*)(uintptr_t)poly1305_blocks_fpu; 133e7ccb6d1Schristos func[1] = (void*)(uintptr_t)poly1305_emit_fpu; 1344ec2eca9Schristos } else { 1354ec2eca9Schristos poly1305_init_int(ctx, key); 136e7ccb6d1Schristos func[0] = (void*)(uintptr_t)poly1305_blocks; 137e7ccb6d1Schristos func[1] = (void*)(uintptr_t)poly1305_emit; 1384ec2eca9Schristos } 1394ec2eca9Schristos return 1; 1404ec2eca9Schristos } 1414ec2eca9Schristos #endif 1424ec2eca9Schristos 143e7ccb6d1Schristos #ifdef ECP_NISTZ256_ASM 144e7ccb6d1Schristos void ecp_nistz256_mul_mont(unsigned long res[4], const unsigned long a[4], 145e7ccb6d1Schristos const unsigned long b[4]); 146e7ccb6d1Schristos 147e7ccb6d1Schristos void ecp_nistz256_to_mont(unsigned long res[4], const unsigned long in[4]); 148e7ccb6d1Schristos void ecp_nistz256_to_mont(unsigned long res[4], const unsigned long in[4]) 149e7ccb6d1Schristos { 150e7ccb6d1Schristos static const unsigned long RR[] = { 0x0000000000000003U, 151e7ccb6d1Schristos 0xfffffffbffffffffU, 152e7ccb6d1Schristos 0xfffffffffffffffeU, 153e7ccb6d1Schristos 0x00000004fffffffdU }; 154e7ccb6d1Schristos 155e7ccb6d1Schristos ecp_nistz256_mul_mont(res, in, RR); 156e7ccb6d1Schristos } 157e7ccb6d1Schristos 158e7ccb6d1Schristos void ecp_nistz256_from_mont(unsigned long res[4], const unsigned long in[4]); 159e7ccb6d1Schristos void ecp_nistz256_from_mont(unsigned long res[4], const unsigned long in[4]) 160e7ccb6d1Schristos { 161e7ccb6d1Schristos static const unsigned long one[] = { 1, 0, 0, 0 }; 162e7ccb6d1Schristos 163e7ccb6d1Schristos ecp_nistz256_mul_mont(res, in, one); 164e7ccb6d1Schristos } 165e7ccb6d1Schristos #endif 166e7ccb6d1Schristos 16713ce5681Schristos static sigjmp_buf ill_jmp; 168d572d25fSspz static void ill_handler(int sig) 169d572d25fSspz { 170d572d25fSspz siglongjmp(ill_jmp, sig); 171d572d25fSspz } 17213ce5681Schristos 1734ec2eca9Schristos void OPENSSL_fpu_probe(void); 17413ce5681Schristos void OPENSSL_ppc64_probe(void); 17521bfa713Schristos void OPENSSL_altivec_probe(void); 1767fa80bafSspz void OPENSSL_crypto207_probe(void); 1774ec2eca9Schristos void OPENSSL_madd300_probe(void); 17813ce5681Schristos 17992d83a12Schristos long OPENSSL_rdtsc_mftb(void); 18092d83a12Schristos long OPENSSL_rdtsc_mfspr268(void); 18192d83a12Schristos 18292d83a12Schristos uint32_t OPENSSL_rdtsc(void) 18392d83a12Schristos { 18492d83a12Schristos if (OPENSSL_ppccap_P & PPC_MFTB) 18592d83a12Schristos return OPENSSL_rdtsc_mftb(); 18692d83a12Schristos else if (OPENSSL_ppccap_P & PPC_MFSPR268) 18792d83a12Schristos return OPENSSL_rdtsc_mfspr268(); 18892d83a12Schristos else 18992d83a12Schristos return 0; 19092d83a12Schristos } 19192d83a12Schristos 19292d83a12Schristos size_t OPENSSL_instrument_bus_mftb(unsigned int *, size_t); 19392d83a12Schristos size_t OPENSSL_instrument_bus_mfspr268(unsigned int *, size_t); 19492d83a12Schristos 19592d83a12Schristos size_t OPENSSL_instrument_bus(unsigned int *out, size_t cnt) 19692d83a12Schristos { 19792d83a12Schristos if (OPENSSL_ppccap_P & PPC_MFTB) 19892d83a12Schristos return OPENSSL_instrument_bus_mftb(out, cnt); 19992d83a12Schristos else if (OPENSSL_ppccap_P & PPC_MFSPR268) 20092d83a12Schristos return OPENSSL_instrument_bus_mfspr268(out, cnt); 20192d83a12Schristos else 20292d83a12Schristos return 0; 20392d83a12Schristos } 20492d83a12Schristos 20592d83a12Schristos size_t OPENSSL_instrument_bus2_mftb(unsigned int *, size_t, size_t); 20692d83a12Schristos size_t OPENSSL_instrument_bus2_mfspr268(unsigned int *, size_t, size_t); 20792d83a12Schristos 20892d83a12Schristos size_t OPENSSL_instrument_bus2(unsigned int *out, size_t cnt, size_t max) 20992d83a12Schristos { 21092d83a12Schristos if (OPENSSL_ppccap_P & PPC_MFTB) 21192d83a12Schristos return OPENSSL_instrument_bus2_mftb(out, cnt, max); 21292d83a12Schristos else if (OPENSSL_ppccap_P & PPC_MFSPR268) 21392d83a12Schristos return OPENSSL_instrument_bus2_mfspr268(out, cnt, max); 21492d83a12Schristos else 21592d83a12Schristos return 0; 21692d83a12Schristos } 21792d83a12Schristos 21892d83a12Schristos #if defined(__GLIBC__) && defined(__GLIBC_PREREQ) 21992d83a12Schristos # if __GLIBC_PREREQ(2, 16) 22092d83a12Schristos # include <sys/auxv.h> 22192d83a12Schristos # define OSSL_IMPLEMENT_GETAUXVAL 22292d83a12Schristos # endif 2234ec2eca9Schristos #endif 2244ec2eca9Schristos 2254ec2eca9Schristos /* I wish <sys/auxv.h> was universally available */ 2264ec2eca9Schristos #define HWCAP 16 /* AT_HWCAP */ 2274ec2eca9Schristos #define HWCAP_PPC64 (1U << 30) 2284ec2eca9Schristos #define HWCAP_ALTIVEC (1U << 28) 2294ec2eca9Schristos #define HWCAP_FPU (1U << 27) 2304ec2eca9Schristos #define HWCAP_POWER6_EXT (1U << 9) 2314ec2eca9Schristos #define HWCAP_VSX (1U << 7) 2324ec2eca9Schristos 2334ec2eca9Schristos #define HWCAP2 26 /* AT_HWCAP2 */ 2344ec2eca9Schristos #define HWCAP_VEC_CRYPTO (1U << 25) 2354ec2eca9Schristos #define HWCAP_ARCH_3_00 (1U << 23) 2364ec2eca9Schristos 2374ec2eca9Schristos # if defined(__GNUC__) && __GNUC__>=2 2384ec2eca9Schristos __attribute__ ((constructor)) 2394ec2eca9Schristos # endif 24013ce5681Schristos void OPENSSL_cpuid_setup(void) 24113ce5681Schristos { 24213ce5681Schristos char *e; 24313ce5681Schristos struct sigaction ill_oact, ill_act; 24413ce5681Schristos sigset_t oset; 24513ce5681Schristos static int trigger = 0; 24613ce5681Schristos 247d572d25fSspz if (trigger) 248d572d25fSspz return; 24913ce5681Schristos trigger = 1; 25013ce5681Schristos 2514ec2eca9Schristos if ((e = getenv("OPENSSL_ppccap"))) { 2524ec2eca9Schristos OPENSSL_ppccap_P = strtoul(e, NULL, 0); 2534ec2eca9Schristos return; 2544ec2eca9Schristos } 2554ec2eca9Schristos 2564ec2eca9Schristos OPENSSL_ppccap_P = 0; 2574ec2eca9Schristos 2584ec2eca9Schristos #if defined(_AIX) 2594ec2eca9Schristos OPENSSL_ppccap_P |= PPC_FPU; 2604ec2eca9Schristos 2614ec2eca9Schristos if (sizeof(size_t) == 4) { 2624ec2eca9Schristos struct utsname uts; 2634ec2eca9Schristos # if defined(_SC_AIX_KERNEL_BITMODE) 2644ec2eca9Schristos if (sysconf(_SC_AIX_KERNEL_BITMODE) != 64) 2654ec2eca9Schristos return; 2664ec2eca9Schristos # endif 2674ec2eca9Schristos if (uname(&uts) != 0 || atoi(uts.version) < 6) 2684ec2eca9Schristos return; 2694ec2eca9Schristos } 2704ec2eca9Schristos 2714ec2eca9Schristos # if defined(__power_set) 2724ec2eca9Schristos /* 2734ec2eca9Schristos * Value used in __power_set is a single-bit 1<<n one denoting 2744ec2eca9Schristos * specific processor class. Incidentally 0xffffffff<<n can be 2754ec2eca9Schristos * used to denote specific processor and its successors. 2764ec2eca9Schristos */ 2774ec2eca9Schristos if (sizeof(size_t) == 4) { 2784ec2eca9Schristos /* In 32-bit case PPC_FPU64 is always fastest [if option] */ 2794ec2eca9Schristos if (__power_set(0xffffffffU<<13)) /* POWER5 and later */ 2804ec2eca9Schristos OPENSSL_ppccap_P |= PPC_FPU64; 2814ec2eca9Schristos } else { 2824ec2eca9Schristos /* In 64-bit case PPC_FPU64 is fastest only on POWER6 */ 2834ec2eca9Schristos if (__power_set(0x1U<<14)) /* POWER6 */ 2844ec2eca9Schristos OPENSSL_ppccap_P |= PPC_FPU64; 2854ec2eca9Schristos } 2864ec2eca9Schristos 2874ec2eca9Schristos if (__power_set(0xffffffffU<<14)) /* POWER6 and later */ 2884ec2eca9Schristos OPENSSL_ppccap_P |= PPC_ALTIVEC; 2894ec2eca9Schristos 2904ec2eca9Schristos if (__power_set(0xffffffffU<<16)) /* POWER8 and later */ 2914ec2eca9Schristos OPENSSL_ppccap_P |= PPC_CRYPTO207; 2924ec2eca9Schristos 2934ec2eca9Schristos if (__power_set(0xffffffffU<<17)) /* POWER9 and later */ 2944ec2eca9Schristos OPENSSL_ppccap_P |= PPC_MADD300; 2954ec2eca9Schristos 2964ec2eca9Schristos return; 2974ec2eca9Schristos # endif 2984ec2eca9Schristos #endif 2994ec2eca9Schristos 3004ec2eca9Schristos #if defined(__APPLE__) && defined(__MACH__) 3014ec2eca9Schristos OPENSSL_ppccap_P |= PPC_FPU; 3024ec2eca9Schristos 3034ec2eca9Schristos { 3044ec2eca9Schristos int val; 3054ec2eca9Schristos size_t len = sizeof(val); 3064ec2eca9Schristos 3074ec2eca9Schristos if (sysctlbyname("hw.optional.64bitops", &val, &len, NULL, 0) == 0) { 3084ec2eca9Schristos if (val) 3094ec2eca9Schristos OPENSSL_ppccap_P |= PPC_FPU64; 3104ec2eca9Schristos } 3114ec2eca9Schristos 3124ec2eca9Schristos len = sizeof(val); 3134ec2eca9Schristos if (sysctlbyname("hw.optional.altivec", &val, &len, NULL, 0) == 0) { 3144ec2eca9Schristos if (val) 3154ec2eca9Schristos OPENSSL_ppccap_P |= PPC_ALTIVEC; 3164ec2eca9Schristos } 3174ec2eca9Schristos 3184ec2eca9Schristos return; 3194ec2eca9Schristos } 3204ec2eca9Schristos #endif 3214ec2eca9Schristos 32292d83a12Schristos #ifdef OSSL_IMPLEMENT_GETAUXVAL 32392d83a12Schristos { 3244ec2eca9Schristos unsigned long hwcap = getauxval(HWCAP); 325380ea7e6Schristos unsigned long hwcap2 = getauxval(HWCAP2); 3264ec2eca9Schristos 3274ec2eca9Schristos if (hwcap & HWCAP_FPU) { 3284ec2eca9Schristos OPENSSL_ppccap_P |= PPC_FPU; 3294ec2eca9Schristos 3304ec2eca9Schristos if (sizeof(size_t) == 4) { 3314ec2eca9Schristos /* In 32-bit case PPC_FPU64 is always fastest [if option] */ 3324ec2eca9Schristos if (hwcap & HWCAP_PPC64) 3334ec2eca9Schristos OPENSSL_ppccap_P |= PPC_FPU64; 3344ec2eca9Schristos } else { 3354ec2eca9Schristos /* In 64-bit case PPC_FPU64 is fastest only on POWER6 */ 3364ec2eca9Schristos if (hwcap & HWCAP_POWER6_EXT) 3374ec2eca9Schristos OPENSSL_ppccap_P |= PPC_FPU64; 3384ec2eca9Schristos } 3394ec2eca9Schristos } 3404ec2eca9Schristos 3414ec2eca9Schristos if (hwcap & HWCAP_ALTIVEC) { 3424ec2eca9Schristos OPENSSL_ppccap_P |= PPC_ALTIVEC; 3434ec2eca9Schristos 344380ea7e6Schristos if ((hwcap & HWCAP_VSX) && (hwcap2 & HWCAP_VEC_CRYPTO)) 3454ec2eca9Schristos OPENSSL_ppccap_P |= PPC_CRYPTO207; 3464ec2eca9Schristos } 3474ec2eca9Schristos 348380ea7e6Schristos if (hwcap2 & HWCAP_ARCH_3_00) { 3494ec2eca9Schristos OPENSSL_ppccap_P |= PPC_MADD300; 3504ec2eca9Schristos } 3514ec2eca9Schristos } 35292d83a12Schristos #endif 3534ec2eca9Schristos 35413ce5681Schristos sigfillset(&all_masked); 35513ce5681Schristos sigdelset(&all_masked, SIGILL); 35613ce5681Schristos sigdelset(&all_masked, SIGTRAP); 35713ce5681Schristos #ifdef SIGEMT 35813ce5681Schristos sigdelset(&all_masked, SIGEMT); 35913ce5681Schristos #endif 36013ce5681Schristos sigdelset(&all_masked, SIGFPE); 36113ce5681Schristos sigdelset(&all_masked, SIGBUS); 36213ce5681Schristos sigdelset(&all_masked, SIGSEGV); 36313ce5681Schristos 36413ce5681Schristos memset(&ill_act, 0, sizeof(ill_act)); 36513ce5681Schristos ill_act.sa_handler = ill_handler; 36613ce5681Schristos ill_act.sa_mask = all_masked; 36713ce5681Schristos 36813ce5681Schristos sigprocmask(SIG_SETMASK, &ill_act.sa_mask, &oset); 36913ce5681Schristos sigaction(SIGILL, &ill_act, &ill_oact); 37013ce5681Schristos 37192d83a12Schristos #ifndef OSSL_IMPLEMENT_GETAUXVAL 372*d4503398Srin # ifdef __NetBSD__ 373*d4503398Srin int error, val; 374*d4503398Srin size_t len = sizeof(val); 375*d4503398Srin 376*d4503398Srin /* 377*d4503398Srin * If machdep.fpu_present == 0, FPU is absent and emulated by software. 378*d4503398Srin * Avoid using it as calculation results may not be correct in bit-to-bit 379*d4503398Srin * precision. 380*d4503398Srin */ 381*d4503398Srin error = sysctlbyname("machdep.fpu_present", &val, &len, NULL, 0); 382*d4503398Srin if (error != 0 || (error == 0 && val != 0)) 383*d4503398Srin # endif 3844ec2eca9Schristos if (sigsetjmp(ill_jmp,1) == 0) { 3854ec2eca9Schristos OPENSSL_fpu_probe(); 3864ec2eca9Schristos OPENSSL_ppccap_P |= PPC_FPU; 3874ec2eca9Schristos 388d572d25fSspz if (sizeof(size_t) == 4) { 3897fa80bafSspz # ifdef __linux 3907fa80bafSspz struct utsname uts; 3917fa80bafSspz if (uname(&uts) == 0 && strcmp(uts.machine, "ppc64") == 0) 3927fa80bafSspz # endif 393d572d25fSspz if (sigsetjmp(ill_jmp, 1) == 0) { 39413ce5681Schristos OPENSSL_ppc64_probe(); 39513ce5681Schristos OPENSSL_ppccap_P |= PPC_FPU64; 39613ce5681Schristos } 397d572d25fSspz } else { 39813ce5681Schristos /* 39913ce5681Schristos * Wanted code detecting POWER6 CPU and setting PPC_FPU64 40013ce5681Schristos */ 40113ce5681Schristos } 4024ec2eca9Schristos } 40313ce5681Schristos 404d572d25fSspz if (sigsetjmp(ill_jmp, 1) == 0) { 40513ce5681Schristos OPENSSL_altivec_probe(); 40613ce5681Schristos OPENSSL_ppccap_P |= PPC_ALTIVEC; 4077fa80bafSspz if (sigsetjmp(ill_jmp, 1) == 0) { 4087fa80bafSspz OPENSSL_crypto207_probe(); 4097fa80bafSspz OPENSSL_ppccap_P |= PPC_CRYPTO207; 4107fa80bafSspz } 41113ce5681Schristos } 41213ce5681Schristos 4134ec2eca9Schristos if (sigsetjmp(ill_jmp, 1) == 0) { 4144ec2eca9Schristos OPENSSL_madd300_probe(); 4154ec2eca9Schristos OPENSSL_ppccap_P |= PPC_MADD300; 4164ec2eca9Schristos } 41792d83a12Schristos #endif 41892d83a12Schristos 41992d83a12Schristos if (sigsetjmp(ill_jmp, 1) == 0) { 42092d83a12Schristos OPENSSL_rdtsc_mftb(); 42192d83a12Schristos OPENSSL_ppccap_P |= PPC_MFTB; 42292d83a12Schristos } else if (sigsetjmp(ill_jmp, 1) == 0) { 42392d83a12Schristos OPENSSL_rdtsc_mfspr268(); 42492d83a12Schristos OPENSSL_ppccap_P |= PPC_MFSPR268; 42592d83a12Schristos } 4264ec2eca9Schristos 42713ce5681Schristos sigaction(SIGILL, &ill_oact, NULL); 42813ce5681Schristos sigprocmask(SIG_SETMASK, &oset, NULL); 42913ce5681Schristos } 430