TCG TIS 1.3 compliant TPM driver to use the TPM as hardware crypto library.

/media/uploads/LordOfDorks/wp_20150409_16_47_21_pro.jpg The TPM 2.0 architecture, commands and structures are defined in the set of 4 Trusted Platform Module Library Specification, Family "2.0" specifications that that can be found at http://www.trustedcomputinggroup.org/resources/tpm_library_specification

The "PC Client Specific TPM Interface Specification (TIS), Version 1.3" that was used for this implementation can be found at http://www.trustedcomputinggroup.org/resources/pc_client_work_group_pc_client_specific_tpm_interface_specification_tis

All the information to get going is in SPITIS_TPM20.h!

GizmosNGadgets.h

Committer:
LordOfDorks
Date:
2015-04-07
Revision:
1:fd0a59e55a85
Child:
3:4b9ad18eae02

File content as of revision 1:fd0a59e55a85:

/* mbed TCG SPI TPM 2.0 TIS 1.3 driver,
 * Copyright (c) 2015, Microsoft Coprporation Inc.
 * by Stefan Thom (LordOfDorks) StefanTh@Microsoft.com, Stefan@ThomsR.Us
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 */

#ifndef min
#define min(a,b) (((a) < (b)) ? (a) : (b))
#endif

#ifndef max
#define max(a,b) (((a) > (b)) ? (a) : (b))
#endif

#define BE_UINT16_TO_BYTEARRAY(__dataIn, __array, __offset)\
__array[__offset] = (uint8_t)((__dataIn >> 8) & 0x00ff);\
__array[__offset + 1] = (uint8_t)(__dataIn & 0x00ff);\

#define LE_UINT16_TO_BYTEARRAY(__dataIn, __array, __offset)\
__array[__offset + 1] = (uint8_t)((__dataIn >> 8) & 0x00ff);\
__array[__offset] = (uint8_t)(__dataIn & 0x00ff);\

#define BE_UINT32_TO_BYTEARRAY(__dataIn, __array, __offset)\
__array[__offset + 0] = (uint8_t)((__dataIn >> 24) & 0x000000ff);\
__array[__offset + 1] = (uint8_t)((__dataIn >> 16) & 0x000000ff);\
__array[__offset + 2] = (uint8_t)((__dataIn >> 8) & 0x000000ff);\
__array[__offset + 3] = (uint8_t)(__dataIn & 0x000000ff);\

#define LE_UINT32_TO_BYTEARRAY(__dataIn, __array, __offset)\
__array[__offset + 0] = (uint8_t)(__dataIn & 0x000000ff);\
__array[__offset + 1] = (uint8_t)((__dataIn >> 8) & 0x000000ff);\
__array[__offset + 2] = (uint8_t)((__dataIn >> 16) & 0x000000ff);\
__array[__offset + 3] = (uint8_t)((__dataIn >> 24) & 0x000000ff);\

#define BE_BYTEARRAY_TO_UINT16(__arrayIn, __offset)\
((((uint16_t)(__arrayIn[__offset])) << 8) | \
   (uint16_t)(__arrayIn[__offset + 1])) \

#define LE_BYTEARRAY_TO_UINT16(__arrayIn, __offset)\
((((uint16_t)(__arrayIn[__offset + 1])) << 8) | \
   (uint16_t)(__arrayIn[__offset])) \

#define BE_BYTEARRAY_TO_UINT32(__arrayIn, __offset)\
((((uint32_t)(__arrayIn[__offset])) << 24) | \
 (((uint32_t)(__arrayIn[__offset + 1])) << 16) | \
 (((uint32_t)(__arrayIn[__offset + 2])) << 8) | \
  (uint32_t)(__arrayIn[__offset + 3])) \

#define LE_BYTEARRAY_TO_UINT32(__arrayIn, __offset)\
((((uint32_t)(__arrayIn[__offset + 3])) << 24) | \
 (((uint32_t)(__arrayIn[__offset + 2])) << 16) | \
 (((uint32_t)(__arrayIn[__offset + 1])) << 8) | \
  (uint32_t)(__arrayIn[__offset])) \
  
#define ALL_FLAGS_SET(__value, __flags) \
((__value & __flags) == __flags) \

#define TIS_BASE_ADDRESS (0x00d40000)
#define TIS_HEADER(__LOCALITY, __READCYCLE, __REGISTER, __PAYLOAD)\
(TIS_BASE_ADDRESS | \
 (__READCYCLE ? 0x80000000 : 0x00000000) | \
 ((__PAYLOAD - 1) << 24) | \
 (__LOCALITY << 12) | \
 (__REGISTER))