• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 _OSSL_CRYPTO_ENGINE_H
9 #define _OSSL_CRYPTO_ENGINE_H
10 #include <openssl/aes.h>
11 #include <openssl/evp.h>
12 #include <openssl/sha.h>
13 #include <openssl/ec.h>
14 #include <openssl/rand.h>
15 #include <openssl/bn.h>
16 #define     CRYPTO_ENGINE
17 #include "CryptoEngine.h"
18 #include "CpriMisc_fp.h"
19 #define MAX_ECC_PARAMETER_BYTES 32
20 #define MAX_2B_BYTES MAX((MAX_RSA_KEY_BYTES * ALG_RSA),                              \
21                          MAX((MAX_ECC_PARAMETER_BYTES * ALG_ECC),                   \
22                              MAX_DIGEST_SIZE))
23 #define assert2Bsize(a) pAssert((a).size <= sizeof((a).buffer))
24 #ifdef TPM_ALG_RSA
25 #   ifdef   RSA_KEY_SIEVE
26 #       include     "RsaKeySieve.h"
27 #       include     "RsaKeySieve_fp.h"
28 #   endif
29 #   include    "CpriRSA_fp.h"
30 #endif
31 
32 #ifdef OPENSSL_IS_BORINGSSL
33 // libtpm2 reads internal EVP_MD state (e.g. ctx_size). The boringssl headers
34 // don't expose this type so define it here.
35 struct env_md_st {
36   /* type contains a NID identifing the digest function. (For example,
37    * NID_md5.) */
38   int type;
39 
40   /* md_size contains the size, in bytes, of the resulting digest. */
41   unsigned md_size;
42 
43   /* flags contains the OR of |EVP_MD_FLAG_*| values. */
44   uint32_t flags;
45 
46   /* init initialises the state in |ctx->md_data|. */
47   void (*init)(EVP_MD_CTX *ctx);
48 
49   /* update hashes |len| bytes of |data| into the state in |ctx->md_data|. */
50   void (*update)(EVP_MD_CTX *ctx, const void *data, size_t count);
51 
52   /* final completes the hash and writes |md_size| bytes of digest to |out|. */
53   void (*final)(EVP_MD_CTX *ctx, uint8_t *out);
54 
55   /* block_size contains the hash's native block size. */
56   unsigned block_size;
57 
58   /* ctx_size contains the size, in bytes, of the state of the hash function. */
59   unsigned ctx_size;
60 };
61 #endif
62 
63 //
64 //     This is a structure to hold the parameters for the version of KDFa() used by the CryptoEngine(). This
65 //     structure allows the state to be passed between multiple functions that use the same pseudo-random
66 //     sequence.
67 //
68 typedef struct {
69    CPRI_HASH_STATE          iPadCtx;
70    CPRI_HASH_STATE          oPadCtx;
71    TPM2B                   *extra;
72    UINT32                  *outer;
73    TPM_ALG_ID               hashAlg;
74    UINT16                   keySizeInBits;
75 } KDFa_CONTEXT;
76 #endif // _OSSL_CRYPTO_ENGINE_H
77