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

stefanberger / libtpms / #2015

05 Aug 2025 12:00AM UTC coverage: 77.231% (+0.4%) from 76.783%
#2015

push

travis-ci

web-flow
Merge 3cee57d10 into c0a2f2222

36108 of 46753 relevant lines covered (77.23%)

122677.58 hits per line

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

60.99
/src/tpm2/BackwardsCompatibilityObject.c
1
/********************************************************************************/
2
/*                                                                                */
3
/*                Backwards compatibility stuff related to OBJECT                */
4
/*                             Written by Stefan Berger                                */
5
/*                       IBM Thomas J. Watson Research Center                        */
6
/*                                                                                */
7
/* (c) Copyright IBM Corporation 2017,2018.                                        */
8
/*                                                                                */
9
/* All rights reserved.                                                                */
10
/*                                                                                 */
11
/* Redistribution and use in source and binary forms, with or without                */
12
/* modification, are permitted provided that the following conditions are        */
13
/* met:                                                                                */
14
/*                                                                                 */
15
/* Redistributions of source code must retain the above copyright notice,        */
16
/* this list of conditions and the following disclaimer.                        */
17
/*                                                                                 */
18
/* Redistributions in binary form must reproduce the above copyright                */
19
/* notice, this list of conditions and the following disclaimer in the                */
20
/* documentation and/or other materials provided with the distribution.                */
21
/*                                                                                 */
22
/* Neither the names of the IBM Corporation nor the names of its                */
23
/* contributors may be used to endorse or promote products derived from                */
24
/* this software without specific prior written permission.                        */
25
/*                                                                                 */
26
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS                */
27
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT                */
28
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR        */
29
/* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT                */
30
/* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,        */
31
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT                */
32
/* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,        */
33
/* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY        */
34
/* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT                */
35
/* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE        */
36
/* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.                */
37
/********************************************************************************/
38

39
#include <assert.h>
40

41
#include "BackwardsCompatibilityObject.h"
42

43
/* The following are data structure from libtpms 0.7.x with RSA 2048 support
44
 * that help to resume key and hash contexts (TPM2_ContextSave/Load) from this
45
 * earlier version. All structures that have different sizes in 0.8 are found
46
 * here.
47
 */
48
typedef union {
49
    struct {
50
        UINT16                  size;
51
        BYTE                    buffer[2048/8];
52
    }            t;
53
    TPM2B        b;
54
} RSA2048_TPM2B_PUBLIC_KEY_RSA;
55

56
typedef union {
57
    TPM2B_DIGEST                 keyedHash;
58
    TPM2B_DIGEST                 sym;
59
    RSA2048_TPM2B_PUBLIC_KEY_RSA rsa;
60
    TPMS_ECC_POINT               ecc;
61
//    TPMS_DERIVE                derive;
62
} RSA2048_TPMU_PUBLIC_ID;
63

64
typedef struct {
65
    TPMI_ALG_PUBLIC         type;
66
    TPMI_ALG_HASH           nameAlg;
67
    TPMA_OBJECT             objectAttributes;
68
    TPM2B_DIGEST            authPolicy;
69
    TPMU_PUBLIC_PARMS       parameters;
70
    RSA2048_TPMU_PUBLIC_ID  unique;
71
} RSA2048_TPMT_PUBLIC;
72

73
MUST_BE(sizeof(RSA2048_TPMT_PUBLIC) == 356);
74

75
typedef union {
76
    struct {
77
        UINT16                  size;
78
        BYTE                    buffer[((2048/8)/2)*5];
79
    }            t;
80
    TPM2B        b;
81
} RSA2048_TPM2B_PRIVATE_KEY_RSA;
82

83
MUST_BE(sizeof(RSA2048_TPM2B_PRIVATE_KEY_RSA) == 642);
84

85
typedef union {
86
    struct {
87
        UINT16                  size;
88
        BYTE                    buffer[((2048/8)/2)*5];
89
    }            t;
90
    TPM2B        b;
91
} RSA2048_TPM2B_PRIVATE_VENDOR_SPECIFIC;
92

