36
36
#include " pal_os_timer.h"
37
37
#include < FreeRTOS.h>
38
38
39
- optiga_crypt_t * p_local_crypt = NULL ;
40
- optiga_util_t * p_local_util = NULL ;
39
+ optiga_crypt_t * me_crypt = NULL ;
40
+ optiga_util_t * me_util = NULL ;
41
41
static bool trustm_isOpen = false ;
42
42
#define ENABLE_HMAC_MULTI_STEP (0 )
43
43
#define OPTIGA_UTIL_DER_BITSTRING_TAG (0x03 )
@@ -120,37 +120,37 @@ void trustm_Open(void)
120
120
do
121
121
{
122
122
// Create Optiga crypt instance
123
- if (p_local_crypt == NULL )
123
+ if (me_crypt == NULL )
124
124
{
125
- p_local_crypt = optiga_crypt_create (0 , optiga_crypt_callback, NULL );
126
- if (NULL == p_local_crypt )
125
+ me_crypt = optiga_crypt_create (0 , optiga_crypt_callback, NULL );
126
+ if (NULL == me_crypt )
127
127
{
128
128
break ;
129
129
}
130
130
}
131
131
else
132
132
{
133
- printf (" Error: p_local_crypt already initialised\n " );
133
+ printf (" Error: me_crypt already initialised\n " );
134
134
}
135
135
// Create Optiga Util instance
136
- if (p_local_util == NULL )
136
+ if (me_util == NULL )
137
137
{
138
- p_local_util = optiga_util_create (0 , optiga_util_callback, NULL );
139
- if (NULL == p_local_util )
138
+ me_util = optiga_util_create (0 , optiga_util_callback, NULL );
139
+ if (NULL == me_util )
140
140
{
141
141
break ;
142
142
}
143
143
}
144
144
else
145
145
{
146
- printf (" Error: p_local_crypt already initialised\n " );
146
+ printf (" Error: me_crypt already initialised\n " );
147
147
}
148
148
/* *
149
149
* Open the application on OPTIGA which is a precondition to perform any other operations
150
150
* using optiga_util_open_application
151
151
*/
152
152
optiga_lib_status = OPTIGA_LIB_BUSY;
153
- return_status = optiga_util_open_application (p_local_util , 0 ); // skip restore
153
+ return_status = optiga_util_open_application (me_util , 0 ); // skip restore
154
154
if (OPTIGA_LIB_SUCCESS != return_status)
155
155
{
156
156
printf (" optiga_util_open_application api returns error %02X\n " , return_status);
@@ -165,15 +165,17 @@ void trustm_Open(void)
165
165
printf (" optiga_util_open_application failed\n " );
166
166
break ;
167
167
}
168
+ trustm_isOpen = true ;
169
+
168
170
// Only run once for initialisation
169
- if (init)
170
- {
171
- return_status = optiga_util_write_data (p_local_util, dOptigaOID, OPTIGA_UTIL_WRITE_ONLY, 0 , &cCurrentLimit, 1 );
172
- if (OPTIGA_LIB_SUCCESS != return_status)
171
+ if (!init)
173
172
{
174
- printf (" optiga_util_write_data api returns error %02X\n " , return_status);
175
- break ;
176
- }
173
+ return_status = optiga_util_write_data (me_util, dOptigaOID, OPTIGA_UTIL_WRITE_ONLY, 0 , &cCurrentLimit, 1 );
174
+ if (OPTIGA_LIB_SUCCESS != return_status)
175
+ {
176
+ printf (" optiga_util_write_data api returns error %02X\n " , return_status);
177
+ break ;
178
+ }
177
179
WAIT_FOR_COMPLETION (return_status);
178
180
if (OPTIGA_LIB_SUCCESS != return_status)
179
181
{
@@ -184,8 +186,6 @@ void trustm_Open(void)
184
186
init = true ;
185
187
}
186
188
} while (0 );
187
-
188
- trustm_isOpen = true ;
189
189
}
190
190
}
191
191
@@ -200,7 +200,7 @@ void trustm_close(void)
200
200
* using optiga_util_close_application
201
201
*/
202
202
optiga_lib_status = OPTIGA_LIB_BUSY;
203
- return_status = optiga_util_close_application (p_local_util , 0 );
203
+ return_status = optiga_util_close_application (me_util , 0 );
204
204
if (OPTIGA_LIB_SUCCESS != return_status)
205
205
{
206
206
printf (" optiga_util_close_application api returns error %02X\n " , return_status);
@@ -217,11 +217,11 @@ void trustm_close(void)
217
217
}
218
218
219
219
// destroy util and crypt instances
220
- optiga_util_destroy (p_local_util );
221
- optiga_crypt_destroy (p_local_crypt );
220
+ optiga_util_destroy (me_util );
221
+ optiga_crypt_destroy (me_crypt );
222
222
pal_os_event_destroy (NULL );
223
- p_local_util = NULL ;
224
- p_local_crypt = NULL ;
223
+ me_util = NULL ;
224
+ me_crypt = NULL ;
225
225
trustm_isOpen = false ;
226
226
return_status = OPTIGA_LIB_SUCCESS;
227
227
} while (0 );
@@ -241,7 +241,7 @@ void read_certificate_from_optiga(uint16_t optiga_oid, char * cert_pem, uint16_t
241
241
do
242
242
{
243
243
optiga_lib_status = OPTIGA_LIB_BUSY;
244
- return_status = optiga_util_read_data (p_local_util , optiga_oid, 0 , ifx_cert_hex, &ifx_cert_hex_len);
244
+ return_status = optiga_util_read_data (me_util , optiga_oid, 0 , ifx_cert_hex, &ifx_cert_hex_len);
245
245
if (OPTIGA_LIB_SUCCESS != return_status)
246
246
{
247
247
printf (" optiga_util_read_data api returns error %02X\n " , return_status);
@@ -292,7 +292,7 @@ void write_data(uint16_t optiga_oid, const uint8_t * p_data, uint16_t length)
292
292
do
293
293
{
294
294
optiga_lib_status = OPTIGA_LIB_BUSY;
295
- return_status = optiga_util_write_data (p_local_util , optiga_oid, OPTIGA_UTIL_ERASE_AND_WRITE, 0 , p_data, length);
295
+ return_status = optiga_util_write_data (me_util , optiga_oid, OPTIGA_UTIL_ERASE_AND_WRITE, 0 , p_data, length);
296
296
if (OPTIGA_LIB_SUCCESS != return_status)
297
297
{
298
298
printf (" optiga_util_write_data api returns error %02X\n " , return_status);
@@ -316,7 +316,7 @@ void write_metadata(uint16_t optiga_oid, const uint8_t * p_data, uint8_t length)
316
316
do
317
317
{
318
318
optiga_lib_status = OPTIGA_LIB_BUSY;
319
- return_status = optiga_util_write_metadata (p_local_util , optiga_oid, p_data, length);
319
+ return_status = optiga_util_write_metadata (me_util , optiga_oid, p_data, length);
320
320
if (OPTIGA_LIB_SUCCESS != return_status)
321
321
{
322
322
printf (" optiga_util_write_metadata api returns error %02X\n " , return_status);
@@ -339,7 +339,7 @@ optiga_lib_status_t deriveKey_HKDF(const uint8_t * salt, uint16_t salt_length, c
339
339
do
340
340
{
341
341
optiga_lib_status = OPTIGA_LIB_BUSY;
342
- return_status = optiga_crypt_hkdf (p_local_crypt , OPTIGA_HKDF_SHA_256, TRUSTM_HKDF_OID_KEY, /* Input secret OID */
342
+ return_status = optiga_crypt_hkdf (me_crypt , OPTIGA_HKDF_SHA_256, TRUSTM_HKDF_OID_KEY, /* Input secret OID */
343
343
salt, salt_length, info, info_length, derived_key_length, TRUE , derived_key);
344
344
if (OPTIGA_LIB_SUCCESS != return_status)
345
345
{
@@ -369,7 +369,7 @@ optiga_lib_status_t hmac_sha256(optiga_hmac_type_t type, const uint8_t * input_d
369
369
// If the size is less than the max length supported
370
370
if (input_data_length <= MAX_MAC_DATA_LEN)
371
371
{
372
- return_status = optiga_crypt_hmac (p_local_crypt , type, TRUSTM_HMAC_OID_KEY, input_data, input_data_length, mac, mac_length);
372
+ return_status = optiga_crypt_hmac (me_crypt , type, TRUSTM_HMAC_OID_KEY, input_data, input_data_length, mac, mac_length);
373
373
if (OPTIGA_LIB_SUCCESS != return_status)
374
374
{
375
375
// optiga_crypt_hmac returns error !!!
@@ -391,7 +391,7 @@ optiga_lib_status_t hmac_sha256(optiga_hmac_type_t type, const uint8_t * input_d
391
391
uint32_t dataLenTemp = 0 ;
392
392
uint32_t remainingLen = input_data_length;
393
393
// Start the HMAC Operation
394
- return_status = optiga_crypt_hmac_start (p_local_crypt , type, TRUSTM_HMAC_OID_KEY, input_data, MAX_MAC_DATA_LEN);
394
+ return_status = optiga_crypt_hmac_start (me_crypt , type, TRUSTM_HMAC_OID_KEY, input_data, MAX_MAC_DATA_LEN);
395
395
if (OPTIGA_LIB_SUCCESS != return_status)
396
396
{
397
397
// optiga_crypt_hmac returns error !!!
@@ -415,7 +415,7 @@ optiga_lib_status_t hmac_sha256(optiga_hmac_type_t type, const uint8_t * input_d
415
415
{
416
416
optiga_lib_status = OPTIGA_LIB_BUSY;
417
417
return_status =
418
- optiga_crypt_hmac_update (p_local_crypt , (input_data + (input_data_length - remainingLen)), dataLenTemp);
418
+ optiga_crypt_hmac_update (me_crypt , (input_data + (input_data_length - remainingLen)), dataLenTemp);
419
419
if (OPTIGA_LIB_SUCCESS != return_status)
420
420
{
421
421
// optiga_crypt_hmac_update returns error !!!
@@ -436,7 +436,7 @@ optiga_lib_status_t hmac_sha256(optiga_hmac_type_t type, const uint8_t * input_d
436
436
// End HMAC sequence and return the MAC generated
437
437
// printf("HMAC Finalize\n");
438
438
optiga_lib_status = OPTIGA_LIB_BUSY;
439
- return_status = optiga_crypt_hmac_finalize (p_local_crypt , (input_data + (input_data_length - remainingLen)),
439
+ return_status = optiga_crypt_hmac_finalize (me_crypt , (input_data + (input_data_length - remainingLen)),
440
440
dataLenTemp, mac, mac_length);
441
441
if (OPTIGA_LIB_SUCCESS != return_status)
442
442
{
@@ -456,7 +456,7 @@ optiga_lib_status_t hmac_sha256(optiga_hmac_type_t type, const uint8_t * input_d
456
456
}
457
457
#else
458
458
459
- return_status = optiga_crypt_hmac (p_local_crypt , type, TRUSTM_HMAC_OID_KEY, input_data, input_data_length, mac, mac_length);
459
+ return_status = optiga_crypt_hmac (me_crypt , type, TRUSTM_HMAC_OID_KEY, input_data, input_data_length, mac, mac_length);
460
460
if (OPTIGA_LIB_SUCCESS != return_status)
461
461
{
462
462
// optiga_crypt_hmac returns error !!!
@@ -482,7 +482,7 @@ optiga_lib_status_t optiga_crypt_rng(uint8_t * random_data, uint16_t random_data
482
482
do
483
483
{
484
484
optiga_lib_status = OPTIGA_LIB_BUSY;
485
- return_status = optiga_crypt_random (p_local_crypt , OPTIGA_RNG_TYPE_DRNG, random_data, random_data_length);
485
+ return_status = optiga_crypt_random (me_crypt , OPTIGA_RNG_TYPE_DRNG, random_data, random_data_length);
486
486
if (OPTIGA_LIB_SUCCESS != return_status)
487
487
{
488
488
// optiga_crypt_random returns error !!!
@@ -514,7 +514,7 @@ optiga_lib_status_t trustm_ecc_keygen(uint16_t optiga_key_id, uint8_t key_type,
514
514
do
515
515
{
516
516
optiga_lib_status = OPTIGA_LIB_BUSY;
517
- return_status = optiga_crypt_ecc_generate_keypair (p_local_crypt , curve_id, key_type, FALSE , &optiga_key_id, (pubkey + i),
517
+ return_status = optiga_crypt_ecc_generate_keypair (me_crypt , curve_id, key_type, FALSE , &optiga_key_id, (pubkey + i),
518
518
pubkey_length);
519
519
if (OPTIGA_LIB_SUCCESS != return_status)
520
520
{
@@ -541,7 +541,7 @@ void trustmGetKey(uint16_t optiga_oid, uint8_t * pubkey, uint16_t * pubkeyLen)
541
541
do
542
542
{
543
543
optiga_lib_status = OPTIGA_LIB_BUSY;
544
- return_status = optiga_util_read_data (p_local_util , optiga_oid, offset, pubkey, pubkeyLen);
544
+ return_status = optiga_util_read_data (me_util , optiga_oid, offset, pubkey, pubkeyLen);
545
545
if (OPTIGA_LIB_SUCCESS != return_status)
546
546
{
547
547
// optiga_util_read_data api returns error !!!
@@ -566,7 +566,7 @@ optiga_lib_status_t trustm_hash(uint8_t * msg, uint16_t msg_length, uint8_t * di
566
566
hash_data_host.buffer = msg;
567
567
hash_data_host.length = msg_length;
568
568
optiga_lib_status = OPTIGA_LIB_BUSY;
569
- return_status = optiga_crypt_hash (p_local_crypt , OPTIGA_HASH_TYPE_SHA_256, OPTIGA_CRYPT_HOST_DATA, &hash_data_host, digest);
569
+ return_status = optiga_crypt_hash (me_crypt , OPTIGA_HASH_TYPE_SHA_256, OPTIGA_CRYPT_HOST_DATA, &hash_data_host, digest);
570
570
if (OPTIGA_LIB_SUCCESS != return_status)
571
571
{
572
572
// optiga_crypt_hash api returns error !!!
@@ -592,7 +592,7 @@ optiga_lib_status_t trustm_ecdsa_sign(optiga_key_id_t optiga_key_id, uint8_t * d
592
592
do
593
593
{
594
594
optiga_lib_status = OPTIGA_LIB_BUSY;
595
- return_status = optiga_crypt_ecdsa_sign (p_local_crypt , digest, digest_length, optiga_key_id, signature, signature_length);
595
+ return_status = optiga_crypt_ecdsa_sign (me_crypt , digest, digest_length, optiga_key_id, signature, signature_length);
596
596
if (OPTIGA_LIB_SUCCESS != return_status)
597
597
{
598
598
// optiga_crypt_ecdsa_sign api returns error !!!
@@ -657,7 +657,7 @@ optiga_lib_status_t trustm_ecdsa_verify(uint8_t * digest, uint8_t digest_length,
657
657
}
658
658
659
659
optiga_lib_status = OPTIGA_LIB_BUSY;
660
- return_status = optiga_crypt_ecdsa_verify (p_local_crypt , digest, digest_length, signature, signature_length,
660
+ return_status = optiga_crypt_ecdsa_verify (me_crypt , digest, digest_length, signature, signature_length,
661
661
OPTIGA_CRYPT_HOST_DATA, &public_key_details);
662
662
if (OPTIGA_LIB_SUCCESS != return_status)
663
663
{
@@ -690,7 +690,7 @@ CHIP_ERROR trustmGetCertificate(uint16_t optiga_oid, uint8_t * buf, uint16_t * b
690
690
do
691
691
{
692
692
optiga_lib_status = OPTIGA_LIB_BUSY;
693
- return_status = optiga_util_read_data (p_local_util , optiga_oid, 0 , ifx_cert_hex, &ifx_cert_hex_len);
693
+ return_status = optiga_util_read_data (me_util , optiga_oid, 0 , ifx_cert_hex, &ifx_cert_hex_len);
694
694
if (OPTIGA_LIB_SUCCESS != return_status)
695
695
{
696
696
// optiga_util_read_data api returns error !!!
@@ -730,7 +730,7 @@ optiga_lib_status_t trustm_ecdh_derive_secret(optiga_key_id_t optiga_key_id, uin
730
730
do
731
731
{
732
732
optiga_lib_status = OPTIGA_LIB_BUSY;
733
- return_status = optiga_crypt_ecdh (p_local_crypt , optiga_key_id, &public_key_details, TRUE , shared_secret);
733
+ return_status = optiga_crypt_ecdh (me_crypt , optiga_key_id, &public_key_details, TRUE , shared_secret);
734
734
if (OPTIGA_LIB_SUCCESS != return_status)
735
735
{
736
736
// optiga_util_read_data api returns error !!!
@@ -764,7 +764,7 @@ optiga_lib_status_t trustm_PBKDF2_HMAC(const unsigned char * salt, size_t slen,
764
764
// Calculate U1, U1 ends up in work
765
765
optiga_lib_status = OPTIGA_LIB_BUSY;
766
766
return_status =
767
- optiga_crypt_hmac (p_local_crypt , OPTIGA_HMAC_SHA_256, TRUSTM_HMAC_OID_KEY, salt, (uint32_t ) slen, work, &work_len);
767
+ optiga_crypt_hmac (me_crypt , OPTIGA_HMAC_SHA_256, TRUSTM_HMAC_OID_KEY, salt, (uint32_t ) slen, work, &work_len);
768
768
if (OPTIGA_LIB_SUCCESS != return_status)
769
769
{
770
770
// optiga_crypt_hmac api returns error !!!
@@ -782,7 +782,7 @@ optiga_lib_status_t trustm_PBKDF2_HMAC(const unsigned char * salt, size_t slen,
782
782
{
783
783
optiga_lib_status = OPTIGA_LIB_BUSY;
784
784
// Calculated subsequent U, which ends up in md1
785
- return_status = optiga_crypt_hmac (p_local_crypt , OPTIGA_HMAC_SHA_256, TRUSTM_HMAC_OID_KEY, md1, md1_len, md1, &md1_len);
785
+ return_status = optiga_crypt_hmac (me_crypt , OPTIGA_HMAC_SHA_256, TRUSTM_HMAC_OID_KEY, md1, md1_len, md1, &md1_len);
786
786
if (OPTIGA_LIB_SUCCESS != return_status)
787
787
{
788
788
// optiga_crypt_hmac api returns error !!!
0 commit comments