blob: bfcb50d60dc1f9b510001e5a237bba7997bc33a3 [file] [log] [blame]
Vadim Bendebury56797522015-05-20 10:32:25 -07001// 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
Vadim Bendeburyfea3a142015-05-28 18:53:22 -07008#include "CryptoEngine.h"
Vadim Bendebury56797522015-05-20 10:32:25 -07009#include "OsslCryptoEngine.h"
10static void Trap(const char *function, int line, int code);
11FAIL_FUNCTION TpmFailFunction = (FAIL_FUNCTION)&Trap;
12//
13//
14// Functions
15//
16// TpmFail()
17//
18// This is a shim function that is called when a failure occurs. It simply relays the call to the callback pointed
19// to by TpmFailFunction(). It is only defined for the sake of NO_RETURN specifier that cannot be added to
20// a function pointer with some compilers.
21//
22void
23TpmFail(
24 const char *function,
25 int line,
26 int code)
27{
28 TpmFailFunction(function, line, code);
29}
30//
31//
32// FAILURE_TRAP()
33//
34// This function is called if the caller to _cpri__InitCryptoUnits() doesn't provide a call back address.
35//
36static void
37Trap(
38 const char *function,
39 int line,
40 int code
41 )
42{
43 UNREFERENCED(function);
44 UNREFERENCED(line);
45 UNREFERENCED(code);
46 abort();
47}
48//
49//
50// _cpri__InitCryptoUnits()
51//
52// This function calls the initialization functions of the other crypto modules that are part of the crypto engine
53// for this implementation. This function should be called as a result of _TPM_Init(). The parameter to this
54// function is a call back function it TPM.lib that is called when the crypto engine has a failure.
55//
56LIB_EXPORT CRYPT_RESULT
57_cpri__InitCryptoUnits(
58 FAIL_FUNCTION failFunction
59 )
60{
61 TpmFailFunction = failFunction;
62 _cpri__RngStartup();
63 _cpri__HashStartup();
64 _cpri__SymStartup();
65#ifdef TPM_ALG_RSA
66 _cpri__RsaStartup();
67#endif
68#ifdef TPM_ALG_ECC
69 _cpri__EccStartup();
70#endif
71 return CRYPT_SUCCESS;
72}
73//
74//
75// _cpri__StopCryptoUnits()
76//
77// This function calls the shutdown functions of the other crypto modules that are part of the crypto engine
78// for this implementation.
79//
80LIB_EXPORT void
81_cpri__StopCryptoUnits(
82 void
83 )
84{
85 return;
86}
87//
88//
89// _cpri__Startup()
90//
91// This function calls the startup functions of the other crypto modules that are part of the crypto engine for
92// this implementation. This function should be called during processing of TPM2_Startup().
93//
94LIB_EXPORT BOOL
95_cpri__Startup(
96 void
97 )
98{
99 return( _cpri__HashStartup()
100 && _cpri__RngStartup()
101#ifdef TPM_ALG_RSA
102 && _cpri__RsaStartup()
103#endif // TPM_ALG_RSA
104#ifdef TPM_ALG_ECC
105 && _cpri__EccStartup()
106#endif // TPM_ALG_ECC
107 && _cpri__SymStartup());
108}