aboutsummaryrefslogtreecommitdiff
path: root/OsslCryptoEngine.h
blob: 3c5f3cb733137fe7796e10f149ff908e31189831 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// This file was extracted from the TCG Published
// Trusted Platform Module Library
// Part 4: Supporting Routines
// Family "2.0"
// Level 00 Revision 01.16
// October 30, 2014

#ifndef _OSSL_CRYPTO_ENGINE_H
#define _OSSL_CRYPTO_ENGINE_H
#include <openssl/aes.h>
#include <openssl/evp.h>
#include <openssl/sha.h>
#include <openssl/ec.h>
#include <openssl/rand.h>
#include <openssl/bn.h>
#define     CRYPTO_ENGINE
#include "CryptoEngine.h"
#include "CpriMisc_fp.h"
#define MAX_ECC_PARAMETER_BYTES 32
#define MAX_2B_BYTES MAX((MAX_RSA_KEY_BYTES * ALG_RSA),                              \
                         MAX((MAX_ECC_PARAMETER_BYTES * ALG_ECC),                   \
                             MAX_DIGEST_SIZE))
#define assert2Bsize(a) pAssert((a).size <= sizeof((a).buffer))
#ifdef TPM_ALG_RSA
#   ifdef   RSA_KEY_SIEVE
#       include     "RsaKeySieve.h"
#       include     "RsaKeySieve_fp.h"
#   endif
#   include    "CpriRSA_fp.h"
#endif

#ifdef OPENSSL_IS_BORINGSSL
// libtpm2 reads internal EVP_MD state (e.g. ctx_size). The boringssl headers
// don't expose this type so define it here.
struct env_md_st {
  /* type contains a NID identifing the digest function. (For example,
   * NID_md5.) */
  int type;

  /* md_size contains the size, in bytes, of the resulting digest. */
  unsigned md_size;

  /* flags contains the OR of |EVP_MD_FLAG_*| values. */
  uint32_t flags;

  /* init initialises the state in |ctx->md_data|. */
  void (*init)(EVP_MD_CTX *ctx);

  /* update hashes |len| bytes of |data| into the state in |ctx->md_data|. */
  void (*update)(EVP_MD_CTX *ctx, const void *data, size_t count);

  /* final completes the hash and writes |md_size| bytes of digest to |out|. */
  void (*final)(EVP_MD_CTX *ctx, uint8_t *out);

  /* block_size contains the hash's native block size. */
  unsigned block_size;

  /* ctx_size contains the size, in bytes, of the state of the hash function. */
  unsigned ctx_size;
};
#endif

//
//     This is a structure to hold the parameters for the version of KDFa() used by the CryptoEngine(). This
//     structure allows the state to be passed between multiple functions that use the same pseudo-random
//     sequence.
//
typedef struct {
   CPRI_HASH_STATE          iPadCtx;
   CPRI_HASH_STATE          oPadCtx;
   TPM2B                   *extra;
   UINT32                  *outer;
   TPM_ALG_ID               hashAlg;
   UINT16                   keySizeInBits;
} KDFa_CONTEXT;
#endif // _OSSL_CRYPTO_ENGINE_H