diff options
author | Trusted Logic <smc_support@trusted-logic.com> | 2012-01-27 14:41:51 -0600 |
---|---|---|
committer | Hashcode <hashcode0f@gmail.com> | 2015-02-02 16:20:30 -0800 |
commit | 0704a22d8c894594d1443edeac79cb366b50f69a (patch) | |
tree | 5e76fae4eba902bf8e8bdaebbf4393c54bb47563 /security | |
parent | 5ecc7eacd32653947b73bf442fd61833b6360e46 (diff) | |
download | hardware_ti_omap4-0704a22d8c894594d1443edeac79cb366b50f69a.tar.gz hardware_ti_omap4-0704a22d8c894594d1443edeac79cb366b50f69a.tar.bz2 hardware_ti_omap4-0704a22d8c894594d1443edeac79cb366b50f69a.zip |
Security: tf_sdk: Update to 1.06e1
This contains the C header files for compiling both the normal-world and
secure-world software. The rest of the SDK is available in the mshield
package.
Some of these headers are:
cryptoki.h - definitions for the External Cry ptographic API
sst.h - definitions for the External Secure Storage API
mtc.h - definitions for the External Monotonic Counter API
ssdi.h - definitions for SSDI
tee_client_api.h - definitions for the TF Client API
(cherry picked from commit 41ab3216ed1b54184d0575ef9601394e7ba53f0d)
Change-Id: I24828f423456ac12f014a406acee42b60b40ae17
Signed-off-by: Bryan Buckley <bryan.buckley@ti.com>
Diffstat (limited to 'security')
-rw-r--r-- | security/tf_sdk/include/s_type.h | 2 | ||||
-rw-r--r-- | security/tf_sdk/include/sddi.h | 211 | ||||
-rw-r--r-- | security/tf_sdk/include/sdrv_crypto.h | 595 | ||||
-rw-r--r-- | security/tf_sdk/include/smapi.h | 366 | ||||
-rw-r--r-- | security/tf_sdk/include/smapi_ex.h | 123 | ||||
-rw-r--r-- | security/tf_sdk/include/ssdi.h | 529 | ||||
-rw-r--r-- | security/tf_sdk/include/ssdi_smc_ext.h | 61 | ||||
-rw-r--r-- | security/tf_sdk/include/ssdi_v2_compat.h | 308 |
8 files changed, 2194 insertions, 1 deletions
diff --git a/security/tf_sdk/include/s_type.h b/security/tf_sdk/include/s_type.h index 72f2a8a..ae260cc 100644 --- a/security/tf_sdk/include/s_type.h +++ b/security/tf_sdk/include/s_type.h @@ -35,7 +35,7 @@ #define __S_TYPE_H__ /* C99 integer types */ -#if (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) &&(!defined(__ANDROID32__)) +#if (!defined(__STDC_VERSION__) || __STDC_VERSION__ < 199901L) &&(!defined(ANDROID)) #include <limits.h> diff --git a/security/tf_sdk/include/sddi.h b/security/tf_sdk/include/sddi.h new file mode 100644 index 0000000..2627ae0 --- /dev/null +++ b/security/tf_sdk/include/sddi.h @@ -0,0 +1,211 @@ +/** + * Copyright(c) 2011 Trusted Logic. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name Trusted Logic nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __SDDI_H__ +#define __SDDI_H__ + +#include "ssdi.h" + +#ifndef SDDI_EXPORT +#if defined(WIN32) || defined(__ARMCC_VERSION) +#ifdef SMODULE_IMPLEMENTATION +#define SDDI_EXPORT __declspec(dllexport) +#else +#define SDDI_EXPORT __declspec(dllimport) +#endif +#elif defined(__GNUC__) +#define SDDI_EXPORT __attribute__ ((visibility ("default"))) +#else +#define SDDI_EXPORT +#endif +#endif /* !SDDI_EXPORT */ + +#ifndef SDRV_EXPORT +#if defined(WIN32) || defined(_WIN32_WCE) || defined(__ARMCC_VERSION) +#define SDRV_EXPORT __declspec(dllexport) +#elif defined(__GNUC__) +#define SDRV_EXPORT __attribute__ ((visibility ("default"))) +#else +#define SDRV_EXPORT +#endif +#endif /* !SDRV_EXPORT */ + +#define SDRV_SIGNAL_SW_BOOT 0x00000001 +#define SDRV_SIGNAL_SW_ACTIVE 0x00000002 +#define SDRV_SIGNAL_SW_PANIC 0x00000003 +#define SDRV_SIGNAL_CPU_SW 0x00000004 +#define SDRV_SIGNAL_THREAD_SW 0x00000005 + +#define SDRV_TRACE_MAX_STRING_LEN 0xFF +#define SDRV_INTERRUPT_CONTROLLER_NONE 0xFFFFFFFF + +#define S_CACHE_OPERATION_CLEAN 0x00000001 +#define S_CACHE_OPERATION_INVALIDATE 0x00000002 +#define S_CACHE_OPERATION_CLEAN_AND_INVALIDATE 0x00000003 + +typedef struct +{ + uint32_t low; + uint32_t high; +} SDRV_MONOTONIC_COUNTER_VALUE; + +void SDDI_EXPORT *SMemGetVirtual(uint32_t nSegmentID); + +S_RESULT SDDI_EXPORT SMemGetPhysical(void* pVirtual, uint32_t* pnPhysical); + +S_RESULT SDDI_EXPORT SMemFlush( + uint32_t nSegmentID, + uint32_t nOperation); + +S_RESULT SDDI_EXPORT SMemFlushByAddress( + void* pStartAddress, + uint32_t nLength, + uint32_t nOperation); + +S_RESULT SDDI_EXPORT SInterruptDisable(uint32_t nInterruptID); + +S_RESULT SDDI_EXPORT SInterruptEnable(uint32_t nInterruptID); + +/*------------------------------------------------------------------------------ + Key Stream Functions +------------------------------------------------------------------------------*/ + +void SDDI_EXPORT SKeyStreamWrite( + const uint8_t* pBuffer, + uint32_t nBufferLength); + +S_RESULT SDDI_EXPORT SKeyStreamRead( + uint8_t* pBuffer, + uint32_t* pnBufferLength); + +/*------------------------------------------------------------------------------ + Driver Common Entry Points +------------------------------------------------------------------------------*/ + +S_RESULT SDRV_EXPORT SDrvCreate(uint32_t nParam0, uint32_t nParam1); + +void SDRV_EXPORT SDrvDestroy(void); + +bool SDRV_EXPORT SDrvHandleInterrupt( + IN OUT void* pInstanceData, + uint32_t nInterruptId); + +/*------------------------------------------------------------------------------ + Secure Interrupt Controller Driver Entry Points +------------------------------------------------------------------------------*/ + +uint32_t SDRV_EXPORT SDrvSICGetSystemInterrupt(void* pInstanceData); + +void SDRV_EXPORT SDrvSICDisableInterrupt( + void* pInstanceData, + uint32_t nInterrupt); + +void SDRV_EXPORT SDrvSICEnableInterrupt( + void* pInstanceData, + uint32_t nInterrupt); + +/*------------------------------------------------------------------------------ + Normal Interrupt Controller Driver Entry Points +------------------------------------------------------------------------------*/ + +void SDRV_EXPORT SDrvNICSignalNormalWorld(void* pInstanceData); + +void SDRV_EXPORT SDrvNICResetSignalNormalWorld(void* pInstanceData); + +/*------------------------------------------------------------------------------ + Interrupt Controller Driver Entry Points +------------------------------------------------------------------------------*/ + +S_RESULT SDRV_EXPORT SDrvMonotonicCounterOpen( + uint32_t nReserved, + void** ppCounterContext, + SDRV_MONOTONIC_COUNTER_VALUE* pMaxCounterValue); + +void SDRV_EXPORT SDrvMonotonicCounterClose( void* pCounterContext); + +S_RESULT SDRV_EXPORT SDrvMonotonicCounterGet( + IN void* pCounterContext, + IN OUT SDRV_MONOTONIC_COUNTER_VALUE* pCounterValue); + +S_RESULT SDRV_EXPORT SDrvMonotonicCounterIncrement( + IN void* pCounterContext, + IN OUT SDRV_MONOTONIC_COUNTER_VALUE* pNewCounterValue); + +/*------------------------------------------------------------------------------ + RTC Driver Entry Points +------------------------------------------------------------------------------*/ + +S_RESULT SDRV_EXPORT SDrvRTCOpen( + uint32_t nReserved, + void** ppRTCContext); + +void SDRV_EXPORT SDrvRTCClose( + void* pRTCContext); + +S_RESULT SDRV_EXPORT SDrvRTCRead( + void* pRTCContext, + uint32_t* pnTime, + bool* pbIsCorrupted); + +S_RESULT SDRV_EXPORT SDrvRTCResetCorruptedFlag( + void* pRTCContext); + +/*------------------------------------------------------------------------------ + Trace Driver Entry Points +------------------------------------------------------------------------------*/ + +void SDRV_EXPORT SDrvTracePrint( + IN void* pInstanceData, + IN const char* pString); + +void SDRV_EXPORT SDrvTraceSignal( + IN void* pInstanceData, + IN uint32_t nSignal, + IN uint32_t nReserved); + +/*------------------------------------------------------------------------------ + Crypto Driver Interface definition is in the file sdrv_crypto.h +------------------------------------------------------------------------------*/ +#include "sdrv_crypto.h" + +/*------------------------------------------------------------------------------ + Memory Driver Functions +------------------------------------------------------------------------------*/ + +S_RESULT SDRV_EXPORT SDrvMemoryAllocateRegion( + uint32_t nReserved, +IN OUT uint32_t* pnPageCount, +OUT uint32_t* pnRegionPhysicalAddressAndAttributes, +OUT void** ppRegionContext); + +void SDRV_EXPORT SDrvMemoryFreeRegion(void* pRegionContext); + + +#endif /* #ifndef __SDDI_H__ */ diff --git a/security/tf_sdk/include/sdrv_crypto.h b/security/tf_sdk/include/sdrv_crypto.h new file mode 100644 index 0000000..057090e --- /dev/null +++ b/security/tf_sdk/include/sdrv_crypto.h @@ -0,0 +1,595 @@ +/** + * Copyright(c) 2011 Trusted Logic. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name Trusted Logic nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * File : sdrv_crypto.h + * + * Last-Author : Trusted Logic S.A. + * Created : August 28, 2007 + * + */ + + +/** + * SDDI Crypto Driver specification header file. + */ + +#ifndef __SDRV_CRYPTO_H__ +#define __SDRV_CRYPTO_H__ + +#include "s_type.h" +#include "s_error.h" +#include "sddi.h" + +#ifndef SSDI_EXPORT +#if defined(WIN32) || defined(__ARMCC_VERSION) +#ifdef SMODULE_IMPLEMENTATION +#define SSDI_EXPORT __declspec(dllexport) +#else +#define SSDI_EXPORT __declspec(dllimport) +#endif +#elif defined(__GNUC__) +#define SSDI_EXPORT __attribute__ ((visibility ("default"))) +#else +#define SSDI_EXPORT +#endif +#endif /* !SSDI_EXPORT */ + +#ifndef SSPI_EXPORT +#if defined(WIN32) || defined(_WIN32_WCE) || defined(__ARMCC_VERSION) +#define SSPI_EXPORT __declspec(dllexport) +#elif defined(__GNUC__) +#define SSPI_EXPORT __attribute__ ((visibility ("default"))) +#else +#define SSPI_EXPORT +#endif +#endif /* !SSPI_EXPORT */ + + + + +/*------------------------------------------------------------------------------ + SSDI Types +------------------------------------------------------------------------------*/ + +typedef struct SDRV_CRYPTO_KEY_INFO +{ + uint32_t nKeyType; + uint32_t nKeyAlgorithm; + uint32_t nKeyBits; + uint32_t nUseType; + uint32_t nFlags; + uint32_t nReserved1; + uint32_t nReserved2; +} SDRV_CRYPTO_KEY_INFO; +/* Caution: the meaning of nKeyBits depends on the algorithm and the key type */ + +typedef struct SDRV_CRYPTO_BIGNUM +{ + uint32_t nLength; + uint8_t *pBuffer; +} SDRV_CRYPTO_BIGNUM; + +/*------------------------------------------------------------------------------ + Algorithm-dependent structures +------------------------------------------------------------------------------*/ + +typedef struct SDRV_CRYPTO_RSA_PUBLIC_KEY +{ + SDRV_CRYPTO_BIGNUM modulus; + SDRV_CRYPTO_BIGNUM publicExponent; +} SDRV_CRYPTO_RSA_PUBLIC_KEY; + +typedef struct SDRV_CRYPTO_RSA_PRIVATE_KEY +{ + SDRV_CRYPTO_BIGNUM modulus; + SDRV_CRYPTO_BIGNUM publicExponent; + SDRV_CRYPTO_BIGNUM privateExponent; + SDRV_CRYPTO_BIGNUM primeP; + SDRV_CRYPTO_BIGNUM primeQ; + SDRV_CRYPTO_BIGNUM exp1; + SDRV_CRYPTO_BIGNUM exp2; + SDRV_CRYPTO_BIGNUM coef; +} SDRV_CRYPTO_RSA_PRIVATE_KEY; + +typedef struct SDRV_CRYPTO_DH_PUBLIC_KEY +{ + SDRV_CRYPTO_BIGNUM p; + SDRV_CRYPTO_BIGNUM g; + SDRV_CRYPTO_BIGNUM y; +} SDRV_CRYPTO_DH_PUBLIC_KEY; + +typedef struct SDRV_CRYPTO_DH_PRIVATE_KEY +{ + SDRV_CRYPTO_BIGNUM p; + SDRV_CRYPTO_BIGNUM g; + SDRV_CRYPTO_BIGNUM x; +} SDRV_CRYPTO_DH_PRIVATE_KEY; + +typedef struct SDRV_CRYPTO_DH_PARAMETERS +{ + SDRV_CRYPTO_BIGNUM p; + SDRV_CRYPTO_BIGNUM g; +} SDRV_CRYPTO_DH_PARAMETERS; + +typedef struct SDRV_CRYPTO_DSA_PARAMETER +{ + SDRV_CRYPTO_BIGNUM p; + SDRV_CRYPTO_BIGNUM q; + SDRV_CRYPTO_BIGNUM g; +} SDRV_CRYPTO_DSA_PARAMETERS; + +typedef struct SDRV_CRYPTO_DSA_PUBLIC_KEY +{ + SDRV_CRYPTO_BIGNUM p; + SDRV_CRYPTO_BIGNUM q; + SDRV_CRYPTO_BIGNUM g; + SDRV_CRYPTO_BIGNUM y; +} SDRV_CRYPTO_DSA_PUBLIC_KEY; + +typedef struct SDRV_CRYPTO_DSA_PRIVATE_KEY +{ + SDRV_CRYPTO_BIGNUM p; + SDRV_CRYPTO_BIGNUM q; + SDRV_CRYPTO_BIGNUM g; + SDRV_CRYPTO_BIGNUM x; +} SDRV_CRYPTO_DSA_PRIVATE_KEY; + +typedef SDRV_CRYPTO_BIGNUM SDRV_CRYPTO_FIELD_ELEMENT; + +typedef struct SDRV_CRYPTO_EC_POINT { + uint32_t type; + SDRV_CRYPTO_FIELD_ELEMENT x, y; +} SDRV_CRYPTO_EC_POINT; + +typedef struct SDRV_CRYPTO_EC_PARAMETERS +{ + uint32_t fieldType; + SDRV_CRYPTO_BIGNUM fieldParam; + SDRV_CRYPTO_EC_POINT generator; + SDRV_CRYPTO_FIELD_ELEMENT a; + SDRV_CRYPTO_FIELD_ELEMENT b; + SDRV_CRYPTO_BIGNUM order; + uint32_t cofactor; + uint32_t seedLen; + uint8_t *pSeed; +} SDRV_CRYPTO_EC_PARAMETERS; + +typedef struct SDRV_CRYPTO_EC_PUBLIC_KEY +{ + SDRV_CRYPTO_EC_PARAMETERS domainParameters; + SDRV_CRYPTO_EC_POINT publicKey; +} SDRV_CRYPTO_EC_PUBLIC_KEY; + +typedef struct SDRV_CRYPTO_EC_PRIVATE_KEY +{ + SDRV_CRYPTO_EC_PARAMETERS domainParameters; + SDRV_CRYPTO_BIGNUM privateKey; +} SDRV_CRYPTO_EC_PRIVATE_KEY; + +typedef struct SDRV_CRYPTO_ECSVP_DH_KDF_SHA1_PARAMETERS +{ + uint32_t sharedInfoLen; + uint8_t *pSharedInfo; + SDRV_CRYPTO_EC_POINT publicKey; +} SDRV_CRYPTO_ECSVP_DH_KDF_SHA1_PARAMETERS; + +typedef struct SDRV_CRYPTO_EXTENDED_TYPE +{ + uint32_t nType; + void* pValue; + uint32_t nLen; +} SDRV_CRYPTO_EXTENDED_TYPE; + + +/*------------------------------------------------------------------------------ + Constants +------------------------------------------------------------------------------*/ + +/* Hardware Key IDs */ +#define SDRV_CRYPTO_HW_KEY_MASTER_ID 1 +#define SDRV_CRYPTO_HW_KEY_CEK_CUSTOMER_ID 3 +#define SDRV_CRYPTO_HW_KEY_KEK_ID 4 + +/* operation codes */ +#define SDRV_CRYPTO_OP_DIGEST 0x00000001 +#define SDRV_CRYPTO_OP_SIGN 0x00000002 +#define SDRV_CRYPTO_OP_VERIFY 0x00000003 +#define SDRV_CRYPTO_OP_ENCRYPT 0x00000004 +#define SDRV_CRYPTO_OP_DECRYPT 0x00000005 + +/* encoding formats */ +#define SDRV_CRYPTO_ENCODING_FORMAT_NONE 0x00000000 + +/* key parameters */ +#define SDRV_CRYPTO_KEY_PARAM_MODULUS 0x00000001 +#define SDRV_CRYPTO_KEY_PARAM_PUBLIC_EXPONENT 0x00000002 +#define SDRV_CRYPTO_KEY_PARAM_GENERATOR 0x00000003 +#define SDRV_CRYPTO_KEY_PARAM_SUBPRIME 0x00000004 +#define SDRV_CRYPTO_KEY_PARAM_PUBLIC_VALUE 0x00000005 +#define SDRV_CRYPTO_KEY_PARAM_VALUE 0x00000006 + +#define SDRV_CRYPTO_KEY_PARAM_PRIVATE_EXPONENT 0x00000007 +#define SDRV_CRYPTO_KEY_PARAM_PRIME_1 0x00000008 +#define SDRV_CRYPTO_KEY_PARAM_PRIME_2 0x00000009 +#define SDRV_CRYPTO_KEY_PARAM_EXPONENT_1 0x0000000A +#define SDRV_CRYPTO_KEY_PARAM_EXPONENT_2 0x0000000B +#define SDRV_CRYPTO_KEY_PARAM_COEFFICIENT 0x0000000C + +#define SDRV_CRYPTO_KEY_PARAM_EC_FIELD_TYPE 0x00000010 +#define SDRV_CRYPTO_KEY_PARAM_EC_GENERATOR_X_UNCOMPRESSED 0x00000011 +#define SDRV_CRYPTO_KEY_PARAM_EC_GENERATOR_Y_UNCOMPRESSED 0x00000012 +#define SDRV_CRYPTO_KEY_PARAM_EC_A 0x00000013 +#define SDRV_CRYPTO_KEY_PARAM_EC_B 0x00000014 +#define SDRV_CRYPTO_KEY_PARAM_EC_ORDER 0x00000015 +#define SDRV_CRYPTO_KEY_PARAM_EC_COFACTOR 0x00000016 +#define SDRV_CRYPTO_KEY_PARAM_EC_PRIME 0x00000017 +#define SDRV_CRYPTO_KEY_PARAM_EC_REDUCTION_POLYNOMIAL 0x00000018 +#define SDRV_CRYPTO_KEY_PARAM_EC_SEED 0x00000019 +#define SDRV_CRYPTO_KEY_PARAM_EC_PUBLIC_VALUE_X_UNCOMPRESSED 0x0000001A +#define SDRV_CRYPTO_KEY_PARAM_EC_PUBLIC_VALUE_Y_UNCOMPRESSED 0x0000001B +#define SDRV_CRYPTO_KEY_PARAM_EC_FIELD_SIZE 0x0000001C + +/* key types */ +#define SDRV_CRYPTO_KEY_TYPE_SECRET 0x00000001 +#define SDRV_CRYPTO_KEY_TYPE_PUBLIC 0x00000002 +#define SDRV_CRYPTO_KEY_TYPE_PRIVATE 0x00000003 +#define SDRV_CRYPTO_KEY_TYPE_DATA 0x00000004 + +#define SDRV_CRYPTO_FIELD_P 0x00000001 +#define SDRV_CRYPTO_FIELD_2M_POLYNOMIAL 0x00000002 + +/* key and algorithm usage */ +#define SDRV_CRYPTO_USE_SIGN 0x00000001 +#define SDRV_CRYPTO_USE_VERIFY 0x00000002 +#define SDRV_CRYPTO_USE_ENCRYPT 0x00000004 +#define SDRV_CRYPTO_USE_DECRYPT 0x00000008 +#define SDRV_CRYPTO_USE_DERIVE 0x00000010 +#define SDRV_CRYPTO_USE_UNWRAP 0x00000020 +#define SDRV_CRYPTO_USE_WRAP 0x00000040 +#define SDRV_CRYPTO_USE_DIGEST 0x00000080 +#define SDRV_CRYPTO_USE_SECRET_GENERATION 0x00000100 +#define SDRV_CRYPTO_USE_KEYPAIR_GENERATION 0x00000200 + +/* key flags */ +#define SDRV_CRYPTO_FLAG_WRAPPABLE 0x00000001 +#define SDRV_CRYPTO_FLAG_NON_SENSITIVE 0x00000002 +#define SDRV_CRYPTO_FLAG_ALLOW_NON_SENSITIVE_DERIVED_KEY 0x00000004 +#define SDRV_CRYPTO_FLAG_COPY_PROHIBITED 0x00000008 + +/* key storage */ +#define SDRV_CRYPTO_STORAGE_TEMPORARY 0x00000001 +#define SDRV_CRYPTO_STORAGE_PERMANENT 0x00000002 + +/* algorithm constants */ +#define SDRV_CRYPTO_ALG_NONE 0x00000000 +#define SDRV_CRYPTO_ALG_RSA_RAW 0x30001001 +#define SDRV_CRYPTO_ALG_RSA_PKCS1_5_NONE 0x30002001 +#define SDRV_CRYPTO_ALG_RSA_PKCS1_5_MD5 0x30002601 +#define SDRV_CRYPTO_ALG_RSA_PKCS1_5_SHA1 0x30002101 +#define SDRV_CRYPTO_ALG_RSA_PKCS1_5_SHA224 0x30002201 +#define SDRV_CRYPTO_ALG_RSA_PKCS1_5_SHA256 0x30002301 +#define SDRV_CRYPTO_ALG_RSA_PKCS1_5_SHA384 0x30002401 +#define SDRV_CRYPTO_ALG_RSA_PKCS1_5_SHA512 0x30002501 +#define SDRV_CRYPTO_ALG_DSA 0x30000081 +#define SDRV_CRYPTO_ALG_DSA_SHA1 0x30000181 +#define SDRV_CRYPTO_ALG_DH_PKCS3 0x30000082 +#define SDRV_CRYPTO_ALG_ECDSA_SHA1 0x40000101 +#define SDRV_CRYPTO_ALG_AES_ECB 0x10000101 +#define SDRV_CRYPTO_ALG_AES_CBC 0x10000201 +#define SDRV_CRYPTO_ALG_AES_CTR 0x10000301 +#define SDRV_CRYPTO_ALG_AES_MAC 0x60001001 +#define SDRV_CRYPTO_ALG_DES_ECB 0x10000102 +#define SDRV_CRYPTO_ALG_DES_CBC 0x10000202 +#define SDRV_CRYPTO_ALG_DES_MAC 0x60001002 +#define SDRV_CRYPTO_ALG_DES3_EDE_ECB 0x10010104 +#define SDRV_CRYPTO_ALG_DES3_EDE_CBC 0x10010204 +#define SDRV_CRYPTO_ALG_DES3_EDE_MAC 0x60011004 +#define SDRV_CRYPTO_ALG_ARC4 0x20000005 +#define SDRV_CRYPTO_ALG_MD5 0x50000061 +#define SDRV_CRYPTO_ALG_SHA1 0x50000012 +#define SDRV_CRYPTO_ALG_SHA224 0x50000022 +#define SDRV_CRYPTO_ALG_SHA256 0x50000032 +#define SDRV_CRYPTO_ALG_SHA384 0x50000042 +#define SDRV_CRYPTO_ALG_SHA512 0x50000052 +#define SDRV_CRYPTO_ALG_HMAC_SHA1 0x60000106 +#define SDRV_CRYPTO_ALG_HMAC_SHA224 0x60000206 +#define SDRV_CRYPTO_ALG_HMAC_SHA256 0x60000306 +#define SDRV_CRYPTO_ALG_HMAC_SHA384 0x60000406 +#define SDRV_CRYPTO_ALG_HMAC_SHA512 0x60000506 +#define SDRV_CRYPTO_ALG_HMAC_MD5 0x60000606 +#define SDRV_CRYPTO_ALG_WRAP_SECURE_STORAGE 0x80000000 +#define SDRV_CRYPTO_ALG_GEN_RSA_PKCS1 0x90000001 +#define SDRV_CRYPTO_ALG_GEN_DSA 0x90000002 +#define SDRV_CRYPTO_ALG_GEN_EC 0x90000003 +#define SDRV_CRYPTO_ALG_GEN_DH_PKCS3 0x90000004 +#define SDRV_CRYPTO_ALG_GEN_AES 0x90000081 +#define SDRV_CRYPTO_ALG_GEN_DES 0x90000082 +#define SDRV_CRYPTO_ALG_GEN_DES2 0x90000083 +#define SDRV_CRYPTO_ALG_GEN_DES3 0x90000084 +#define SDRV_CRYPTO_ALG_GEN_ARC4 0x90000085 +#define SDRV_CRYPTO_ALG_GEN_GENERIC_SECRET 0x90000080 + +/* vendor defined algorithms constants */ +#define SDRV_CRYPTO_ALG_VENDOR_DEFINED_0 0x100000F0 +#define SDRV_CRYPTO_ALG_VENDOR_DEFINED_1 0x100000F1 +#define SDRV_CRYPTO_ALG_VENDOR_DEFINED_2 0x100000F2 +#define SDRV_CRYPTO_ALG_VENDOR_DEFINED_3 0x100000F3 +#define SDRV_CRYPTO_ALG_VENDOR_DEFINED_4 0x100000F4 +#define SDRV_CRYPTO_ALG_VENDOR_DEFINED_5 0x100000F5 +#define SDRV_CRYPTO_ALG_VENDOR_DEFINED_6 0x100000F6 +#define SDRV_CRYPTO_ALG_VENDOR_DEFINED_7 0x100000F7 +#define SDRV_CRYPTO_ALG_VENDOR_DEFINED_8 0x100000F8 +#define SDRV_CRYPTO_ALG_VENDOR_DEFINED_9 0x100000F9 +#define SDRV_CRYPTO_ALG_VENDOR_DEFINED_10 0x100000FA +#define SDRV_CRYPTO_ALG_VENDOR_DEFINED_11 0x100000FB +#define SDRV_CRYPTO_ALG_VENDOR_DEFINED_12 0x100000FC +#define SDRV_CRYPTO_ALG_VENDOR_DEFINED_13 0x100000FD +#define SDRV_CRYPTO_ALG_VENDOR_DEFINED_14 0x100000FE +#define SDRV_CRYPTO_ALG_VENDOR_DEFINED_15 0x100000FF + +/* key algorithm mask */ +#define SDRV_CRYPTO_ALG_KEY_MASK 0xF00000FF + +/* standard and restricted modes */ +#define SDRV_CRYPTO_STANDARD_MODE 0x00000000 +#define SDRV_CRYPTO_RESTRICTED_MODE 0x00000001 + +/*------------------------------------------------------------------------------ + Crypto Driver Functions +------------------------------------------------------------------------------*/ + +S_RESULT SDRV_EXPORT SDrvCryptoOpen( + OUT void** ppSessionContext); + +void SDRV_EXPORT SDrvCryptoClose( + IN void* pSessionContext); + +S_RESULT SDRV_EXPORT SDrvCryptoOpenHardwareKey( + IN void* pSessionContext, + IN uint32_t nHWKeyID, + IN uint32_t nHWFlags, + OUT void** ppKeyContext, + OUT SDRV_CRYPTO_KEY_INFO* pKeyInfo); + +void SDRV_EXPORT SDrvCryptoCloseKeyContext( + IN void* pSessionContext, + IN void* pKeyContext); + +S_RESULT SDRV_EXPORT SDrvCryptoInitOperation( + IN void* pSessionContext, + uint32_t nOperation, + uint32_t nAlgorithm, + IN const void* pParameter, + uint32_t nParameterLen, + IN void* pKeyContext, + OUT void** ppOperationContext); + +S_RESULT SDRV_EXPORT SDrvCryptoEncrypt( + IN void* pOperationContext, + IN const uint8_t* pData, + uint32_t nDataLen, + OUT uint8_t* pEncryptedData, + void* pReserved, + bool bTerminate); + +S_RESULT SDRV_EXPORT SDrvCryptoEncryptUpdate( + IN void* pOperationContext, + IN const uint8_t* pPart, + uint32_t nPartLen, + OUT uint8_t* pEncryptedPart, + void* pReserved, + bool bTerminate); + +S_RESULT SDRV_EXPORT SDrvCryptoDecrypt( + IN void* pOperationContext, + IN const uint8_t* pEncryptedData, + uint32_t nEncryptedDataLen, + OUT uint8_t* pData, + void* pReserved, + IN bool bTerminate); + +S_RESULT SDRV_EXPORT SDrvCryptoDecryptUpdate( + IN void* pOperationContext, + IN const uint8_t* pEncryptedPart, + uint32_t nEncryptedPartLen, + OUT uint8_t* pPart, + void* pReserved, + bool bTerminate); + +S_RESULT SDRV_EXPORT SDrvCryptoSign( + IN void* pOperationContext, + IN const uint8_t* pData, + uint32_t nDataLen, + OUT uint8_t* pSignature, + void* pReserved, + bool bTerminate); + +S_RESULT SDRV_EXPORT SDrvCryptoSignUpdate( + IN void* pOperationContext, + IN const uint8_t* pPart, + uint32_t nPartLen); + +S_RESULT SDRV_EXPORT SDrvCryptoSignLast( + IN void* pOperationContext, + OUT uint8_t* pSignature, + void* pReserved, + IN bool bTerminate); + +S_RESULT SDRV_EXPORT SDrvCryptoVerify( + IN void* pOperationContext, + IN const uint8_t* pData, + uint32_t nDataLen, + IN const uint8_t* pSignature, + void* pReserved, + bool bTerminate); + +S_RESULT SDRV_EXPORT SDrvCryptoVerifyUpdate( + IN void* pOperationContext, + IN const uint8_t* pPart, + uint32_t nPartLen); + +S_RESULT SDRV_EXPORT SDrvCryptoVerifyLast( + IN void* pOperationContext, + IN const uint8_t* pSignature, + void* pReserved, + bool bTerminate); + +S_RESULT SDRV_EXPORT SDrvCryptoDigest( + IN void* pOperationContext, + IN const uint8_t* pData, + uint32_t nDataLen, + OUT uint8_t* pDigest, + void* pReserved, + bool bTerminate); + +S_RESULT SDRV_EXPORT SDrvCryptoDigestUpdate( + IN void* pOperationContext, + IN const uint8_t* pPart, + uint32_t nPartLen); + +S_RESULT SDRV_EXPORT SDrvCryptoDigestLast( + IN void* pOperationContext, + OUT uint8_t* pDigest, + void* pReserved, + bool bTerminate); + +S_RESULT SDRV_EXPORT SDrvCryptoResetOperation( + IN void* pOperationContext, + IN uint32_t nOperation, + IN void* pKeyContext, + IN const void* pParameter, + uint32_t nParameterLen); + +void SDRV_EXPORT SDrvCryptoTerminateOperation( + IN void* pOperationContext, + void* pReserved); + +S_RESULT SDRV_EXPORT SDrvCryptoCreateKey( + IN void* pSessionContext, + IN OUT SDRV_CRYPTO_KEY_INFO* pKeyInfo, +IN const void* pKey, + uint32_t nKeyLen, + OUT void** ppKeyContext); + +S_RESULT SDRV_EXPORT SDrvCryptoStoreKey( + IN void* pSessionContext, + IN void* pSourceKeyContext, + IN SDRV_CRYPTO_KEY_INFO* pSourceKeyInfo); + +S_RESULT SDRV_EXPORT SDrvCryptoLoadKey( + IN void* pSessionContext, + IN SDRV_CRYPTO_KEY_INFO* pDestinationKeyInfo, + OUT void** ppDestinationKeyContext); + +S_RESULT SDRV_EXPORT SDrvCryptoCopyObject( + IN void* pSessionContext, + IN void* pSourceKeyContext, + IN OUT SDRV_CRYPTO_KEY_INFO* pTargetKeyInfo, + OUT void** ppTargetKeyContext); + +S_RESULT SDRV_EXPORT SDrvCryptoGenerateSecretKey( + IN void* pSessionContext, + uint32_t nGenerationAlgorithm, + IN OUT SDRV_CRYPTO_KEY_INFO* pKeyInfo, +IN const void* pParameter, + uint32_t nParameterLen, + void* pReserved, + uint32_t nReservedLen, + OUT void** ppKeyContext); + +S_RESULT SDRV_EXPORT SDrvCryptoGenerateKeyPair( + IN void* pSessionContext, + uint32_t nGenerationAlgorithm, + IN OUT SDRV_CRYPTO_KEY_INFO* pPrivateKeyInfo, + IN OUT SDRV_CRYPTO_KEY_INFO* pPublicKeyInfo, +IN const void* pParameter, + uint32_t nParameterLen, + void* pReserved1, + uint32_t nReserved1Len, + void* pReserved2, + uint32_t nReserved2Len, + OUT void** ppPrivateKeyContext, + OUT void** ppPublicKeyContext); + +S_RESULT SDRV_EXPORT SDrvCryptoDeriveKey( + IN void* pSessionContext, + uint32_t derivationAlgorithm, +IN const void* pParameter, + uint32_t nParameterLen, + IN void* pSourceKeyContext, + IN OUT SDRV_CRYPTO_KEY_INFO* pTargetKeyInfo, + IN void* pReserved, + uint32_t nReservedLen, + OUT void** ppTargetKeyContext); + +S_RESULT SDRV_EXPORT SDrvCryptoUnwrapKey( + IN void* pSessionContext, + uint32_t nDecryptionAlgorithm, + uint32_t nEncodingFormat, +IN const void* pParameter, + uint32_t nParameterLen, + IN void* pDecryptionKeyContext, +IN const uint8_t* pWrappedBuffer, + uint32_t nWrappedBufferLength, + IN OUT SDRV_CRYPTO_KEY_INFO* pKeyInfo, + void* pReserved, + uint32_t nReservedLen, + OUT void** ppKeyContext); + +S_RESULT SDRV_EXPORT SDrvCryptoWrapKey( + IN void* pSessionContext, + uint32_t nEncodingFormat, + uint32_t nEncryptionAlgorithm, + IN const void* pParameter, + uint32_t nParameterLen, + IN void* pEncryptionKeyContext, + IN void* pSourceKeyContext, + IN OUT uint8_t* pWrappedBuffer, + void* pReserved); + +S_RESULT SDRV_EXPORT SDrvCryptoGetKeyParam( + IN void* pKeyContext, + uint32_t keyParam, + OUT uint8_t* pParameter, + IN OUT uint32_t* pnParameterLen); + +S_RESULT SDRV_EXPORT SDrvCryptoAddEntropy( + IN void* pSessionContext, + IN const uint8_t* pSeed, + uint32_t nSeedLen); + +S_RESULT SDRV_EXPORT SDrvCryptoGenerateRandom( + IN void* pSessionContext, + uint32_t nReserved, + OUT uint8_t* pResultBuffer, + uint32_t nResultBufferLen); + +#endif /* __SDRV_CRYPTO_H__ */ diff --git a/security/tf_sdk/include/smapi.h b/security/tf_sdk/include/smapi.h new file mode 100644 index 0000000..2fc3e5e --- /dev/null +++ b/security/tf_sdk/include/smapi.h @@ -0,0 +1,366 @@ +/** + * Copyright(c) 2011 Trusted Logic. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name Trusted Logic nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * File : smapi.h + * Last-Author : Trusted Logic S.A. + * Created : March 15, 2003 + */ + +#ifndef __SMAPI_H__ +#define __SMAPI_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +/*------------------------------------------------------------------------------ + Includes +------------------------------------------------------------------------------*/ + +#include "s_type.h" +#include "s_error.h" +/*------------------------------------------------------------------------------ + SMAPI Types +------------------------------------------------------------------------------*/ + + +#ifdef SM_EXPORT_IMPLEMENTATION +#define SM_EXPORT S_DLL_EXPORT +#else +#define SM_EXPORT S_DLL_IMPORT +#endif + +typedef struct SM_PROPERTY +{ + wchar_t* pName; + wchar_t* pValue; +} SM_PROPERTY; + +typedef struct SM_TIME_LIMIT +{ + uint32_t nHighTime; + uint32_t nLowTime; +} SM_TIME_LIMIT; + +/*------------------------------------------------------------------------------ + Constants +------------------------------------------------------------------------------*/ + + +#define SM_API_VERSION 0x03000000 + +#define SM_CONTROL_MODE_USER ( (uint32_t)0x00000002 ) +#define SM_CONTROL_MODE_MANAGER ( (uint32_t)0x00000008 ) +#define SM_CONTROL_MODE_EXCLUSIVE_MANAGER ( (uint32_t)0x00000010 ) + +#define SM_LOGIN_PUBLIC ( (uint32_t)0x00000000 ) +#define SM_LOGIN_OS_IDENTIFICATION ( (uint32_t)0x00000005 ) +#define SM_LOGIN_AUTHENTICATION ( (uint32_t)0x80000000 ) +#define SM_LOGIN_AUTHENTICATION_FALLBACK_OS_IDENTIFICATION ( (uint32_t)0x80000001 ) +#define SM_LOGIN_PRIVILEGED ( (uint32_t)0x80000002 ) + +#define SM_MEMORY_ACCESS_CLIENT_WRITE_SERVICE_READ ( (uint32_t)0x00000001 ) +#define SM_MEMORY_ACCESS_CLIENT_READ_SERVICE_WRITE ( (uint32_t)0x00000002 ) + +#define SMX_MEMORY_ACCESS_DIRECT ( (uint32_t)0x80000000 ) +#define SMX_MEMORY_ACCESS_DIRECT_FORCE ( (uint32_t)0x40000000 ) + +#define SM_INFINITE_TIMEOUT ( (uint32_t)0xFFFFFFFF ) + +#define SM_NULL_ELEMENT ( (uint32_t)0xFFFFFFFF ) + +/*------------------------------------------------------------------------------ + Functions and Macros +------------------------------------------------------------------------------*/ + +SM_EXPORT SM_ERROR SMDeviceCreateContext( + const wchar_t* pDeviceName, + uint32_t nReserved, + SM_HANDLE* phDevice); + +SM_EXPORT SM_ERROR SMDeviceDeleteContext( + SM_HANDLE hDevice); + +SM_EXPORT void SMFree( + SM_HANDLE hElement, + void* pBuffer); + +SM_EXPORT SM_ERROR SMStubGetTimeLimit( + SM_HANDLE hElement, + uint32_t nTimeout, + SM_TIME_LIMIT* pTimeLimit); + +SM_EXPORT SM_ERROR SMStubPrepareOpenOperation( + SM_HANDLE hDevice, + uint32_t nLoginType, + const void* pLoginInfo, + const SM_UUID* pidService, + uint32_t nControlMode, + const SM_TIME_LIMIT* pTimeLimit, + uint32_t nReserved1, + uint32_t nReserved2, + SM_HANDLE* phClientSession, + SM_HANDLE* phParameterEncoder, + SM_HANDLE* phOperation); + +SM_EXPORT SM_ERROR SMStubPrepareInvokeOperation( + SM_HANDLE hClientSession, + uint32_t nCommandIdentifier, + const SM_TIME_LIMIT* pTimeLimit, + uint32_t nReserved1, + uint32_t nReserved2, + SM_HANDLE* phParameterEncoder, + SM_HANDLE* phOperation); + +SM_EXPORT SM_ERROR SMStubPrepareCloseOperation( + SM_HANDLE hClientSession, + uint32_t nReserved1, + uint32_t nReserved2, + SM_HANDLE* phParameterEncoder, + SM_HANDLE* phOperation); + +SM_EXPORT SM_ERROR SMStubPerformOperation( + SM_HANDLE hOperation, + uint32_t nReserved, + SM_ERROR* pnServiceErrorCode, + SM_HANDLE* phAnswerDecoder); + +SM_EXPORT SM_ERROR SMStubCancelOperation( + SM_HANDLE hOperation); + +SM_EXPORT SM_ERROR SMStubReleaseOperation( + SM_HANDLE hOperation); + +SM_EXPORT SM_ERROR SMStubAllocateSharedMemory( + SM_HANDLE hClientSession, + uint32_t nLength, + uint32_t nFlags, + uint32_t nReserved, + void** ppBlock, + SM_HANDLE* phBlockHandle); + +SM_EXPORT SM_ERROR SMStubRegisterSharedMemory( + SM_HANDLE hClientSession, + void* pBuffer, + uint32_t nBufferLength, + uint32_t nFlags, + uint32_t nReserved, + SM_HANDLE* phBlockHandle); + +SM_EXPORT SM_ERROR SMStubReleaseSharedMemory( + SM_HANDLE hBlockHandle); + +SM_EXPORT void SMStubEncoderWriteUint8( + SM_HANDLE hEncoder, + uint8_t nValue); + +SM_EXPORT void SMStubEncoderWriteUint16( + SM_HANDLE hEncoder, + uint16_t nValue); + +SM_EXPORT void SMStubEncoderWriteUint32( + SM_HANDLE hEncoder, + uint32_t nValue); + +SM_EXPORT void SMStubEncoderWriteBoolean( + SM_HANDLE hEncoder, + bool nValue); + +SM_EXPORT void SMStubEncoderWriteHandle( + SM_HANDLE hEncoder, + SM_HANDLE hValue); + +SM_EXPORT void SMStubEncoderWriteString( + SM_HANDLE hEncoder, + const wchar_t* pValue); + +SM_EXPORT void SMStubEncoderWriteUint8Array( + SM_HANDLE hEncoder, + uint32_t nArrayLength, + const uint8_t* pnArray); + +SM_EXPORT void SMStubEncoderWriteUint16Array( + SM_HANDLE hEncoder, + uint32_t nArrayLength, + const uint16_t* pnArray); + +SM_EXPORT void SMStubEncoderWriteUint32Array( + SM_HANDLE hEncoder, + uint32_t nArrayLength, + const uint32_t* pnArray); + +SM_EXPORT void SMStubEncoderWriteHandleArray( + SM_HANDLE hEncoder, + uint32_t nArrayLength, + const SM_HANDLE* pnArray); + +SM_EXPORT void SMStubEncoderWriteMemoryReference( + SM_HANDLE hEncoder, + SM_HANDLE hBlock, + uint32_t nOffset, + uint32_t nLength, + uint32_t nFlags); + +SM_EXPORT void SMStubEncoderOpenSequence( + SM_HANDLE hEncoder); + +SM_EXPORT void SMStubEncoderCloseSequence( + SM_HANDLE hEncoder); + +SM_EXPORT SM_ERROR SMStubDecoderGetError( + SM_HANDLE hDecoder); + +SM_EXPORT bool SMStubDecoderHasData( + SM_HANDLE hDecoder); + +SM_EXPORT uint8_t SMStubDecoderReadUint8( + SM_HANDLE hDecoder); + +SM_EXPORT uint16_t SMStubDecoderReadUint16( + SM_HANDLE hDecoder); + +SM_EXPORT uint32_t SMStubDecoderReadUint32( + SM_HANDLE hDecoder); + +SM_EXPORT bool SMStubDecoderReadBoolean( + SM_HANDLE hDecoder); + +SM_EXPORT SM_HANDLE SMStubDecoderReadHandle( + SM_HANDLE hDecoder); + +SM_EXPORT wchar_t* SMStubDecoderReadString( + SM_HANDLE hDecoder); + +SM_EXPORT uint8_t* SMStubDecoderReadUint8Array( + SM_HANDLE hDecoder, + uint32_t* pnArrayLength); + +SM_EXPORT uint16_t* SMStubDecoderReadUint16Array( + SM_HANDLE hDecoder, + uint32_t* pnArrayLength); + +SM_EXPORT uint32_t* SMStubDecoderReadUint32Array( + SM_HANDLE hDecoder, + uint32_t* pnArrayLength); + +SM_EXPORT SM_HANDLE* SMStubDecoderReadHandleArray( + SM_HANDLE hDecoder, + uint32_t* pnArrayLength); + +SM_EXPORT uint32_t SMStubDecoderReadArrayLength( + SM_HANDLE hDecoder); + +SM_EXPORT uint32_t SMStubDecoderCopyUint8Array( + SM_HANDLE hDecoder, + uint32_t nIndex, + uint32_t nMaxLength, + uint8_t* pArray); + +SM_EXPORT uint32_t SMStubDecoderCopyUint16Array( + SM_HANDLE hDecoder, + uint32_t nIndex, + uint32_t nMaxLength, + uint16_t* pArray); + +SM_EXPORT uint32_t SMStubDecoderCopyUint32Array( + SM_HANDLE hDecoder, + uint32_t nIndex, + uint32_t nMaxLength, + uint32_t* pArray); + +SM_EXPORT uint32_t SMStubDecoderCopyHandleArray( + SM_HANDLE hDecoder, + uint32_t nIndex, + uint32_t nMaxLength, + SM_HANDLE* pArray); + +SM_EXPORT void SMStubDecoderReadSequence( + SM_HANDLE hDecoder, + SM_HANDLE* phSequenceDecoder); + +SM_EXPORT void SMStubDecoderSkip( + SM_HANDLE hDecoder); + +SM_EXPORT SM_ERROR SMManagerOpen( + SM_HANDLE hDevice, + uint32_t nLoginType, + const void* pLoginInfo, + uint32_t nControlMode, + SM_HANDLE* phServiceManager); + +SM_EXPORT SM_ERROR SMManagerClose( + SM_HANDLE hServiceManager); + +SM_EXPORT SM_ERROR SMManagerGetAllServices( + SM_HANDLE hServiceManager, + SM_UUID** ppServiceIdentifierList, + uint32_t* pnListLength); + +SM_EXPORT SM_ERROR SMManagerGetServiceProperty( + SM_HANDLE hServiceManager, + const SM_UUID* pidService, + wchar_t* pPropertyName, + wchar_t** ppPropertyValue); + +SM_EXPORT SM_ERROR SMManagerGetAllServiceProperties( + SM_HANDLE hServiceManager, + const SM_UUID* pidService, + SM_PROPERTY** ppProperties, + uint32_t* pnPropertiesLength); + +SM_EXPORT SM_ERROR SMManagerDownloadService( + SM_HANDLE hServiceManager, + const uint8_t* pServiceCode, + uint32_t nServiceCodeSize, + SM_UUID* pidService); + +SM_EXPORT SM_ERROR SMManagerRemoveService( + SM_HANDLE hServiceManager, + const SM_UUID* pidService); + +SM_EXPORT SM_ERROR SMGetImplementationProperty( + SM_HANDLE hDevice, + const wchar_t* pPropertyName, + wchar_t** ppPropertyValue); + +SM_EXPORT SM_ERROR SMGetAllImplementationProperties( + SM_HANDLE hDevice, + SM_PROPERTY** ppProperties, + uint32_t* pnPropertiesLength); + +#include "smapi_ex.h" + +#ifdef __cplusplus +} +#endif + +#endif /* __SMAPI_H__ */ diff --git a/security/tf_sdk/include/smapi_ex.h b/security/tf_sdk/include/smapi_ex.h new file mode 100644 index 0000000..14444f7 --- /dev/null +++ b/security/tf_sdk/include/smapi_ex.h @@ -0,0 +1,123 @@ +/** + * Copyright(c) 2011 Trusted Logic. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name Trusted Logic nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * File : smapi_ex.h + * Last-Author : Trusted Logic S.A. + * Created : April 23, 2007 + */ + +#ifndef __SMAPI_EX_H__ +#define __SMAPI_EX_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Appends the specified UUID value to the encoded data of the specified + * encoder instance. + * + * Upon error, this function sets the error state of the encoder. No other state + * is affected. + * + * This function does nothing if the error state of the encoder is set upon + * entry. + * + * @param hEncoder The handle of the encoder instance. + * + * @param pUUID A pointer to the UUID value to encode. + */ +SM_EXPORT void SMStubEncoderWriteUUID( + SM_HANDLE hEncoder, + const SM_UUID *pUUID); + +/** + * Reads the UUID value at the current offset in the encoded data parsed by the + * specified decoder instance. + * + * Upon return, the current offset of the decoder references the first item + * following the decoded item. + * + * If the decoder error state is set upon entry, the function sets the UUID + * placeholder to the nil UUID and does nothing more. + * + * @param hDecoder The handle of the decoder instance. + * + * @param pUUID A pointer to the placeholder to be set to the decoded UUID + * value. This placeholder is set to the nil UUID upon failure. + */ +SM_EXPORT void SMStubDecoderReadUUID( + SM_HANDLE hDecoder, + SM_UUID *pUUID); + +/** + * Opens a sequence in the current decoder. The current decoder must point to a + * sequence. + * + * After this function is called, the current decoder points to the first element + * of the sequence. + * + * If the error state of the decoder is set upon entry, this function does nothing. + * + * Upon error, this function sets the error state of the current decoder. + * In particular, if the decoder does not point to a sequence, the error state + * is set to S_ERROR_BAD_FORMAT. + * + * @param hDecoder A handle of the decoder instance. + * + */ +SM_EXPORT void SMStubDecoderOpenSequence( + SM_HANDLE hDecoder); + +/** + * Closes a sequence in the current decoder. At least one sequence must have been + * opened using the function {SMStubDecoderOpenSequence} + * + * When this function returns, the current decoder points to the first element + * following the current sequence. + * + * If the error state of the decoder is set upon entry, this function does nothing. + * + * Upon error, this function sets the error state of the current decoder. + * In particular, if the decoder does not point within a sequence, the error state + * is set to S_ERROR_ILLEGAL_STATE. + * + * @param hDecoder A handle of the decoder instance. + * + */ +SM_EXPORT void SMStubDecoderCloseSequence( + SM_HANDLE hDecoder); + +#ifdef __cplusplus +} +#endif + +#endif /* __SMAPI_EX_H__ */ diff --git a/security/tf_sdk/include/ssdi.h b/security/tf_sdk/include/ssdi.h new file mode 100644 index 0000000..256f62e --- /dev/null +++ b/security/tf_sdk/include/ssdi.h @@ -0,0 +1,529 @@ +/** + * Copyright(c) 2011 Trusted Logic. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name Trusted Logic nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* +* File : ssdi.h +* +* Original-Author : Trusted Logic S.A. +* +* Created : May 31, 2006 +*/ + +/** + * SSDI specification 3.0 header file. + */ + +#ifndef __SSDI_H__ +#define __SSDI_H__ + +#include "s_type.h" +#include "s_error.h" + +#ifndef SSDI_EXPORT +#ifdef SMODULE_IMPLEMENTATION +#define SSDI_EXPORT S_DLL_EXPORT +#else +#define SSDI_EXPORT S_DLL_IMPORT +#endif +#endif + +#ifndef SRVX_EXPORT +#define SRVX_EXPORT S_DLL_EXPORT +#endif + +/*------------------------------------------------------------------------------ + SSDI Types +------------------------------------------------------------------------------*/ + +typedef struct S_PROPERTY +{ + char* pName; + char* pValue ; +} S_PROPERTY; + +typedef struct S_TIME_LIMIT +{ + uint32_t nTime1; + uint32_t nTime2; +} S_TIME_LIMIT; + +typedef struct S_CALENDAR +{ + int32_t nYear; + int32_t nMonth; + int32_t nDayOfWeek; + int32_t nDay; + int32_t nHour; + int32_t nMinute; + int32_t nSecond; +} S_CALENDAR; + +typedef enum +{ + S_FILE_SEEK_SET = 0, + S_FILE_SEEK_CUR, + S_FILE_SEEK_END +} S_WHENCE; + +typedef struct S_FILE_INFO +{ + char* pName; + uint32_t nSize; + uint32_t nNameLength; +}S_FILE_INFO; + +typedef struct +{ + void* pBuffer; + uint32_t nSize; +} +S_PARAM_MEMREF; + +typedef struct +{ + uint32_t a; + uint32_t b; +} +S_PARAM_VALUE; + +typedef union +{ + S_PARAM_MEMREF memref; + S_PARAM_VALUE value; +} +S_PARAM; + + +/*------------------------------------------------------------------------------ + Constants +------------------------------------------------------------------------------*/ +#define S_TIMEOUT_INFINITE 0xFFFFFFFF + +/* storage private to the service */ +#define S_FILE_STORAGE_PRIVATE 0x00000001 + +#ifdef SUPPORT_RPMB_PARTITION +/* storage on rpmb */ +#define S_FILE_STORAGE_RPMB 0x00000002 +#endif + +/* Cryptoki slotID constants */ +#define S_CRYPTOKI_KEYSTORE_PRIVATE 0x00000001 +#define S_CRYPTOKI_KEYSTORE_PRIVATE_USER 0x00004004 + +/* SFile constants */ +#define S_FILE_FLAG_ACCESS_READ 0x0001 +#define S_FILE_FLAG_ACCESS_WRITE 0x0002 +#define S_FILE_FLAG_ACCESS_WRITE_META 0x0004 + +#define S_FILE_FLAG_SHARE_READ 0x0010 +#define S_FILE_FLAG_SHARE_WRITE 0x0020 + +#define S_FILE_FLAG_CREATE 0x0200 +#define S_FILE_FLAG_EXCLUSIVE 0x0400 + +#define S_FILE_NAME_MAX 0x40 +#define S_FILE_MAX_POSITION 0xFFFFFFFF + +/* SDate constants */ +#define S_DATE_STATUS_NOT_SET 0xFFFF5000 +#define S_DATE_STATUS_NEEDS_RESET 0xFFFF5001 +#define S_DATE_STATUS_SET 0x00000000 + +/* Login types */ +#define S_LOGIN_PUBLIC 0x00000000 +#define S_LOGIN_USER 0x00000001 +#define S_LOGIN_GROUP 0x00000002 +#define S_LOGIN_APPLICATION 0x00000004 +#define S_LOGIN_APPLICATION_USER 0x00000005 +#define S_LOGIN_APPLICATION_GROUP 0x00000006 +#define S_LOGIN_AUTHENTICATION 0x80000000 +#define S_LOGIN_PRIVILEGED 0x80000002 +#define S_LOGIN_CLIENT_IS_SERVICE 0xF0000000 +#define S_LOGIN_SYSTEM 0xF0000001 + +/* Parameter types */ +#define S_PARAM_TYPE_NONE 0x0 +#define S_PARAM_TYPE_VALUE_INPUT 0x1 +#define S_PARAM_TYPE_VALUE_OUTPUT 0x2 +#define S_PARAM_TYPE_VALUE_INOUT 0x3 +#define S_PARAM_TYPE_MEMREF_INPUT 0x5 +#define S_PARAM_TYPE_MEMREF_OUTPUT 0x6 +#define S_PARAM_TYPE_MEMREF_INOUT 0x7 + +#define S_PARAM_TYPE_INPUT_FLAG 0x1 +#define S_PARAM_TYPE_OUTPUT_FLAG 0x2 +#define S_PARAM_TYPE_MEMREF_FLAG 0x4 + +#define S_PARAM_TYPES(t0,t1,t2,t3) ((t0) | ((t1) << 4) | ((t2) << 8) | ((t3) << 12)) +#define S_PARAM_TYPE_GET(t, i) (((t) >> (i*4)) & 0xF) + +#define S_ORIGIN_API 1 +#define S_ORIGIN_COMMS 2 +#define S_ORIGIN_TEE 3 +#define S_ORIGIN_TRUSTED_APP 4 + +/*------------------------------------------------------------------------------ + Implementation Functions +------------------------------------------------------------------------------*/ + +S_RESULT SSDI_EXPORT SImplementationGetAllProperties( + S_PROPERTY** ppProperties, + uint32_t* pnPropertiesCount); + +S_RESULT SSDI_EXPORT SImplementationGetProperty(const char* pName, + char** ppValue); + +S_RESULT SSDI_EXPORT SImplementationGetPropertyAsInt(const char* pName, + uint32_t* pnValue); + +S_RESULT SSDI_EXPORT SImplementationGetPropertyAsBool(const char* pName, + bool* pbValue); + +/*------------------------------------------------------------------------------ + Service Functions +------------------------------------------------------------------------------*/ + +S_RESULT SSDI_EXPORT SServiceGetAllProperties( + OUT S_PROPERTY** ppProperties, + OUT uint32_t* pnPropertiesCount); + +S_RESULT SSDI_EXPORT SServiceGetProperty ( + IN const char* pName, + OUT char** ppValue); + +S_RESULT SSDI_EXPORT SServiceGetPropertyAsInt ( + IN const char* pName, + OUT uint32_t* pnValue); + +S_RESULT SSDI_EXPORT SServiceGetPropertyAsBool( + IN const char* pName, + OUT bool* pbValue); + +/*------------------------------------------------------------------------------ + Instance Functions +------------------------------------------------------------------------------*/ + +void SSDI_EXPORT SInstanceSetData( + void* pInstanceData); + +void SSDI_EXPORT *SInstanceGetData(void); + +/*------------------------------------------------------------------------------ + Session Functions +------------------------------------------------------------------------------*/ + +void SSDI_EXPORT SSessionGetClientID( + S_UUID* pClientID); + +S_RESULT SSDI_EXPORT SSessionGetAllClientProperties( + OUT uint32_t* pnPropertyCount, + OUT S_PROPERTY** ppPropertyArray); + +S_RESULT SSDI_EXPORT SSessionGetClientProperty( + IN const char* pName, + OUT char** ppValue); + +S_RESULT SSDI_EXPORT SSessionGetClientPropertyAsInt ( + IN const char* pName, + OUT uint32_t* pnValue); + +S_RESULT SSDI_EXPORT SSessionGetClientPropertyAsBool ( + IN const char* pName, + OUT bool* pnValue); + +/*------------------------------------------------------------------------------ + Memory Management Functions +------------------------------------------------------------------------------*/ + +void SSDI_EXPORT *SMemAlloc(uint32_t size); + +void SSDI_EXPORT *SMemRealloc(void* ptr, uint32_t newSize); + +void SSDI_EXPORT SMemFree(void *ptr); + +void SSDI_EXPORT *SMemMove(void *dest, const void *src, uint32_t n); + +int32_t SSDI_EXPORT SMemCompare(const void *s1, const void *s2, uint32_t n); + +void SSDI_EXPORT *SMemFill(void *s, uint32_t c, uint32_t n); + +void SSDI_EXPORT *SMemAllocEx(uint32_t nPoolID, uint32_t nSize); + +S_RESULT SMemDup(void *src, uint32_t n, void **dest); + +/*------------------------------------------------------------------------------ + Trace & Debug Functions +------------------------------------------------------------------------------*/ +void SSDI_EXPORT _SLogTrace( + const char *message, + ... /* arguments */); +void SSDI_EXPORT _SLogWarning( + const char *message, + ... /* arguments */); +void SSDI_EXPORT _SLogError( + const char *message, + ... /* arguments */); + +#ifdef __SSDI_USE_TRACE_EX +#include "ssdi_trace_ex.h" +#else + +#ifndef SSDI_NO_TRACE + +#define SLogTrace _SLogTrace +#define SLogWarning _SLogWarning +#define SLogError _SLogError + +#else /* defined(SSDI_NO_TRACE) */ + +/* Note that the following code depends on the compiler's supporting variadic macros */ +#define SLogTrace(...) do ; while(false) +#define SLogWarning(...) do ; while(false) +#define SLogError(...) do ; while(false) + +#endif /* !defined(SSDI_NO_TRACE) */ + +#endif /* __SSDI_USE_TRACE_EX */ + +void SSDI_EXPORT _SAssertionFailed( + const char* pFileName, + uint32_t nLine, + const char* pExpression); + +#ifdef SSDI_DEBUG +#define SAssert(test) \ + do \ + { \ + if (!(test)) \ + { \ + _SAssertionFailed(__FILE__, __LINE__, #test); \ + } \ + } \ + while (0) +#else /* !defined(SSDI_DEBUG) */ +#define SAssert(test) +#endif /* defined(SSDI_DEBUG) */ + +#define S_VAR_NOT_USED(variable) do{(void)(variable);}while(0); + +/*------------------------------------------------------------------------------ + Time Utility +------------------------------------------------------------------------------*/ +void SSDI_EXPORT STimeGetLimit( + uint32_t nTimeout, + OUT S_TIME_LIMIT* pTimeLimit ); + + +/*------------------------------------------------------------------------------ + Thread Functions +------------------------------------------------------------------------------*/ +S_RESULT SSDI_EXPORT SThreadCreate( + OUT S_HANDLE* phThread, + uint32_t stackSize, + uint32_t (*pEntryPoint)(void*), + IN void* pThreadArg); + +S_RESULT SSDI_EXPORT SThreadJoin( + S_HANDLE hThread, + uint32_t* pnExitCode, + const S_TIME_LIMIT* pTimeLimit); + +void SSDI_EXPORT SThreadYield(void); + +S_RESULT SSDI_EXPORT SThreadSleep(const S_TIME_LIMIT* pTimeLimit); + +void SSDI_EXPORT SThreadCancel(S_HANDLE hThread, uint32_t nReserved); + +bool SSDI_EXPORT SThreadIsCancelled (void* pReserved); + +void SSDI_EXPORT SThreadResetCancel(void); + +void SSDI_EXPORT SThreadMaskCancellation ( bool bMask ); + +/*------------------------------------------------------------------------------ + Semaphore Functions +------------------------------------------------------------------------------*/ + +S_RESULT SSDI_EXPORT SSemaphoreCreate ( + uint32_t initialCount, + S_HANDLE* phSemaphore); + +S_RESULT SSDI_EXPORT SSemaphoreAcquire(S_HANDLE hSemaphore, const S_TIME_LIMIT* pTimeLimit); + +void SSDI_EXPORT SSemaphoreRelease(S_HANDLE hSemaphore); + +/*------------------------------------------------------------------------------ + File System Functions +------------------------------------------------------------------------------*/ + +S_RESULT SSDI_EXPORT SFileOpen( + uint32_t nStorageID, + const char *pFilename, + uint32_t nFlags, + uint32_t nReserved, + S_HANDLE *phFile); + +S_RESULT SSDI_EXPORT SFileRead(S_HANDLE hFile, + uint8_t* pBuffer, + uint32_t nSize, + uint32_t* pnCount); + +S_RESULT SSDI_EXPORT SFileWrite (S_HANDLE hFile, + const uint8_t* pBuffer, + uint32_t nSize); + +S_RESULT SSDI_EXPORT SFileTruncate(S_HANDLE hFile, + uint32_t nSize); + +S_RESULT SSDI_EXPORT SFileSeek(S_HANDLE hFile, + int32_t nOffset, + S_WHENCE eWhence); + +uint32_t SSDI_EXPORT SFileTell(S_HANDLE hFile); + +bool SSDI_EXPORT SFileEOF(S_HANDLE hFile); + +S_RESULT SSDI_EXPORT SFileCloseAndDelete(S_HANDLE hFile); + +S_RESULT SSDI_EXPORT SFileRename(S_HANDLE hFile, const char* pNewFilename); + +S_RESULT SSDI_EXPORT SFileGetSize(uint32_t nStorageID, + const char* pFilename, + uint32_t* pnFileSize); + +S_RESULT SSDI_EXPORT SFileEnumerationStart ( + uint32_t nStorageID, + const char* pFilenamePattern, + uint32_t nReserved1, + uint32_t nReserved2, + S_HANDLE* phFileEnumeration); + +S_RESULT SSDI_EXPORT SFileEnumerationGetNext ( + S_HANDLE hFileEnumeration, + OUT S_FILE_INFO** ppFileInfo); + +/*------------------------------------------------------------------------------ + Date Functions +------------------------------------------------------------------------------*/ + +S_RESULT SSDI_EXPORT SDateSet ( + int32_t nSeconds, + uint32_t nReserved); + +S_RESULT SSDI_EXPORT SDateGet( + OUT int32_t* pnSeconds, + OUT uint32_t* pnDateStatus, + uint32_t nReserved ); + +int32_t SSDI_EXPORT SClockGet(void); + +S_RESULT SSDI_EXPORT SDateConvertSecondsToCalendar( + IN int32_t nSeconds, + IN const S_CALENDAR* pOrigin, + OUT S_CALENDAR* pDate ); + +S_RESULT SSDI_EXPORT SDateConvertCalendarToSeconds( + IN const S_CALENDAR* pOrigin, + IN const S_CALENDAR* pDate, + OUT int32_t* pnSeconds); + +/*------------------------------------------------------------------------------ + Handle Functions +------------------------------------------------------------------------------*/ +void SSDI_EXPORT SHandleClose ( S_HANDLE hHandle); + +/*------------------------------------------------------------------------------ + Crypto API +------------------------------------------------------------------------------*/ + +#define PKCS11_EXPORT SSDI_EXPORT + +#include "pkcs11.h" + +/*------------------------------------------------------------------------------ + Cryptoki Update Shortcut +------------------------------------------------------------------------------*/ + +#define S_UPDATE_SHORTCUT_FLAG_AGGRESSIVE 0x00000001 + +CK_RV SSDI_EXPORT CV_ActivateUpdateShortcut2( + CK_SESSION_HANDLE hCryptokiSession, + uint32_t nCommandID, + uint32_t nFlags, + uint32_t nReserved); + +void SSDI_EXPORT CV_DeactivateUpdateShortcut( + CK_SESSION_HANDLE hCryptokiSession); + + +/*------------------------------------------------------------------------------ + Panic Function +------------------------------------------------------------------------------*/ + +void SSDI_EXPORT SPanic(uint32_t nReserved); + +/*------------------------------------------------------------------------------ + SXControl functions +------------------------------------------------------------------------------*/ +S_RESULT SSDI_EXPORT SXControlOpenClientSession ( + const S_UUID* pDestination, + S_TIME_LIMIT* pDeadline, + uint32_t nParamTypes, + S_PARAM pParams[4], + OUT S_HANDLE* phSessionHandle, + uint32_t* pnReturnOrigin); + +S_RESULT SSDI_EXPORT SXControlInvokeCommand ( + S_HANDLE hSessionHandle, + S_TIME_LIMIT* pDeadline, + uint32_t nCommandID, + uint32_t nParamTypes, + S_PARAM pParams[4], + uint32_t* pnReturnOrigin); + +/*------------------------------------------------------------------------------ + SRVX Entry Points +------------------------------------------------------------------------------*/ + +extern S_RESULT SRVX_EXPORT SRVXCreate(void); +extern void SRVX_EXPORT SRVXDestroy(void); +extern S_RESULT SRVX_EXPORT SRVXOpenClientSession(uint32_t nParamTypes, + IN OUT S_PARAM pParams[4], + OUT void** ppSessionContext); +extern S_RESULT SRVX_EXPORT SRVXInvokeCommand(IN OUT void* pSessionContext, + uint32_t nCommandID, + uint32_t nParamTypes, + IN OUT S_PARAM pParams[4]); +extern void SRVX_EXPORT SRVXCloseClientSession(IN OUT void* pSessionContext); + +#include "ssdi_v2_compat.h" + +#endif /* __SSDI_H__ */ diff --git a/security/tf_sdk/include/ssdi_smc_ext.h b/security/tf_sdk/include/ssdi_smc_ext.h new file mode 100644 index 0000000..d0cb1c7 --- /dev/null +++ b/security/tf_sdk/include/ssdi_smc_ext.h @@ -0,0 +1,61 @@ +/** + * Copyright(c) 2011 Trusted Logic. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name Trusted Logic nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* +* File : ssdi_smc_ext.h +* +* Original-Author : Trusted Logic S.A. +* +* Created : October 27, 2008 +*/ + +/** + * SSDI SMC Extensions specification header file. + */ + +#ifndef __SSDI_SMC_EXT_H__ +#define __SSDI_SMC_EXT_H__ + + +/* Cryptoki slotID constants */ +#define S_CRYPTOKI_KEYSTORE_HW_TOKEN 0x00007FFF + + +#define CKMV_SMC_KEK_DERIVE 0xC0000000 + + +typedef struct CKV_SMC_KEK_DERIVE_PARAMS +{ + CK_ULONG Id; + CK_BYTE diversify[16]; +} CKV_SMC_KEK_DERIVE_PARAMS; + + +#endif /* __SSDI_SMC_EXT_H__ */ diff --git a/security/tf_sdk/include/ssdi_v2_compat.h b/security/tf_sdk/include/ssdi_v2_compat.h new file mode 100644 index 0000000..06a3b0e --- /dev/null +++ b/security/tf_sdk/include/ssdi_v2_compat.h @@ -0,0 +1,308 @@ +/** + * Copyright(c) 2011 Trusted Logic. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name Trusted Logic nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* +* File : ssdi_v2_compat.h +* +* Original-Author : Trusted Logic S.A. +* +* Created : July 08, 2010 +*/ + +/** + * This header file contains the definitions for the legacy + * SSDI-V2 types and functions + */ + +#ifndef __SSDI_V2_COMPAT_H__ +#define __SSDI_V2_COMPAT_H__ + +#include "s_type.h" +#include "s_error.h" +#include "ssdi.h" + +/* SSPI entry points must not be exported. + SRVX entry points defined in the ssdi_v2_compat library are exported. */ +#define SSPI_EXPORT + +/*------------------------------------------------------------------------------ + Constants +------------------------------------------------------------------------------*/ +#define S_SHARED_MEMORY_ACCESS_READ 0x01 +#define S_SHARED_MEMORY_ACCESS_WRITE 0x02 + +#define S_NULL_ELEMENT 0xFFFFFFFF + +#define S_SHARED_MEMORY_ACCESS_READ 0x01 +#define S_SHARED_MEMORY_ACCESS_WRITE 0x02 + +/* SControl constants */ +#define S_CONTROL_MODE_USER 0x00000002 +#define S_CONTROL_MODE_MANAGER 0x00000008 +#define S_CONTROL_MODE_EXCLUSIVE_MANAGER 0x00000010 + +/* Shared memory access */ +#define S_MEMORY_ACCESS_CLIENT_WRITE_SERVICE_READ 0x00000001 +#define S_MEMORY_ACCESS_CLIENT_READ_SERVICE_WRITE 0x00000002 + +/* Login types */ +#define S_LOGIN_OS_IDENTIFICATION S_LOGIN_APPLICATION_USER + +/*------------------------------------------------------------------------------ + Decoder Functions +------------------------------------------------------------------------------*/ + +S_RESULT SDecoderGetError(S_HANDLE hDecoder); + +bool SDecoderHasData(S_HANDLE hDecoder); + +uint8_t SDecoderReadUint8(S_HANDLE hDecoder); + +uint16_t SDecoderReadUint16(S_HANDLE hDecoder); + +uint32_t SDecoderReadUint32(S_HANDLE hDecoder); + +char *SDecoderReadString(S_HANDLE hDecoder); + +bool SDecoderReadBoolean(S_HANDLE hDecoder); + +uint8_t *SDecoderReadUint8Array( + S_HANDLE hDecoder, + OUT uint32_t* pnArrayLength); + +uint16_t *SDecoderReadUint16Array( + S_HANDLE hDecoder, + OUT uint32_t* pnArrayLength); + +uint32_t *SDecoderReadUint32Array( + S_HANDLE hDecoder, + OUT uint32_t* pnArrayLength); + +uint32_t SDecoderReadArrayLength(S_HANDLE hDecoder); + +uint32_t SDecoderCopyUint8Array( + IN S_HANDLE hDecoder, + IN uint32_t nIndex, + IN uint32_t nMaxLength, + OUT uint8_t* pArray); + +uint32_t SDecoderCopyUint16Array( + IN S_HANDLE hDecoder, + IN uint32_t nIndex, + IN uint32_t nMaxLength, + OUT uint16_t* pArray); + +uint32_t SDecoderCopyUint32Array( + IN S_HANDLE hDecoder, + IN uint32_t nIndex, + IN uint32_t nMaxLength, + OUT uint32_t* pArray); + +void SDecoderOpenSequence(S_HANDLE hDecoder); + +void SDecoderCloseSequence(S_HANDLE hDecoder); + +void SDecoderSkip(S_HANDLE hDecoder); + +uint8_t *SDecoderReadMemoryReference( + S_HANDLE hDecoder, + uint32_t nFlags, + OUT uint32_t* pnSize); +void SDecoderReadUUID( + IN S_HANDLE hDecoder, + OUT S_UUID* pUUID); + +/*------------------------------------------------------------------------------ + Encoder Functions +------------------------------------------------------------------------------*/ + +void SEncoderWriteUint8( + IN S_HANDLE hEncoder, + IN uint8_t value); + +void SEncoderWriteUint16( + IN S_HANDLE hEncoder, + IN uint16_t value); + +void SEncoderWriteUint32(IN S_HANDLE hEncoder, + IN uint32_t value); + +void SEncoderWriteBoolean(IN S_HANDLE hEncoder, + IN bool value); + +void SEncoderWriteString(IN S_HANDLE hEncoder, + IN const char* value); + +void SEncoderWriteUint8Array(IN S_HANDLE hEncoder, + IN uint32_t nArrayLength, + IN const uint8_t* pnArray); + +void SEncoderWriteUint16Array(IN S_HANDLE hEncoder, + IN uint32_t nArrayLength, + IN const uint16_t* pnArray); + +void SEncoderWriteUint32Array(IN S_HANDLE hEncoder, + IN uint32_t nArrayLength, + IN const uint32_t* pnArray); + +void SEncoderWriteBooleanArray(IN S_HANDLE hEncoder, + IN uint32_t nArrayLength, + IN const bool* pnArray); + +void SEncoderWriteStringArray(IN S_HANDLE hEncoder, + IN uint32_t nArrayLength, + IN const char** pnArray); + +void SEncoderWriteMemoryReference( + S_HANDLE hEncoder, + S_HANDLE hBlock, + uint32_t nOffset, + uint32_t nLength, + uint32_t nFlags); + +void SEncoderOpenSequence( S_HANDLE hEncoder ); + +void SEncoderCloseSequence( S_HANDLE hEncoder ); + +S_RESULT SEncoderGetError(S_HANDLE hEncoder); + +void SEncoderReset( S_HANDLE hEncoder ); + +void SEncoderWriteUUID( + IN S_HANDLE hEncoder, + IN const S_UUID* pUUID); + +/*------------------------------------------------------------------------------ + Service Control Functions +------------------------------------------------------------------------------*/ + +S_RESULT SControlPrepareOpenOperation( + IN const S_UUID* pIdService, + uint32_t nControlMode, + IN const S_TIME_LIMIT* pTimeLimit, + uint32_t nEncoderBufferSize, + uint32_t nDecoderBufferSize, + OUT S_HANDLE* phClientSession, + OUT S_HANDLE* phParameterEncoder, + OUT S_HANDLE* phOperation ); + +S_RESULT SControlPrepareInvokeOperation( + S_HANDLE hClientSession, + uint32_t nCommandIdentifier, + IN const S_TIME_LIMIT* pTimeLimit, + uint32_t nEncoderBufferSize, + uint32_t nDecoderBufferSize, + OUT S_HANDLE* phParameterEncoder, + OUT S_HANDLE* phOperation ); + +S_RESULT SControlPrepareCloseOperation( + S_HANDLE hClientSession, + uint32_t nEncoderBufferSize, + uint32_t nDecoderBufferSize, + OUT S_HANDLE* phParameterEncoder, + OUT S_HANDLE* phOperation ); + +S_RESULT SControlPerformOperation( + S_HANDLE hOperation, + uint32_t nReserved, + OUT S_RESULT* pnServiceErrorCode, + OUT S_HANDLE* phAnswerDecoder ); + +S_RESULT SControlCancelOperation( S_HANDLE hOperation ); + +S_RESULT SControlAllocateSharedMemory( + S_HANDLE hClientSession, + uint32_t nLength, + uint32_t nFlags, + uint32_t nReserved, + OUT void** ppBlock, + OUT S_HANDLE* phBlockHandle); + +S_RESULT SControlRegisterSharedMemory( + S_HANDLE hClientSession, + IN const void* pBuffer, + uint32_t nBufferLength, + uint32_t nFlags, + uint32_t nReserved, + OUT S_HANDLE* phBlockHandle ); + +/*------------------------------------------------------------------------------ + Service Manager Functions +------------------------------------------------------------------------------*/ + +S_RESULT SManagerOpen( + uint32_t nControlMode, + S_HANDLE* phServiceManager); + +S_RESULT SManagerGetAllServices( + S_HANDLE hServiceManager, + S_UUID** ppServiceIdentifierList, + uint32_t* pnListLength); + +S_RESULT SManagerGetServiceProperty( + S_HANDLE hServiceManager, + const S_UUID* pidService, + const char* pPropertyName, + char** ppPropertyValue); + +S_RESULT SManagerGetAllServiceProperties( + S_HANDLE hServiceManager, + const S_UUID* pidService, + S_PROPERTY** ppProperties, + uint32_t* pnPropertiesLength); + +S_RESULT SManagerDownloadService( + S_HANDLE hServiceManager, + const uint8_t* pServiceCode, + uint32_t nServiceCodeSize, + S_UUID* pidService); + +S_RESULT SManagerRemoveService( + S_HANDLE hServiceManager, + const S_UUID* pidService); + +/*------------------------------------------------------------------------------ + SSPI Entry Points +------------------------------------------------------------------------------*/ + +S_RESULT SSPICreate(void); +void SSPIDestroy(void); +S_RESULT SSPIOpenClientSession(S_HANDLE hDecoder, + S_HANDLE hEncoder, + OUT void** ppSessionContext); +S_RESULT SSPIInvokeCommand(IN OUT void* pSessionContext, + uint32_t nCommandID, + S_HANDLE hDecoder, + S_HANDLE hEncoder); +S_RESULT SSPICloseClientSession(IN OUT void* pSessionContext, + uint32_t nCause, + S_HANDLE hDecoder, + S_HANDLE hEncoder); +#endif /* __SSDI_V2_COMPAT_H__ */ |