• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stefanberger / libtpms / #1996

10 Jun 2025 01:38PM UTC coverage: 76.794% (+0.02%) from 76.773%
#1996

push

travis-ci

web-flow
Merge e65bedd5e into 06a717f7c

33760 of 43962 relevant lines covered (76.79%)

87788.18 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.01
/src/tpm2/AlgorithmTests.c
1
/********************************************************************************/
2
/*                                                                                */
3
/*                          Code to perform the various self-test functions.        */
4
/*                             Written by Ken Goldman                                */
5
/*                       IBM Thomas J. Watson Research Center                        */
6
/*            $Id: AlgorithmTests.c 1594 2020-03-26 22:15:48Z kgoldman $        */
7
/*                                                                                */
8
/*  Licenses and Notices                                                        */
9
/*                                                                                */
10
/*  1. Copyright Licenses:                                                        */
11
/*                                                                                */
12
/*  - Trusted Computing Group (TCG) grants to the user of the source code in        */
13
/*    this specification (the "Source Code") a worldwide, irrevocable,                 */
14
/*    nonexclusive, royalty free, copyright license to reproduce, create         */
15
/*    derivative works, distribute, display and perform the Source Code and        */
16
/*    derivative works thereof, and to grant others the rights granted herein.        */
17
/*                                                                                */
18
/*  - The TCG grants to the user of the other parts of the specification         */
19
/*    (other than the Source Code) the rights to reproduce, distribute,         */
20
/*    display, and perform the specification solely for the purpose of                 */
21
/*    developing products based on such documents.                                */
22
/*                                                                                */
23
/*  2. Source Code Distribution Conditions:                                        */
24
/*                                                                                */
25
/*  - Redistributions of Source Code must retain the above copyright licenses,         */
26
/*    this list of conditions and the following disclaimers.                        */
27
/*                                                                                */
28
/*  - Redistributions in binary form must reproduce the above copyright         */
29
/*    licenses, this list of conditions        and the following disclaimers in the         */
30
/*    documentation and/or other materials provided with the distribution.        */
31
/*                                                                                */
32
/*  3. Disclaimers:                                                                */
33
/*                                                                                */
34
/*  - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF        */
35
/*  LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH        */
36
/*  RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES)        */
37
/*  THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE.                */
38
/*  Contact TCG Administration (admin@trustedcomputinggroup.org) for                 */
39
/*  information on specification licensing rights available through TCG         */
40
/*  membership agreements.                                                        */
41
/*                                                                                */
42
/*  - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED         */
43
/*    WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR         */
44
/*    FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR                 */
45
/*    NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY                 */
46
/*    OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE.                */
47
/*                                                                                */
48
/*  - Without limitation, TCG and its members and licensors disclaim all         */
49
/*    liability, including liability for infringement of any proprietary         */
50
/*    rights, relating to use of information in this specification and to the        */
51
/*    implementation of this specification, and TCG disclaims all liability for        */
52
/*    cost of procurement of substitute goods or services, lost profits, loss         */
53
/*    of use, loss of data or any incidental, consequential, direct, indirect,         */
54
/*    or special damages, whether under contract, tort, warranty or otherwise,         */
55
/*    arising in any way out of use or reliance upon this specification or any         */
56
/*    information herein.                                                        */
57
/*                                                                                */
58
/*  (c) Copyright IBM Corp. and others, 2016 - 2020                                */
59
/*                                                                                */
60
/********************************************************************************/
61

62
/* 10.2.1 AlgorithmTests.c */
63
/* 10.2.1.1 Introduction */
64
/* This file contains the code to perform the various self-test functions. */
65
/* 10.2.1.2 Includes and Defines */
66
#include    "Tpm.h"
67
#define     SELF_TEST_DATA
68
#if SELF_TEST
69
/* These includes pull in the data structures. They contain data definitions for the various
70
   tests. */
71
#include    "SelfTest.h"
72
#include    "SymmetricTest.h"
73
#include    "RsaTestData.h"
74
#include    "EccTestData.h"
75
#include    "HashTestData.h"
76
#include    "KdfTestData.h"
77
#define TEST_DEFAULT_TEST_HASH(vector)                                        \
78
    if(TEST_BIT(DEFAULT_TEST_HASH, g_toTest))                                \
79
        TestHash(DEFAULT_TEST_HASH, vector);
80
/* Make sure that the algorithm has been tested */
81
#define CLEAR_BOTH(alg)     {   CLEAR_BIT(alg, *toTest);                \
82
        if(toTest != &g_toTest)                                                \
83
            CLEAR_BIT(alg, g_toTest); }
84
#define SET_BOTH(alg)     {   SET_BIT(alg, *toTest);                        \
85
        if(toTest != &g_toTest)                                                \
86
            SET_BIT(alg, g_toTest); }
87
#define TEST_BOTH(alg)       ((toTest != &g_toTest)                        \
88
                              ? TEST_BIT(alg, *toTest) || TEST_BIT(alg, g_toTest) \
89
                              : TEST_BIT(alg, *toTest))
90
/* Can only cancel if doing a list. */
91
#define CHECK_CANCELED                                                        \
92
    if(_plat__IsCanceled() && toTest != &g_toTest)                        \
93
        return TPM_RC_CANCELED;
94
/* 10.2.1.3 Hash Tests */
95
/* 10.2.1.3.1 Description */
96
/* The hash test does a known-value HMAC using the specified hash algorithm. */
97
/* 10.2.1.3.2 TestHash() */
98
/* The hash test function. */
99
static TPM_RC
100
TestHash(
1,925✔
101
         TPM_ALG_ID          hashAlg,
102
         ALGORITHM_VECTOR    *toTest
103
         )
