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

stefanberger / libtpms / #2063

11 Feb 2026 02:58PM UTC coverage: 77.18% (-0.02%) from 77.195%
#2063

push

travis-ci

web-flow
Merge c175b6f1e into c2a8109f8

1174 of 1370 new or added lines in 95 files covered. (85.69%)

2190 existing lines in 89 files now uncovered.

36347 of 47094 relevant lines covered (77.18%)

125164.35 hits per line

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

93.44
/src/tpm2/LibtpmsCallbacks.c
1
// SPDX-License-Identifier: BSD-2-Clause
2

3
// (c) Copyright IBM Corporation 2018.
4

5
#include <stdint.h>
6
#include <string.h>
7

8
#include "Platform.h"
9
#include "LibtpmsCallbacks.h"
10
#include "NVMarshal.h"
11

12
#define TPM_HAVE_TPM2_DECLARATIONS
13
#include "tpm_library_intern.h"
14
#include "tpm_error.h"
15
#include "tpm_nvfilename.h"
16

17
int
18
libtpms_plat__NVEnable(void)
12,514✔
19
{
20
    unsigned char *data = NULL;
12,514✔
21
    uint32_t length = 0;
12,514✔
22
    struct libtpms_callbacks *cbs = TPMLIB_GetCallbacks();
12,514✔
23
    TPM_RC rc;
12,514✔
24
    bool is_empty_state;
12,514✔
25

26
    /* try to get state blob set via TPMLIB_SetState() */
27
    GetCachedState(TPMLIB_STATE_PERMANENT, &data, &length, &is_empty_state);
12,514✔
28
    if (is_empty_state) {
12,514✔
UNCOV
29
        memset(s_NV, 0, NV_MEMORY_SIZE);
×
UNCOV
30
        return 0;
×
31
    }
32

33
    if (data == NULL && cbs->tpm_nvram_loaddata) {
12,514✔
34
        uint32_t tpm_number = 0;
8,504✔
35
        const char *name = TPM_PERMANENT_ALL_NAME;
8,504✔
36
        TPM_RESULT ret;
8,504✔
37

38
        ret = cbs->tpm_nvram_loaddata(&data, &length, tpm_number, name);
8,504✔
39
        switch (ret) {
8,504✔
40
        case TPM_RETRY:
4,142✔
41
            if (!cbs->tpm_nvram_storedata) {
4,142✔
42
                return -1;
43
            }
44
            memset(s_NV, 0, NV_MEMORY_SIZE);
4,142✔
45
            return 0;
4,142✔
46

47
        case TPM_SUCCESS:
48
            /* got the data -- unmarshal them... */
49
            break;
50

51
        case TPM_FAIL:
52
        default:
53
            return -1;
54
        }
55
    }
56

57
    if (data) {
8,356✔
58
        unsigned char *buffer = data;
8,324✔
59
        INT32 size = length;
8,324✔
60

61
        rc = PERSISTENT_ALL_Unmarshal(&buffer, &size);
8,324✔
62
        free(data);
8,324✔
63
        if (rc != TPM_RC_SUCCESS)
8,324✔
64
            return -1;
65
         return 0;
8,324✔
66
    }
67
    return LIBTPMS_CALLBACK_FALLTHROUGH; /* -2 */
68
}
69

70
int
71
libtpms_plat__NVDisable(
8,352✔
72
                 void
73
                 )
74
{
75
    struct libtpms_callbacks *cbs = TPMLIB_GetCallbacks();
8,352✔
76

77
    if (cbs->tpm_nvram_loaddata)
8,352✔
78
        return 0;
8,334✔
79
    return LIBTPMS_CALLBACK_FALLTHROUGH; /* -2 */
80
}
81

82
int
83
libtpms_plat__IsNvAvailable(
21,957✔
84
                     void
85
                     )
86
{
87
    struct libtpms_callbacks *cbs = TPMLIB_GetCallbacks();
21,957✔
88

89
    if (cbs->tpm_nvram_loaddata &&
21,957✔
90
        cbs->tpm_nvram_storedata) {
21,915✔
91
        return 1;
21,915✔
92
    }
93
    return LIBTPMS_CALLBACK_FALLTHROUGH; /* -2 */
94
}
95

96
int
97
libtpms_plat__NvCommit(
14,931✔
98
                void
99
                )
100
{
101
    struct libtpms_callbacks *cbs = TPMLIB_GetCallbacks();
14,931✔
102

103
    if (cbs->tpm_nvram_storedata) {
14,931✔
104
        uint32_t tpm_number = 0;
14,904✔
105
        const char *name = TPM_PERMANENT_ALL_NAME;
14,904✔
106
        TPM_RESULT ret;
14,904✔
107
        BYTE *buf;
14,904✔
108
        uint32_t buflen;
14,904✔
109

110
        ret = TPM2_PersistentAllStore(&buf, &buflen);
14,904✔
111
        if (ret != TPM_SUCCESS)
14,904✔
UNCOV
112
            return ret;
×
113

114
        ret = cbs->tpm_nvram_storedata(buf, buflen,
14,904✔
115
                                       tpm_number, name);
116
        free(buf);
14,904✔
117
        if (ret == TPM_SUCCESS)
14,904✔
118
            return 0;
119

UNCOV
120
        return -1;
×
121
    }
122
    return LIBTPMS_CALLBACK_FALLTHROUGH; /* -2 */
123
}
124

125
int
126
libtpms_plat__PhysicalPresenceAsserted(
12✔
127
                                BOOL *pp
128
                                )
129
{
130
    struct libtpms_callbacks *cbs = TPMLIB_GetCallbacks();
12✔
131

132
    if (cbs->tpm_io_getphysicalpresence) {
12✔
133
        uint32_t tpm_number = 0;
12✔
134
        TPM_RESULT res;
12✔
135
        unsigned char mypp;
12✔
136

137
        res = cbs->tpm_io_getphysicalpresence(&mypp, tpm_number);
12✔
138
        if (res == TPM_SUCCESS) {
12✔
139
            *pp = mypp;
12✔
140
            return 0;
12✔
141
        }
142
    }
143
    return LIBTPMS_CALLBACK_FALLTHROUGH;
144
}
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