mirror of
https://github.com/stefanberger/libtpms
synced 2026-08-11 19:26:27 +00:00
tpm2: Add missing SM4; do not enable it
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
parent
5233aa9e54
commit
5f0e2aef9d
@ -351,6 +351,51 @@ const BYTE dataOut_CAMELLIA256_CTR [] = {
|
||||
0x1a, 0x7b, 0xbb, 0xfc, 0x7f, 0x6e, 0x9e, 0xe5,
|
||||
0x86, 0x46, 0xc3, 0xef, 0x8d, 0xab, 0xc5, 0x40};
|
||||
#endif
|
||||
#if SM4_128
|
||||
// source: https://tools.ietf.org/html/draft-ribose-cfrg-sm4-04#appendix-A.2
|
||||
const BYTE key_SM4128 [] = {
|
||||
0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
|
||||
0xFE, 0xDC, 0xBA, 0x98, 0x76, 0x54, 0x32, 0x10};
|
||||
const BYTE dataIn_SM4128 [] = {
|
||||
0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB,
|
||||
0xCC, 0xCC, 0xCC, 0xCC, 0xDD, 0xDD, 0xDD, 0xDD
|
||||
0xEE, 0xEE, 0xEE, 0xEE, 0xFF, 0xFF, 0xFF, 0xFF,
|
||||
0xAA, 0xAA, 0xAA, 0xAA, 0xBB, 0xBB, 0xBB, 0xBB};
|
||||
const BYTE dataOut_SM4128_ECB [] = {
|
||||
0x5E, 0xC8, 0x14, 0x3D, 0xE5, 0x09, 0xCF, 0xF7,
|
||||
0xB5, 0x17, 0x9F, 0x8F, 0x47, 0x4B, 0x86, 0x19,
|
||||
0x2F, 0x1D, 0x30, 0x5A, 0x7F, 0xB1, 0x7D, 0xF9,
|
||||
0x85, 0xF8, 0x1C, 0x84, 0x82, 0x19, 0x23, 0x04,
|
||||
0x00, 0x2A, 0x8A, 0x4E, 0xFA, 0x86, 0x3C, 0xCA,
|
||||
0xD0, 0x24, 0xAC, 0x03, 0x00, 0xBB, 0x40, 0xD2}
|
||||
const BYTE dataOut_SM4128_CBC [] = {
|
||||
0x78, 0xEB, 0xB1, 0x1C, 0xC4, 0x0B, 0x0A, 0x48,
|
||||
0x31, 0x2A, 0xAE, 0xB2, 0x04, 0x02, 0x44, 0xCB,
|
||||
0x4C, 0xB7, 0x01, 0x69, 0x51, 0x90, 0x92, 0x26,
|
||||
0x97, 0x9B, 0x0D, 0x15, 0xDC, 0x6A, 0x8F, 0x6D,
|
||||
0x40, 0xD8, 0x41, 0x32, 0xE9, 0x99, 0x74, 0xA4,
|
||||
0xA8, 0x80, 0x88, 0x68, 0x42, 0x07, 0x48, 0x59};
|
||||
const BYTE dataOut_SM4128_CFB [] = {
|
||||
0xAC, 0x32, 0x36, 0xCB, 0x86, 0x1D, 0xD3, 0x16,
|
||||
0xE6, 0x41, 0x3B, 0x4E, 0x3C, 0x75, 0x24, 0xB7,
|
||||
0x69, 0xD4, 0xC5, 0x4E, 0xD4, 0x33, 0xB9, 0xA0,
|
||||
0x34, 0x60, 0x09, 0xBE, 0xB3, 0x7B, 0x2B, 0x3F};
|
||||
const BYTE dataOut_SM4128_OFB [] = {
|
||||
0xAC, 0x32, 0x36, 0xCB, 0x86, 0x1D, 0xD3, 0x16,
|
||||
0xE6, 0x41, 0x3B, 0x4E, 0x3C, 0x75, 0x24, 0xB7,
|
||||
0x1D, 0x01, 0xAC, 0xA2, 0x48, 0x7C, 0xA5, 0x82,
|
||||
0xCB, 0xF5, 0x46, 0x3E, 0x66, 0x98, 0x53, 0x9B};
|
||||
const BYTE dataOut_SM4128_CTR [] = {
|
||||
/* FIXME: The IETF doc uses a different IV than what we do....*/
|
||||
0xAC, 0x32, 0x36, 0xCB, 0x97, 0x0C, 0xC2, 0x07,
|
||||
0x91, 0x36, 0x4C, 0x39, 0x5A, 0x13, 0x42, 0xD1,
|
||||
0xA3, 0xCB, 0xC1, 0x87, 0x8C, 0x6F, 0x30, 0xCD,
|
||||
0x07, 0x4C, 0xCE, 0x38, 0x5C, 0xDD, 0x70, 0xC7,
|
||||
0xF2, 0x34, 0xBC, 0x0E, 0x24, 0xC1, 0x19, 0x80,
|
||||
0xFD, 0x12, 0x86, 0x31, 0x0C, 0xE3, 0x7B, 0x92,
|
||||
0x6E, 0x02, 0xFC, 0xD0, 0xFA, 0xA0, 0xBA, 0xF3,
|
||||
0x8B, 0x29, 0x33, 0x85, 0x1D, 0x82, 0x45, 0x14};
|
||||
#endif
|
||||
// libtpms added end
|
||||
|
||||
#endif
|
||||
|
||||
@ -444,7 +444,7 @@
|
||||
#define ALG_SM3_256 ALG_NO /* libtpms: NO */
|
||||
#endif
|
||||
#ifndef ALG_SM4
|
||||
#define ALG_SM4 ALG_NO
|
||||
#define ALG_SM4 ALG_NO /* libtpms: NO */
|
||||
#endif
|
||||
#ifndef ALG_SYMCIPHER
|
||||
#define ALG_SYMCIPHER ALG_YES
|
||||
|
||||
@ -189,8 +189,35 @@ evpfunc GetEVPCipher(TPM_ALG_ID algorithm, // IN
|
||||
#endif
|
||||
|
||||
#if ALG_SM4
|
||||
#error Missing implementation of EVP for SM4
|
||||
case TPM_ALG_SM4:
|
||||
*keyToUseLen = keySizeInBytes;
|
||||
switch (mode) {
|
||||
#if ALG_CTR
|
||||
case ALG_CTR_VALUE:
|
||||
evpfn = (evpfunc[]){EVP_sm4_ctr, NULL, NULL}[i];
|
||||
break;
|
||||
#endif
|
||||
#if ALG_OFB
|
||||
case ALG_OFB_VALUE:
|
||||
evpfn = (evpfunc[]){EVP_sm4_ofb, NULL, NULL}[i];
|
||||
break;
|
||||
#endif
|
||||
#if ALG_CBC
|
||||
case ALG_CBC_VALUE:
|
||||
evpfn = (evpfunc[]){EVP_sm4_cbc, NULL, NULL}[i];
|
||||
break;
|
||||
#endif
|
||||
#if ALG_CFB
|
||||
case ALG_CFB_VALUE:
|
||||
evpfn = (evpfunc[]){EVP_sm4_cfb, NULL, NULL}[i];
|
||||
break;
|
||||
#endif
|
||||
#if ALG_ECB
|
||||
case ALG_ECB_VALUE:
|
||||
evpfn = (evpfunc[]){EVP_sm4_ecb, NULL, NULL}[i];
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
/* Splice the OpenSSL() library into the TPM code. */
|
||||
/* Written by Ken Goldman */
|
||||
/* IBM Thomas J. Watson Research Center */
|
||||
/* $Id: TpmToOsslSym.h 1476 2019-06-10 19:32:03Z kgoldman $ */
|
||||
/* $Id: TpmToOsslSym.h 1519 2019-11-15 20:43:51Z kgoldman $ */
|
||||
/* */
|
||||
/* Licenses and Notices */
|
||||
/* */
|
||||
@ -71,6 +71,9 @@
|
||||
#define SYM_LIB_OSSL
|
||||
#include <openssl/aes.h>
|
||||
#include <openssl/des.h>
|
||||
#if ALG_SM4 /* kgold */
|
||||
#include <openssl/sm4.h>
|
||||
#endif
|
||||
#include <openssl/camellia.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/ossl_typ.h>
|
||||
@ -132,9 +135,18 @@ typedef void(*TpmCryptSetSymKeyCall_t)(
|
||||
#include "TpmToOsslDesSupport_fp.h"
|
||||
#endif // libtpms added end
|
||||
|
||||
#if ALG_SM4
|
||||
#error "SM4 is not available"
|
||||
#endif
|
||||
/* B.2.2.3.5. Links to the OpenSSL SM4 code */
|
||||
/* Macros to set up the encryption/decryption key schedules */
|
||||
|
||||
#define TpmCryptSetEncryptKeySM4(key, keySizeInBits, schedule) \
|
||||
SM4_set_key((key), (tpmKeyScheduleSM4 *)(schedule))
|
||||
#define TpmCryptSetDecryptKeySM4(key, keySizeInBits, schedule) \
|
||||
SM4_set_key((key), (tpmKeyScheduleSM4 *)(schedule))
|
||||
/* Macros to alias encryption calls to specific algorithms. This should be used sparingly. */
|
||||
|
||||
#define TpmCryptEncryptSM4 SM4_encrypt
|
||||
#define TpmCryptDecryptSM4 SM4_decrypt
|
||||
#define tpmKeyScheduleSM4 SM4_KEY
|
||||
|
||||
/* B.2.2.3.6. Links to the OpenSSL CAMELLIA code */
|
||||
/* Macros to set up the encryption/decryption key schedules */
|
||||
|
||||
Loading…
Reference in New Issue
Block a user