104
{
105
    TPM2B_DIGEST      computed;  // value computed
1,925✔
106
    HMAC_STATE        state;
1,925✔
107
    UINT16                   digestSize;
1,925✔
108
    const TPM2B             *testDigest = NULL;
1,925✔
109
    //    TPM2B_TYPE(HMAC_BLOCK, DEFAULT_TEST_HASH_BLOCK_SIZE);
110
    pAssert(hashAlg != ALG_NULL_VALUE);
1,925✔
111
    switch(hashAlg)
1,925✔
112
        {
113
#if ALG_SHA1
114
          case ALG_SHA1_VALUE:
115
            testDigest = &c_SHA1_digest.b;
116
            break;
117
#endif
118
#if ALG_SHA256
119
          case ALG_SHA256_VALUE:
378✔
120
            testDigest = &c_SHA256_digest.b;
378✔
121
            break;
378✔
122
#endif
123
#if ALG_SHA384
124
          case ALG_SHA384_VALUE:
312✔
125
            testDigest = &c_SHA384_digest.b;
312✔
126
            break;
312✔
127
#endif
128
#if ALG_SHA512
129
          case ALG_SHA512_VALUE:
631✔
130
            testDigest = &c_SHA512_digest.b;
631✔
131
            break;
631✔
132
#endif
133
#if ALG_SM3_256
134
          case ALG_SM3_256_VALUE:
135
#error Missing test case for SM3  // libtpms added
136
            // There are currently no test vectors for SM3
137
            //            testDigest = &c_SM3_256_digest.b;
138
            testDigest = NULL;
139
            break;
140
#endif
141
          default:
×
142
            FAIL(FATAL_ERROR_INTERNAL);
×
143
        }
144
    // Clear the to-test bits
145
    CLEAR_BOTH(hashAlg);
1,925✔
146
    
147
    // If there is an algorithm without test vectors, then assume that things are OK.
148
    if(testDigest == NULL)
1,925✔
149
        return TPM_RC_SUCCESS;
150

151
    // Set the HMAC key to twice the digest size
152
    digestSize = CryptHashGetDigestSize(hashAlg);
1,925✔
153
    CryptHmacStart(&state, hashAlg, digestSize * 2,
1,925✔
154
                   (BYTE *)c_hashTestKey.t.buffer);
155
    CryptDigestUpdate(&state.hashState, 2 * CryptHashGetBlockSize(hashAlg),
1,925✔
156
                      (BYTE *)c_hashTestData.t.buffer);
157
    computed.t.size = digestSize;
1,925✔
158
    CryptHmacEnd(&state, digestSize, computed.t.buffer);
1,925✔
159
    if((testDigest->size != computed.t.size)
1,925✔
160
       || (memcmp(testDigest->buffer, computed.t.buffer, computed.b.size) != 0)) {
1,925✔
161
        SELF_TEST_FAILURE;
×
162
    }
163
    return TPM_RC_SUCCESS;
164
}
165
// libtpms added begin
166
#if SMAC_IMPLEMENTED && ALG_CMAC
167
static TPM_RC
168
TestSMAC(
23✔
169
         ALGORITHM_VECTOR    *toTest
170
         )
171
{
172
    HMAC_STATE          state;
23✔
173
    UINT16              copied;
23✔
174
    BYTE                out[MAX_SYM_BLOCK_SIZE];
23✔
175
    UINT32              outSize = sizeof(out);
23✔
176
    UINT16              blocksize;
23✔
177
    int                 i;
23✔
178
    TPMU_PUBLIC_PARMS   cmac_keyParms;
23✔
179

180
    // initializing this statically seems impossible with gcc...
181
    cmac_keyParms.symDetail.sym.algorithm = ALG_AES_VALUE;
23✔
182
    cmac_keyParms.symDetail.sym.keyBits.sym = 128;
23✔
183

184
    for (i = 0; CMACTests[i].key; i++ )
115✔
185
        {
186
            blocksize = CryptMacStart(&state, &cmac_keyParms,
92✔
187
                                      TPM_ALG_CMAC, CMACTests[i].key);
188
            pAssert(blocksize <= outSize);
92✔
189
            CryptDigestUpdate(&state.hashState, CMACTests[i].datalen,
92✔
190
                              CMACTests[i].data);
92✔
191
            copied = CryptMacEnd(&state, outSize, out);
92✔
192
            if((CMACTests[i].outlen != copied)
92✔
193
              || (memcmp(out, CMACTests[i].out, CMACTests[i].outlen) != 0)) {
92✔
194
                SELF_TEST_FAILURE;
×
195
            }
196
        }
197
    return TPM_RC_SUCCESS;
23✔
198
}
199
#endif
200
// libtpms added end
201
/* 10.2.1.4 Symmetric Test Functions */
202
/* 10.2.1.4.1 MakeIv() */
203
/* Internal function to make the appropriate IV depending on the mode. */
204
static UINT32
205
MakeIv(
768✔
206
       TPM_ALG_ID    mode,     // IN: symmetric mode
207
       UINT32        size,     // IN: block size of the algorithm
208
       BYTE         *iv        // OUT: IV to fill in
209
       )
210
{
211
    BYTE          i;
768✔
212
    if(mode == ALG_ECB_VALUE)
768✔
213
        return 0;
214
    if(mode == ALG_CTR_VALUE)
632✔
215
        {
216
            // The test uses an IV that has 0xff in the last byte
217
            for(i = 1; i <= size; i++)
1,960✔
218
                *iv++ = 0xff - (BYTE)(size - i);
1,824✔
219
        }
220
    else
221
        {
222
            for(i = 0; i < size; i++)
6,672✔
223
                *iv++ = i;
6,176✔
224
        }
225
    return size;
226
}
227
/* 10.2.1.4.2 TestSymmetricAlgorithm() */
228
/* Function to test a specific algorithm, key size, and mode. */
229
static void
230
TestSymmetricAlgorithm(
450✔
231
                       const SYMMETRIC_TEST_VECTOR     *test,          //
232
                       TPM_ALG_ID                       mode           //
233
                       )
234
{
235
    BYTE                            encrypted[MAX_SYM_BLOCK_SIZE * 2];
450✔
236
    BYTE                            decrypted[MAX_SYM_BLOCK_SIZE * 2];
450✔
237
    TPM2B_IV                        iv;
450✔
238

239
    // libtpms added beging
240
    if (test->dataOut[mode - ALG_CTR_VALUE] == NULL)
450✔
241
        return;
66✔
242
    // libtpms added end
243

244
    //
245
    // Get the appropriate IV
246
    iv.t.size = (UINT16)MakeIv(mode, test->ivSize, iv.t.buffer);
384✔
247
    // Encrypt known data
248
    CryptSymmetricEncrypt(encrypted, test->alg, test->keyBits, test->key, &iv,
384✔
249
                          mode, test->dataInOutSize, test->dataIn);
384✔
250
    // Check that it matches the expected value
251
    if(!MemoryEqual(encrypted, test->dataOut[mode - ALG_CTR_VALUE],
384✔
252
                    test->dataInOutSize)) {
384✔
253
        SELF_TEST_FAILURE;
×
254
    }
255
    // Reinitialize the iv for decryption
256
    MakeIv(mode, test->ivSize, iv.t.buffer);
384✔
257
    CryptSymmetricDecrypt(decrypted, test->alg, test->keyBits, test->key, &iv,
384✔
258
                          mode, test->dataInOutSize,
384✔
259
                          test->dataOut[mode - ALG_CTR_VALUE]);
384✔
260
    // Make sure that it matches what we started with
261
    if(!MemoryEqual(decrypted, test->dataIn, test->dataInOutSize)) {
384✔
262
        SELF_TEST_FAILURE;
×
263
    }
264
}
265
/* 10.2.1.4.3 AllSymsAreDone() */
266
/* Checks if both symmetric algorithms have been tested. This is put here so that addition of a
267
   symmetric algorithm will be relatively easy to handle */
