rev164: Change AGL_XYZ_VALUE to equivalend TPM_ALG_XYZ

$ grep -En "ALG_[A-Z]*_VALUE" src/tpm2/TpmTypes.h
71:#define     ALG_ERROR_VALUE             0x0000
72:#define TPM_ALG_ERROR                   (TPM_ALG_ID)(ALG_ERROR_VALUE)
73:#define     ALG_RSA_VALUE               0x0001
74:#define TPM_ALG_RSA                     (TPM_ALG_ID)(ALG_RSA_VALUE)
[...]

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
This commit is contained in:
Stefan Berger 2021-02-22 18:47:24 -05:00 committed by Stefan Berger
parent 97d2df2510
commit 9137a773d8
17 changed files with 239 additions and 237 deletions

View File

@ -3,7 +3,7 @@
/* Code to perform the various self-test functions. */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: AlgorithmTests.c 1594 2020-03-26 22:15:48Z kgoldman $ */
/* $Id: AlgorithmTests.c 1658 2021-01-22 23:14:01Z kgoldman $ */
/* */
/* Licenses and Notices */
/* */
@ -55,7 +55,7 @@
/* arising in any way out of use or reliance upon this specification or any */
/* information herein. */
/* */
/* (c) Copyright IBM Corp. and others, 2016 - 2020 */
/* (c) Copyright IBM Corp. and others, 2016 - 2021 */
/* */
/********************************************************************************/
@ -107,7 +107,7 @@ TestHash(
UINT16 digestSize;
const TPM2B *testDigest = NULL;
// TPM2B_TYPE(HMAC_BLOCK, DEFAULT_TEST_HASH_BLOCK_SIZE);
pAssert(hashAlg != ALG_NULL_VALUE);
pAssert(hashAlg != TPM_ALG_NULL);
#define HASH_CASE_FOR_TEST(HASH, hash) case ALG_##HASH##_VALUE: \
testDigest = &c_##HASH##_digest.b; \
break;
@ -155,7 +155,7 @@ TestSMAC(
TPMU_PUBLIC_PARMS cmac_keyParms;
// initializing this statically seems impossible with gcc...
cmac_keyParms.symDetail.sym.algorithm = ALG_AES_VALUE;
cmac_keyParms.symDetail.sym.algorithm = TPM_ALG_AES;
cmac_keyParms.symDetail.sym.keyBits.sym = 128;
for (i = 0; CMACTests[i].key; i++ )
@ -186,9 +186,9 @@ MakeIv(
)
{
BYTE i;
if(mode == ALG_ECB_VALUE)
if(mode == TPM_ALG_ECB)
return 0;
if(mode == ALG_CTR_VALUE)
if(mode == TPM_ALG_CTR)
{
// The test uses an IV that has 0xff in the last byte
for(i = 1; i <= size; i++)
@ -214,7 +214,7 @@ TestSymmetricAlgorithm(
TPM2B_IV iv;
// libtpms added beging
if (test->dataOut[mode - ALG_CTR_VALUE] == NULL)
if (test->dataOut[mode - TPM_ALG_CTR] == NULL)
return;
// libtpms added end
@ -225,7 +225,7 @@ TestSymmetricAlgorithm(
CryptSymmetricEncrypt(encrypted, test->alg, test->keyBits, test->key, &iv,
mode, test->dataInOutSize, test->dataIn);
// Check that it matches the expected value
if(!MemoryEqual(encrypted, test->dataOut[mode - ALG_CTR_VALUE],
if(!MemoryEqual(encrypted, test->dataOut[mode - TPM_ALG_CTR],
test->dataInOutSize)) {
SELF_TEST_FAILURE;
}
@ -233,7 +233,7 @@ TestSymmetricAlgorithm(
MakeIv(mode, test->ivSize, iv.t.buffer);
CryptSymmetricDecrypt(decrypted, test->alg, test->keyBits, test->key, &iv,
mode, test->dataInOutSize,
test->dataOut[mode - ALG_CTR_VALUE]);
test->dataOut[mode - TPM_ALG_CTR]);
// Make sure that it matches what we started with
if(!MemoryEqual(decrypted, test->dataIn, test->dataInOutSize)) {
SELF_TEST_FAILURE;
@ -250,7 +250,7 @@ AllSymsAreDone(
ALGORITHM_VECTOR *toTest
)
{
return (!TEST_BOTH(ALG_AES_VALUE) && !TEST_BOTH(ALG_SM4_VALUE));
return (!TEST_BOTH(TPM_ALG_AES) && !TEST_BOTH(TPM_ALG_SM4));
}
/* 10.2.1.4.4 AllModesAreDone() */
/* Checks if all the modes have been tested */
@ -282,7 +282,7 @@ TestSymmetric(
//
if(!TEST_BIT(alg, *toTest))
return TPM_RC_SUCCESS;
if(alg == ALG_AES_VALUE || alg == ALG_SM4_VALUE || alg == ALG_CAMELLIA_VALUE || alg == ALG_TDES_VALUE)
if(alg == TPM_ALG_AES || alg == TPM_ALG_SM4 || alg == TPM_ALG_CAMELLIA || alg == TPM_ALG_TDES)
{
// Will test the algorithm for all modes and key sizes
CLEAR_BOTH(alg);
@ -318,8 +318,8 @@ TestSymmetric(
// tested first. That means that all of their modes would have been
// tested for all key sizes. If there is no block cipher left to
// test, then clear this mode bit.
if(!TEST_BIT(ALG_AES_VALUE, *toTest)
&& !TEST_BIT(ALG_SM4_VALUE, *toTest))
if(!TEST_BIT(TPM_ALG_AES, *toTest)
&& !TEST_BIT(TPM_ALG_SM4, *toTest))
{
CLEAR_BOTH(alg);
}
@ -336,8 +336,8 @@ TestSymmetric(
}
if(AllModesAreDone(toTest))
{
CLEAR_BOTH(ALG_AES_VALUE);
CLEAR_BOTH(ALG_SM4_VALUE);
CLEAR_BOTH(TPM_ALG_AES);
CLEAR_BOTH(TPM_ALG_SM4);
}
}
else
@ -400,8 +400,8 @@ TestRsaEncryptDecrypt(
rsaScheme.scheme = scheme;
rsaScheme.details.anySig.hashAlg = DEFAULT_TEST_HASH;
CLEAR_BOTH(scheme);
CLEAR_BOTH(ALG_NULL_VALUE);
if(scheme == ALG_NULL_VALUE)
CLEAR_BOTH(TPM_ALG_NULL);
if(scheme == TPM_ALG_NULL)
{
// This is an encryption scheme using the private key without any encoding.
memcpy(testInput.t.buffer, c_RsaTestValue, sizeof(c_RsaTestValue));
@ -425,24 +425,24 @@ TestRsaEncryptDecrypt(
}
else
{
// ALG_RSAES_VALUE:
// TPM_ALG_RSAES:
// This is an decryption scheme using padding according to
// PKCS#1v2.1, 7.2. This padding uses random bits. To test a public
// key encryption that uses random data, encrypt a value and then
// decrypt the value and see that we get the encrypted data back.
// The hash is not used by this encryption so it can be TMP_ALG_NULL
// ALG_OAEP_VALUE:
// TPM_ALG_OAEP_:
// This is also an decryption scheme and it also uses a
// pseudo-random
// value. However, this also uses a hash algorithm. So, we may need
// to test that algorithm before use.
if(scheme == ALG_OAEP_VALUE)
if(scheme == TPM_ALG_OAEP)
{
TEST_DEFAULT_TEST_HASH(toTest);
kvtValue = &c_OaepKvt;
testLabel = OAEP_TEST_STRING;
}
else if(scheme == ALG_RSAES_VALUE)
else if(scheme == TPM_ALG_RSAES)
{
kvtValue = &c_RsaesKvt;
testLabel = NULL;
@ -510,8 +510,8 @@ TestRsaSignAndVerify(
// Clear the bits indicating that the function has not been checked. This is to
// prevent looping
CLEAR_BOTH(scheme);
CLEAR_BOTH(ALG_NULL_VALUE);
CLEAR_BOTH(ALG_RSA_VALUE);
CLEAR_BOTH(TPM_ALG_NULL);
CLEAR_BOTH(TPM_ALG_RSA);
RsaKeyInitialize(&testObject);
memcpy(testDigest.t.buffer, (BYTE *)c_RsaTestValue, DEFAULT_TEST_DIGEST_SIZE);
testDigest.t.size = DEFAULT_TEST_DIGEST_SIZE;
@ -534,7 +534,7 @@ TestRsaSignAndVerify(
SELF_TEST_FAILURE;
}
// For RSASSA, make sure the results is what we are looking for
if(testSig.sigAlg == ALG_RSASSA_VALUE)
if(testSig.sigAlg == TPM_ALG_RSASSA)
{
if(testSig.signature.rsassa.sig.t.size != RSA_TEST_KEY_SIZE
|| !MemoryEqual(c_RsassaKvt.buffer,
@ -550,7 +550,7 @@ TestRsaSignAndVerify(
}
// If this is RSAPSS, check the verification with known signature
// Have to copy because CrytpRsaValidateSignature() eats the signature
if(ALG_RSAPSS_VALUE == scheme)
if(TPM_ALG_RSAPSS == scheme)
{
MemoryCopy2B(&testSig.signature.rsapss.sig.b, (P2B)&c_RsapssKvt,
sizeof(testSig.signature.rsapss.sig.t.buffer));
@ -574,29 +574,29 @@ TestRsa(
//
switch(alg)
{
case ALG_NULL_VALUE:
case TPM_ALG_NULL:
// This is the RSAEP/RSADP function. If we are processing a list, don't
// need to test these now because any other test will validate
// RSAEP/RSADP. Can tell this is list of test by checking to see if
// 'toTest' is pointing at g_toTest. If so, this is an isolated test
// an need to go ahead and do the test;
if((toTest == &g_toTest)
|| (!TEST_BIT(ALG_RSASSA_VALUE, *toTest)
&& !TEST_BIT(ALG_RSAES_VALUE, *toTest)
&& !TEST_BIT(ALG_RSAPSS_VALUE, *toTest)
&& !TEST_BIT(ALG_OAEP_VALUE, *toTest)))
|| (!TEST_BIT(TPM_ALG_RSASSA, *toTest)
&& !TEST_BIT(TPM_ALG_RSAES, *toTest)
&& !TEST_BIT(TPM_ALG_RSAPSS, *toTest)
&& !TEST_BIT(TPM_ALG_OAEP, *toTest)))
// Not running a list of tests or no other tests on the list
// so run the test now
result = TestRsaEncryptDecrypt(alg, toTest);
// if not running the test now, leave the bit on, just in case things
// get interrupted
break;
case ALG_OAEP_VALUE:
case ALG_RSAES_VALUE:
case TPM_ALG_OAEP:
case TPM_ALG_RSAES:
result = TestRsaEncryptDecrypt(alg, toTest);
break;
case ALG_RSAPSS_VALUE:
case ALG_RSASSA_VALUE:
case TPM_ALG_RSAPSS:
case TPM_ALG_RSASSA:
result = TestRsaSignAndVerify(alg, toTest);
break;
default:
@ -642,7 +642,7 @@ TestECDH(
TPM_RC result = TPM_RC_SUCCESS;
//
NOT_REFERENCED(scheme);
CLEAR_BOTH(ALG_ECDH_VALUE);
CLEAR_BOTH(TPM_ALG_ECDH);
LoadEccParameter(&ds, &c_ecTestKey_ds);
LoadEccPoint(&Qe, &c_ecTestKey_QeX, &c_ecTestKey_QeY);
if(TPM_RC_SUCCESS != CryptEccPointMultiply(&Z, c_testCurve, &Qe, &ds,
@ -670,21 +670,21 @@ TestEccSignAndVerify(
eccScheme.scheme = scheme;
eccScheme.details.anySig.hashAlg = DEFAULT_TEST_HASH;
CLEAR_BOTH(scheme);
CLEAR_BOTH(ALG_ECDH_VALUE);
CLEAR_BOTH(TPM_ALG_ECDH);
// ECC signature verification testing uses a KVT.
switch(scheme)
{
case ALG_ECDSA_VALUE:
case TPM_ALG_ECDSA:
LoadEccParameter(&testSig.signature.ecdsa.signatureR, &c_TestEcDsa_r);
LoadEccParameter(&testSig.signature.ecdsa.signatureS, &c_TestEcDsa_s);
break;
case ALG_ECSCHNORR_VALUE:
case TPM_ALG_ECSCHNORR:
LoadEccParameter(&testSig.signature.ecschnorr.signatureR,
&c_TestEcSchnorr_r);
LoadEccParameter(&testSig.signature.ecschnorr.signatureS,
&c_TestEcSchnorr_s);
break;
case ALG_SM2_VALUE:
case TPM_ALG_SM2:
// don't have a test for SM2
return TPM_RC_SUCCESS;
default:
@ -730,7 +730,7 @@ TestKDFa(
static TPM2B_KDF_TEST_KEY keyOut;
UINT32 counter = 0;
//
CLEAR_BOTH(ALG_KDF1_SP800_108_VALUE);
CLEAR_BOTH(TPM_ALG_KDF1_SP800_108);
keyOut.t.size = CryptKDFa(KDF_TEST_ALG, &c_kdfTestKeyIn.b, &c_kdfTestLabel.b,
&c_kdfTestContextU.b, &c_kdfTestContextV.b,
TEST_KDF_KEY_SIZE * 8, keyOut.t.buffer,
@ -752,23 +752,23 @@ TestEcc(
NOT_REFERENCED(toTest);
switch(alg)
{
case ALG_ECC_VALUE:
case ALG_ECDH_VALUE:
case TPM_ALG_ECC:
case TPM_ALG_ECDH:
// If this is in a loop then see if another test is going to deal with
// this.
// If toTest is not a self-test list
if((toTest == &g_toTest)
// or this is the only ECC test in the list
|| !(TEST_BIT(ALG_ECDSA_VALUE, *toTest)
|| TEST_BIT(ALG_ECSCHNORR, *toTest)
|| TEST_BIT(ALG_SM2_VALUE, *toTest)))
|| !(TEST_BIT(TPM_ALG_ECDSA, *toTest)
|| TEST_BIT(TPM_ALG_ECSCHNORR, *toTest)
|| TEST_BIT(TPM_ALG_SM2, *toTest)))
{
result = TestECDH(alg, toTest);
}
break;
case ALG_ECDSA_VALUE:
case ALG_ECSCHNORR_VALUE:
case ALG_SM2_VALUE:
case TPM_ALG_ECDSA:
case TPM_ALG_ECSCHNORR:
case TPM_ALG_SM2:
result = TestEccSignAndVerify(alg, toTest);
break;
default:
@ -797,9 +797,9 @@ TestAlgorithm(
ALGORITHM_VECTOR *toTest
)
{
TPM_ALG_ID first = (alg == ALG_ERROR_VALUE) ? ALG_FIRST_VALUE : alg;
TPM_ALG_ID last = (alg == ALG_ERROR_VALUE) ? ALG_LAST_VALUE : alg;
BOOL doTest = (alg != ALG_ERROR_VALUE);
TPM_ALG_ID first = (alg == TPM_ALG_ERROR) ? TPM_ALG_FIRST : alg;
TPM_ALG_ID last = (alg == TPM_ALG_ERROR) ? TPM_ALG_LAST : alg;
BOOL doTest = (alg != TPM_ALG_ERROR);
TPM_RC result = TPM_RC_SUCCESS;
if(toTest == NULL)
toTest = &g_toTest;
@ -831,7 +831,7 @@ TestAlgorithm(
{
// Symmetric block ciphers
#if ALG_AES
case ALG_AES_VALUE:
case TPM_ALG_AES:
// libtpms added begin
#if SMAC_IMPLEMENTED && ALG_CMAC
if (doTest) {
@ -845,33 +845,33 @@ TestAlgorithm(
#if ALG_SM4
// if SM4 is implemented, its test is like other block ciphers but there
// aren't any test vectors for it yet
// case ALG_SM4_VALUE:
// case TPM_ALG_SM4:
#endif
#if ALG_CAMELLIA
case ALG_CAMELLIA_VALUE: // libtpms activated
case TPM_ALG_CAMELLIA: // libtpms activated
#endif
#if ALG_TDES
case ALG_TDES_VALUE: // libtpms added
case TPM_ALG_TDES: // libtpms added
#endif
// Symmetric modes
#if !ALG_CFB
# error CFB is required in all TPM implementations
#endif // !TPM_ALG_CFB
case ALG_CFB_VALUE:
case TPM_ALG_CFB:
if(doTest)
result = TestSymmetric(alg, toTest);
break;
#if ALG_CTR
case ALG_CTR_VALUE:
case TPM_ALG_CTR:
#endif // TPM_ALG_CRT
#if ALG_OFB
case ALG_OFB_VALUE:
case TPM_ALG_OFB:
#endif // TPM_ALG_OFB
#if ALG_CBC
case ALG_CBC_VALUE:
case TPM_ALG_CBC:
#endif // TPM_ALG_CBC
#if ALG_ECB
case ALG_ECB_VALUE:
case TPM_ALG_ECB:
#endif
if(doTest)
result = TestSymmetric(alg, toTest);
@ -885,7 +885,7 @@ TestAlgorithm(
#if !ALG_HMAC
# error HMAC is required in all TPM implementations
#endif
case ALG_HMAC_VALUE:
case TPM_ALG_HMAC:
// Clear the bit that indicates that HMAC is required because
// HMAC is used as the basic test for all hash algorithms.
CLEAR_BOTH(alg);
@ -908,50 +908,50 @@ TestAlgorithm(
break;
// RSA-dependent
#if ALG_RSA
case ALG_RSA_VALUE:
case TPM_ALG_RSA:
CLEAR_BOTH(alg);
if(doTest)
result = TestRsa(ALG_NULL_VALUE, toTest);
result = TestRsa(TPM_ALG_NULL, toTest);
else
SET_BOTH(ALG_NULL_VALUE);
SET_BOTH(TPM_ALG_NULL);
break;
case ALG_RSASSA_VALUE:
case ALG_RSAES_VALUE:
case ALG_RSAPSS_VALUE:
case ALG_OAEP_VALUE:
case ALG_NULL_VALUE: // used or RSADP
case TPM_ALG_RSASSA:
case TPM_ALG_RSAES:
case TPM_ALG_RSAPSS:
case TPM_ALG_OAEP:
case TPM_ALG_NULL: // used or RSADP
if(doTest)
result = TestRsa(alg, toTest);
break;
#endif // ALG_RSA_VALUE
#endif // ALG_RSA
#if ALG_KDF1_SP800_108
case ALG_KDF1_SP800_108_VALUE:
case TPM_ALG_KDF1_SP800_108:
if(doTest)
result = TestKDFa(toTest);
break;
#endif // ALG_KDF1_SP800_108_VALUE
#endif // ALG_KDF1_SP800_108
#if ALG_ECC
// ECC dependent but no tests
// case ALG_ECDAA_VALUE:
// case ALG_ECMQV_VALUE:
// case ALG_KDF1_SP800_56a_VALUE:
// case ALG_KDF2_VALUE:
// case ALG_MGF1_VALUE:
case ALG_ECC_VALUE:
// case TPM_ALG_ECDAA:
// case TPM_ALG_ECMQV:
// case TPM_ALG_KDF1_SP800_56a:
// case TPM_ALG_KDF2:
// case TPM_ALG_MGF1:
case TPM_ALG_ECC:
CLEAR_BOTH(alg);
if(doTest)
result = TestEcc(ALG_ECDH_VALUE, toTest);
result = TestEcc(TPM_ALG_ECDH, toTest);
else
SET_BOTH(ALG_ECDH_VALUE);
SET_BOTH(TPM_ALG_ECDH);
break;
case ALG_ECDSA_VALUE:
case ALG_ECDH_VALUE:
case ALG_ECSCHNORR_VALUE:
// case ALG_SM2_VALUE:
case TPM_ALG_ECDSA:
case TPM_ALG_ECDH:
case TPM_ALG_ECSCHNORR:
// case TPM_ALG_SM2:
if(doTest)
result = TestEcc(alg, toTest);
break;
#endif // ALG_ECC_VALUE
#endif // ALG_ECC
default:
CLEAR_BIT(alg, *toTest);
break;

View File

@ -3,7 +3,7 @@
/* Context Management */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: ContextCommands.c 1490 2019-07-26 21:13:22Z kgoldman $ */
/* $Id: ContextCommands.c 1658 2021-01-22 23:14:01Z kgoldman $ */
/* */
/* Licenses and Notices */
/* */
@ -55,7 +55,7 @@
/* arising in any way out of use or reliance upon this specification or any */
/* information herein. */
/* */
/* (c) Copyright IBM Corp. and others, 2016 - 2018 */
/* (c) Copyright IBM Corp. and others, 2016 - 2021 */
/* */
/********************************************************************************/
@ -209,7 +209,7 @@ TPM2_ContextSave(
// Encrypt context blob
CryptSymmetricEncrypt(out->context.contextBlob.t.buffer + integritySize,
CONTEXT_ENCRYPT_ALG, CONTEXT_ENCRYPT_KEY_BITS,
symKey.t.buffer, &iv, ALG_CFB_VALUE,
symKey.t.buffer, &iv, TPM_ALG_CFB,
out->context.contextBlob.t.size - integritySize,
out->context.contextBlob.t.buffer + integritySize);
// Compute integrity hash for the object
@ -278,7 +278,7 @@ TPM2_ContextLoad(
ComputeContextProtectionKey(&in->context, &symKey, &iv);
// Decrypt context data in place
CryptSymmetricDecrypt(buffer, CONTEXT_ENCRYPT_ALG, CONTEXT_ENCRYPT_KEY_BITS,
symKey.t.buffer, &iv, ALG_CFB_VALUE, size, buffer);
symKey.t.buffer, &iv, TPM_ALG_CFB, size, buffer);
// See if the fingerprint value matches. If not, it is symptomatic of either
// a broken TPM or that the TPM is under attack so go into failure mode.
if(!MemoryEqual(buffer, &in->context.sequence, sizeof(in->context.sequence)))

View File

@ -3,7 +3,7 @@
/* ECC curve data */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: CryptEccData.c 1519 2019-11-15 20:43:51Z kgoldman $ */
/* $Id: CryptEccData.c 1658 2021-01-22 23:14:01Z kgoldman $ */
/* */
/* Licenses and Notices */
/* */
@ -55,7 +55,7 @@
/* arising in any way out of use or reliance upon this specification or any */
/* information herein. */
/* */
/* (c) Copyright IBM Corp. and others, 2018 - 2019 */
/* (c) Copyright IBM Corp. and others, 2018 - 2021 */
/* */
/********************************************************************************/
@ -522,8 +522,8 @@ const ECC_CURVE eccCurves[] = {
comma
{TPM_ECC_NIST_P192,
192,
{ALG_KDF1_SP800_56A_VALUE, {{ALG_SHA256_VALUE}}},
{ALG_NULL_VALUE, {{ALG_NULL_VALUE}}},
{TPM_ALG_KDF1_SP800_56A, {{TPM_ALG_SHA256}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
&NIST_P192,
OID_ECC_NIST_P192
CURVE_NAME("NIST_P192")}
@ -534,8 +534,8 @@ const ECC_CURVE eccCurves[] = {
comma
{TPM_ECC_NIST_P224,
224,
{ALG_KDF1_SP800_56A_VALUE, {{ALG_SHA256_VALUE}}},
{ALG_NULL_VALUE, {{ALG_NULL_VALUE}}},
{TPM_ALG_KDF1_SP800_56A, {{TPM_ALG_SHA256}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
&NIST_P224,
OID_ECC_NIST_P224
CURVE_NAME("NIST_P224")}
@ -546,8 +546,8 @@ const ECC_CURVE eccCurves[] = {
comma
{TPM_ECC_NIST_P256,
256,
{ALG_KDF1_SP800_56A_VALUE, {{ALG_SHA256_VALUE}}},
{ALG_NULL_VALUE, {{ALG_NULL_VALUE}}},
{TPM_ALG_KDF1_SP800_56A, {{TPM_ALG_SHA256}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
&NIST_P256,
OID_ECC_NIST_P256
CURVE_NAME("NIST_P256")}
@ -558,8 +558,8 @@ const ECC_CURVE eccCurves[] = {
comma
{TPM_ECC_NIST_P384,
384,
{ALG_KDF1_SP800_56A_VALUE, {{ALG_SHA384_VALUE}}},
{ALG_NULL_VALUE, {{ALG_NULL_VALUE}}},
{TPM_ALG_KDF1_SP800_56A, {{TPM_ALG_SHA384}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
&NIST_P384,
OID_ECC_NIST_P384
CURVE_NAME("NIST_P384")}
@ -570,8 +570,8 @@ const ECC_CURVE eccCurves[] = {
comma
{TPM_ECC_NIST_P521,
521,
{ALG_KDF1_SP800_56A_VALUE, {{ALG_SHA512_VALUE}}},
{ALG_NULL_VALUE, {{ALG_NULL_VALUE}}},
{TPM_ALG_KDF1_SP800_56A, {{TPM_ALG_SHA512}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
&NIST_P521,
OID_ECC_NIST_P521
CURVE_NAME("NIST_P521")}
@ -582,8 +582,8 @@ const ECC_CURVE eccCurves[] = {
comma
{TPM_ECC_BN_P256,
256,
{ALG_NULL_VALUE, {{ALG_NULL_VALUE}}},
{ALG_NULL_VALUE, {{ALG_NULL_VALUE}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
&BN_P256,
OID_ECC_BN_P256
CURVE_NAME("BN_P256")}
@ -594,8 +594,8 @@ const ECC_CURVE eccCurves[] = {
comma
{TPM_ECC_BN_P638,
638,
{ALG_NULL_VALUE, {{ALG_NULL_VALUE}}},
{ALG_NULL_VALUE, {{ALG_NULL_VALUE}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
&BN_P638,
OID_ECC_BN_P638
CURVE_NAME("BN_P638")}
@ -606,8 +606,8 @@ const ECC_CURVE eccCurves[] = {
comma
{TPM_ECC_SM2_P256,
256,
{ALG_KDF1_SP800_56A_VALUE, {{ALG_SM3_256_VALUE}}},
{ALG_NULL_VALUE, {{ALG_NULL_VALUE}}},
{TPM_ALG_KDF1_SP800_56A, {{TPM_ALG_SM3_256}}},
{TPM_ALG_NULL, {{TPM_ALG_NULL}}},
&SM2_P256,
OID_ECC_SM2_P256
CURVE_NAME("SM2_P256")}

View File

@ -3,7 +3,7 @@
/* Interfaces to the Crypto Engine */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: CryptUtil.c 1519 2019-11-15 20:43:51Z kgoldman $ */
/* $Id: CryptUtil.c 1658 2021-01-22 23:14:01Z kgoldman $ */
/* */
/* Licenses and Notices */
/* */
@ -55,7 +55,7 @@
/* arising in any way out of use or reliance upon this specification or any */
/* information herein. */
/* */
/* (c) Copyright IBM Corp. and others, 2016 - 2019 */
/* (c) Copyright IBM Corp. and others, 2016 - 2021 */
/* */
/********************************************************************************/
@ -200,7 +200,7 @@ CryptIsSchemeAnonymous(
TPM_ALG_ID scheme // IN: the scheme algorithm to test
)
{
return scheme == ALG_ECDAA_VALUE;
return scheme == TPM_ALG_ECDAA;
}
/* 10.2.6.4 Symmetric Functions */
/* 10.2.6.4.1 ParmDecryptSym() */

View File

@ -3,7 +3,7 @@
/* Encrypt Decrypt Support */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: EncryptDecrypt_spt.c 1264 2018-07-12 14:21:07Z kgoldman $ */
/* $Id: EncryptDecrypt_spt.c 1658 2021-01-22 23:14:01Z kgoldman $ */
/* */
/* Licenses and Notices */
/* */
@ -55,7 +55,7 @@
/* arising in any way out of use or reliance upon this specification or any */
/* information herein. */
/* */
/* (c) Copyright IBM Corp. and others, 2016 - 2018 */
/* (c) Copyright IBM Corp. and others, 2016 - 2021 */
/* */
/********************************************************************************/
@ -130,12 +130,12 @@ EncryptDecryptShared(
// reverify the algorithm. This is mainly to keep static analysis tools happy
if(blockSize == 0)
return TPM_RCS_KEY + RC_EncryptDecrypt_keyHandle;
if(((mode == ALG_ECB_VALUE) && (ivIn->t.size != 0))
|| ((mode != ALG_ECB_VALUE) && (ivIn->t.size != blockSize)))
if(((mode == TPM_ALG_ECB) && (ivIn->t.size != 0))
|| ((mode != TPM_ALG_ECB) && (ivIn->t.size != blockSize)))
return TPM_RCS_SIZE + RC_EncryptDecrypt_ivIn;
// The input data size of CBC mode or ECB mode must be an even multiple of
// the symmetric algorithm's block size
if(((mode == ALG_CBC_VALUE) || (mode == ALG_ECB_VALUE))
if(((mode == TPM_ALG_CBC) || (mode == TPM_ALG_ECB))
&& ((inData->t.size % blockSize) != 0))
return TPM_RCS_SIZE + RC_EncryptDecrypt_inData;
// Copy IV

View File

@ -3,7 +3,7 @@
/* Object Commands */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: ObjectCommands.c 1594 2020-03-26 22:15:48Z kgoldman $ */
/* $Id: ObjectCommands.c 1658 2021-01-22 23:14:01Z kgoldman $ */
/* */
/* Licenses and Notices */
/* */
@ -55,7 +55,7 @@
/* arising in any way out of use or reliance upon this specification or any */
/* information herein. */
/* */
/* (c) Copyright IBM Corp. and others, 2016 - 2020 */
/* (c) Copyright IBM Corp. and others, 2016 - 2021 */
/* */
/********************************************************************************/
@ -462,7 +462,7 @@ TPM2_CreateLoaded(
pAssert(scheme->details.xorr.hashAlg != TPM_ALG_NULL
&& scheme->details.xorr.kdf == TPM_ALG_KDF1_SP800_108);
// Don't derive RSA keys
if(publicArea->type == ALG_RSA_VALUE)
if(publicArea->type == TPM_ALG_RSA)
return TPM_RCS_TYPE + RC_CreateLoaded_inPublic;
// sensitiveDataOrigin has to be CLEAR in a derived object. Since this
// is specific to a derived object, it is checked here.

View File

@ -3,7 +3,7 @@
/* Symmetric Commands */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: SymmetricCommands.c 1594 2020-03-26 22:15:48Z kgoldman $ */
/* $Id: SymmetricCommands.c 1658 2021-01-22 23:14:01Z kgoldman $ */
/* */
/* Licenses and Notices */
/* */
@ -55,7 +55,7 @@
/* arising in any way out of use or reliance upon this specification or any */
/* information herein. */
/* */
/* (c) Copyright IBM Corp. and others, 2016 - 2018 */
/* (c) Copyright IBM Corp. and others, 2016 - 2021 */
/* */
/********************************************************************************/
@ -130,12 +130,12 @@ TPM2_EncryptDecrypt(
// If it was not supported the unmarshaling code would have rejected it before
// this function were called. This means that, depending on the implementation,
// the check could be redundant but it doesn't hurt.
if(((mode == ALG_ECB_VALUE) && (in->ivIn.t.size != 0))
|| ((mode != ALG_ECB_VALUE) && (in->ivIn.t.size != blockSize)))
if(((mode == TPM_ALG_ECB) && (in->ivIn.t.size != 0))
|| ((mode != TPM_ALG_ECB) && (in->ivIn.t.size != blockSize)))
return TPM_RCS_SIZE + RC_EncryptDecrypt_ivIn;
// The input data size of CBC mode or ECB mode must be an even multiple of
// the symmetric algorithm's block size
if(((mode == ALG_CBC_VALUE) || (mode == ALG_ECB_VALUE))
if(((mode == TPM_ALG_CBC) || (mode == TPM_ALG_ECB))
&& ((in->inData.t.size % blockSize) != 0))
return TPM_RCS_SIZE + RC_EncryptDecrypt_inData;
// Copy IV

View File

@ -3,7 +3,7 @@
/* Structures and data definitions for the symmetric tests */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: SymmetricTest.h 1519 2019-11-15 20:43:51Z kgoldman $ */
/* $Id: SymmetricTest.h 1658 2021-01-22 23:14:01Z kgoldman $ */
/* */
/* Licenses and Notices */
/* */
@ -55,7 +55,7 @@
/* arising in any way out of use or reliance upon this specification or any */
/* information herein. */
/* */
/* (c) Copyright IBM Corp. and others, 2016 - 2019 */
/* (c) Copyright IBM Corp. and others, 2016 - 2021 */
/* */
/********************************************************************************/
@ -79,54 +79,54 @@
const SYMMETRIC_TEST_VECTOR c_symTestValues[NUM_SYMS + 1] = {
#if ALG_AES && AES_128
{ALG_AES_VALUE, 128, key_AES128, 16, sizeof(dataIn_AES128), dataIn_AES128,
{TPM_ALG_AES, 128, key_AES128, 16, sizeof(dataIn_AES128), dataIn_AES128,
{dataOut_AES128_CTR, dataOut_AES128_OFB, dataOut_AES128_CBC,
dataOut_AES128_CFB, dataOut_AES128_ECB}},
#endif
#if ALG_AES && AES_192
{ALG_AES_VALUE, 192, key_AES192, 16, sizeof(dataIn_AES192), dataIn_AES192,
{TPM_ALG_AES_, 192, key_AES192, 16, sizeof(dataIn_AES192), dataIn_AES192,
{dataOut_AES192_CTR, dataOut_AES192_OFB, dataOut_AES192_CBC,
dataOut_AES192_CFB, dataOut_AES192_ECB}},
#endif
#if ALG_AES && AES_256
{ALG_AES_VALUE, 256, key_AES256, 16, sizeof(dataIn_AES256), dataIn_AES256,
{TPM_ALG_AES, 256, key_AES256, 16, sizeof(dataIn_AES256), dataIn_AES256,
{dataOut_AES256_CTR, dataOut_AES256_OFB, dataOut_AES256_CBC,
dataOut_AES256_CFB, dataOut_AES256_ECB}},
#endif
#if ALG_SM4 && SM4_128 // libtpms activated
{ALG_SM4_VALUE, 128, key_SM4128, 16, sizeof(dataIn_SM4128), dataIn_SM4128,
{TPM_ALG_SM4, 128, key_SM4128, 16, sizeof(dataIn_SM4128), dataIn_SM4128,
{dataOut_SM4128_CTR, dataOut_SM4128_OFB, dataOut_SM4128_CBC,
dataOut_SM4128_CFB, dataOut_AES128_ECB}},
#endif
// libtpms added begin
#if ALG_TDES && TDES_128
{ALG_TDES_VALUE, 128, key_TDES128, 8, sizeof(dataIn_TDES128), dataIn_TDES128,
{TPM_ALG_TDES, 128, key_TDES128, 8, sizeof(dataIn_TDES128), dataIn_TDES128,
{dataOut_TDES128_CTR, dataOut_TDES128_OFB, dataOut_TDES128_CBC,
dataOut_TDES128_CFB, dataOut_TDES128_ECB}},
{ALG_TDES_VALUE, 128, key_TDES128, 8, sizeof(dataInShort_TDES128), dataInShort_TDES128,
{TPM_ALG_TDES, 128, key_TDES128, 8, sizeof(dataInShort_TDES128), dataInShort_TDES128,
{NULL, dataOutShort_TDES128_OFB, NULL,
dataOutShort_TDES128_CFB, NULL}},
#endif
#if ALG_TDES && TDES_192
{ALG_TDES_VALUE, 192, key_TDES192, 8, sizeof(dataIn_TDES192), dataIn_TDES192,
{TPM_ALG_TDES, 192, key_TDES192, 8, sizeof(dataIn_TDES192), dataIn_TDES192,
{dataOut_TDES192_CTR, dataOut_TDES192_OFB, dataOut_TDES192_CBC,
dataOut_TDES192_CFB, dataOut_TDES192_ECB}},
{ALG_TDES_VALUE, 192, key_TDES192, 8, sizeof(dataInShort_TDES192), dataInShort_TDES192,
{TPM_ALG_TDES, 192, key_TDES192, 8, sizeof(dataInShort_TDES192), dataInShort_TDES192,
{NULL, dataOutShort_TDES192_OFB, NULL,
dataOutShort_TDES192_CFB, NULL}},
#endif
#if ALG_CAMELLIA && CAMELLIA_128
{ALG_CAMELLIA_VALUE, 128, key_CAMELLIA128, 16, sizeof(dataIn_CAMELLIA128), dataIn_CAMELLIA128,
{TPM_ALG_CAMELLIA, 128, key_CAMELLIA128, 16, sizeof(dataIn_CAMELLIA128), dataIn_CAMELLIA128,
{dataOut_CAMELLIA128_CTR, dataOut_CAMELLIA128_OFB, dataOut_CAMELLIA128_CBC,
dataOut_CAMELLIA128_CFB, dataOut_CAMELLIA128_ECB}},
#endif
#if ALG_CAMELLIA && CAMELLIA_192
{ALG_CAMELLIA_VALUE, 192, key_CAMELLIA192, 16, sizeof(dataIn_CAMELLIA192), dataIn_CAMELLIA192,
{TPM_ALG_CAMELLIA, 192, key_CAMELLIA192, 16, sizeof(dataIn_CAMELLIA192), dataIn_CAMELLIA192,
{dataOut_CAMELLIA192_CTR, dataOut_CAMELLIA192_OFB, dataOut_CAMELLIA192_CBC,
dataOut_CAMELLIA192_CFB, dataOut_CAMELLIA192_ECB}},
#endif
#if ALG_CAMELLIA && CAMELLIA_256
{ALG_CAMELLIA_VALUE, 256, key_CAMELLIA256, 16, sizeof(dataIn_CAMELLIA256), dataIn_CAMELLIA256,
{TPM_ALG_CAMELLIA, 256, key_CAMELLIA256, 16, sizeof(dataIn_CAMELLIA256), dataIn_CAMELLIA256,
{dataOut_CAMELLIA256_CTR, dataOut_CAMELLIA256_OFB, dataOut_CAMELLIA256_CBC,
dataOut_CAMELLIA256_CFB, dataOut_CAMELLIA256_ECB}},
#endif

View File

@ -3,7 +3,7 @@
/* TPM X509 ECC */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: X509_ECC.c 1594 2020-03-26 22:15:48Z kgoldman $ */
/* $Id: X509_ECC.c 1658 2021-01-22 23:14:01Z kgoldman $ */
/* */
/* Licenses and Notices */
/* */
@ -55,7 +55,7 @@
/* arising in any way out of use or reliance upon this specification or any */
/* information herein. */
/* */
/* (c) Copyright IBM Corp. and others, 2019 - 2020 */
/* (c) Copyright IBM Corp. and others, 2019 - 2021 */
/* */
/********************************************************************************/
@ -112,7 +112,8 @@ X509AddSigningAlgorithmECC(
switch(scheme->scheme)
{
case ALG_ECDSA_VALUE:
#if ALG_ECDSA
case TPM_ALG_ECDSA:
// Make sure that we have an OID for this hash and ECC
if((hashDef->ECDSA)[0] != ASN1_OBJECT_IDENTIFIER)
break;
@ -123,6 +124,7 @@ X509AddSigningAlgorithmECC(
ASN1StartMarshalContext(ctx);
ASN1PushOID(ctx, hashDef->ECDSA);
return ASN1EndEncapsulation(ctx, ASN1_CONSTRUCTED_SEQUENCE);
#endif // ALG_ECDSA
default:
break;
}

View File

@ -3,7 +3,7 @@
/* TPM X509 RSA */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: X509_RSA.c 1594 2020-03-26 22:15:48Z kgoldman $ */
/* $Id: X509_RSA.c 1658 2021-01-22 23:14:01Z kgoldman $ */
/* */
/* Licenses and Notices */
/* */
@ -55,7 +55,7 @@
/* arising in any way out of use or reliance upon this specification or any */
/* information herein. */
/* */
/* (c) Copyright IBM Corp. and others, 2019 - 2020 */
/* (c) Copyright IBM Corp. and others, 2019 - 2021 */
/* */
/********************************************************************************/
@ -92,7 +92,7 @@ X509AddSigningAlgorithmRSA(
return 0;
switch(scheme->scheme)
{
case ALG_RSASSA_VALUE:
case TPM_ALG_RSASSA:
{
// if the hash is implemented but there is no PKCS1 OID defined
// then this is not a valid signing combination.
@ -102,14 +102,14 @@ X509AddSigningAlgorithmRSA(
return 1;
return X509PushAlgorithmIdentifierSequence(ctx, hashDef->PKCS1);
}
case ALG_RSAPSS_VALUE:
case TPM_ALG_RSAPSS:
// leave if this is just an implementation check
if(ctx == NULL)
return 1;
// In the case of SHA1, everything is default and RFC4055 says that
// implementations that do signature generation MUST omit the parameter
// when defaults are used. )-:
if(hashDef->hashAlg == ALG_SHA1_VALUE)
if(hashDef->hashAlg == TPM_ALG_SHA1)
{
return X509PushAlgorithmIdentifierSequence(ctx, OID_RSAPSS);
}

View File

@ -3,7 +3,7 @@
/* X509 Support */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: X509_spt.c 1594 2020-03-26 22:15:48Z kgoldman $ */
/* $Id: X509_spt.c 1658 2021-01-22 23:14:01Z kgoldman $ */
/* */
/* Licenses and Notices */
/* */
@ -55,7 +55,7 @@
/* arising in any way out of use or reliance upon this specification or any */
/* information herein. */
/* */
/* (c) Copyright IBM Corp. and others, 2019 - 2020 */
/* (c) Copyright IBM Corp. and others, 2019 - 2021 */
/* */
/********************************************************************************/
@ -283,15 +283,15 @@ X509AddPublicKey(
switch(object->publicArea.type)
{
#if ALG_RSA
case ALG_RSA_VALUE:
case TPM_ALG_RSA:
return X509AddPublicRSA(object, ctx);
#endif
#if ALG_ECC
case ALG_ECC_VALUE:
case TPM_ALG_ECC:
return X509AddPublicECC(object, ctx);
#endif
#if ALG_SM2
case ALG_SM2_VALUE:
case TPM_ALG_SM2:
break;
#endif
default:

View File

@ -3,7 +3,7 @@
/* Functions that are used for the two-phase, ECC, key-exchange protocols */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: CryptEccKeyExchange.c 1594 2020-03-26 22:15:48Z kgoldman $ */
/* $Id: CryptEccKeyExchange.c 1658 2021-01-22 23:14:01Z kgoldman $ */
/* */
/* Licenses and Notices */
/* */
@ -55,7 +55,7 @@
/* arising in any way out of use or reliance upon this specification or any */
/* information herein. */
/* */
/* (c) Copyright IBM Corp. and others, 2016 - 2018 */
/* (c) Copyright IBM Corp. and others, 2016 - 2021 */
/* */
/********************************************************************************/
@ -249,16 +249,16 @@ CryptEcc2PhaseKeyExchange(
}
switch(scheme)
{
case ALG_ECDH_VALUE:
case TPM_ALG_ECDH:
return C_2_2_ECDH(outZ1, outZ2, curveId, dsA, deA, QsB, QeB);
break;
#if ALG_ECMQV
case ALG_ECMQV_VALUE:
case TPM_ALG_ECMQV:
return C_2_2_MQV(outZ1, curveId, dsA, deA, QsB, QeB);
break;
#endif
#if ALG_SM2
case ALG_SM2_VALUE:
case TPM_ALG_SM2:
return SM2KeyExchange(outZ1, curveId, dsA, deA, QsB, QeB);
break;
#endif

View File

@ -3,7 +3,7 @@
/* ECC Signatures */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: CryptEccSignature.c 1370 2018-11-02 19:39:07Z kgoldman $ */
/* $Id: CryptEccSignature.c 1658 2021-01-22 23:14:01Z kgoldman $ */
/* */
/* Licenses and Notices */
/* */
@ -55,7 +55,7 @@
/* arising in any way out of use or reliance upon this specification or any */
/* information herein. */
/* */
/* (c) Copyright IBM Corp. and others, 2016 - 2018 */
/* (c) Copyright IBM Corp. and others, 2016 - 2021 */
/* */
/********************************************************************************/
@ -608,25 +608,25 @@ CryptEccSign(
TEST(signature->sigAlg);
switch(signature->sigAlg)
{
case ALG_ECDSA_VALUE:
case TPM_ALG_ECDSA:
retVal = BnSignEcdsa(bnR, bnS, E, bnD, digest, rand);
break;
#if ALG_ECDAA
case ALG_ECDAA_VALUE:
case TPM_ALG_ECDAA:
retVal = BnSignEcdaa(&signature->signature.ecdaa.signatureR, bnS, E,
bnD, digest, scheme, signKey, rand);
bnR = NULL;
break;
#endif
#if ALG_ECSCHNORR
case ALG_ECSCHNORR_VALUE:
case TPM_ALG_ECSCHNORR:
retVal = BnSignEcSchnorr(bnR, bnS, E, bnD, digest,
signature->signature.ecschnorr.hash,
rand);
break;
#endif
#if ALG_SM2
case ALG_SM2_VALUE:
case TPM_ALG_SM2:
retVal = BnSignEcSm2(bnR, bnS, E, bnD, digest, rand);
break;
#endif
@ -908,12 +908,12 @@ CryptEccValidateSignature(
// // Make sure that the scheme is valid
switch(signature->sigAlg)
{
case ALG_ECDSA_VALUE:
case TPM_ALG_ECDSA:
#if ALG_ECSCHNORR
case ALG_ECSCHNORR_VALUE:
case TPM_ALG_ECSCHNORR:
#endif
#if ALG_SM2
case ALG_SM2_VALUE:
case TPM_ALG_SM2:
#endif
break;
default:
@ -933,18 +933,18 @@ CryptEccValidateSignature(
ERROR_RETURN(TPM_RC_SIGNATURE);
switch(signature->sigAlg)
{
case ALG_ECDSA_VALUE:
case TPM_ALG_ECDSA:
retVal = BnValidateSignatureEcdsa(bnR, bnS, E, ecQ, digest);
break;
#if ALG_ECSCHNORR
case ALG_ECSCHNORR_VALUE:
case TPM_ALG_ECSCHNORR:
retVal = BnValidateSignatureEcSchnorr(bnR, bnS,
signature->signature.any.hashAlg,
E, ecQ, digest);
break;
#endif
#if ALG_SM2
case ALG_SM2_VALUE:
case TPM_ALG_SM2:
retVal = BnValidateSignatureEcSm2(bnR, bnS, E, ecQ, digest);
break;
#endif

View File

@ -3,7 +3,7 @@
/* Implementation of cryptographic primitives for RSA */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: CryptRsa.c 1594 2020-03-26 22:15:48Z kgoldman $ */
/* $Id: CryptRsa.c 1658 2021-01-22 23:14:01Z kgoldman $ */
/* */
/* Licenses and Notices */
/* */
@ -55,7 +55,7 @@
/* arising in any way out of use or reliance upon this specification or any */
/* information herein. */
/* */
/* (c) Copyright IBM Corp. and others, 2016 - 2020 */
/* (c) Copyright IBM Corp. and others, 2016 - 2021 */
/* */
/********************************************************************************/
@ -880,7 +880,7 @@ CryptRsaLoadPrivateExponent(
TPM_RC retVal = TPM_RC_SUCCESS;
if(!rsaKey->attributes.privateExp)
{
TEST(ALG_NULL_VALUE);
TEST(TPM_ALG_NULL);
// Make sure that the bigNum used for the exponent is properly initialized
RsaInitializeExponent(&rsaKey->privateExponent);
// Find the second prime by division
@ -938,7 +938,7 @@ CryptRsaEncrypt(
TEST(scheme->scheme);
switch(scheme->scheme)
{
case ALG_NULL_VALUE: // 'raw' encryption
case TPM_ALG_NULL: // 'raw' encryption
{
INT32 i;
INT32 dSize = dIn->size;
@ -957,10 +957,10 @@ CryptRsaEncrypt(
// the modulus. If it is, then RSAEP() will catch it.
}
break;
case ALG_RSAES_VALUE:
case TPM_ALG_RSAES:
retVal = RSAES_PKCS1v1_5Encode(&cOut->b, dIn, rand);
break;
case ALG_OAEP_VALUE:
case TPM_ALG_OAEP:
retVal = OaepEncode(&cOut->b, scheme->details.oaep.hashAlg, label, dIn,
rand);
break;
@ -1008,15 +1008,15 @@ CryptRsaDecrypt(
// Remove padding
switch(scheme->scheme)
{
case ALG_NULL_VALUE:
case TPM_ALG_NULL:
if(dOut->size < cIn->size)
return TPM_RC_VALUE;
MemoryCopy2B(dOut, cIn, dOut->size);
break;
case ALG_RSAES_VALUE:
case TPM_ALG_RSAES:
retVal = RSAES_Decode(dOut, cIn);
break;
case ALG_OAEP_VALUE:
case TPM_ALG_OAEP:
retVal = OaepDecode(dOut, scheme->details.oaep.hashAlg, label, cIn);
break;
default:
@ -1051,14 +1051,14 @@ CryptRsaSign(
TEST(sigOut->sigAlg);
switch(sigOut->sigAlg)
{
case ALG_NULL_VALUE:
case TPM_ALG_NULL:
sigOut->signature.rsapss.sig.t.size = 0;
return TPM_RC_SUCCESS;
case ALG_RSAPSS_VALUE:
case TPM_ALG_RSAPSS:
retVal = PssEncode(&sigOut->signature.rsapss.sig.b,
sigOut->signature.rsapss.hash, &hIn->b, rand);
break;
case ALG_RSASSA_VALUE:
case TPM_ALG_RSASSA:
retVal = RSASSA_Encode(&sigOut->signature.rsassa.sig.b,
sigOut->signature.rsassa.hash, &hIn->b);
break;
@ -1092,8 +1092,8 @@ CryptRsaValidateSignature(
pAssert(key != NULL && sig != NULL && digest != NULL);
switch(sig->sigAlg)
{
case ALG_RSAPSS_VALUE:
case ALG_RSASSA_VALUE:
case TPM_ALG_RSAPSS:
case TPM_ALG_RSASSA:
break;
default:
return TPM_RC_SCHEME;
@ -1108,11 +1108,11 @@ CryptRsaValidateSignature(
{
switch(sig->sigAlg)
{
case ALG_RSAPSS_VALUE:
case TPM_ALG_RSAPSS:
retVal = PssDecode(sig->signature.any.hashAlg, &digest->b,
&sig->signature.rsassa.sig.b);
break;
case ALG_RSASSA_VALUE:
case TPM_ALG_RSASSA:
retVal = RSASSA_Decode(sig->signature.any.hashAlg, &digest->b,
&sig->signature.rsassa.sig.b);
break;
@ -1182,7 +1182,7 @@ CryptRsaGenerateKey(
return TPM_RC_SUCCESS;
#endif
// Make sure that key generation has been tested
TEST(ALG_NULL_VALUE);
TEST(TPM_ALG_NULL);
#if USE_OPENSSL_FUNCTIONS_RSA // libtpms added begin
if (rand == NULL)
return OpenSSLCryptRsaGenerateKey(rsaKey, e, keySizeInBits);
@ -1313,7 +1313,7 @@ CryptRsaEncrypt(
switch(scheme->scheme)
{
case ALG_NULL_VALUE: // 'raw' encryption
case TPM_ALG_NULL: // 'raw' encryption
{
INT32 i;
INT32 dSize = dIn->size;
@ -1336,11 +1336,11 @@ CryptRsaEncrypt(
if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_NO_PADDING) <= 0)
ERROR_RETURN(TPM_RC_FAILURE);
break;
case ALG_RSAES_VALUE:
case TPM_ALG_RSAES:
if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0)
ERROR_RETURN(TPM_RC_FAILURE);
break;
case ALG_OAEP_VALUE:
case TPM_ALG_OAEP:
digestname = GetDigestNameByHashAlg(scheme->details.oaep.hashAlg);
if (digestname == NULL)
ERROR_RETURN(TPM_RC_VALUE);
@ -1419,15 +1419,15 @@ CryptRsaDecrypt(
switch(scheme->scheme)
{
case ALG_NULL_VALUE: // 'raw' encryption
case TPM_ALG_NULL: // 'raw' encryption
if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_NO_PADDING) <= 0)
ERROR_RETURN(TPM_RC_FAILURE);
break;
case ALG_RSAES_VALUE:
case TPM_ALG_RSAES:
if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_PADDING) <= 0)
ERROR_RETURN(TPM_RC_FAILURE);
break;
case ALG_OAEP_VALUE:
case TPM_ALG_OAEP:
digestname = GetDigestNameByHashAlg(scheme->details.oaep.hashAlg);
if (digestname == NULL)
ERROR_RETURN(TPM_RC_VALUE);
@ -1504,14 +1504,14 @@ CryptRsaSign(
switch(sigOut->sigAlg)
{
case ALG_NULL_VALUE:
case TPM_ALG_NULL:
sigOut->signature.rsapss.sig.t.size = 0;
return TPM_RC_SUCCESS;
case ALG_RSAPSS_VALUE:
case TPM_ALG_RSAPSS:
padding = RSA_PKCS1_PSS_PADDING;
hashAlg = sigOut->signature.rsapss.hash;
break;
case ALG_RSASSA_VALUE:
case TPM_ALG_RSASSA:
padding = RSA_PKCS1_PADDING;
hashAlg = sigOut->signature.rsassa.hash;
break;
@ -1584,10 +1584,10 @@ CryptRsaValidateSignature(
pAssert(key != NULL && sig != NULL && digest != NULL);
switch(sig->sigAlg)
{
case ALG_RSAPSS_VALUE:
case TPM_ALG_RSAPSS:
padding = RSA_PKCS1_PSS_PADDING;
break;
case ALG_RSASSA_VALUE:
case TPM_ALG_RSASSA:
padding = RSA_PKCS1_PADDING;
break;
default:

View File

@ -3,7 +3,7 @@
/* Message Authentication Codes Based on a Symmetric Block Cipher */
/* Written by Ken Goldman */
/* IBM Thomas J. Watson Research Center */
/* $Id: CryptSmac.c 1490 2019-07-26 21:13:22Z kgoldman $ */
/* $Id: CryptSmac.c 1658 2021-01-22 23:14:01Z kgoldman $ */
/* */
/* Licenses and Notices */
/* */
@ -55,7 +55,7 @@
/* arising in any way out of use or reliance upon this specification or any */
/* information herein. */
/* */
/* (c) Copyright IBM Corp. and others, 2018 */
/* (c) Copyright IBM Corp. and others, 2018 - 2021 */
/* */
/********************************************************************************/
@ -87,7 +87,7 @@ CryptSmacStart(
switch(macAlg)
{
#if ALG_CMAC
case ALG_CMAC_VALUE:
case TPM_ALG_CMAC:
retVal = CryptCmacStart(&state->state.smac, keyParameters,
macAlg, key);
break;

View File

@ -201,7 +201,7 @@ CryptSymmetricEncrypt(
// If the iv is provided, then it is expected to be block sized. In some cases,
// the caller is providing an array of 0's that is equal to [MAX_SYM_BLOCK_SIZE]
// with no knowledge of the actual block size. This function will set it.
if((ivInOut != NULL) && (mode != ALG_ECB_VALUE))
if((ivInOut != NULL) && (mode != TPM_ALG_ECB))
{
ivInOut->t.size = blockSize;
iv = ivInOut->t.buffer;
@ -214,7 +214,7 @@ CryptSymmetricEncrypt(
switch(mode)
{
#if ALG_CTR
case ALG_CTR_VALUE:
case TPM_ALG_CTR:
for(; dSize > 0; dSize -= blockSize)
{
// Encrypt the current value of the IV(counter)
@ -231,7 +231,7 @@ CryptSymmetricEncrypt(
break;
#endif
#if ALG_OFB
case ALG_OFB_VALUE:
case TPM_ALG_OFB:
// This is written so that dIn and dOut may be the same
for(; dSize > 0; dSize -= blockSize)
{
@ -245,7 +245,7 @@ CryptSymmetricEncrypt(
break;
#endif
#if ALG_CBC
case ALG_CBC_VALUE:
case TPM_ALG_CBC:
// For CBC the data size must be an even multiple of the
// cipher block size
if((dSize % blockSize) != 0)
@ -265,7 +265,7 @@ CryptSymmetricEncrypt(
break;
#endif
// CFB is not optional
case ALG_CFB_VALUE:
case TPM_ALG_CFB:
// Encrypt the IV into the IV, XOR in the data, and copy to output
for(; dSize > 0; dSize -= blockSize)
{
@ -285,7 +285,7 @@ CryptSymmetricEncrypt(
*pIv++ = 0;
break;
#if ALG_ECB
case ALG_ECB_VALUE:
case TPM_ALG_ECB:
// For ECB the data size must be an even multiple of the
// cipher block size
if((dSize % blockSize) != 0)
@ -349,7 +349,7 @@ CryptSymmetricDecrypt(
// If the iv is provided, then it is expected to be block sized. In some cases,
// the caller is providing an array of 0's that is equal to [MAX_SYM_BLOCK_SIZE]
// with no knowledge of the actual block size. This function will set it.
if((ivInOut != NULL) && (mode != ALG_ECB_VALUE))
if((ivInOut != NULL) && (mode != TPM_ALG_ECB))
{
ivInOut->t.size = blockSize;
iv = ivInOut->t.buffer;
@ -363,8 +363,8 @@ CryptSymmetricDecrypt(
switch(mode)
{
#if ALG_CBC || ALG_ECB
case ALG_CBC_VALUE: // decrypt = decrypt
case ALG_ECB_VALUE:
case TPM_ALG_CBC: // decrypt = decrypt
case TPM_ALG_ECB:
// For ECB and CBC, the data size must be an even multiple of the
// cipher block size
if((dSize % blockSize) != 0)
@ -381,7 +381,7 @@ CryptSymmetricDecrypt(
switch(mode)
{
#if ALG_CBC
case ALG_CBC_VALUE:
case TPM_ALG_CBC:
// Copy the input data to a temp buffer, decrypt the buffer into the
// output, XOR in the IV, and copy the temp buffer to the IV and repeat.
for(; dSize > 0; dSize -= blockSize)
@ -420,7 +420,7 @@ CryptSymmetricDecrypt(
*pIv++ = 0;
break;
#if ALG_CTR
case ALG_CTR_VALUE:
case TPM_ALG_CTR:
for(; dSize > 0; dSize -= blockSize)
{
// Encrypt the current value of the IV(counter)
@ -437,7 +437,7 @@ CryptSymmetricDecrypt(
break;
#endif
#if ALG_ECB
case ALG_ECB_VALUE:
case TPM_ALG_ECB:
for(; dSize > 0; dSize -= blockSize)
{
DECRYPT(&keySchedule, dIn, dOut);
@ -547,7 +547,7 @@ CryptSymmetricEncrypt(
// If the iv is provided, then it is expected to be block sized. In some cases,
// the caller is providing an array of 0's that is equal to [MAX_SYM_BLOCK_SIZE]
// with no knowledge of the actual block size. This function will set it.
if((ivInOut != NULL) && (mode != ALG_ECB_VALUE))
if((ivInOut != NULL) && (mode != TPM_ALG_ECB))
{
ivInOut->t.size = blockSize;
iv = ivInOut->t.buffer;
@ -557,8 +557,8 @@ CryptSymmetricEncrypt(
switch (mode)
{
case ALG_ECB_VALUE:
case ALG_CBC_VALUE:
case TPM_ALG_ECB:
case TPM_ALG_CBC:
// For ECB & CBC the data size must be an even multiple of the
// cipher block size
if((dSize % blockSize) != 0)
@ -581,7 +581,7 @@ CryptSymmetricEncrypt(
}
#if ALG_TDES && ALG_CTR
if (algorithm == TPM_ALG_TDES && mode == ALG_CTR_VALUE) {
if (algorithm == TPM_ALG_TDES && mode == TPM_ALG_CTR) {
TDES_CTR(keyToUse, keyToUseLen * 8, dSize, dIn, iv, pOut, blockSize);
outlen1 = dSize;
ERROR_RETURN(TPM_RC_SUCCESS);
@ -665,7 +665,7 @@ CryptSymmetricDecrypt(
// If the iv is provided, then it is expected to be block sized. In some cases,
// the caller is providing an array of 0's that is equal to [MAX_SYM_BLOCK_SIZE]
// with no knowledge of the actual block size. This function will set it.
if((ivInOut != NULL) && (mode != ALG_ECB_VALUE))
if((ivInOut != NULL) && (mode != TPM_ALG_ECB))
{
ivInOut->t.size = blockSize;
iv = ivInOut->t.buffer;
@ -676,8 +676,8 @@ CryptSymmetricDecrypt(
switch(mode)
{
#if ALG_CBC || ALG_ECB
case ALG_CBC_VALUE:
case ALG_ECB_VALUE:
case TPM_ALG_CBC:
case TPM_ALG_ECB:
// For ECB and CBC, the data size must be an even multiple of the
// cipher block size
if((dSize % blockSize) != 0)
@ -700,7 +700,7 @@ CryptSymmetricDecrypt(
ERROR_RETURN(TPM_RC_FAILURE);
#if ALG_TDES && ALG_CTR
if (algorithm == TPM_ALG_TDES && mode == ALG_CTR_VALUE) {
if (algorithm == TPM_ALG_TDES && mode == TPM_ALG_CTR) {
TDES_CTR(keyToUse, keyToUseLen * 8, dSize, dIn, iv, buffer, blockSize);
outlen1 = dSize;
ERROR_RETURN(TPM_RC_SUCCESS);

View File

@ -122,31 +122,31 @@ evpfunc GetEVPCipher(TPM_ALG_ID algorithm, // IN
*keyToUseLen = keySizeInBytes;
switch (mode) {
#if ALG_CTR
case ALG_CTR_VALUE:
case TPM_ALG_CTR:
evpfn = (evpfunc []){EVP_aes_128_ctr, EVP_aes_192_ctr,
EVP_aes_256_ctr}[i];
break;
#endif
#if ALG_OFB
case ALG_OFB_VALUE:
case TPM_ALG_OFB:
evpfn = (evpfunc[]){EVP_aes_128_ofb, EVP_aes_192_ofb,
EVP_aes_256_ofb}[i];
break;
#endif
#if ALG_CBC
case ALG_CBC_VALUE:
case TPM_ALG_CBC:
evpfn = (evpfunc[]){EVP_aes_128_cbc, EVP_aes_192_cbc,
EVP_aes_256_cbc}[i];
break;
#endif
#if ALG_CFB
case ALG_CFB_VALUE:
case TPM_ALG_CFB:
evpfn = (evpfunc[]){EVP_aes_128_cfb, EVP_aes_192_cfb,
EVP_aes_256_cfb}[i];
break;
#endif
#if ALG_ECB
case ALG_ECB_VALUE:
case TPM_ALG_ECB:
evpfn = (evpfunc[]){EVP_aes_128_ecb, EVP_aes_192_ecb,
EVP_aes_256_ecb}[i];
break;
@ -165,27 +165,27 @@ evpfunc GetEVPCipher(TPM_ALG_ID algorithm, // IN
switch (mode) {
#if ALG_CTR
case ALG_CTR_VALUE:
case TPM_ALG_CTR:
evpfn = (evpfunc[]){EVP_des_ede3, EVP_des_ede3, NULL}[i];
break;
#endif
#if ALG_OFB
case ALG_OFB_VALUE:
case TPM_ALG_OFB:
evpfn = (evpfunc[]){EVP_des_ede3_ofb, EVP_des_ede3_ofb, NULL}[i];
break;
#endif
#if ALG_CBC
case ALG_CBC_VALUE:
case TPM_ALG_CBC:
evpfn = (evpfunc[]){EVP_des_ede3_cbc, EVP_des_ede3_cbc, NULL}[i];
break;
#endif
#if ALG_CFB
case ALG_CFB_VALUE:
case TPM_ALG_CFB:
evpfn = (evpfunc[]){EVP_des_ede3_cfb64, EVP_des_ede3_cfb64, NULL}[i];
break;
#endif
#if ALG_ECB
case ALG_ECB_VALUE:
case TPM_ALG_ECB:
evpfn = (evpfunc[]){EVP_des_ede3_ecb, EVP_des_ede3_ecb, NULL}[i];
break;
#endif
@ -198,27 +198,27 @@ evpfunc GetEVPCipher(TPM_ALG_ID algorithm, // IN
*keyToUseLen = keySizeInBytes;
switch (mode) {
#if ALG_CTR
case ALG_CTR_VALUE:
case TPM_ALG_CTR:
evpfn = (evpfunc[]){EVP_sm4_ctr, NULL, NULL}[i];
break;
#endif
#if ALG_OFB
case ALG_OFB_VALUE:
case TPM_ALG_OFB:
evpfn = (evpfunc[]){EVP_sm4_ofb, NULL, NULL}[i];
break;
#endif
#if ALG_CBC
case ALG_CBC_VALUE:
case TPM_ALG_CBC:
evpfn = (evpfunc[]){EVP_sm4_cbc, NULL, NULL}[i];
break;
#endif
#if ALG_CFB
case ALG_CFB_VALUE:
case TPM_ALG_CFB:
evpfn = (evpfunc[]){EVP_sm4_cfb, NULL, NULL}[i];
break;
#endif
#if ALG_ECB
case ALG_ECB_VALUE:
case TPM_ALG_ECB:
evpfn = (evpfunc[]){EVP_sm4_ecb, NULL, NULL}[i];
break;
#endif
@ -231,31 +231,31 @@ evpfunc GetEVPCipher(TPM_ALG_ID algorithm, // IN
*keyToUseLen = keySizeInBytes;
switch (mode) {
#if ALG_CTR
case ALG_CTR_VALUE:
case TPM_ALG_CTR:
evpfn = (evpfunc []){EVP_camellia_128_ctr, EVP_camellia_192_ctr,
EVP_camellia_256_ctr}[i];
break;
#endif
#if ALG_OFB
case ALG_OFB_VALUE:
case TPM_ALG_OFB:
evpfn = (evpfunc[]){EVP_camellia_128_ofb, EVP_camellia_192_ofb,
EVP_camellia_256_ofb}[i];
break;
#endif
#if ALG_CBC
case ALG_CBC_VALUE:
case TPM_ALG_CBC:
evpfn = (evpfunc[]){EVP_camellia_128_cbc, EVP_camellia_192_cbc,
EVP_camellia_256_cbc}[i];
break;
#endif
#if ALG_CFB
case ALG_CFB_VALUE:
case TPM_ALG_CFB:
evpfn = (evpfunc[]){EVP_camellia_128_cfb, EVP_camellia_192_cfb,
EVP_camellia_256_cfb}[i];
break;
#endif
#if ALG_ECB
case ALG_ECB_VALUE:
case TPM_ALG_ECB:
evpfn = (evpfunc[]){EVP_camellia_128_ecb, EVP_camellia_192_ecb,
EVP_camellia_256_ecb}[i];
break;