1111static struct cxt {
1212 char const * keyPath ;
1313 char const * digest ;
14+ char const * data ;
1415 char const * signature ;
1516 char const * publicKey ;
1617 char const * certificate ;
@@ -27,6 +28,9 @@ static bool on_option(char key, char *value) {
2728 case 'd' :
2829 ctx .digest = value ;
2930 break ;
31+ case 'm' :
32+ ctx .data = value ;
33+ break ;
3034 case 'f' :
3135 ctx .overwrite = true;
3236 break ;
@@ -52,22 +56,34 @@ static bool tss2_tool_onstart(tpm2_options **opts) {
5256 {"keyPath" , required_argument , NULL , 'p' },
5357 {"padding" , required_argument , NULL , 's' },
5458 {"digest" , required_argument , NULL , 'd' },
59+ {"data" , required_argument , NULL , 'm' },
5560 {"signature" , required_argument , NULL , 'o' },
5661 {"publicKey" , required_argument , NULL , 'k' },
5762 {"force" , no_argument , NULL , 'f' },
5863 {"certificate" , required_argument , NULL , 'c' },
5964
6065 };
61- return (* opts = tpm2_options_new ("c:d:fp:k:o:s:" , ARRAY_LEN (topts ), topts ,
66+ return (* opts = tpm2_options_new ("c:d:m: fp:k:o:s:" , ARRAY_LEN (topts ), topts ,
6267 on_option , NULL , 0 )) != NULL ;
6368}
6469
6570/* Execute specific tool */
6671static int tss2_tool_onrun (FAPI_CONTEXT * fctx ) {
6772
6873 /* Check availability of required parameters */
69- if (!ctx .digest ) {
70- fprintf (stderr , "digest missing, use --digest\n" );
74+
75+ #ifndef HAVE_FAPI_DIGEST_AND_SIGN
76+ if (ctx .data ) {
77+ fprintf (stderr , "Fapi_DigestAndSign not available in the current FAPI version.\n" );
78+ return -1 ;
79+ }
80+ #endif
81+ if (!ctx .digest && !ctx .data ) {
82+ fprintf (stderr , "digest or dataa missing, use --digest or --data\n" );
83+ return -1 ;
84+ }
85+ if (ctx .digest && ctx .data ) {
86+ fprintf (stderr , "use --digest or --data\n" );
7187 return -1 ;
7288 }
7389 if (!ctx .keyPath ) {
@@ -91,23 +107,43 @@ static int tss2_tool_onrun (FAPI_CONTEXT *fctx) {
91107 }
92108
93109 /* Read data needed to create signature */
94- uint8_t * digest , * signature ;
95- size_t digestSize , signatureSize ;
96- char * publicKey , * certificate = NULL ;
97- TSS2_RC r = open_read_and_close (ctx .digest , (void * * )& digest , & digestSize );
110+ uint8_t * data = NULL , * digest = NULL , * signature = NULL ;
111+ size_t dataSize = 0 , digestSize = 0 , signatureSize ;
112+ char * publicKey = NULL , * certificate = NULL ;
113+ TSS2_RC r ;
114+ if (ctx .digest ) {
115+ r = open_read_and_close (ctx .digest , (void * * )& digest , & digestSize );
116+ } else {
117+ r = open_read_and_close (ctx .data , (void * * )& data , & dataSize );
118+ }
119+
98120 if (r ){
99121 return 1 ;
100122 }
101123
102124 /* Execute FAPI command with passed arguments */
103- r = Fapi_Sign (fctx , ctx .keyPath , ctx .padding , digest ,
125+ if (ctx .digest ) {
126+ r = Fapi_Sign (fctx , ctx .keyPath , ctx .padding , digest ,
104127 digestSize , & signature , & signatureSize , & publicKey , & certificate );
105- if (r != TSS2_RC_SUCCESS ) {
106- LOG_PERR ("Fapi_Sign" , r );
128+ if (r != TSS2_RC_SUCCESS ) {
129+ LOG_PERR ("Fapi_Sign" , r );
130+ free (digest );
131+ return 1 ;
132+ }
107133 free (digest );
108- return 1 ;
109134 }
110- free (digest );
135+ #ifdef HAVE_FAPI_DIGEST_AND_SIGN
136+ else if (ctx .data ) {
137+ r = Fapi_DigestAndSign (fctx , ctx .keyPath , ctx .padding , data ,
138+ dataSize , & signature , & signatureSize , & publicKey , & certificate );
139+ if (r != TSS2_RC_SUCCESS ) {
140+ LOG_PERR ("Fapi_Sign" , r );
141+ free (data );
142+ return 1 ;
143+ }
144+ free (data );
145+ }
146+ #endif
111147
112148 /* Write returned data to file(s) */
113149 if (ctx .certificate && certificate && strlen (certificate )) {
0 commit comments