93
typedef union {
94
    RSA2048_TPM2B_PRIVATE_KEY_RSA         rsa;
95
    TPM2B_ECC_PARAMETER                   ecc;
96
    TPM2B_SENSITIVE_DATA                  bits;
97
    TPM2B_SYM_KEY                         sym;
98
    RSA2048_TPM2B_PRIVATE_VENDOR_SPECIFIC any;
99
} RSA2048_TPMU_SENSITIVE_COMPOSITE;
100

101
typedef struct {
102
    TPMI_ALG_PUBLIC                  sensitiveType;
103
    TPM2B_AUTH                       authValue;
104
    TPM2B_DIGEST                     seedValue;
105
    RSA2048_TPMU_SENSITIVE_COMPOSITE sensitive;
106
} RSA2048_TPMT_SENSITIVE;
107

108
MUST_BE(sizeof(RSA2048_TPMT_SENSITIVE) == 776);
109

110
BN_TYPE(old_prime, (2048 / 2));
111

112
typedef struct RSA2048_privateExponent
113
{
114
    bn_old_prime_t          Q;
115
    bn_old_prime_t          dP;
116
    bn_old_prime_t          dQ;
117
    bn_old_prime_t          qInv;
118
} RSA2048_privateExponent_t;
119

120
static inline void CopyFromOldPrimeT(ci_prime_t *dst,
121
                                     const bn_old_prime_t *src)
122
{
123
    dst->allocated = src->allocated;
×
124
    dst->size = src->size;
×
125
    memcpy(dst->d, src->d, sizeof(src->d));
×
126
}
127

128
MUST_BE(sizeof(RSA2048_privateExponent_t) == 608);
129

130
typedef struct RSA2048_OBJECT
131
{
132
    // The attributes field is required to be first followed by the publicArea.
133
    // This allows the overlay of the object structure and a sequence structure
134
    OBJECT_ATTRIBUTES   attributes;         // object attributes
135
    RSA2048_TPMT_PUBLIC     publicArea;         // public area of an object
136
    RSA2048_TPMT_SENSITIVE  sensitive;          // sensitive area of an object
137
    RSA2048_privateExponent_t privateExponent;  // Additional field for the private
138
    TPM2B_NAME          qualifiedName;      // object qualified name
139
    TPMI_DH_OBJECT      evictHandle;        // if the object is an evict object,
140
    // the original handle is kept here.
141
    // The 'working' handle will be the
142
    // handle of an object slot.
143
    TPM2B_NAME          name;               // Name of the object name. Kept here
144
    // to avoid repeatedly computing it.
145

146
    // libtpms added: OBJECT lies in NVRAM; to avoid that it needs different number
147
    // of bytes on 32 bit and 64 bit architectures, we need to make sure it's the
148
    // same size; simple padding at the end works here
149
    UINT32             _pad;
150
} RSA2048_OBJECT;
151

152
MUST_BE(sizeof(RSA2048_OBJECT) == 1896);
153

154
TPMI_RH_HIERARCHY ObjectGetHierarchyFromAttributes(OBJECT* object)
68,819✔
155
{
156
    if(object->attributes.spsHierarchy)
68,819✔
157
        return TPM_RH_OWNER;
158

159
    if(object->attributes.epsHierarchy)
1,217✔
160
        return TPM_RH_ENDORSEMENT;
161

162
    if(object->attributes.ppsHierarchy)
110✔
163
        return TPM_RH_PLATFORM;
22✔
164

165
    return TPM_RH_NULL;
166
}
167