268
/* Return Value        Meaning */
269
/* TRUE(1)        all symmetric algorithms tested */
270
/* FALSE(0)        not all symmetric algorithms tested */
271
static BOOL
272
AllSymsAreDone(
34✔
273
               ALGORITHM_VECTOR        *toTest
274
               )
275
{
276
    return (!TEST_BOTH(ALG_AES_VALUE) && !TEST_BOTH(ALG_SM4_VALUE));
34✔
277
}
278
/* 10.2.1.4.4 AllModesAreDone() */
279
/* Checks if all the modes have been tested */
280
/* Return Value        Meaning */
281
/* TRUE(1)        all modes tested */
282
/* FALSE(0)        all modes not tested */
283
static BOOL
284
AllModesAreDone(
8✔
285
                ALGORITHM_VECTOR            *toTest
286
                )
287
{
288
    TPM_ALG_ID                  alg;
8✔
289
    for(alg = SYM_MODE_FIRST; alg <= SYM_MODE_LAST; alg++)
32✔
290
        if(TEST_BOTH(alg))
40✔
291
            return FALSE;
292
    return TRUE;
293
}
294
/* 10.2.1.4.5 TestSymmetric() */
295
/* If alg is a symmetric block cipher, then all of the modes that are selected are tested. If alg is
296
   a mode, then all algorithms of that mode are tested. */
297
static TPM_RC
298
TestSymmetric(
42✔
299
              TPM_ALG_ID                   alg,
300
              ALGORITHM_VECTOR            *toTest
301
              )
302
{
303
    SYM_INDEX                    index;
42✔
304
    TPM_ALG_ID                   mode;
42✔
305
    //
306
    if(!TEST_BIT(alg, *toTest))
42✔
307
        return TPM_RC_SUCCESS;
308
    if(alg == ALG_AES_VALUE || alg == ALG_SM4_VALUE || alg == ALG_CAMELLIA_VALUE || alg == ALG_TDES_VALUE)
42✔
309
        {
310
            // Will test the algorithm for all modes and key sizes
311
            CLEAR_BOTH(alg);
34✔
312
            // A test this algorithm for all modes
313
            for(index = 0; index < NUM_SYMS; index++)
238✔
314
                {
315
                    if(c_symTestValues[index].alg == alg)
204✔
316
                        {
317
                            for(mode = SYM_MODE_FIRST;
318
                                mode <= SYM_MODE_LAST;
540✔
319
                                mode++)
450✔
320
                                {
321
                                    if(TEST_BIT(mode, g_implementedAlgorithms)) // libtpms always test implemented modes
450✔
322
                                        TestSymmetricAlgorithm(&c_symTestValues[index], mode);
450✔
323
                                }
324
                        }
325
                }
326
            // if all the symmetric tests are done
327
            if(AllSymsAreDone(toTest))
34✔
328
                {
329
                    // all symmetric algorithms tested so no modes should be set
330
                    for(alg = SYM_MODE_FIRST; alg <= SYM_MODE_LAST; alg++)
138✔
331
                        CLEAR_BOTH(alg);
115✔
332
                }
333
        }
334
    else if(SYM_MODE_FIRST <= alg && alg <= SYM_MODE_LAST)
335
        {
336
            // Test this mode for all key sizes and algorithms
337
            for(index = 0; index < NUM_SYMS; index++)
56✔
338
                {
339
                    // The mode testing only comes into play when doing self tests
340
                    // by command. When doing self tests by command, the block ciphers are
341
                    // tested first. That means that all of their modes would have been
342
                    // tested for all key sizes. If there is no block cipher left to
343
                    // test, then clear this mode bit.
344
                    if(!TEST_BIT(ALG_AES_VALUE, *toTest)
48✔
345
                       && !TEST_BIT(ALG_SM4_VALUE, *toTest))
48✔
346
                        {
347
                            CLEAR_BOTH(alg);
48✔
348
                        }
349
                    else
350
                        {
351
                            for(index = 0; index < NUM_SYMS; index++)
×
352
                                {
353
                                    if(TEST_BIT(c_symTestValues[index].alg, *toTest))
×
354
                                        TestSymmetricAlgorithm(&c_symTestValues[index], alg);
×
355
                                }
356
                            // have tested this mode for all algorithms
357
                            CLEAR_BOTH(alg);
48✔
358
                        }
359
                }
360
            if(AllModesAreDone(toTest))
8✔
361
                {
362
                    CLEAR_BOTH(ALG_AES_VALUE);
×
363
                    CLEAR_BOTH(ALG_SM4_VALUE);
×
364
                }
365
        }
366
    else
367
        pAssert(alg == 0 && alg != 0);
×
368
    return TPM_RC_SUCCESS;
369
}
370
/* 10.2.1.5 RSA Tests */
371
#if ALG_RSA
372
/* 10.2.1.5.1 Introduction */
373
/* The tests are for public key only operations and for private key operations. Signature
374
   verification and encryption are public key operations. They are tested by using a KVT. For
375
   signature verification, this means that a known good signature is checked by
376
   CryptRsaValidateSignature(). If it fails, then the TPM enters failure mode. For encryption, the
377
   TPM encrypts known values using the selected scheme and checks that the returned value matches
378
   the expected value. */
379
/* For private key operations, a full scheme check is used. For a signing key, a known key is used
380
   to sign a known message. Then that signature is verified. since the signature may involve use of
381
   random values, the signature will be different each time and we can't always check that the
382
   signature matches a known value. The same technique is used for decryption (RSADP/RSAEP). */
383
/* When an operation uses the public key and the verification has not been tested, the TPM will do a
384
   KVT. */
385
/* The test for the signing algorithm is built into the call for the algorithm */
386
/* 10.2.1.5.2 RsaKeyInitialize() */
387
/* The test key is defined by a public modulus and a private prime. The TPM's RSA code computes the
388
   second prime and the private exponent. */
