~ubuntu-branches/debian/sid/botan/sid

« back to all changes in this revision

Viewing changes to src/lib/entropy/rdseed/rdseed.cpp

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2018-03-01 22:23:25 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20180301222325-7p7vc45gu3hta34d
Tags: 2.4.0-2
* Don't remove .doctrees from the manual if it doesn't exist.
* Don't specify parallel to debhelper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
* Entropy Source Using Intel's rdseed instruction
 
3
* (C) 2015 Jack Lloyd, Daniel Neus
 
4
*
 
5
* Botan is released under the Simplified BSD License (see license.txt)
 
6
*/
 
7
 
 
8
#include <botan/internal/rdseed.h>
 
9
#include <botan/cpuid.h>
 
10
 
 
11
#if !defined(BOTAN_USE_GCC_INLINE_ASM)
 
12
  #include <immintrin.h>
 
13
#endif
 
14
 
 
15
namespace Botan {
 
16
 
 
17
BOTAN_FUNC_ISA("rdseed")
 
18
size_t Intel_Rdseed::poll(RandomNumberGenerator& rng) {
 
19
   if(CPUID::has_rdseed())
 
20
      {
 
21
      for(size_t p = 0; p != BOTAN_ENTROPY_INTEL_RNG_POLLS; ++p)
 
22
         {
 
23
         for(size_t i = 0; i != BOTAN_ENTROPY_RDSEED_RETRIES; ++i)
 
24
            {
 
25
            uint32_t r = 0;
 
26
 
 
27
#if defined(BOTAN_USE_GCC_INLINE_ASM)
 
28
            int cf = 0;
 
29
 
 
30
            // Encoding of rdseed %eax
 
31
            asm(".byte 0x0F, 0xC7, 0xF8; adcl $0,%1" :
 
32
                "=a" (r), "=r" (cf) : "0" (r), "1" (cf) : "cc");
 
33
#else
 
34
            int cf = _rdseed32_step(&r);
 
35
#endif
 
36
            if(1 == cf)
 
37
               {
 
38
               rng.add_entropy_T(r);
 
39
               break;
 
40
               }
 
41
            }
 
42
         }
 
43
      }
 
44
 
 
45
   return 0;
 
46
   }
 
47
 
 
48
}