xref: /aosp_15_r20/external/ms-tpm-20-ref/TPMCmd/tpm/include/SelfTest.h (revision 5c591343844d1f9da7da26467c4bf7efc8a7a413)
1*5c591343SA. Cody Schuffelen /* Microsoft Reference Implementation for TPM 2.0
2*5c591343SA. Cody Schuffelen  *
3*5c591343SA. Cody Schuffelen  *  The copyright in this software is being made available under the BSD License,
4*5c591343SA. Cody Schuffelen  *  included below. This software may be subject to other third party and
5*5c591343SA. Cody Schuffelen  *  contributor rights, including patent rights, and no such rights are granted
6*5c591343SA. Cody Schuffelen  *  under this license.
7*5c591343SA. Cody Schuffelen  *
8*5c591343SA. Cody Schuffelen  *  Copyright (c) Microsoft Corporation
9*5c591343SA. Cody Schuffelen  *
10*5c591343SA. Cody Schuffelen  *  All rights reserved.
11*5c591343SA. Cody Schuffelen  *
12*5c591343SA. Cody Schuffelen  *  BSD License
13*5c591343SA. Cody Schuffelen  *
14*5c591343SA. Cody Schuffelen  *  Redistribution and use in source and binary forms, with or without modification,
15*5c591343SA. Cody Schuffelen  *  are permitted provided that the following conditions are met:
16*5c591343SA. Cody Schuffelen  *
17*5c591343SA. Cody Schuffelen  *  Redistributions of source code must retain the above copyright notice, this list
18*5c591343SA. Cody Schuffelen  *  of conditions and the following disclaimer.
19*5c591343SA. Cody Schuffelen  *
20*5c591343SA. Cody Schuffelen  *  Redistributions in binary form must reproduce the above copyright notice, this
21*5c591343SA. Cody Schuffelen  *  list of conditions and the following disclaimer in the documentation and/or
22*5c591343SA. Cody Schuffelen  *  other materials provided with the distribution.
23*5c591343SA. Cody Schuffelen  *
24*5c591343SA. Cody Schuffelen  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS""
25*5c591343SA. Cody Schuffelen  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26*5c591343SA. Cody Schuffelen  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27*5c591343SA. Cody Schuffelen  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
28*5c591343SA. Cody Schuffelen  *  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29*5c591343SA. Cody Schuffelen  *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30*5c591343SA. Cody Schuffelen  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31*5c591343SA. Cody Schuffelen  *  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32*5c591343SA. Cody Schuffelen  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33*5c591343SA. Cody Schuffelen  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34*5c591343SA. Cody Schuffelen  */
35*5c591343SA. Cody Schuffelen //** Introduction
36*5c591343SA. Cody Schuffelen // This file contains the structure definitions for the self-test. It also contains
37*5c591343SA. Cody Schuffelen // macros for use when the self-test is implemented.
38*5c591343SA. Cody Schuffelen #ifndef                 _SELF_TEST_H_
39*5c591343SA. Cody Schuffelen #define                 _SELF_TEST_H_
40*5c591343SA. Cody Schuffelen 
41*5c591343SA. Cody Schuffelen //** Defines
42*5c591343SA. Cody Schuffelen 
43*5c591343SA. Cody Schuffelen // Was typing this a lot
44*5c591343SA. Cody Schuffelen #define SELF_TEST_FAILURE   FAIL(FATAL_ERROR_SELF_TEST)
45*5c591343SA. Cody Schuffelen 
46*5c591343SA. Cody Schuffelen // Use the definition of key sizes to set algorithm values for key size.
47*5c591343SA. Cody Schuffelen #define AES_ENTRIES (AES_128 + AES_192 + AES_256)
48*5c591343SA. Cody Schuffelen #define SM4_ENTRIES (SM4_128)
49*5c591343SA. Cody Schuffelen #define CAMELLIA_ENTRIES (CAMELLIA_128 + CAMELLIA_192 + CAMELLIA_256)
50*5c591343SA. Cody Schuffelen #define TDES_ENTRIES (TDES_128 + TDES_192)
51*5c591343SA. Cody Schuffelen 
52*5c591343SA. Cody Schuffelen #define NUM_SYMS    (AES_ENTRIES + SM4_ENTRIES + CAMELLIA_ENTRIES + TDES_ENTRIES)
53*5c591343SA. Cody Schuffelen 
54*5c591343SA. Cody Schuffelen typedef UINT32      SYM_INDEX;
55*5c591343SA. Cody Schuffelen 
56*5c591343SA. Cody Schuffelen // These two defines deal with the fact that the TPM_ALG_ID table does not delimit
57*5c591343SA. Cody Schuffelen // the symmetric mode values with a SYM_MODE_FIRST and SYM_MODE_LAST
58*5c591343SA. Cody Schuffelen #define SYM_MODE_FIRST       ALG_CTR_VALUE
59*5c591343SA. Cody Schuffelen #define SYM_MODE_LAST        ALG_ECB_VALUE
60*5c591343SA. Cody Schuffelen 
61*5c591343SA. Cody Schuffelen #define NUM_SYM_MODES   (SYM_MODE_LAST - SYM_MODE_FIRST + 1)
62*5c591343SA. Cody Schuffelen 
63*5c591343SA. Cody Schuffelen // Define a type to hold a bit vector for the modes.
64*5c591343SA. Cody Schuffelen #if NUM_SYM_MODES <= 0
65*5c591343SA. Cody Schuffelen #error  "No symmetric modes implemented"
66*5c591343SA. Cody Schuffelen #elif NUM_SYM_MODES <= 8
67*5c591343SA. Cody Schuffelen typedef BYTE    SYM_MODES;
68*5c591343SA. Cody Schuffelen #elif NUM_SYM_MODES <= 16
69*5c591343SA. Cody Schuffelen typedef UINT16  SYM_MODES;
70*5c591343SA. Cody Schuffelen #elif NUM_SYM_MODES <= 32
71*5c591343SA. Cody Schuffelen typedef UINT32  SYM_MODES;
72*5c591343SA. Cody Schuffelen #else
73*5c591343SA. Cody Schuffelen #error "Too many symmetric modes"
74*5c591343SA. Cody Schuffelen #endif
75*5c591343SA. Cody Schuffelen 
76*5c591343SA. Cody Schuffelen typedef struct SYMMETRIC_TEST_VECTOR {
77*5c591343SA. Cody Schuffelen     const TPM_ALG_ID     alg;                   // the algorithm
78*5c591343SA. Cody Schuffelen     const UINT16         keyBits;               // bits in the key
79*5c591343SA. Cody Schuffelen     const BYTE          *key;                   // The test key
80*5c591343SA. Cody Schuffelen     const UINT32         ivSize;                // block size of the algorithm
81*5c591343SA. Cody Schuffelen     const UINT32         dataInOutSize;         // size  to encrypt/decrypt
82*5c591343SA. Cody Schuffelen     const BYTE          *dataIn;                // data to encrypt
83*5c591343SA. Cody Schuffelen     const BYTE          *dataOut[NUM_SYM_MODES];// data to decrypt
84*5c591343SA. Cody Schuffelen } SYMMETRIC_TEST_VECTOR;
85*5c591343SA. Cody Schuffelen 
86*5c591343SA. Cody Schuffelen #if ALG_SHA512
87*5c591343SA. Cody Schuffelen #       define  DEFAULT_TEST_HASH               ALG_SHA512_VALUE
88*5c591343SA. Cody Schuffelen #       define  DEFAULT_TEST_DIGEST_SIZE        SHA512_DIGEST_SIZE
89*5c591343SA. Cody Schuffelen #       define  DEFAULT_TEST_HASH_BLOCK_SIZE    SHA512_BLOCK_SIZE
90*5c591343SA. Cody Schuffelen #elif ALG_SHA384
91*5c591343SA. Cody Schuffelen #       define  DEFAULT_TEST_HASH               ALG_SHA384_VALUE
92*5c591343SA. Cody Schuffelen #       define  DEFAULT_TEST_DIGEST_SIZE        SHA384_DIGEST_SIZE
93*5c591343SA. Cody Schuffelen #       define  DEFAULT_TEST_HASH_BLOCK_SIZE    SHA384_BLOCK_SIZE
94*5c591343SA. Cody Schuffelen #elif ALG_SHA256
95*5c591343SA. Cody Schuffelen #       define  DEFAULT_TEST_HASH               ALG_SHA256_VALUE
96*5c591343SA. Cody Schuffelen #       define  DEFAULT_TEST_DIGEST_SIZE        SHA256_DIGEST_SIZE
97*5c591343SA. Cody Schuffelen #       define  DEFAULT_TEST_HASH_BLOCK_SIZE    SHA256_BLOCK_SIZE
98*5c591343SA. Cody Schuffelen #elif ALG_SHA1
99*5c591343SA. Cody Schuffelen #       define  DEFAULT_TEST_HASH               ALG_SHA1_VALUE
100*5c591343SA. Cody Schuffelen #       define  DEFAULT_TEST_DIGEST_SIZE        SHA1_DIGEST_SIZE
101*5c591343SA. Cody Schuffelen #       define  DEFAULT_TEST_HASH_BLOCK_SIZE    SHA1_BLOCK_SIZE
102*5c591343SA. Cody Schuffelen #endif
103*5c591343SA. Cody Schuffelen 
104*5c591343SA. Cody Schuffelen 
105*5c591343SA. Cody Schuffelen #endif      // _SELF_TEST_H_