389
static void
390
RsaKeyInitialize(
89✔
391
                 OBJECT          *testObject
392
                 )
393
{
394
    MemoryCopy2B(&testObject->publicArea.unique.rsa.b, (P2B)&c_rsaPublicModulus,
89✔
395
                 sizeof(c_rsaPublicModulus));
396
    MemoryCopy2B(&testObject->sensitive.sensitive.rsa.b, (P2B)&c_rsaPrivatePrime,
89✔
397
                 sizeof(testObject->sensitive.sensitive.rsa.t.buffer));
398
    testObject->publicArea.parameters.rsaDetail.keyBits = RSA_TEST_KEY_SIZE * 8;
89✔
399
    // Use the default exponent
400
    testObject->publicArea.parameters.rsaDetail.exponent = 0;
89✔
401
    testObject->attributes.privateExp = 0;
89✔
402
}
89✔
403
/* 10.2.1.5.3 TestRsaEncryptDecrypt() */
404
/* These tests are for a public key encryption that uses a random value. */
405
static TPM_RC
406
TestRsaEncryptDecrypt(
52✔
407
                      TPM_ALG_ID           scheme,            // IN: the scheme
408
                      ALGORITHM_VECTOR    *toTest             //
409
                      )
410
{
411
    TPM2B_PUBLIC_KEY_RSA             testInput;
52✔
412
    TPM2B_PUBLIC_KEY_RSA             testOutput;
52✔
413
    OBJECT                           testObject;
52✔
414
    const TPM2B_RSA_TEST_KEY        *kvtValue = NULL;
52✔
415
    TPM_RC                           result = TPM_RC_SUCCESS;
52✔
416
    const TPM2B                     *testLabel = NULL;
52✔
417
    TPMT_RSA_DECRYPT                 rsaScheme;
52✔
418
    //
419
    // Don't need to initialize much of the test object but do need to initialize
420
    // the flag indicating that the private exponent has been computed.
421
    testObject.attributes.privateExp = CLEAR;
52✔
422
    RsaKeyInitialize(&testObject);
52✔
423
    rsaScheme.scheme = scheme;
52✔
424
    rsaScheme.details.anySig.hashAlg = DEFAULT_TEST_HASH;
52✔
425
    CLEAR_BOTH(scheme);
52✔
426
    CLEAR_BOTH(ALG_NULL_VALUE);
52✔
427
    if(scheme == ALG_NULL_VALUE)
52✔
428
        {
429
            // This is an encryption scheme using the private key without any encoding.
430
            memcpy(testInput.t.buffer, c_RsaTestValue, sizeof(c_RsaTestValue));
27✔
431
            testInput.t.size = sizeof(c_RsaTestValue);
27✔
432
            if(TPM_RC_SUCCESS != CryptRsaEncrypt(&testOutput, &testInput.b,
27✔
433
                                                 &testObject, &rsaScheme, NULL, NULL)) {
434
                SELF_TEST_FAILURE;
×
435
            }
436
            if(!MemoryEqual(testOutput.t.buffer, c_RsaepKvt.buffer, c_RsaepKvt.size)) {
27✔
437
                SELF_TEST_FAILURE;
×
438
            }
439
            MemoryCopy2B(&testInput.b, &testOutput.b, sizeof(testInput.t.buffer));
27✔
440
            if(TPM_RC_SUCCESS != CryptRsaDecrypt(&testOutput.b, &testInput.b,
27✔
441
                                                 &testObject, &rsaScheme, NULL)) {
442
                SELF_TEST_FAILURE;
×
443
            }
444
            if(!MemoryEqual(testOutput.t.buffer, c_RsaTestValue,
27✔
445
                            sizeof(c_RsaTestValue))) {
446
                SELF_TEST_FAILURE;
×
447
            }
448
        }
449
    else
450
        {
451
            // ALG_RSAES_VALUE:
452
            // This is an decryption scheme using padding according to
453
            // PKCS#1v2.1, 7.2. This padding uses random bits. To test a public
454
            // key encryption that uses random data, encrypt a value and then
455
            // decrypt the value and see that we get the encrypted data back.
456
            // The hash is not used by this encryption so it can be TMP_ALG_NULL
457
            // ALG_OAEP_VALUE:
458
            // This is also an decryption scheme and it also uses a
459
            // pseudo-random
460
            // value. However, this also uses a hash algorithm. So, we may need
461
            // to test that algorithm before use.
462
            if(scheme == ALG_OAEP_VALUE)
25✔
463
                {
464
                    TEST_DEFAULT_TEST_HASH(toTest);
13✔
465
                    kvtValue = &c_OaepKvt;
13✔
466
                    testLabel = OAEP_TEST_STRING;
13✔
467
                }
468
            else if(scheme == ALG_RSAES_VALUE)
12✔
469
                {
470
                    kvtValue = &c_RsaesKvt;
471
                    testLabel = NULL;
472
                }
473
            else {
474
                SELF_TEST_FAILURE;
×
475
            }
476
            // Only use a digest-size portion of the test value
477
            memcpy(testInput.t.buffer, c_RsaTestValue, DEFAULT_TEST_DIGEST_SIZE);
25✔
478
            testInput.t.size = DEFAULT_TEST_DIGEST_SIZE;
25✔
479
            // See if the encryption works
480
            if(TPM_RC_SUCCESS != CryptRsaEncrypt(&testOutput, &testInput.b,
25✔
481
                                                 &testObject, &rsaScheme, testLabel,
482
                                                 NULL)) {
483
                SELF_TEST_FAILURE;
×
484
            }
485
            MemoryCopy2B(&testInput.b, &testOutput.b, sizeof(testInput.t.buffer));
25✔
486
            // see if we can decrypt this value and get the original data back
487
            if(TPM_RC_SUCCESS != CryptRsaDecrypt(&testOutput.b, &testInput.b,
25✔
488
                                                 &testObject, &rsaScheme, testLabel)) {
489
                SELF_TEST_FAILURE;
×
490
            }
491
            // See if the results compare
492
            if(testOutput.t.size != DEFAULT_TEST_DIGEST_SIZE
25✔
493
               || !MemoryEqual(testOutput.t.buffer, c_RsaTestValue,
25✔
494
                               DEFAULT_TEST_DIGEST_SIZE)) {
495
                SELF_TEST_FAILURE;
×
496
            }
497
            // Now check that the decryption works on a known value
498
            MemoryCopy2B(&testInput.b, (P2B)kvtValue,
25✔
499
                         sizeof(testInput.t.buffer));
500
            if(TPM_RC_SUCCESS != CryptRsaDecrypt(&testOutput.b, &testInput.b,
25✔
501
                                                 &testObject, &rsaScheme, testLabel)) {
502
                SELF_TEST_FAILURE;
×
503
            }
504
            if(testOutput.t.size != DEFAULT_TEST_DIGEST_SIZE
25✔
505
               || !MemoryEqual(testOutput.t.buffer, c_RsaTestValue,
25✔
506
                               DEFAULT_TEST_DIGEST_SIZE)) {
507
                SELF_TEST_FAILURE;
×
508
            }
509
        }
510
    return result;
52✔
511
}
512
/* 10.2.1.5.4 TestRsaSignAndVerify() */
513
/* This function does the testing of the RSA sign and verification functions. This test does a
514
   KVT. */