168
static void RSA2048_OBJECT_To_OBJECT(OBJECT* dest, const RSA2048_OBJECT* src)
169
{
170
    dest->attributes = src->attributes;
×
171
    dest->hierarchy = ObjectGetHierarchyFromAttributes(dest);
×
172

173
    dest->publicArea.type = src->publicArea.type;
×
174
    dest->publicArea.nameAlg = src->publicArea.nameAlg;
×
175
    dest->publicArea.objectAttributes = src->publicArea.objectAttributes;
×
176
    dest->publicArea.authPolicy = src->publicArea.authPolicy;
×
177
    dest->publicArea.parameters = src->publicArea.parameters;
×
178
    /* the unique part can be one or two TPM2B's */
179
    switch (dest->publicArea.type) {
×
180
    case TPM_ALG_KEYEDHASH:
×
181
        MemoryCopy2B(&dest->publicArea.unique.keyedHash.b,
×
182
                     &src->publicArea.unique.keyedHash.b,
183
                     sizeof(src->publicArea.unique.keyedHash.t.buffer));
184
        memset(&dest->privateExponent, 0, sizeof(dest->privateExponent));
×
185
        break;
186
    case TPM_ALG_SYMCIPHER:
×
187
        MemoryCopy2B(&dest->publicArea.unique.sym.b,
×
188
                     &src->publicArea.unique.sym.b,
189
                     sizeof(src->publicArea.unique.sym.t.buffer));
190
        memset(&dest->privateExponent, 0, sizeof(dest->privateExponent));
×
191
        break;
192
    case TPM_ALG_RSA:
×
193
        MemoryCopy2B(&dest->publicArea.unique.rsa.b,
×
194
                     &src->publicArea.unique.rsa.b,
195
                     sizeof(src->publicArea.unique.rsa.t.buffer));
196

197
        CopyFromOldPrimeT(&dest->privateExponent.Q, &src->privateExponent.Q);
×
198
        CopyFromOldPrimeT(&dest->privateExponent.dP, &src->privateExponent.dP);
×
199
        CopyFromOldPrimeT(&dest->privateExponent.dQ, &src->privateExponent.dQ);
×
200
        CopyFromOldPrimeT(&dest->privateExponent.qInv, &src->privateExponent.qInv);
×
201
        break;
×
202
    case TPM_ALG_ECC:
×
203
        MemoryCopy2B(&dest->publicArea.unique.ecc.x.b,
×
204
                     &src->publicArea.unique.ecc.x.b,
205
                     sizeof(src->publicArea.unique.ecc.x.t.buffer));
206
        MemoryCopy2B(&dest->publicArea.unique.ecc.y.b,
×
207
                     &src->publicArea.unique.ecc.y.b,
208
                     sizeof(src->publicArea.unique.ecc.y.t.buffer));
209
        memset(&dest->privateExponent, 0, sizeof(dest->privateExponent));
×
210
        break;
211
    }
212

213
    dest->sensitive.sensitiveType = src->sensitive.sensitiveType;
×
214
    dest->sensitive.authValue = src->sensitive.authValue;
×
215
    dest->sensitive.seedValue = src->sensitive.seedValue;
×
216
    /* The RSA2048_TPMU_SENSITIVE_COMPOSITE is always a TPM2B */
217
    MemoryCopy2B(&dest->sensitive.sensitive.any.b,
×
218
                 &src->sensitive.sensitive.any.b,
219
                 sizeof(src->sensitive.sensitive.any.t.buffer));
220

221
    dest->qualifiedName = src->qualifiedName;
×
222
    dest->evictHandle = src->evictHandle;
×
223
    dest->name = src->name;
×
224
}
225

226
// Convert an RSA2048_OBJECT that was copied into buffer using MemoryCopy
227
TPM_RC
228
RSA2048_OBJECT_Buffer_To_OBJECT(OBJECT* newObject, BYTE* buffer, INT32 size)
×
229
{
230
    RSA2048_OBJECT    oldObject;
×
231
    TPM_RC        rc = 0;
×
232

233
    // get the attributes
234
    MemoryCopy(newObject, buffer, sizeof(newObject->attributes));
×
235
    if (ObjectIsSequence(newObject))
×
236
        {
237
            /* resuming old hash contexts is not supported */
238
            rc = TPM_RC_DISABLED;
239
        }
240
    else
241
        {
242
            if (size != sizeof(RSA2048_OBJECT))
×
243
                return TPM_RC_SIZE;
244
            MemoryCopy(&oldObject, buffer, sizeof(RSA2048_OBJECT));
×
245

246
            /* fill the newObject with the contents of the oldObject */
247
            RSA2048_OBJECT_To_OBJECT(newObject, &oldObject);
×
248
    }
249

250
    return rc;
251
}
252

