Home | History | Annotate | Download | only in tpm2
      1 // This file was extracted from the TCG Published
      2 // Trusted Platform Module Library
      3 // Part 4: Supporting Routines
      4 // Family "2.0"
      5 // Level 00 Revision 01.16
      6 // October 30, 2014
      7 
      8 #ifndef        RSA_H
      9 #define        RSA_H
     10 //
     11 //       This value is used to set the size of the table that is searched by the prime iterator. This is used during
     12 //       the generation of different primes. The smaller tables are used when generating smaller primes.
     13 //
     14 extern const UINT16        primeTableBytes;
     15 //
     16 //       The following define determines how large the prime number difference table will be defined. The value of
     17 //       13 will allocate the maximum size table which allows generation of the first 6542 primes which is all the
     18 //       primes less than 2^16.
     19 #define PRIME_DIFF_TABLE_512_BYTE_PAGES                  13
     20 //
     21 //     This set of macros used the value above to set the table size.
     22 //
     23 #ifndef PRIME_DIFF_TABLE_512_BYTE_PAGES
     24 #   define PRIME_DIFF_TABLE_512_BYTE_PAGES      4
     25 #endif
     26 #ifdef PRIME_DIFF_TABLE_512_BYTE_PAGES
     27 #   if PRIME_DIFF_TABLE_512_BYTE_PAGES > 12
     28 #        define PRIME_DIFF_TABLE_BYTES 6542
     29 #   else
     30 #        if PRIME_DIFF_TABLE_512_BYTE_PAGES <= 0
     31 #             define PRIME_DIFF_TABLE_BYTES 512
     32 #        else
     33 #             define PRIME_DIFF_TABLE_BYTES (PRIME_DIFF_TABLE_512_BYTE_PAGES * 512)
     34 #        endif
     35 #   endif
     36 #endif
     37 extern const BYTE primeDiffTable [PRIME_DIFF_TABLE_BYTES];
     38 //
     39 //     This determines the number of bits in the sieve field This must be a power of two.
     40 //
     41 #define FIELD_POWER            14  // This is the only value in this group that should be
     42                                   // changed
     43 #define FIELD_BITS             (1 << FIELD_POWER)
     44 #define MAX_FIELD_SIZE             ((FIELD_BITS / 8) + 1)
     45 //
     46 //     This is the pre-sieved table. It already has the bits for multiples of 3, 5, and 7 cleared.
     47 //
     48 #define SEED_VALUES_SIZE                    105
     49 const extern BYTE                           seedValues[SEED_VALUES_SIZE];
     50 //
     51 //     This allows determination of the number of bits that are set in a byte without having to count them
     52 //     individually.
     53 //
     54 const extern BYTE                           bitsInByte[256];
     55 //
     56 //     This is the iterator structure for accessing the compressed prime number table. The expectation is that
     57 //     values will need to be accesses sequentially. This tries to save some data access.
     58 //
     59 typedef struct {
     60    UINT32       lastPrime;
     61    UINT32       index;
     62    UINT32       final;
     63 } PRIME_ITERATOR;
     64 #ifdef RSA_INSTRUMENT
     65 #   define INSTRUMENT_SET(a, b) ((a) = (b))
     66 #   define INSTRUMENT_ADD(a, b) (a) = (a) + (b)
     67 #   define INSTRUMENT_INC(a)     (a) = (a) + 1
     68 extern UINT32 failedAtIteration[10];
     69 extern UINT32 MillerRabinTrials;
     70 extern UINT32 totalFieldsSieved;
     71 extern UINT32 emptyFieldsSieved;
     72 extern UINT32 noPrimeFields;
     73 extern UINT32 primesChecked;
     74 extern UINT16    lastSievePrime;
     75 #else
     76 #   define INSTRUMENT_SET(a, b)
     77 #   define INSTRUMENT_ADD(a, b)
     78 #   define INSTRUMENT_INC(a)
     79 #endif
     80 #ifdef RSA_DEBUG
     81 extern UINT16    defaultFieldSize;
     82 #define NUM_PRIMES                2047
     83 extern const __int16              primes[NUM_PRIMES];
     84 #else
     85 #define defaultFieldSize          MAX_FIELD_SIZE
     86 #endif
     87 #endif
     88