515
static TPM_RC
516
TestRsaSignAndVerify(
37✔
517
                     TPM_ALG_ID               scheme,
518
                     ALGORITHM_VECTOR        *toTest
519
                     )
520
{
521
    TPM_RC                      result = TPM_RC_SUCCESS;
37✔
522
    OBJECT                      testObject;
37✔
523
    TPM2B_DIGEST                testDigest;
37✔
524
    TPMT_SIGNATURE              testSig;
37✔
525
    // Do a sign and signature verification.
526
    // RSASSA:
527
    // This is a signing scheme according to PKCS#1-v2.1 8.2. It does not
528
    // use random data so there is a KVT for the signing operation. On
529
    // first use of the scheme for signing, use the TPM's RSA key to
530
    // sign a portion of c_RsaTestData and compare the results to c_RsassaKvt. Then
531
    // decrypt the data to see that it matches the starting value. This verifies
532
    // the signature with a KVT
533
    // Clear the bits indicating that the function has not been checked. This is to
534
    // prevent looping
535
    CLEAR_BOTH(scheme);
37✔
536
    CLEAR_BOTH(ALG_NULL_VALUE);
37✔
537
    CLEAR_BOTH(ALG_RSA_VALUE);
37✔
538
    RsaKeyInitialize(&testObject);
37✔
539
    memcpy(testDigest.t.buffer, (BYTE *)c_RsaTestValue, DEFAULT_TEST_DIGEST_SIZE);
37✔
540
    testDigest.t.size = DEFAULT_TEST_DIGEST_SIZE;
37✔
541
    testSig.sigAlg = scheme;
37✔
542
    testSig.signature.rsapss.hash = DEFAULT_TEST_HASH;
37✔
543
    // RSAPSS:
544
    // This is a signing scheme a according to PKCS#1-v2.2 8.1 it uses
545
    // random data in the signature so there is no KVT for the signing
546
    // operation. To test signing, the TPM will use the TPM's RSA key
547
    // to sign a portion of c_RsaTestValue and then it will verify the
548
    // signature. For verification, c_RsapssKvt is verified before the
549
    // user signature blob is verified. The worst case for testing of this
550
    // algorithm is two private and one public key operation.
551
    // The process is to sign known data. If RSASSA is being done, verify that the
552
    // signature matches the precomputed value. For both, use the signed value and
553
    // see that the verification says that it is a good signature. Then
554
    // if testing RSAPSS, do a verify of a known good signature. This ensures that
555
    // the validation function works.
556
    if(TPM_RC_SUCCESS != CryptRsaSign(&testSig, &testObject, &testDigest, NULL)) {
37✔
557
        SELF_TEST_FAILURE;
×
558
    }
559
    // For RSASSA, make sure the results is what we are looking for
560
    if(testSig.sigAlg == ALG_RSASSA_VALUE)
37✔
561
        {
562
            if(testSig.signature.rsassa.sig.t.size != RSA_TEST_KEY_SIZE
25✔
563
               || !MemoryEqual(c_RsassaKvt.buffer,
25✔
564
                               testSig.signature.rsassa.sig.t.buffer,
565
                               RSA_TEST_KEY_SIZE)) {
566
                SELF_TEST_FAILURE;
×
567
            }
568
        }
569
    // See if the TPM will validate its own signatures
570
    if(TPM_RC_SUCCESS != CryptRsaValidateSignature(&testSig, &testObject,
37✔
571
                                                   &testDigest)) {
572
        SELF_TEST_FAILURE;
×
573
    }
574
    // If this is RSAPSS, check the verification with known signature
575
    // Have to copy because  CrytpRsaValidateSignature() eats the signature
576
    if(ALG_RSAPSS_VALUE == scheme)
37✔
577
        {
578
            MemoryCopy2B(&testSig.signature.rsapss.sig.b, (P2B)&c_RsapssKvt,
12✔
579
                         sizeof(testSig.signature.rsapss.sig.t.buffer));
580
            if(TPM_RC_SUCCESS != CryptRsaValidateSignature(&testSig, &testObject,
12✔
581
                                                           &testDigest)) {
582
                SELF_TEST_FAILURE;
×
583
            }
584
        }
585
    return result;
37✔
586
}
587
/* 10.2.1.5.5 TestRSA() */
588
/* Function uses the provided vector to indicate which tests to run. It will clear the vector after
589
   each test is run and also clear g_toTest */
590
static TPM_RC
591
TestRsa(
89✔
592
        TPM_ALG_ID               alg,
593
        ALGORITHM_VECTOR        *toTest
594
        )
