12 #ifdef CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY
17 #if defined(_ARCH_PWR8) || defined(__CRYPTO__)
22 extern const char PPC_POWER8_FNAME[] = __FILE__;
28 #ifdef CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY
30 typedef void (*SigHandler)(int);
32 static jmp_buf s_jmpSIGILL;
33 static void SigIllHandler(
int)
35 longjmp(s_jmpSIGILL, 1);
40 #if (CRYPTOPP_BOOL_PPC32 || CRYPTOPP_BOOL_PPC64)
42 bool CPU_ProbePower8()
44 #if defined(CRYPTOPP_NO_CPU_FEATURE_PROBES)
46 #elif (_ARCH_PWR8) && defined(CRYPTOPP_POWER8_AVAILABLE)
47 # if defined(CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY)
51 volatile int result =
true;
53 volatile SigHandler oldHandler = signal(SIGILL, SigIllHandler);
54 if (oldHandler == SIG_ERR)
57 volatile sigset_t oldMask;
58 if (sigprocmask(0, NULLPTR, (sigset_t*)&oldMask))
61 if (setjmp(s_jmpSIGILL))
66 const word64 x = W64LIT(0xffffffffffffffff);
67 word64 w1[2] = {x, x}, w2[2] = {4, 6}, w3[2];
70 #if defined(__ibmxl__) || (defined(_AIX) && defined(__xlC__))
71 const uint64x2_p v1 = vec_xl(0, (
unsigned long long*)w1);
72 const uint64x2_p v2 = vec_xl(0, (
unsigned long long*)w2);
74 vec_xst(v3, 0, (
unsigned long long*)w3);
83 result = (w3[0] == 3 && w3[1] == 5);
86 sigprocmask(SIG_SETMASK, (sigset_t*)&oldMask, NULLPTR);
87 signal(SIGILL, oldHandler);
97 #if defined(CRYPTOPP_NO_CPU_FEATURE_PROBES)
99 #elif (__CRYPTO__) && defined(CRYPTOPP_POWER8_AES_AVAILABLE)
100 # if defined(CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY)
104 volatile int result =
true;
106 volatile SigHandler oldHandler = signal(SIGILL, SigIllHandler);
107 if (oldHandler == SIG_ERR)
110 volatile sigset_t oldMask;
111 if (sigprocmask(0, NULLPTR, (sigset_t*)&oldMask))
114 if (setjmp(s_jmpSIGILL))
118 byte key[16] = {0xA0, 0xFA, 0xFE, 0x17, 0x88, 0x54, 0x2c, 0xb1,
119 0x23, 0xa3, 0x39, 0x39, 0x2a, 0x6c, 0x76, 0x05};
120 byte state[16] = {0x19, 0x3d, 0xe3, 0xb3, 0xa0, 0xf4, 0xe2, 0x2b,
121 0x9a, 0xc6, 0x8d, 0x2a, 0xe9, 0xf8, 0x48, 0x08};
122 byte r[16] = {255}, z[16] = {};
132 result = (0 != std::memcmp(r, z, 16));
135 sigprocmask(SIG_SETMASK, (sigset_t*)&oldMask, NULLPTR);
136 signal(SIGILL, oldHandler);
144 bool CPU_ProbeSHA256()
146 #if defined(CRYPTOPP_NO_CPU_FEATURE_PROBES)
148 #elif (__CRYPTO__) && defined(CRYPTOPP_POWER8_SHA_AVAILABLE)
149 # if defined(CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY)
153 volatile int result =
false;
155 volatile SigHandler oldHandler = signal(SIGILL, SigIllHandler);
156 if (oldHandler == SIG_ERR)
159 volatile sigset_t oldMask;
160 if (sigprocmask(0, NULLPTR, (sigset_t*)&oldMask))
163 if (setjmp(s_jmpSIGILL))
167 byte r[16], z[16] = {0};
168 uint8x16_p x = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
170 x = VecSHA256<0,0>(x);
171 x = VecSHA256<0,0xf>(x);
172 x = VecSHA256<1,0>(x);
173 x = VecSHA256<1,0xf>(x);
176 result = (0 == std::memcmp(r, z, 16));
179 sigprocmask(SIG_SETMASK, (sigset_t*)&oldMask, NULLPTR);
180 signal(SIGILL, oldHandler);
188 bool CPU_ProbeSHA512()
190 #if defined(CRYPTOPP_NO_CPU_FEATURE_PROBES)
192 #elif (__CRYPTO__) && defined(CRYPTOPP_POWER8_SHA_AVAILABLE)
193 # if defined(CRYPTOPP_GNU_STYLE_INLINE_ASSEMBLY)
197 volatile int result =
false;
199 volatile SigHandler oldHandler = signal(SIGILL, SigIllHandler);
200 if (oldHandler == SIG_ERR)
203 volatile sigset_t oldMask;
204 if (sigprocmask(0, NULLPTR, (sigset_t*)&oldMask))
207 if (setjmp(s_jmpSIGILL))
211 byte r[16], z[16] = {0};
212 uint8x16_p x = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
214 x = VecSHA512<0,0>(x);
215 x = VecSHA512<0,0xf>(x);
216 x = VecSHA512<1,0>(x);
217 x = VecSHA512<1,0xf>(x);
220 result = (0 == std::memcmp(r, z, 16));
223 sigprocmask(SIG_SETMASK, (sigset_t*)&oldMask, NULLPTR);
224 signal(SIGILL, oldHandler);
Library configuration file.
Crypto++ library namespace.
Support functions for PowerPC and vector operations.
__vector unsigned char uint8x16_p
Vector of 8-bit elements.
__vector unsigned long long uint64x2_p
Vector of 64-bit elements.
T1 VecEncryptLast(const T1 state, const T2 key)
Final round of AES encryption.
T1 VecEncrypt(const T1 state, const T2 key)
One round of AES encryption.
T1 VecDecryptLast(const T1 state, const T2 key)
Final round of AES decryption.
T1 VecDecrypt(const T1 state, const T2 key)
One round of AES decryption.
void VecStore(const T data, byte dest[16])
Stores a vector to a byte array.
uint32x4_p VecLoad(const byte src[16])
Loads a vector from a byte array.