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