595
{
596
    TPM_RC                  result = TPM_RC_SUCCESS;
89✔
597
    //
598
    switch(alg)
89✔
599
        {
600
          case ALG_NULL_VALUE:
27✔
601
            // This is the RSAEP/RSADP function. If we are processing a list, don't
602
            // need to test these now because any other test will validate
603
            // RSAEP/RSADP. Can tell this is list of test by checking to see if
604
            // 'toTest' is pointing at g_toTest. If so, this is an isolated test
605
            // an need to go ahead and do the test;
606
            if((toTest == &g_toTest)
27✔
607
               || (!TEST_BIT(ALG_RSASSA_VALUE, *toTest)
20✔
608
                   && !TEST_BIT(ALG_RSAES_VALUE, *toTest)
20✔
609
                   && !TEST_BIT(ALG_RSAPSS_VALUE, *toTest)
20✔
610
                   && !TEST_BIT(ALG_OAEP_VALUE, *toTest)))
20✔
611
                // Not running a list of tests or no other tests on the list
612
                // so run the test now
613
                result = TestRsaEncryptDecrypt(alg, toTest);
27✔
614
            // if not running the test now, leave the bit on, just in case things
615
            // get interrupted
616
            break;
617
          case ALG_OAEP_VALUE:
25✔
618
          case ALG_RSAES_VALUE:
619
            result = TestRsaEncryptDecrypt(alg, toTest);
25✔
620
            break;
25✔
621
          case ALG_RSAPSS_VALUE:
37✔
622
          case ALG_RSASSA_VALUE:
623
            result = TestRsaSignAndVerify(alg, toTest);
37✔
624
            break;
37✔
625
          default:
×
626
            SELF_TEST_FAILURE;
×
627
        }
628
    return result;
89✔
629
}
630
#endif // TPM_ALG_RSA
631
/* 10.2.1.6 ECC Tests */
632
#if ALG_ECC
633
/* 10.2.1.6.1 LoadEccParameter() */
634
/* This function is mostly for readability and type checking */
635
static void
636
LoadEccParameter(
359✔
637
                 TPM2B_ECC_PARAMETER          *to,       // target
638
                 const TPM2B_EC_TEST          *from      // source
639
                 )
640
{
641
    MemoryCopy2B(&to->b, &from->b, sizeof(to->t.buffer));
359✔
642
}
70✔
643
/* 10.2.1.6.2 LoadEccPoint() */
644
static void
645
LoadEccPoint(
289✔
646
             TPMS_ECC_POINT               *point,       // target
647
             const TPM2B_EC_TEST          *x,             // source
648
             const TPM2B_EC_TEST           *y
649
             )
650
{
651
    MemoryCopy2B(&point->x.b, (TPM2B *)x, sizeof(point->x.t.buffer));
289✔
652
    MemoryCopy2B(&point->y.b, (TPM2B *)y, sizeof(point->y.t.buffer));
289✔
653
}
289✔
654
/* 10.2.1.6.3 TestECDH() */
655
/* This test does a KVT on a point multiply. */
656
static TPM_RC
657
TestECDH(
219✔
658
         TPM_ALG_ID          scheme,         // IN: for consistency
659
         ALGORITHM_VECTOR    *toTest         // IN/OUT: modified after test is run
660
         )
661
{
662
    TPMS_ECC_POINT          Z;
219✔
663
    TPMS_ECC_POINT          Qe;
219✔
664
    TPM2B_ECC_PARAMETER     ds;
219✔
665
    TPM_RC                  result = TPM_RC_SUCCESS;
219✔
666
    //
667
    NOT_REFERENCED(scheme);
219✔
668
    CLEAR_BOTH(ALG_ECDH_VALUE);
219✔
669
    LoadEccParameter(&ds, &c_ecTestKey_ds);
219✔
670
    LoadEccPoint(&Qe, &c_ecTestKey_QeX, &c_ecTestKey_QeY);
219✔
671
    if(TPM_RC_SUCCESS != CryptEccPointMultiply(&Z, c_testCurve, &Qe, &ds,
219✔
672
                                               NULL, NULL)) {
673
        SELF_TEST_FAILURE;
×
674
    }
675
    if(!MemoryEqual2B(&c_ecTestEcdh_X.b, &Z.x.b)
219✔
676
       || !MemoryEqual2B(&c_ecTestEcdh_Y.b, &Z.y.b)) {
219✔
677
        SELF_TEST_FAILURE;
×
678
    }
679
    return result;
219✔
680
}
681
/* 10.2.1.6.4        TestEccSignAndVerify() */
682
static TPM_RC
683
TestEccSignAndVerify(
70✔
684
                     TPM_ALG_ID                   scheme,
685
                     ALGORITHM_VECTOR            *toTest
686
                     )
687
{
688
    OBJECT                       testObject;
70✔
689
    TPMT_SIGNATURE               testSig;
70✔
690
    TPMT_ECC_SCHEME              eccScheme;
70✔
691
    testSig.sigAlg = scheme;
70✔
692
    testSig.signature.ecdsa.hash = DEFAULT_TEST_HASH;
70✔
693
    eccScheme.scheme = scheme;
70✔
694
    eccScheme.details.anySig.hashAlg = DEFAULT_TEST_HASH;
70✔
695
    CLEAR_BOTH(scheme);
70✔
696
    CLEAR_BOTH(ALG_ECDH_VALUE);
70✔
697
    // ECC signature verification testing uses a KVT.
698
    switch(scheme)
70✔
699
        {
700
          case ALG_ECDSA_VALUE:
701
            LoadEccParameter(&testSig.signature.ecdsa.signatureR, &c_TestEcDsa_r);
59✔
702
            LoadEccParameter(&testSig.signature.ecdsa.signatureS, &c_TestEcDsa_s);
59✔
703
            break;
704
          case ALG_ECSCHNORR_VALUE:
705
            LoadEccParameter(&testSig.signature.ecschnorr.signatureR,
11✔
706
                             &c_TestEcSchnorr_r);
707
            LoadEccParameter(&testSig.signature.ecschnorr.signatureS,
11✔
708
                             &c_TestEcSchnorr_s);
709
            break;
710
          case ALG_SM2_VALUE:
711
            // don't have a test for SM2
712
            return TPM_RC_SUCCESS;
713
          default:
×
714
            SELF_TEST_FAILURE;
×
715
            break;
70✔
716
        }
717
    TEST_DEFAULT_TEST_HASH(toTest);
70✔
718
    // Have to copy the key. This is because the size used in the test vectors
719
    // is the size of the ECC parameter for the test key while the size of a point
720
    // is TPM dependent
721
    MemoryCopy2B(&testObject.sensitive.sensitive.ecc.b, &c_ecTestKey_ds.b,
70✔
722
                 sizeof(testObject.sensitive.sensitive.ecc.t.buffer));
723
    LoadEccPoint(&testObject.publicArea.unique.ecc, &c_ecTestKey_QsX,
70✔
724
                 &c_ecTestKey_QsY);
725
    testObject.publicArea.parameters.eccDetail.curveID = c_testCurve;
70✔
726
    if(TPM_RC_SUCCESS != CryptEccValidateSignature(&testSig, &testObject,
70✔
727
                                                   (TPM2B_DIGEST *)&c_ecTestValue.b))
728
        {
729
            SELF_TEST_FAILURE;
×
730
        }
731
    CHECK_CANCELED;
70✔
732
    // Now sign and verify some data
733
    if(TPM_RC_SUCCESS != CryptEccSign(&testSig, &testObject,
70✔
734
                                      (TPM2B_DIGEST *)&c_ecTestValue,
735
                                      &eccScheme, NULL)) {
736
        SELF_TEST_FAILURE;
×
737
    }
738
    CHECK_CANCELED;
70✔
739
    if(TPM_RC_SUCCESS != CryptEccValidateSignature(&testSig, &testObject,
70✔
740
                                                   (TPM2B_DIGEST *)&c_ecTestValue)) {
741
        SELF_TEST_FAILURE;
×
742
    }
743
    CHECK_CANCELED;
70✔
744
    return TPM_RC_SUCCESS;
745
}
746
/* 10.2.1.6.5        TestKDFa() */
747

