Crypto++  5.6.3
Free C++ class library of cryptographic schemes
cpu.cpp
1 // cpu.cpp - written and placed in the public domain by Wei Dai
2 
3 #include "pch.h"
4 #include "config.h"
5 
6 #ifndef EXCEPTION_EXECUTE_HANDLER
7 # define EXCEPTION_EXECUTE_HANDLER 1
8 #endif
9 
10 #ifndef CRYPTOPP_IMPORTS
11 
12 #include "cpu.h"
13 #include "misc.h"
14 #include <algorithm>
15 
16 #ifndef CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY
17 #include <signal.h>
18 #include <setjmp.h>
19 #endif
20 
21 #if CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE
22 #include <emmintrin.h>
23 #endif
24 
25 NAMESPACE_BEGIN(CryptoPP)
26 
27 #ifndef CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY
28 
29 // MacPorts/GCC does not provide constructor(priority). Apple/GCC and Fink/GCC do provide it.
30 #define HAVE_GCC_CONSTRUCTOR1 (__GNUC__ && (CRYPTOPP_INIT_PRIORITY > 0) && ((CRYPTOPP_GCC_VERSION >= 40300) || (CRYPTOPP_CLANG_VERSION >= 20900) || (_INTEL_COMPILER >= 300)) && !(MACPORTS_GCC_COMPILER > 0))
31 #define HAVE_GCC_CONSTRUCTOR0 (__GNUC__ && (CRYPTOPP_INIT_PRIORITY > 0) && !(MACPORTS_GCC_COMPILER > 0))
32 
33 extern "C" {
34  typedef void (*SigHandler)(int);
35 };
36 #endif // Not CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY
37 
38 #ifdef CRYPTOPP_CPUID_AVAILABLE
39 
40 #if _MSC_VER >= 1400 && CRYPTOPP_BOOL_X64
41 
42 bool CpuId(word32 input, word32 output[4])
43 {
44  __cpuid((int *)output, input);
45  return true;
46 }
47 
48 #else
49 
50 #ifndef CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY
51 extern "C" {
52 
53 static jmp_buf s_jmpNoCPUID;
54 static void SigIllHandlerCPUID(int)
55 {
56  longjmp(s_jmpNoCPUID, 1);
57 }
58 
59 static jmp_buf s_jmpNoSSE2;
60 static void SigIllHandlerSSE2(int)
61 {
62  longjmp(s_jmpNoSSE2, 1);
63 }
64 }
65 #endif
66 
67 bool CpuId(word32 input, word32 output[4])
68 {
69 #if defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY)
70  __try
71  {
72  __asm
73  {
74  mov eax, input
75  mov ecx, 0
76  cpuid
77  mov edi, output
78  mov [edi], eax
79  mov [edi+4], ebx
80  mov [edi+8], ecx
81  mov [edi+12], edx
82  }
83  }
84  // GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION
85  __except (EXCEPTION_EXECUTE_HANDLER)
86  {
87  return false;
88  }
89 
90  // function 0 returns the highest basic function understood in EAX
91  if(input == 0)
92  return !!output[0];
93 
94  return true;
95 #else
96  // longjmp and clobber warnings. Volatile is required.
97  // http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854
98  volatile bool result = true;
99 
100  SigHandler oldHandler = signal(SIGILL, SigIllHandlerCPUID);
101  if (oldHandler == SIG_ERR)
102  result = false;
103 
104  if (setjmp(s_jmpNoCPUID))
105  result = false;
106  else
107  {
108  asm volatile
109  (
110  // save ebx in case -fPIC is being used
111  // TODO: this might need an early clobber on EDI.
112 # if CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64
113  "pushq %%rbx; cpuid; mov %%ebx, %%edi; popq %%rbx"
114 # else
115  "push %%ebx; cpuid; mov %%ebx, %%edi; pop %%ebx"
116 # endif
117  : "=a" (output[0]), "=D" (output[1]), "=c" (output[2]), "=d" (output[3])
118  : "a" (input), "c" (0)
119  );
120  }
121 
122  signal(SIGILL, oldHandler);
123  return result;
124 #endif
125 }
126 
127 #endif
128 
129 static bool TrySSE2()
130 {
131 #if CRYPTOPP_BOOL_X64
132  return true;
133 #elif defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY)
134  __try
135  {
136 #if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE
137  AS2(por xmm0, xmm0) // executing SSE2 instruction
138 #elif CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE
139  __m128i x = _mm_setzero_si128();
140  return _mm_cvtsi128_si32(x) == 0;
141 #endif
142  }
143  // GetExceptionCode() == EXCEPTION_ILLEGAL_INSTRUCTION
144  __except (EXCEPTION_EXECUTE_HANDLER)
145  {
146  return false;
147  }
148  return true;
149 #else
150  // longjmp and clobber warnings. Volatile is required.
151  // http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854
152  volatile bool result = true;
153 
154  SigHandler oldHandler = signal(SIGILL, SigIllHandlerSSE2);
155  if (oldHandler == SIG_ERR)
156  return false;
157 
158  if (setjmp(s_jmpNoSSE2))
159  result = true;
160  else
161  {
162 #if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE
163  __asm __volatile ("por %xmm0, %xmm0");
164 #elif CRYPTOPP_BOOL_SSE2_INTRINSICS_AVAILABLE
165  __m128i x = _mm_setzero_si128();
166  result = _mm_cvtsi128_si32(x) == 0;
167 #endif
168  }
169 
170  signal(SIGILL, oldHandler);
171  return result;
172 #endif
173 }
174 
175 bool g_x86DetectionDone = false;
176 bool g_hasMMX = false, g_hasISSE = false, g_hasSSE2 = false, g_hasSSSE3 = false, g_hasSSE4 = false, g_hasAESNI = false, g_hasCLMUL = false, g_isP4 = false, g_hasRDRAND = false, g_hasRDSEED = false;
177 bool g_hasPadlockRNG = false, g_hasPadlockACE = false, g_hasPadlockACE2 = false, g_hasPadlockPHE = false, g_hasPadlockPMM = false;
178 word32 g_cacheLineSize = CRYPTOPP_L1_CACHE_LINE_SIZE;
179 
180 static inline bool IsIntel(const word32 output[4])
181 {
182  // This is the "GenuineIntel" string
183  return (output[1] /*EBX*/ == 0x756e6547) &&
184  (output[2] /*ECX*/ == 0x6c65746e) &&
185  (output[3] /*EDX*/ == 0x49656e69);
186 }
187 
188 static inline bool IsAMD(const word32 output[4])
189 {
190  // This is the "AuthenticAMD" string. Some early K5's can return "AMDisbetter!"
191  return (output[1] /*EBX*/ == 0x68747541) &&
192  (output[2] /*ECX*/ == 0x444D4163) &&
193  (output[3] /*EDX*/ == 0x69746E65);
194 }
195 
196 static inline bool IsVIA(const word32 output[4])
197 {
198  // This is the "CentaurHauls" string. Some non-PadLock can return "VIA VIA VIA ".
199  return (output[1] /*EBX*/ == 0x746e6543) &&
200  (output[2] /*ECX*/ == 0x736c7561) &&
201  (output[3] /*EDX*/ == 0x48727561);
202 }
203 
204 #if HAVE_GCC_CONSTRUCTOR1
205 void __attribute__ ((constructor (CRYPTOPP_INIT_PRIORITY + 50))) DetectX86Features()
206 #elif HAVE_GCC_CONSTRUCTOR0
207 void __attribute__ ((constructor)) DetectX86Features()
208 #else
209 void DetectX86Features()
210 #endif
211 {
212  word32 cpuid[4], cpuid1[4];
213  if (!CpuId(0, cpuid))
214  return;
215  if (!CpuId(1, cpuid1))
216  return;
217 
218  g_hasMMX = (cpuid1[3] & (1 << 23)) != 0;
219  if ((cpuid1[3] & (1 << 26)) != 0)
220  g_hasSSE2 = TrySSE2();
221  g_hasSSSE3 = g_hasSSE2 && (cpuid1[2] & (1<<9));
222  g_hasSSE4 = g_hasSSE2 && ((cpuid1[2] & (1<<19)) && (cpuid1[2] & (1<<20)));
223  g_hasAESNI = g_hasSSE2 && (cpuid1[2] & (1<<25));
224  g_hasCLMUL = g_hasSSE2 && (cpuid1[2] & (1<<1));
225 
226  if ((cpuid1[3] & (1 << 25)) != 0)
227  g_hasISSE = true;
228  else
229  {
230  word32 cpuid2[4];
231  CpuId(0x080000000, cpuid2);
232  if (cpuid2[0] >= 0x080000001)
233  {
234  CpuId(0x080000001, cpuid2);
235  g_hasISSE = (cpuid2[3] & (1 << 22)) != 0;
236  }
237  }
238 
239  if (IsIntel(cpuid))
240  {
241  static const unsigned int RDRAND_FLAG = (1 << 30);
242  static const unsigned int RDSEED_FLAG = (1 << 18);
243 
244  g_isP4 = ((cpuid1[0] >> 8) & 0xf) == 0xf;
245  g_cacheLineSize = 8 * GETBYTE(cpuid1[1], 1);
246  g_hasRDRAND = !!(cpuid1[2] /*ECX*/ & RDRAND_FLAG);
247 
248  if (cpuid[0] /*EAX*/ >= 7)
249  {
250  word32 cpuid3[4];
251  if (CpuId(7, cpuid3))
252  g_hasRDSEED = !!(cpuid3[1] /*EBX*/ & RDSEED_FLAG);
253  }
254  }
255  else if (IsAMD(cpuid))
256  {
257  static const unsigned int RDRAND_FLAG = (1 << 30);
258 
259  CpuId(0x01, cpuid);
260  g_hasRDRAND = !!(cpuid[2] /*ECX*/ & RDRAND_FLAG);
261 
262  CpuId(0x80000005, cpuid);
263  g_cacheLineSize = GETBYTE(cpuid[2], 0);
264  }
265  else if (IsVIA(cpuid))
266  {
267  static const unsigned int RNG_FLAGS = (0x3 << 2);
268  static const unsigned int ACE_FLAGS = (0x3 << 6);
269  static const unsigned int ACE2_FLAGS = (0x3 << 8);
270  static const unsigned int PHE_FLAGS = (0x3 << 10);
271  static const unsigned int PMM_FLAGS = (0x3 << 12);
272 
273  CpuId(0xC0000000, cpuid);
274  if (cpuid[0] < 0xC0000001)
275  {
276  // No extended features
277  g_hasPadlockRNG = false;
278  g_hasPadlockACE = false;
279  g_hasPadlockACE2 = false;
280  g_hasPadlockPHE = false;
281  g_hasPadlockPMM = false;
282  }
283  else
284  {
285  // Extended features available
286  CpuId(0xC0000001, cpuid);
287  g_hasPadlockRNG = !!(cpuid[3] /*EDX*/ & RNG_FLAGS);
288  g_hasPadlockACE = !!(cpuid[3] /*EDX*/ & ACE_FLAGS);
289  g_hasPadlockACE2 = !!(cpuid[3] /*EDX*/ & ACE2_FLAGS);
290  g_hasPadlockPHE = !!(cpuid[3] /*EDX*/ & PHE_FLAGS);
291  g_hasPadlockPMM = !!(cpuid[3] /*EDX*/ & PMM_FLAGS);
292  }
293  }
294 
295  if (!g_cacheLineSize)
296  g_cacheLineSize = CRYPTOPP_L1_CACHE_LINE_SIZE;
297 
298  *((volatile bool*)&g_x86DetectionDone) = true;
299 }
300 
301 // http://community.arm.com/groups/android-community/blog/2014/10/10/runtime-detection-of-cpu-features-on-an-armv8-a-cpu
302 // http://stackoverflow.com/questions/26701262/how-to-check-the-existence-of-neon-on-arm
303 #elif (CRYPTOPP_BOOL_ARM32 || CRYPTOPP_BOOL_ARM64)
304 
305 bool g_ArmDetectionDone = false;
306 bool g_hasNEON = false, g_hasCRC32 = false, g_hasAES = false, g_hasSHA1 = false, g_hasSHA2 = false;
307 
308 word32 g_cacheLineSize = CRYPTOPP_L1_CACHE_LINE_SIZE;
309 
310 // The ARM equivalent of CPUID is reading a MSR. For example, fetch crypto capabilities with:
311 // #if defined(__arm64__) || defined(__aarch64__)
312 // word64 caps = 0; // Read ID_AA64ISAR0_EL1
313 // __asm __volatile("mrs %0, " "id_aa64isar0_el1" : "=r" (caps));
314 // #elif defined(__arm__) || defined(__aarch32__)
315 // word32 caps = 0; // Read ID_ISAR5_EL1
316 // __asm __volatile("mrs %0, " "id_isar5_el1" : "=r" (caps));
317 // #endif
318 // The code requires Exception Level 1 (EL1) and above, but user space runs at EL0.
319 // Attempting to run the code results in a SIGILL and termination.
320 
321 #ifndef CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY
322 extern "C" {
323 
324  static jmp_buf s_jmpNoNEON;
325  static void SigIllHandlerNEON(int)
326  {
327  longjmp(s_jmpNoNEON, 1);
328  }
329 
330  static jmp_buf s_jmpNoCRC32;
331  static void SigIllHandlerCRC32(int)
332  {
333  longjmp(s_jmpNoCRC32, 1);
334  }
335 
336  static jmp_buf s_jmpNoAES;
337  static void SigIllHandlerAES(int)
338  {
339  longjmp(s_jmpNoAES, 1);
340  }
341 
342  static jmp_buf s_jmpNoSHA1;
343  static void SigIllHandlerSHA1(int)
344  {
345  longjmp(s_jmpNoSHA1, 1);
346  }
347 
348  static jmp_buf s_jmpNoSHA2;
349  static void SigIllHandlerSHA2(int)
350  {
351  longjmp(s_jmpNoSHA2, 1);
352  }
353 };
354 #endif // Not CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY
355 
356 static bool TryNEON()
357 {
358 #if (CRYPTOPP_BOOL_NEON_INTRINSICS_AVAILABLE)
359 # if defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY)
360  __try
361  {
362  static const uint32_t v1[4] = {1,1,1,1};
363  uint32x4_t x1 = vld1q_u32(v1);
364  static const uint64_t v2[2] = {1,1};
365  uint64x2_t x2 = vld1q_u64(v2);
366 
367  uint32x4_t x3 = vdupq_n_u32(0);
368  x3 = vsetq_lane_u32(vgetq_lane_u32(x1,0),x3,0);
369  x3 = vsetq_lane_u32(vgetq_lane_u32(x1,3),x3,3);
370  uint64x2_t x4 = vdupq_n_u64(0);
371  x4 = vsetq_lane_u64(vgetq_lane_u64(x2,0),x4,0);
372  x4 = vsetq_lane_u64(vgetq_lane_u64(x2,1),x4,1);
373  }
374  __except (EXCEPTION_EXECUTE_HANDLER)
375  {
376  return false;
377  }
378  return true;
379 # else
380  // longjmp and clobber warnings. Volatile is required.
381  // http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854
382  volatile bool result = true;
383 
384  SigHandler oldHandler = signal(SIGILL, SigIllHandlerNEON);
385  if (oldHandler == SIG_ERR)
386  result = false;
387 
388  if (setjmp(s_jmpNoNEON))
389  result = false;
390  else
391  {
392  static const uint32_t v1[4] = {1,1,1,1};
393  uint32x4_t x1 = vld1q_u32(v1);
394  static const uint64_t v2[2] = {1,1};
395  uint64x2_t x2 = vld1q_u64(v2);
396 
397  uint32x4_t x3 = vdupq_n_u32(0);
398  x3 = vsetq_lane_u32(vgetq_lane_u32(x1,0),x3,0);
399  x3 = vsetq_lane_u32(vgetq_lane_u32(x1,3),x3,3);
400  uint64x2_t x4 = vdupq_n_u64(0);
401  x4 = vsetq_lane_u64(vgetq_lane_u64(x2,0),x4,0);
402  x4 = vsetq_lane_u64(vgetq_lane_u64(x2,1),x4,1);
403  }
404 
405  signal(SIGILL, oldHandler);
406  return result;
407 # endif
408 #else
409  return false;
410 #endif // CRYPTOPP_BOOL_NEON_INTRINSICS_AVAILABLE
411 }
412 
413 static bool TryCRC32()
414 {
415 #if (CRYPTOPP_BOOL_ARM_CRC32_INTRINSICS_AVAILABLE)
416 # if defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY)
417  __try
418  {
419  word32 w=0, x=0; word16 y=0; byte z=0;
420  w = __crc32cw(w,x);
421  w = __crc32ch(w,y);
422  w = __crc32cb(w,z);
423  }
424  __except (EXCEPTION_EXECUTE_HANDLER)
425  {
426  return false;
427  }
428  return true;
429 # else
430  // longjmp and clobber warnings. Volatile is required.
431  // http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854
432  volatile bool result = true;
433 
434  SigHandler oldHandler = signal(SIGILL, SigIllHandlerCRC32);
435  if (oldHandler == SIG_ERR)
436  result = false;
437 
438  if (setjmp(s_jmpNoCRC32))
439  result = false;
440  else
441  {
442  word32 w=0, x=0; word16 y=0; byte z=0;
443  w = __crc32cw(w,x);
444  w = __crc32ch(w,y);
445  w = __crc32cb(w,z);
446  }
447 
448  signal(SIGILL, oldHandler);
449  return result;
450 # endif
451 #else
452  return false;
453 #endif // CRYPTOPP_BOOL_ARM_CRC32_INTRINSICS_AVAILABLE
454 }
455 
456 static bool TryAES()
457 {
458 #if (CRYPTOPP_BOOL_ARM_CRYPTO_INTRINSICS_AVAILABLE)
459 # if defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY)
460  __try
461  {
462  // AES encrypt and decrypt
463  static const uint8x16_t data = vdupq_n_u8(0), key = vdupq_n_u8(0);
464  uint8x16_t r1 = vaeseq_u8(data, key);
465  uint8x16_t r2 = vaesdq_u8(data, key);
466  CRYPTOPP_UNUSED(r1), CRYPTOPP_UNUSED(r2);
467  }
468  __except (EXCEPTION_EXECUTE_HANDLER)
469  {
470  return false;
471  }
472  return true;
473 # else
474  // longjmp and clobber warnings. Volatile is required.
475  // http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854
476  volatile bool result = true;
477 
478  SigHandler oldHandler = signal(SIGILL, SigIllHandlerAES);
479  if (oldHandler == SIG_ERR)
480  result = false;
481 
482  if (setjmp(s_jmpNoAES))
483  result = false;
484  else
485  {
486  static const uint8x16_t data = vdupq_n_u8(0), key = vdupq_n_u8(0);
487  uint8x16_t r1 = vaeseq_u8(data, key);
488  uint8x16_t r2 = vaesdq_u8(data, key);
489  CRYPTOPP_UNUSED(r1), CRYPTOPP_UNUSED(r2);
490  }
491 
492  signal(SIGILL, oldHandler);
493  return result;
494 # endif
495 #else
496  return false;
497 #endif // CRYPTOPP_BOOL_ARM_CRYPTO_INTRINSICS_AVAILABLE
498 }
499 
500 static bool TrySHA1()
501 {
502 #if (CRYPTOPP_BOOL_ARM_CRYPTO_INTRINSICS_AVAILABLE)
503 # if defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY)
504  __try
505  {
506  static const uint32x4_t data = vdupq_n_u32(0);
507  static const uint32_t hash = 0x0;
508 
509  uint32x4_t r1 = vsha1cq_u32 (data, hash, data);
510  uint32x4_t r2 = vsha1mq_u32 (data, hash, data);
511  uint32x4_t r3 = vsha1pq_u32 (data, hash, data);
512  CRYPTOPP_UNUSED(r1), CRYPTOPP_UNUSED(r2), CRYPTOPP_UNUSED(r3);
513  }
514  __except (EXCEPTION_EXECUTE_HANDLER)
515  {
516  return false;
517  }
518  return true;
519 # else
520  // longjmp and clobber warnings. Volatile is required.
521  // http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854
522  volatile bool result = true;
523 
524  SigHandler oldHandler = signal(SIGILL, SigIllHandlerSHA1);
525  if (oldHandler == SIG_ERR)
526  result = false;
527 
528  if (setjmp(s_jmpNoSHA1))
529  result = false;
530  else
531  {
532  static const uint32x4_t data = vdupq_n_u32(0);
533  static const uint32_t hash = 0x0;
534 
535  uint32x4_t r1 = vsha1cq_u32 (data, hash, data);
536  uint32x4_t r2 = vsha1mq_u32 (data, hash, data);
537  uint32x4_t r3 = vsha1pq_u32 (data, hash, data);
538  CRYPTOPP_UNUSED(r1), CRYPTOPP_UNUSED(r2), CRYPTOPP_UNUSED(r3);
539  }
540 
541  signal(SIGILL, oldHandler);
542  return result;
543 # endif
544 #else
545  return false;
546 #endif // CRYPTOPP_BOOL_ARM_CRYPTO_INTRINSICS_AVAILABLE
547 }
548 
549 static bool TrySHA2()
550 {
551 #if (CRYPTOPP_BOOL_ARM_CRYPTO_INTRINSICS_AVAILABLE)
552 # if defined(CRYPTOPP_MS_STYLE_INLINE_ASSEMBLY)
553  __try
554  {
555  static const uint32x4_t data = vdupq_n_u32(0);
556  static const uint32x4_t hash = vdupq_n_u32(0);
557 
558  uint32x4_t r1 = vsha256hq_u32 (hash, hash, data);
559  uint32x4_t r2 = vsha256h2q_u32 (hash, hash, data);
560  uint32x4_t r3 = vsha256su0q_u32 (data, data);
561  uint32x4_t r4 = vsha256su1q_u32 (data, data, data);
562  CRYPTOPP_UNUSED(r1), CRYPTOPP_UNUSED(r2), CRYPTOPP_UNUSED(r3), CRYPTOPP_UNUSED(r4);
563  }
564  __except (EXCEPTION_EXECUTE_HANDLER)
565  {
566  return false;
567  }
568  return true;
569 # else
570  // longjmp and clobber warnings. Volatile is required.
571  // http://github.com/weidai11/cryptopp/issues/24 and http://stackoverflow.com/q/7721854
572  volatile bool result = true;
573 
574  SigHandler oldHandler = signal(SIGILL, SigIllHandlerSHA2);
575  if (oldHandler == SIG_ERR)
576  result = false;
577 
578  if (setjmp(s_jmpNoSHA2))
579  result = false;
580  else
581  {
582  static const uint32x4_t data = vdupq_n_u32(0);
583  static const uint32x4_t hash = vdupq_n_u32(0);
584 
585  uint32x4_t r1 = vsha256hq_u32 (hash, hash, data);
586  uint32x4_t r2 = vsha256h2q_u32 (hash, hash, data);
587  uint32x4_t r3 = vsha256su0q_u32 (data, data);
588  uint32x4_t r4 = vsha256su1q_u32 (data, data, data);
589  CRYPTOPP_UNUSED(r1), CRYPTOPP_UNUSED(r2), CRYPTOPP_UNUSED(r3), CRYPTOPP_UNUSED(r4);
590  }
591 
592  signal(SIGILL, oldHandler);
593  return result;
594 # endif
595 #else
596  return false;
597 #endif // CRYPTOPP_BOOL_ARM_CRYPTO_INTRINSICS_AVAILABLE
598 }
599 
600 #if HAVE_GCC_CONSTRUCTOR1
601 void __attribute__ ((constructor (CRYPTOPP_INIT_PRIORITY + 50))) DetectArmFeatures()
602 #elif HAVE_GCC_CONSTRUCTOR0
603 void __attribute__ ((constructor)) DetectArmFeatures()
604 #else
605 void DetectArmFeatures()
606 #endif
607 {
608  g_hasNEON = TryNEON();
609  g_hasCRC32 = TryCRC32();
610  g_hasAES = TryAES();
611  g_hasSHA1 = TrySHA1();
612  g_hasSHA2 = TrySHA2();
613 
614  *((volatile bool*)&g_ArmDetectionDone) = true;
615 }
616 
617 #endif
618 
619 NAMESPACE_END
620 
621 #endif
Utility functions for the Crypto++ library.
Library configuration file.
Functions for CPU features and intrinsics.
Crypto++ library namespace.