1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /***********************************************************************;
3  * Copyright (c) 2015 - 2017, Intel Corporation
4  * All rights reserved.
5  ***********************************************************************/
6 
7 #ifdef HAVE_CONFIG_H
8 #include <config.h>
9 #endif
10 
11 #include "tss2_tpm2_types.h"
12 #include "tss2_mu.h"
13 #include "sysapi_util.h"
14 
Tss2_Sys_VerifySignature_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_OBJECT keyHandle,const TPM2B_DIGEST * digest,const TPMT_SIGNATURE * signature)15 TSS2_RC Tss2_Sys_VerifySignature_Prepare(
16     TSS2_SYS_CONTEXT *sysContext,
17     TPMI_DH_OBJECT keyHandle,
18     const TPM2B_DIGEST *digest,
19     const TPMT_SIGNATURE *signature)
20 {
21     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
22     TSS2_RC rval;
23 
24     if (!ctx || !signature)
25         return TSS2_SYS_RC_BAD_REFERENCE;
26 
27     rval = CommonPreparePrologue(ctx, TPM2_CC_VerifySignature);
28     if (rval)
29         return rval;
30 
31     rval = Tss2_MU_UINT32_Marshal(keyHandle, ctx->cmdBuffer,
32                                   ctx->maxCmdSize,
33                                   &ctx->nextData);
34     if (rval)
35         return rval;
36 
37     if (!digest) {
38         ctx->decryptNull = 1;
39 
40         rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
41                                       ctx->maxCmdSize,
42                                       &ctx->nextData);
43     } else {
44 
45         rval = Tss2_MU_TPM2B_DIGEST_Marshal(digest, ctx->cmdBuffer,
46                                             ctx->maxCmdSize,
47                                             &ctx->nextData);
48     }
49 
50     if (rval)
51         return rval;
52 
53     rval = Tss2_MU_TPMT_SIGNATURE_Marshal(signature, ctx->cmdBuffer,
54                                           ctx->maxCmdSize,
55                                           &ctx->nextData);
56     if (rval)
57         return rval;
58 
59     ctx->decryptAllowed = 1;
60     ctx->encryptAllowed = 0;
61     ctx->authAllowed = 1;
62 
63     return CommonPrepareEpilogue(ctx);
64 }
65 
Tss2_Sys_VerifySignature_Complete(TSS2_SYS_CONTEXT * sysContext,TPMT_TK_VERIFIED * validation)66 TSS2_RC Tss2_Sys_VerifySignature_Complete(
67     TSS2_SYS_CONTEXT *sysContext,
68     TPMT_TK_VERIFIED *validation)
69 {
70     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
71     TSS2_RC rval;
72 
73     if (!ctx)
74         return TSS2_SYS_RC_BAD_REFERENCE;
75 
76     rval = CommonComplete(ctx);
77     if (rval)
78         return rval;
79 
80     return Tss2_MU_TPMT_TK_VERIFIED_Unmarshal(ctx->cmdBuffer,
81                                               ctx->maxCmdSize,
82                                               &ctx->nextData, validation);
83 }
84 
Tss2_Sys_VerifySignature(TSS2_SYS_CONTEXT * sysContext,TPMI_DH_OBJECT keyHandle,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPM2B_DIGEST * digest,const TPMT_SIGNATURE * signature,TPMT_TK_VERIFIED * validation,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)85 TSS2_RC Tss2_Sys_VerifySignature(
86     TSS2_SYS_CONTEXT *sysContext,
87     TPMI_DH_OBJECT keyHandle,
88     TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
89     const TPM2B_DIGEST *digest,
90     const TPMT_SIGNATURE *signature,
91     TPMT_TK_VERIFIED *validation,
92     TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
93 {
94     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
95     TSS2_RC rval;
96 
97     if (!signature)
98         return TSS2_SYS_RC_BAD_REFERENCE;
99 
100     rval = Tss2_Sys_VerifySignature_Prepare(sysContext, keyHandle, digest, signature);
101     if (rval)
102         return rval;
103 
104     rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
105     if (rval)
106         return rval;
107 
108     return Tss2_Sys_VerifySignature_Complete(sysContext, validation);
109 }
110