748
static TPM_RC
749
TestKDFa(
66✔
750
         ALGORITHM_VECTOR        *toTest
751
         )
752
{
753
    static TPM2B_KDF_TEST_KEY   keyOut;
66✔
754
    UINT32                      counter = 0;
66✔
755
    //
756
    CLEAR_BOTH(ALG_KDF1_SP800_108_VALUE);
66✔
757
    keyOut.t.size = CryptKDFa(KDF_TEST_ALG, &c_kdfTestKeyIn.b, &c_kdfTestLabel.b,
66✔
758
                              &c_kdfTestContextU.b, &c_kdfTestContextV.b,
759
                              TEST_KDF_KEY_SIZE * 8, keyOut.t.buffer,
760
                              &counter, FALSE);
761
    if (   keyOut.t.size != TEST_KDF_KEY_SIZE
66✔
762
           || !MemoryEqual(keyOut.t.buffer, c_kdfTestKeyOut.t.buffer,
66✔
763
                           TEST_KDF_KEY_SIZE))
764
        SELF_TEST_FAILURE;
×
765
    return TPM_RC_SUCCESS;
66✔
766
}
767
/* 10.2.1.6.6        TestEcc() */
768
static TPM_RC
769
TestEcc(
289✔
770
        TPM_ALG_ID              alg,
771
        ALGORITHM_VECTOR        *toTest
772
        )
773
{
774
    TPM_RC                  result = TPM_RC_SUCCESS;
289✔
775
    NOT_REFERENCED(toTest);
289✔
776
    switch(alg)
289✔
777
        {
778
          case ALG_ECC_VALUE:
219✔
779
          case ALG_ECDH_VALUE:
780
            // If this is in a loop then see if another test is going to deal with
781
            // this.
782
            // If toTest is not a self-test list
783
            if((toTest == &g_toTest)
219✔
784
               // or this is the only ECC test in the list
785
               || !(TEST_BIT(ALG_ECDSA_VALUE, *toTest)
×
786
                    || TEST_BIT(ALG_ECSCHNORR, *toTest)
×
787
                    || TEST_BIT(ALG_SM2_VALUE, *toTest)))
×
788
                {
789
                    result = TestECDH(alg, toTest);
219✔
790
                }
791
            break;
792
          case ALG_ECDSA_VALUE:
70✔
793
          case ALG_ECSCHNORR_VALUE:
794
          case ALG_SM2_VALUE:
795
            result = TestEccSignAndVerify(alg, toTest);
70✔
796
            break;
70✔
797
          default:
×
798
            SELF_TEST_FAILURE;
×
799
            break;
289✔
800
        }
801
    return result;
289✔
802
}
803
#endif // TPM_ALG_ECC
804
/* 10.2.1.6.4 TestAlgorithm() */
805
/* Dispatches to the correct test function for the algorithm or gets a list of testable
806
   algorithms. */
807
/* If toTest is not NULL, then the test decisions are based on the algorithm selections in
808
   toTest. Otherwise, g_toTest is used. When bits are clear in g_toTest they will also be cleared
809
   toTest. */
810
/* If there doesn't happen to be a test for the algorithm, its associated bit is quietly cleared. */
811
/* If alg is zero (TPM_ALG_ERROR), then the toTest vector is cleared of any bits for which there is
812
   no test (i.e. no tests are actually run but the vector is cleared). */
813
/* NOTE: toTest will only ever have bits set for implemented algorithms but alg can be anything. */
814
/* Error Returns Meaning */
815
/* TPM_RC_CANCELED test was canceled */
816
LIB_EXPORT
817
TPM_RC
818
TestAlgorithm(
10,744✔
819
              TPM_ALG_ID               alg,
820
              ALGORITHM_VECTOR        *toTest
821
              )
