1 /*
2  * Copyright 2015 The Chromium OS Authors. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6 
7 #ifndef __TPM2_CPRIHASH_FP_H
8 #define __TPM2_CPRIHASH_FP_H
9 
10 LIB_EXPORT UINT16
11 _cpri__CompleteHash(CPRI_HASH_STATE *hashState,  // IN: the state of hash stack
12                     UINT32 dOutSize,             // IN: size of digest buffer
13                     BYTE *dOut                   // OUT: hash digest
14                     );
15 LIB_EXPORT UINT16
16 _cpri__CopyHashState(CPRI_HASH_STATE *out,  // OUT: destination of the state
17                      CPRI_HASH_STATE *in    // IN: source of the state
18                      );
19 LIB_EXPORT UINT16
20 _cpri__HashBlock(TPM_ALG_ID hashAlg,  //   IN: The hash algorithm
21                  UINT32 dataSize,     //   IN: size of buffer to hash
22                  BYTE *data,          //   IN: the buffer to hash
23                  UINT32 digestSize,   //   IN: size of the digest buffer
24                  BYTE *digest         //   OUT: hash digest
25                  );
26 LIB_EXPORT BOOL _cpri__HashStartup(void);
27 LIB_EXPORT UINT16
28 _cpri__GetDigestSize(TPM_ALG_ID hashAlg  // IN: hash algorithm to look up
29                      );
30 LIB_EXPORT UINT16
31 _cpri__GetHashDER(TPM_ALG_ID hashAlg,  // IN: the algorithm to look up
32                   const BYTE **p);
33 LIB_EXPORT UINT16
34 _cpri__KDFa(TPM_ALG_ID hashAlg,  //   IN: hash algorithm used in HMAC
35             TPM2B *key,          //   IN: HMAC key
36             const char *label,   //   IN: a 0-byte terminated label used in KDF
37             TPM2B *contextU,     //   IN: context U
38             TPM2B *contextV,     //   IN: context V
39             UINT32 sizeInBits,   //   IN: size of generated key in bit
40             BYTE *keyStream,     //   OUT: key buffer
41             UINT32 *counterInOut,  //   IN/OUT: caller may provide the iteration
42                                    //   counter for incremental operations to
43                                    //   avoid large intermediate buffers.
44             BOOL once  //   IN: TRUE if only one iteration is performed FALSE if
45                        //   iteration count determined by "sizeInBits"
46             );
47 LIB_EXPORT UINT16
48 _cpri__KDFe(TPM_ALG_ID hashAlg,  //   IN: hash algorithm used in HMAC
49             TPM2B *Z,            //   IN: Z
50             const char *label,   //   IN: a 0 terminated label using in KDF
51             TPM2B *partyUInfo,   //   IN: PartyUInfo
52             TPM2B *partyVInfo,   //   IN: PartyVInfo
53             UINT32 sizeInBits,   //   IN: size of generated key in bit
54             BYTE *keyStream      //   OUT: key buffer
55             );
56 LIB_EXPORT CRYPT_RESULT
57 _cpri__MGF1(UINT32 mSize,        //   IN: length of the mask to be produced
58             BYTE *mask,          //   OUT: buffer to receive the mask
59             TPM_ALG_ID hashAlg,  //   IN: hash to use
60             UINT32 sSize,        //   IN: size of the seed
61             BYTE *seed           //   IN: seed size
62             );
63 LIB_EXPORT UINT16
64 _cpri__StartHMAC(TPM_ALG_ID hashAlg,  //   IN: the algorithm to use
65                  BOOL sequence,  //   IN: indicates if the state should be saved
66                  CPRI_HASH_STATE *state,  //   IN/OUT: the state buffer
67                  UINT16 keySize,          //   IN: the size of the HMAC key
68                  BYTE *key,               //   IN: the HMAC key
69                  TPM2B *oPadKey  //   OUT: the key prepared for the oPad round
70                  );
71 LIB_EXPORT UINT16
72 _cpri__StartHash(TPM_ALG_ID hashAlg,  // IN: hash algorithm
73                  BOOL sequence,       // IN: TRUE if the state should be saved
74                  CPRI_HASH_STATE *hashState  // OUT: the state of hash stack.
75                  );
76 LIB_EXPORT void _cpri__UpdateHash(
77     CPRI_HASH_STATE *hashState,  // IN: the hash context information
78     UINT32 dataSize,  // IN: the size of data to be added to the digest
79     BYTE *data        // IN: data to be hashed
80     );
81 
82 #endif  // __TPM2_CPRIHASH_FP_H
83 LIB_EXPORT UINT16 _cpri__CompleteHMAC(
84     CPRI_HASH_STATE *hashState,  //   IN: the state of hash stack
85     TPM2B *oPadKey,              //   IN: the HMAC key in oPad format
86     UINT32 dOutSize,             //   IN: size of digest buffer
87     BYTE *dOut                   //   OUT: hash digest
88     );
89 LIB_EXPORT TPM_ALG_ID
90 _cpri__GetContextAlg(CPRI_HASH_STATE *hashState  // IN: the hash context
91                      );
92 LIB_EXPORT TPM_ALG_ID _cpri__GetHashAlgByIndex(UINT32 index  // IN: the index
93                                                );
94 LIB_EXPORT UINT16
95 _cpri__GetHashBlockSize(TPM_ALG_ID hashAlg  // IN: hash algorithm to look up
96                         );
97 LIB_EXPORT void _cpri__ImportExportHashState(
98     CPRI_HASH_STATE *
99         osslFmt,  // IN/OUT: the hash state formated for use by openSSL
100     EXPORT_HASH_STATE *externalFmt,  // IN/OUT: the exported hash state
101     IMPORT_EXPORT direction          //
102     );
103