253
/* The following are data structure from libtpms 0.9.x with RSA 3072 support.
254
 */
255
typedef union {
256
    struct {
257
        UINT16                  size;
258
        BYTE                    buffer[3072/8];
259
    }            t;
260
    TPM2B        b;
261
} RSA3072_TPM2B_PUBLIC_KEY_RSA;
262

263
typedef union {
264
    TPM2B_DIGEST                 keyedHash;
265
    TPM2B_DIGEST                 sym;
266
    RSA3072_TPM2B_PUBLIC_KEY_RSA rsa;
267
    TPMS_ECC_POINT               ecc;
268
    TPMS_DERIVE                  derive;
269
} RSA3072_TPMU_PUBLIC_ID;
270
MUST_BE(sizeof(TPM2B_DIGEST) == 2 + BITS_TO_BYTES(512));
271
MUST_BE(sizeof(TPMS_ECC_POINT) == 2 * (2 + BITS_TO_BYTES(638)));
272
MUST_BE(sizeof(TPMS_DERIVE) == 2 * (2 + 32));
273

274
typedef struct {
275
    TPMI_ALG_PUBLIC         type;
276
    TPMI_ALG_HASH           nameAlg;
277
    TPMA_OBJECT             objectAttributes;
278
    TPM2B_DIGEST            authPolicy;
279
    TPMU_PUBLIC_PARMS       parameters;
280
    RSA3072_TPMU_PUBLIC_ID          unique;
281
} RSA3072_TPMT_PUBLIC;
282
MUST_BE(sizeof(RSA3072_TPMT_PUBLIC) == 484);
283

284
typedef union {
285
    struct {
286
        UINT16                  size;
287
        BYTE                    buffer[((3072 / 8) / 2) * 5];
288
    }            t;
289
    TPM2B        b;
290
} RSA3072_TPM2B_PRIVATE_KEY_RSA;
291
MUST_BE(sizeof(RSA3072_TPM2B_PRIVATE_KEY_RSA) == 962);
292

293
typedef union {
294
    struct {
295
        UINT16                  size;
296
        BYTE                    buffer[((3072 / 8) / 2) * 5];
297
    }            t;
298
    TPM2B        b;
299
} RSA3072_TPM2B_PRIVATE_VENDOR_SPECIFIC;
300

301
typedef union {
302
    RSA3072_TPM2B_PRIVATE_KEY_RSA         rsa;
303
    TPM2B_ECC_PARAMETER                   ecc;
304
    TPM2B_SENSITIVE_DATA                  bits;
305
    TPM2B_SYM_KEY                         sym;
306
    RSA3072_TPM2B_PRIVATE_VENDOR_SPECIFIC any;
307
} RSA3072_TPMU_SENSITIVE_COMPOSITE;
308
MUST_BE(sizeof(TPM2B_ECC_PARAMETER) == 2 + BITS_TO_BYTES(638) /* BN P638 */);
309
MUST_BE(sizeof(TPM2B_SENSITIVE_DATA) == 2 + 128);
310
MUST_BE(sizeof(TPM2B_SYM_KEY) == 2 + BITS_TO_BYTES(256));
311

312
typedef struct {
313
    TPMI_ALG_PUBLIC             sensitiveType;
314
    TPM2B_AUTH                  authValue;
315
    TPM2B_DIGEST                seedValue;
316
    RSA3072_TPMU_SENSITIVE_COMPOSITE    sensitive;
317
} RSA3072_TPMT_SENSITIVE;
318
MUST_BE(sizeof(TPM2B_AUTH) == 2 + BITS_TO_BYTES(512));
319
MUST_BE(sizeof(TPM2B_DIGEST) == 2 + BITS_TO_BYTES(512));
320
MUST_BE(sizeof(RSA3072_TPMT_SENSITIVE) == 1096);
321