822
{
823
    TPM_ALG_ID              first = (alg == ALG_ERROR_VALUE) ? ALG_FIRST_VALUE : alg;
10,744✔
824
    TPM_ALG_ID              last = (alg == ALG_ERROR_VALUE) ? ALG_LAST_VALUE : alg;
10,744✔
825
    BOOL                    doTest = (alg != ALG_ERROR_VALUE);
10,744✔
826
    TPM_RC                  result = TPM_RC_SUCCESS;
10,744✔
827
    if(toTest == NULL)
10,744✔
828
        toTest = &g_toTest;
2,192✔
829
    // This is kind of strange. This function will either run a test of the selected
830
    // algorithm or just clear a bit if there is no test for the algorithm. So,
831
    // either this loop will be executed once for the selected algorithm or once for
832
    // each of the possible algorithms. If it is executed more than once ('alg' ==
833
    // TPM_ALG_ERROR), then no test will be run but bits will be cleared for
834
    // unimplemented algorithms. This was done this way so that there is only one
835
    // case statement with all of the algorithms. It was easier to have one case
836
    // statement than to have multiple ones to manage whenever an algorithm ID is
837
    // added.
838
    for(alg = first; (alg <= last); alg++)
574,841✔
839
        {
840
            // if 'alg' was TPM_ALG_ERROR, then we will be cycling through
841
            // values, some of which may not be implemented. If the bit in toTest
842
            // happens to be set, then we could either generated an assert, or just
843
            // silently CLEAR it. Decided to just clear.
844
            if(!TEST_BIT(alg, g_implementedAlgorithms))
564,097✔
845
                {
846
                    CLEAR_BIT(alg, *toTest);
297,324✔
847
                    continue;
297,324✔
848
                }
849
            // Process whatever is left.
850
            // NOTE: since this switch will only be called if the algorithm is
851
            // implemented, it is not necessary to modify this list except to comment
852
            // out the algorithms for which there is no test
853
            switch(alg)
266,773✔
854
                {
855
                    // Symmetric block ciphers
856
#if ALG_AES
857
                  case ALG_AES_VALUE:
8,282✔
858
// libtpms added begin
859
#if SMAC_IMPLEMENTED && ALG_CMAC
860
                    if (doTest) {
8,282✔
861
                         result = TestSMAC(toTest);
23✔
862
                         if (result != TPM_RC_SUCCESS)
23✔
863
                             break;
864
                    }
865
#endif
866
// libtpms added end
867
#endif
868
#if ALG_SM4
869
                    // if SM4 is implemented, its test is like other block ciphers but there
870
                    // aren't any test vectors for it yet
871
                    //            case ALG_SM4_VALUE:
872
#endif
873
#if ALG_CAMELLIA
874
                  case ALG_CAMELLIA_VALUE:  // libtpms activated
875
#endif
876
#if ALG_TDES
877
                  case ALG_TDES_VALUE:      // libtpms added
878
#endif
879
                    // Symmetric modes
880
#if !ALG_CFB
881
#   error   CFB is required in all TPM implementations
882
#endif // !TPM_ALG_CFB
883
                  case ALG_CFB_VALUE:
884
                    if(doTest)
24,811✔
885
                        result = TestSymmetric(alg, toTest);
34✔
886
                    break;
887
#if ALG_CTR
888
                  case ALG_CTR_VALUE:
33,044✔
889
#endif // TPM_ALG_CRT
890
#if ALG_OFB
891
                  case ALG_OFB_VALUE:
892
#endif // TPM_ALG_OFB
893
#if ALG_CBC
894
                  case ALG_CBC_VALUE:
895
#endif // TPM_ALG_CBC
896
#if ALG_ECB
897
                  case ALG_ECB_VALUE:
898
#endif
899
                    if(doTest)
33,044✔
900
                        result = TestSymmetric(alg, toTest);
8✔
901
                    else
902
                        // If doing the initialization of g_toTest vector, only need
903
                        // to test one of the modes for the symmetric algorithms. If
904
                        // initializing for a SelfTest(FULL_TEST), allow all the modes.
905
                        if(toTest == &g_toTest)
33,036✔
906
                            CLEAR_BIT(alg, *toTest);
33,036✔
907
                    break;
908
#if !ALG_HMAC
909
#   error   HMAC is required in all TPM implementations
910
#endif
911
                  case ALG_HMAC_VALUE:
8,266✔
912
                    // Clear the bit that indicates that HMAC is required because
913
                    // HMAC is used as the basic test for all hash algorithms.
914
                    CLEAR_BOTH(alg);
8,266✔
915
                    // Testing HMAC means test the default hash
916
                    if(doTest)
8,266✔
917
                        TestHash(DEFAULT_TEST_HASH, toTest);
7✔
918
                    else
919
                        // If not testing, then indicate that the hash needs to be
920
                        // tested because this uses HMAC
921
                        SET_BOTH(DEFAULT_TEST_HASH);
8,259✔
922
                    break;
923
#if ALG_SHA1
924
                  case ALG_SHA1_VALUE:
34,950✔
925
#endif // TPM_ALG_SHA1
926
#if ALG_SHA256
927
                  case ALG_SHA256_VALUE:
928
#endif // TPM_ALG_SHA256
929
#if ALG_SHA384
930
                  case ALG_SHA384_VALUE:
931
#endif // TPM_ALG_SHA384
932
#if ALG_SHA512
933
                  case ALG_SHA512_VALUE:
934
#endif // TPM_ALG_SHA512
935
                    // if SM3 is implemented its test is like any other hash, but there
936
                    // aren't any test vectors yet.
937
#if ALG_SM3_256
938
                    //            case ALG_SM3_256_VALUE:
939
#endif // TPM_ALG_SM3_256
940
                    if(doTest)
34,950✔
941
                        result = TestHash(alg, toTest);
1,914✔
942
                    break;
943
                    // RSA-dependent
944
#if ALG_RSA
945
                  case ALG_RSA_VALUE:
8,286✔
946
                    CLEAR_BOTH(alg);
8,286✔
947
                    if(doTest)
8,286✔
948
                        result = TestRsa(ALG_NULL_VALUE, toTest);
27✔
949
                    else
950
                        SET_BOTH(ALG_NULL_VALUE);
8,259✔
951
                    break;
952
                  case ALG_RSASSA_VALUE:
33,098✔
953
                  case ALG_RSAES_VALUE:
954
                  case ALG_RSAPSS_VALUE:
955
                  case ALG_OAEP_VALUE:
956
                  case ALG_NULL_VALUE:    // used or RSADP
957
                    if(doTest)
33,098✔
958
                        result = TestRsa(alg, toTest);
62✔
959
                    break;
960
#endif // ALG_RSA_VALUE
961
#if ALG_KDF1_SP800_108
962
                  case ALG_KDF1_SP800_108_VALUE:
8,325✔
963
                    if(doTest)
8,325✔
964
                        result = TestKDFa(toTest);
66✔
965
                    break;
966
#endif // ALG_KDF1_SP800_108_VALUE
967
#if ALG_ECC
968
                    // ECC dependent but no tests
969
                    //        case ALG_ECDAA_VALUE:
970
                    //        case ALG_ECMQV_VALUE:
971
                    //        case ALG_KDF1_SP800_56a_VALUE:
972
                    //        case ALG_KDF2_VALUE:
973
                    //        case ALG_MGF1_VALUE:
974
                  case ALG_ECC_VALUE:
8,266✔
975
                    CLEAR_BOTH(alg);
8,266✔
976
                    if(doTest)
8,266✔
977
                        result = TestEcc(ALG_ECDH_VALUE, toTest);
7✔
978
                    else
979
                        SET_BOTH(ALG_ECDH_VALUE);
8,259✔
980
                    break;
981
                  case ALG_ECDSA_VALUE:
25,059✔
982
                  case ALG_ECDH_VALUE:
983
                  case ALG_ECSCHNORR_VALUE:
984
                    //            case ALG_SM2_VALUE:
985
                    if(doTest)
25,059✔
986
                        result = TestEcc(alg, toTest);
282✔
987
                    break;
988
#endif // ALG_ECC_VALUE
989
                  default:
82,668✔
990
                    CLEAR_BIT(alg, *toTest);
82,668✔
991
                    break;
82,668✔
992
                }
993
            if(result != TPM_RC_SUCCESS)
266,773✔
994
                break;
995
        }
996
    return result;
10,744✔
997
}
998
#endif // SELF_TESTS
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc