tpm2: Reorganize TpmToOsslSym.h

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2019-11-18 12:01:37 -05:00 committed by Stefan Berger
parent 893dafd7c0
commit e226ea4c2d

View File

@ -59,11 +59,12 @@
/* */
/********************************************************************************/
/* B.2.2.2. TpmToOsslSym.h */
/* B.2.2.2.1. Introduction */
/* B.2.3.2. TpmToOsslSym.h */
/* B.2.3.2.1. Introduction */
/* This header file is used to splice the OpenSSL() library into the TPM code. */
/* The support required of a library are a hash module, a block cipher module and portions of a big
number library. */
number library. All of the library-dependent headers should have the same guard to that only the
first one gets defined. */
#ifndef SYM_LIB_DEFINED
#define SYM_LIB_DEFINED
@ -73,52 +74,74 @@
#include <openssl/bn.h>
#include <openssl/ossl_typ.h>
/* B.2.2.3.2. Links to the OpenSSL AES code */
/* B.2.2.3.2. Links to the OpenSSL symmetric algorithms */
// The Crypt functions that call the block encryption function use the parameters in the order:
// a) keySchedule
// b) in buffer
// c) out buffer Since open SSL uses the order in encryptoCall_t above, need to swizzle the values
// to the order required by the library.
#define SWIZZLE(keySchedule, in, out) \
(const BYTE *)(in), (BYTE *)(out), (void *)(keySchedule)
// Define the order of parameters to the library functions that do block encryption and decryption.
typedef void(*TpmCryptSetSymKeyCall_t)(
const BYTE *in,
BYTE *out,
void *keySchedule
);
/* B.2.2.3.3. Links to the OpenSSL AES code */
/* Macros to set up the encryption/decryption key schedules */
#define TpmCryptSetEncryptKeyAES(key, keySizeInBits, schedule) \
AES_set_encrypt_key((key), (keySizeInBits), (tpmKeyScheduleAES *)(schedule))
#define TpmCryptSetDecryptKeyAES(key, keySizeInBits, schedule) \
AES_set_decrypt_key((key), (keySizeInBits), (tpmKeyScheduleAES *)(schedule))
/* Macros to alias encryption calls to specific algorithms. This should be used
sparingly. Currently, only used by CryptSym.c and CryptRand.c */
/* When using these calls, to call the AES block encryption code, the caller should use:
TpmCryptEncryptAES(SWIZZLE(keySchedule, in, out)); */
#define TpmCryptEncryptAES AES_encrypt
#define TpmCryptDecryptAES AES_decrypt
#define tpmKeyScheduleAES AES_KEY
/* B.2.2.3.4. Links to the OpenSSL DES code */
#if ALG_TDES && 0 // libtpms changed
#include "TpmToOsslDesSupport_fp.h"
#endif
#define TpmCryptSetEncryptKeyTDES(key, keySizeInBits, schedule) \
TDES_set_encrypt_key((key), (keySizeInBits), (tpmKeyScheduleTDES *)(schedule))
#define TpmCryptSetDecryptKeyTDES(key, keySizeInBits, schedule) \
TDES_set_encrypt_key((key), (keySizeInBits), (tpmKeyScheduleTDES *)(schedule))
/* Macros to alias encryption calls to specific algorithms. This should be used
sparingly. Currently, only used by CryptRand.c */
#define TpmCryptEncryptTDES TDES_encrypt
#define TpmCryptDecryptTDES TDES_decrypt
#define tpmKeyScheduleTDES DES_key_schedule
#if ALG_TDES // libtpms added begin
#include "TpmToOsslDesSupport_fp.h"
#endif // libtpms added end
#if ALG_SM4
#error "SM4 is not available"
#endif
#if ALG_CAMELLIA
#error "Camellia is not available"
#endif
/* Define the order of parameters to the library functions that do block encryption and
decryption. */
typedef void(*TpmCryptSetSymKeyCall_t)(
const BYTE *in,
BYTE *out,
void *keySchedule
);
/* The Crypt functions that call the block encryption function use the parameters in the order: */
/* a) keySchedule */
/* b) in buffer */
/* c) out buffer Since open SSL uses the order in encryptoCall_t above, need to swizzle the values
to the order required by the library. */
#define SWIZZLE(keySchedule, in, out) \
(const BYTE *)(in), (BYTE *)(out), (void *)(keySchedule)
/* Macros to set up the encryption/decryption key schedules */
/* AES: */
#define TpmCryptSetEncryptKeyAES(key, keySizeInBits, schedule) \
AES_set_encrypt_key((key), (keySizeInBits), (tpmKeyScheduleAES *)(schedule))
#define TpmCryptSetDecryptKeyAES(key, keySizeInBits, schedule) \
AES_set_decrypt_key((key), (keySizeInBits), (tpmKeyScheduleAES *)(schedule))
/* TDES: */
#define TpmCryptSetEncryptKeyTDES(key, keySizeInBits, schedule) \
TDES_set_encrypt_key((key), (keySizeInBits), (tpmKeyScheduleTDES *)(schedule))
#define TpmCryptSetDecryptKeyTDES(key, keySizeInBits, schedule) \
TDES_set_encrypt_key((key), (keySizeInBits), (tpmKeyScheduleTDES *)(schedule))
/* Macros to alias encryption calls to specific algorithms. This should be used
sparingly. Currently, only used by CryptRand.c */
/* When using these calls, to call the AES block encryption code, the caller should use:
TpmCryptEncryptAES(SWIZZLE(keySchedule, in, out)); */
#define TpmCryptEncryptAES AES_encrypt
#define TpmCryptDecryptAES AES_decrypt
#define tpmKeyScheduleAES AES_KEY
#define TpmCryptEncryptTDES TDES_encrypt
#define TpmCryptDecryptTDES TDES_decrypt
#define tpmKeyScheduleTDES DES_key_schedule
/* Forward reference */
typedef union tpmCryptKeySchedule_t tpmCryptKeySchedule_t;
#if ALG_TDES
#include "TpmToOsslDesSupport_fp.h"
#endif
/* This definition would change if there were something to report */
#define SymLibSimulationEnd()
#endif // SYM_LIB_DEFINED