322
BN_TYPE(rsa3072_prime, (3072 / 2));
323

324
typedef struct RSA3072_privateExponent
325
{
326
    bn_rsa3072_prime_t          Q;
327
    bn_rsa3072_prime_t          dP;
328
    bn_rsa3072_prime_t          dQ;
329
    bn_rsa3072_prime_t          qInv;
330
} RSA3072_privateExponent_t;
331
MUST_BE(sizeof(RSA3072_privateExponent_t) == 864);
332

333
typedef struct RSA3072_OBJECT
334
{
335
    // The attributes field is required to be first followed by the publicArea.
336
    // This allows the overlay of the object structure and a sequence structure
337
    OBJECT_ATTRIBUTES     attributes;     // object attributes
338
    RSA3072_TPMT_PUBLIC     publicArea;     // public area of an object
339
    RSA3072_TPMT_SENSITIVE  sensitive;      // sensitive area of an object
340
#if 1                                        // libtpms added begin: keep
341
    RSA3072_privateExponent_t privateExponent;    // Additional field for the private
342
#endif                                        // libtpms added end
343
    TPM2B_NAME        qualifiedName;  // object qualified name
344
    TPMI_DH_OBJECT    evictHandle;    // if the object is an evict object,
345
    // the original handle is kept here.
346
    // The 'working' handle will be the
347
    // handle of an object slot.
348
    TPM2B_NAME name;                  // Name of the object name. Kept here
349
    // to avoid repeatedly computing it.
350

351
    // libtpms added: SEED_COMPAT_LEVEL to use for deriving child keys
352
    SEED_COMPAT_LEVEL   seedCompatLevel;
353
    // libtpms added: OBJECT lies in NVRAM; to avoid that it needs different number
354
    // of bytes on 32 bit and 64 bit architectures, we need to make sure it's the
355
    // same size; simple padding at the end works here
356
    UINT8               _pad[3];
357
} RSA3072_OBJECT;
358
MUST_BE(sizeof(RSA3072_OBJECT) == 2600);
359

360
static inline void CopyFromRSA3072PrimeT(ci_prime_t* dst,
269,268✔
361
                                       const bn_rsa3072_prime_t* src)
362
{
363
    dst->allocated = src->allocated;
269,268✔
364
    dst->size = src->size;
269,268✔
365
    memcpy(dst->d, src->d, sizeof(src->d));
269,268✔
366
}
269,268✔
367

368
static inline void CopyToRSA3072PrimeT(bn_rsa3072_prime_t* dst,
1,732✔
369
                                       const ci_prime_t* src)
370
{
371
    dst->allocated = src->allocated;
1,732✔
372
    dst->size = src->size;
1,732✔
373
    memcpy(dst->d, src->d, sizeof(dst->d));
1,732✔
374
}
1,732✔
375

