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

stefanberger / libtpms / #2001

10 Jun 2025 05:34PM UTC coverage: 76.734% (-0.5%) from 77.211%
#2001

push

travis-ci

web-flow
Merge 953b57ed4 into 9d6d76cc6

26 of 29 new or added lines in 2 files covered. (89.66%)

2807 existing lines in 74 files now uncovered.

33291 of 43385 relevant lines covered (76.73%)

61752.99 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 1370 2018-11-02 19:39:07Z 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 - 2018                                */
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,875✔
101
         TPM_ALG_ID          hashAlg,
102
         ALGORITHM_VECTOR    *toTest
103
         )
104
{
105
    TPM2B_DIGEST      computed;  // value computed
1,875✔
106
    HMAC_STATE        state;
1,875✔
107
    UINT16                   digestSize;
1,875✔
108
    const TPM2B             *testDigest = NULL;
1,875✔
109
    //    TPM2B_TYPE(HMAC_BLOCK, DEFAULT_TEST_HASH_BLOCK_SIZE);
110
    pAssert(hashAlg != ALG_NULL_VALUE);
1,875✔
111
    switch(hashAlg)
1,875✔
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:
363✔
120
            testDigest = &c_SHA256_digest.b;
363✔
121
            break;
363✔
122
#endif
123
#if ALG_SHA384
124
          case ALG_SHA384_VALUE:
300✔
125
            testDigest = &c_SHA384_digest.b;
300✔
126
            break;
300✔
127
#endif
128
#if ALG_SHA512
129
          case ALG_SHA512_VALUE:
610✔
130
            testDigest = &c_SHA512_digest.b;
610✔
131
            break;
610✔
132
#endif
133
#if ALG_SM3_256
134
          case ALG_SM3_256_VALUE:
135
            testDigest = &c_SM3_256_digest.b;
136
            break;
137
#endif
UNCOV
138
          default:
×
UNCOV
139
            FAIL(FATAL_ERROR_INTERNAL);
×
140
        }
141
    // Clear the to-test bits
142
    CLEAR_BOTH(hashAlg);
1,875✔
143
    // Set the HMAC key to twice the digest size
144
    digestSize = CryptHashGetDigestSize(hashAlg);
1,875✔
145
    CryptHmacStart(&state, hashAlg, digestSize * 2,
1,875✔
146
                   (BYTE *)c_hashTestKey.t.buffer);
147
    CryptDigestUpdate(&state.hashState, 2 * CryptHashGetBlockSize(hashAlg),
1,875✔
148
                      (BYTE *)c_hashTestData.t.buffer);
149
    computed.t.size = digestSize;
1,875✔
150
    CryptHmacEnd(&state, digestSize, computed.t.buffer);
1,875✔
151
    if((testDigest->size != computed.t.size)
1,875✔
152
       || (memcmp(testDigest->buffer, computed.t.buffer, computed.b.size) != 0)) {
1,875✔
UNCOV
153
        SELF_TEST_FAILURE;
×
154
    }
155
    return TPM_RC_SUCCESS;
1,875✔
156
}
157
// libtpms added begin
158
#if ALG_CMAC
159
static TPM_RC
160
TestCMAC(
23✔
161
         ALGORITHM_VECTOR    *toTest
162
         )
163
{
164
    SMAC_STATE          state;
23✔
165
    UINT16              copied;
23✔
166
    BYTE                out[MAX_SYM_BLOCK_SIZE];
23✔
167
    UINT32              outSize = sizeof(out);
23✔
168
    UINT16              blocksize;
23✔
169
    int                 i;
23✔
170
    TPMU_PUBLIC_PARMS   cmac_keyParms;
23✔
171

172
    // initializing this statically seems impossible with gcc...
173
    cmac_keyParms.symDetail.sym.algorithm = ALG_AES_VALUE;
23✔
174
    cmac_keyParms.symDetail.sym.keyBits.sym = 128;
23✔
175

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

231
    // libtpms added beging
232
    if (test->dataOut[mode - ALG_CTR_VALUE] == NULL)
258✔
233
        return;
42✔
234
    // libtpms added end
235

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

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