376
static void RSA3072_OBJECT_To_OBJECT(OBJECT* dest, const RSA3072_OBJECT* src)
67,513✔
377
{
378
    dest->attributes = src->attributes;
67,513✔
379
    dest->hierarchy = ObjectGetHierarchyFromAttributes(dest);
67,513✔
380

381
    dest->publicArea.type = src->publicArea.type;
67,513✔
382
    dest->publicArea.nameAlg = src->publicArea.nameAlg;
67,513✔
383
    dest->publicArea.objectAttributes = src->publicArea.objectAttributes;
67,513✔
384
    dest->publicArea.authPolicy = src->publicArea.authPolicy;
67,513✔
385
    dest->publicArea.parameters = src->publicArea.parameters;
67,513✔
386
    /* the unique part can be one or two TPM2B's */
387
    switch (dest->publicArea.type) {
67,513✔
388
    case TPM_ALG_KEYEDHASH:
×
389
        MemoryCopy2B(&dest->publicArea.unique.keyedHash.b,
×
390
                     &src->publicArea.unique.keyedHash.b,
391
                     sizeof(src->publicArea.unique.keyedHash.t.buffer));
392
        memset(&dest->privateExponent, 0, sizeof(dest->privateExponent));
×
393
        break;
394
    case TPM_ALG_SYMCIPHER:
×
395
        MemoryCopy2B(&dest->publicArea.unique.sym.b,
×
396
                     &src->publicArea.unique.sym.b,
397
                     sizeof(src->publicArea.unique.sym.t.buffer));
398
        memset(&dest->privateExponent, 0, sizeof(dest->privateExponent));
×
399
        break;
400
    case TPM_ALG_RSA:
67,317✔
401
        MemoryCopy2B(&dest->publicArea.unique.rsa.b,
67,317✔
402
                     &src->publicArea.unique.rsa.b,
403
                     sizeof(src->publicArea.unique.rsa.t.buffer));
404

405
        CopyFromRSA3072PrimeT(&dest->privateExponent.Q, &src->privateExponent.Q);
67,317✔
406
        CopyFromRSA3072PrimeT(&dest->privateExponent.dP, &src->privateExponent.dP);
67,317✔
407
        CopyFromRSA3072PrimeT(&dest->privateExponent.dQ, &src->privateExponent.dQ);
67,317✔
408
        CopyFromRSA3072PrimeT(&dest->privateExponent.qInv, &src->privateExponent.qInv);
67,317✔
409
        break;
67,317✔
410
    case TPM_ALG_ECC:
196✔
411
        MemoryCopy2B(&dest->publicArea.unique.ecc.x.b,
196✔
412
                     &src->publicArea.unique.ecc.x.b,
413
                     sizeof(src->publicArea.unique.ecc.x.t.buffer));
414
        MemoryCopy2B(&dest->publicArea.unique.ecc.y.b,
196✔
415
                     &src->publicArea.unique.ecc.y.b,
416
                     sizeof(src->publicArea.unique.ecc.y.t.buffer));
417
        memset(&dest->privateExponent, 0, sizeof(dest->privateExponent));
196✔
418
        break;
419
    }
420

421
    dest->sensitive.sensitiveType = src->sensitive.sensitiveType;
67,513✔
422
    dest->sensitive.authValue = src->sensitive.authValue;
67,513✔
423
    dest->sensitive.seedValue = src->sensitive.seedValue;
67,513✔
424
    /* The OLD_TPMU_SENSITIVE_COMPOSITE is always a TPM2B */
425
    MemoryCopy2B(&dest->sensitive.sensitive.any.b,
67,513✔
426
                 &src->sensitive.sensitive.any.b,
427
                 sizeof(src->sensitive.sensitive.any.t.buffer));
428

429
    dest->qualifiedName = src->qualifiedName;
67,513✔
430
    dest->evictHandle = src->evictHandle;
67,513✔
431
    dest->name = src->name;
67,513✔
432
    dest->seedCompatLevel = src->seedCompatLevel;
67,513✔
433
}
67,513✔
434

435
/* Convert an OBJECT to the (smaller) RSA3072_OBJECT. */
436
static void OBJECT_To_RSA3072_OBJECT(RSA3072_OBJECT* dest, const OBJECT* src)
463✔
437
{
438
    dest->attributes = src->attributes;
463✔
439

440
    dest->publicArea.type = src->publicArea.type;
463✔
441
    dest->publicArea.nameAlg = src->publicArea.nameAlg;
463✔
442
    dest->publicArea.objectAttributes = src->publicArea.objectAttributes;
463✔
443
    dest->publicArea.authPolicy = src->publicArea.authPolicy;
463✔
444
    dest->publicArea.parameters = src->publicArea.parameters;
463✔
445
    /* the unique part can be one or two TPM2B's */
446
    switch (dest->publicArea.type) {
463✔
447
    case TPM_ALG_KEYEDHASH:
×
448
        MemoryCopy2B(&dest->publicArea.unique.keyedHash.b,
×
449
                     &src->publicArea.unique.keyedHash.b,
450
                     sizeof(dest->publicArea.unique.keyedHash.t.buffer));
451
        break;
×
452
    case TPM_ALG_SYMCIPHER:
×
453
        MemoryCopy2B(&dest->publicArea.unique.sym.b,
×
454
                     &src->publicArea.unique.sym.b,
455
                     sizeof(dest->publicArea.unique.sym.t.buffer));
456
        break;
×
457
    case TPM_ALG_RSA:
433✔
458
        MemoryCopy2B(&dest->publicArea.unique.rsa.b,
433✔
459
                     &src->publicArea.unique.rsa.b,
460
                     sizeof(dest->publicArea.unique.rsa.t.buffer));
461

462
        CopyToRSA3072PrimeT(&dest->privateExponent.Q, &src->privateExponent.Q);
433✔
463
        CopyToRSA3072PrimeT(&dest->privateExponent.dP, &src->privateExponent.dP);
433✔
464
        CopyToRSA3072PrimeT(&dest->privateExponent.dQ, &src->privateExponent.dQ);
433✔
465
        CopyToRSA3072PrimeT(&dest->privateExponent.qInv, &src->privateExponent.qInv);
433✔
466
        break;
433✔
467
    case TPM_ALG_ECC:
30✔
468
        MemoryCopy2B(&dest->publicArea.unique.ecc.x.b,
30✔
469
                     &src->publicArea.unique.ecc.x.b,
470
                     sizeof(dest->publicArea.unique.ecc.x.t.buffer));
471
        MemoryCopy2B(&dest->publicArea.unique.ecc.y.b,
30✔
472
                     &src->publicArea.unique.ecc.y.b,
473
                     sizeof(dest->publicArea.unique.ecc.y.t.buffer));
474
        break;
30✔
475
    }
476

477
    dest->sensitive.sensitiveType = src->sensitive.sensitiveType;
463✔
478
    dest->sensitive.authValue = src->sensitive.authValue;
463✔
479
    dest->sensitive.seedValue = src->sensitive.seedValue;
463✔
480
    /* The OLD_TPMU_SENSITIVE_COMPOSITE is always a TPM2B */
481
    MemoryCopy2B(&dest->sensitive.sensitive.any.b,
463✔
482
                 &src->sensitive.sensitive.any.b,
483
                 sizeof(dest->sensitive.sensitive.any.t.buffer));
484

485
    dest->qualifiedName = src->qualifiedName;
463✔
486
    dest->evictHandle = src->evictHandle;
463✔
487
    dest->name = src->name;
463✔
488
    dest->seedCompatLevel = src->seedCompatLevel;
463✔
489
    MemorySet(dest->_pad, 0, sizeof(dest->_pad));
463✔
490
}
463✔
491

492
TPM_RC
493
RSA3072_OBJECT_Buffer_To_OBJECT(OBJECT *object, BYTE *buffer, INT32 size)
67,513✔
494
{
495
    RSA3072_OBJECT rsa3072_object;
67,513✔
496

497
    if (size != sizeof(RSA3072_OBJECT))
67,513✔
498
        return TPM_RC_SIZE;
499

500
    MemoryCopy(&rsa3072_object, buffer, size);
67,513✔
501

502
    RSA3072_OBJECT_To_OBJECT(object, &rsa3072_object);
67,513✔
503

504
    return 0;
67,513✔
505
}
506

507
UINT32 OBJECT_To_Buffer_As_RSA3072_OBJECT(OBJECT* object, BYTE* buffer, UINT32 size)
463✔
508
{
509
    RSA3072_OBJECT rsa3072_object;
463✔
510
    UINT32         written = sizeof(rsa3072_object);
463✔
511

512
    OBJECT_To_RSA3072_OBJECT(&rsa3072_object, object);
463✔
513

514
    pAssert(size >= sizeof(rsa3072_object));
463✔
515
    MemoryCopy(buffer, &rsa3072_object, sizeof(rsa3072_object));
463✔
516

517
    return written;
463✔
518
}
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