Skip to content

Commit bfb8b72

Browse files
committed
device key: fix coding style
1 parent 71d3574 commit bfb8b72

File tree

3 files changed

+37
-37
lines changed

3 files changed

+37
-37
lines changed

features/device_key/TESTS/device_key/functionality/main.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ int inject_dummy_rot_key()
5252

5353
memcpy(key, "1234567812345678", DEVICE_KEY_16BYTE);
5454
int size = DEVICE_KEY_16BYTE;
55-
DeviceKey& devkey = DeviceKey::get_instance();
55+
DeviceKey &devkey = DeviceKey::get_instance();
5656
return devkey.device_inject_root_of_trust(key, size);
5757
#else
5858
return DEVICEKEY_SUCCESS;
@@ -86,8 +86,8 @@ void generate_derived_key_consistency_16_byte_key_long_consistency_test(char *ke
8686
unsigned char salt[] = "Once upon a time, I worked for the circus and I lived in Omaha.";
8787
int key_type = DEVICE_KEY_16BYTE;
8888
uint16_t actual_size = 0;
89-
DeviceKey& devkey = DeviceKey::get_instance();
90-
NVStore& nvstore = NVStore::get_instance();
89+
DeviceKey &devkey = DeviceKey::get_instance();
90+
NVStore &nvstore = NVStore::get_instance();
9191
size_t salt_size = sizeof(salt);
9292

9393
if (strcmp(key, MSG_KEY_DEVICE_TEST_STEP1) == 0) {
@@ -145,8 +145,8 @@ void generate_derived_key_consistency_32_byte_key_long_consistency_test(char *ke
145145
unsigned char salt[] = "The quick brown fox jumps over the lazy dog";
146146
int key_type = DEVICE_KEY_32BYTE;
147147
uint16_t actual_size = 0;
148-
DeviceKey& devkey = DeviceKey::get_instance();
149-
NVStore& nvstore = NVStore::get_instance();
148+
DeviceKey &devkey = DeviceKey::get_instance();
149+
NVStore &nvstore = NVStore::get_instance();
150150
size_t salt_size = sizeof(salt);
151151

152152
if (strcmp(key, MSG_KEY_DEVICE_TEST_STEP3) == 0) {
@@ -198,7 +198,7 @@ void generate_derived_key_consistency_32_byte_key_long_consistency_test(char *ke
198198
*/
199199
void device_inject_root_of_trust_wrong_size_test()
200200
{
201-
DeviceKey& devkey = DeviceKey::get_instance();
201+
DeviceKey &devkey = DeviceKey::get_instance();
202202
uint32_t key[DEVICE_KEY_32BYTE / sizeof(uint32_t)];
203203

204204
memcpy(key, "12345678123456788765432187654321", DEVICE_KEY_32BYTE);
@@ -217,11 +217,11 @@ void device_inject_root_of_trust_wrong_size_test()
217217
*/
218218
void device_inject_root_of_trust_16_byte_size_test()
219219
{
220-
DeviceKey& devkey = DeviceKey::get_instance();
220+
DeviceKey &devkey = DeviceKey::get_instance();
221221
uint32_t rkey[DEVICE_KEY_16BYTE / sizeof(uint32_t)];
222222
uint16_t actual_size;
223223
uint32_t key[DEVICE_KEY_16BYTE / sizeof(uint32_t)];
224-
NVStore& nvstore = NVStore::get_instance();
224+
NVStore &nvstore = NVStore::get_instance();
225225

226226
int ret = nvstore.reset();
227227
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);
@@ -243,11 +243,11 @@ void device_inject_root_of_trust_16_byte_size_test()
243243
*/
244244
void device_inject_root_of_trust_32_byte_size_test()
245245
{
246-
DeviceKey& devkey = DeviceKey::get_instance();
246+
DeviceKey &devkey = DeviceKey::get_instance();
247247
uint32_t rkey[DEVICE_KEY_32BYTE / sizeof(uint32_t)];
248248
uint16_t actual_size;
249249
uint32_t key[DEVICE_KEY_32BYTE / sizeof(uint32_t)];
250-
NVStore& nvstore = NVStore::get_instance();
250+
NVStore &nvstore = NVStore::get_instance();
251251

252252
int ret = nvstore.reset();
253253
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);
@@ -269,9 +269,9 @@ void device_inject_root_of_trust_32_byte_size_test()
269269
*/
270270
void device_inject_root_of_trust_several_times_test()
271271
{
272-
DeviceKey& devkey = DeviceKey::get_instance();
272+
DeviceKey &devkey = DeviceKey::get_instance();
273273
uint32_t key[DEVICE_KEY_32BYTE / sizeof(uint32_t)];
274-
NVStore& nvstore = NVStore::get_instance();
274+
NVStore &nvstore = NVStore::get_instance();
275275

276276
int ret = nvstore.reset();
277277
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);
@@ -299,8 +299,8 @@ void generate_derived_key_consistency_16_byte_key_test()
299299
unsigned char empty_buffer[DEVICE_KEY_16BYTE];
300300
unsigned char salt[] = "Once upon a time, I worked for the circus and I lived in Omaha.";
301301
int key_type = DEVICE_KEY_16BYTE;
302-
DeviceKey& devkey = DeviceKey::get_instance();
303-
NVStore& nvstore = NVStore::get_instance();
302+
DeviceKey &devkey = DeviceKey::get_instance();
303+
NVStore &nvstore = NVStore::get_instance();
304304

305305
int ret = nvstore.reset();
306306
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);
@@ -334,8 +334,8 @@ void generate_derived_key_consistency_32_byte_key_test()
334334
unsigned char empty_buffer[DEVICE_KEY_32BYTE];
335335
unsigned char salt[] = "The quick brown fox jumps over the lazy dog";
336336
int key_type = DEVICE_KEY_32BYTE;
337-
DeviceKey& devkey = DeviceKey::get_instance();
338-
NVStore& nvstore = NVStore::get_instance();
337+
DeviceKey &devkey = DeviceKey::get_instance();
338+
NVStore &nvstore = NVStore::get_instance();
339339

340340
int ret = nvstore.reset();
341341
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);
@@ -369,8 +369,8 @@ void generate_derived_key_key_type_16_test()
369369
unsigned char expectedString[] = "Some String";
370370
int key_type = DEVICE_KEY_16BYTE;
371371
size_t salt_size = sizeof(salt);
372-
DeviceKey& devkey = DeviceKey::get_instance();
373-
NVStore& nvstore = NVStore::get_instance();
372+
DeviceKey &devkey = DeviceKey::get_instance();
373+
NVStore &nvstore = NVStore::get_instance();
374374

375375
int ret = nvstore.reset();
376376
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);
@@ -400,8 +400,8 @@ void generate_derived_key_key_type_32_test()
400400
int key_type = DEVICE_KEY_32BYTE;
401401
size_t salt_size = sizeof(salt);
402402
unsigned char expectedString[] = "Some String";
403-
DeviceKey& devkey = DeviceKey::get_instance();
404-
NVStore& nvstore = NVStore::get_instance();
403+
DeviceKey &devkey = DeviceKey::get_instance();
404+
NVStore &nvstore = NVStore::get_instance();
405405

406406
int ret = nvstore.reset();
407407
TEST_ASSERT_EQUAL_INT(DEVICEKEY_SUCCESS, ret);
@@ -429,8 +429,8 @@ void generate_derived_key_wrong_key_type_test()
429429
unsigned char output[DEVICE_KEY_16BYTE];
430430
unsigned char salt[] = "The quick brown fox jumps over the lazy dog";
431431
size_t salt_size = sizeof(salt);
432-
DeviceKey& devkey = DeviceKey::get_instance();
433-
NVStore& nvstore = NVStore::get_instance();
432+
DeviceKey &devkey = DeviceKey::get_instance();
433+
NVStore &nvstore = NVStore::get_instance();
434434

435435
nvstore.init();
436436
int ret = nvstore.reset();

features/device_key/source/DeviceKey.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ int DeviceKey::write_key_to_nvstore(uint32_t *input, size_t isize)
117117
return ret;
118118
}
119119

120-
NVStore& nvstore = NVStore::get_instance();
120+
NVStore &nvstore = NVStore::get_instance();
121121
ret = nvstore.set(NVSTORE_DEVICEKEY_KEY, (uint16_t)isize, input);
122122
if (NVSTORE_WRITE_ERROR == ret || NVSTORE_BUFF_TOO_SMALL == ret) {
123123
return DEVICEKEY_SAVE_FAILED;
@@ -130,15 +130,15 @@ int DeviceKey::write_key_to_nvstore(uint32_t *input, size_t isize)
130130
return DEVICEKEY_SUCCESS;
131131
}
132132

133-
int DeviceKey::read_key_from_nvstore(uint32_t *output, size_t& size)
133+
int DeviceKey::read_key_from_nvstore(uint32_t *output, size_t &size)
134134
{
135-
if (size > (uint16_t)-1) {
135+
if (size > (uint16_t) -1) {
136136
return DEVICEKEY_INVALID_PARAM;
137137
}
138138

139139
uint16_t in_size = size;
140140
uint16_t out_size = 0;
141-
NVStore& nvstore = NVStore::get_instance();
141+
NVStore &nvstore = NVStore::get_instance();
142142
int nvStatus = nvstore.get(NVSTORE_DEVICEKEY_KEY, in_size, output, out_size);
143143
if (NVSTORE_NOT_FOUND == nvStatus) {
144144
return DEVICEKEY_NOT_FOUND;
@@ -179,18 +179,18 @@ int DeviceKey::get_derived_key(uint32_t *ikey_buff, size_t ikey_size, const unsi
179179

180180
do {
181181

182-
mbedtls_cipher_init(&ctx);
183-
ret = mbedtls_cipher_setup(&ctx, cipher_info);
184-
if (ret != 0) {
185-
goto finish;
186-
}
182+
mbedtls_cipher_init(&ctx);
183+
ret = mbedtls_cipher_setup(&ctx, cipher_info);
184+
if (ret != 0) {
185+
goto finish;
186+
}
187187

188188
ret = mbedtls_cipher_cmac_starts(&ctx, (unsigned char *)ikey_buff, ikey_size * 8);
189189
if (ret != 0) {
190190
goto finish;
191191
}
192192

193-
DEVKEY_WRITE_UINT8_LE(counter_enc, (counter+1));
193+
DEVKEY_WRITE_UINT8_LE(counter_enc, (counter + 1));
194194

195195
ret = mbedtls_cipher_cmac_update(&ctx, (unsigned char *)counter_enc, sizeof(counter_enc));
196196
if (ret != 0) {
@@ -217,15 +217,15 @@ int DeviceKey::get_derived_key(uint32_t *ikey_buff, size_t ikey_size, const unsi
217217
goto finish;
218218
}
219219

220-
mbedtls_cipher_free( &ctx );
220+
mbedtls_cipher_free(&ctx);
221221

222222
counter++;
223223

224224
} while (DEVICE_KEY_16BYTE * counter < ikey_type);
225225

226226
finish:
227227
if (DEVICEKEY_SUCCESS != ret) {
228-
mbedtls_cipher_free( &ctx );
228+
mbedtls_cipher_free(&ctx);
229229
return DEVICEKEY_ERR_CMAC_GENERIC_FAILURE;
230230
}
231231

features/device_key/source/DeviceKey.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class DeviceKey : private mbed::NonCopyable<DeviceKey> {
6161
*
6262
* @returns Singleton instance reference.
6363
*/
64-
static DeviceKey& get_instance()
64+
static DeviceKey &get_instance()
6565
{
6666
// Use this implementation of singleton (Meyer's) rather than the one that allocates
6767
// the instance on the heap, as it ensures destruction at program end (preventing warnings
@@ -100,7 +100,7 @@ class DeviceKey : private mbed::NonCopyable<DeviceKey> {
100100
* Output: The actual size of the written data
101101
* @return 0 on success, negative error code on failure
102102
*/
103-
int read_key_from_nvstore(uint32_t *output, size_t& size);
103+
int read_key_from_nvstore(uint32_t *output, size_t &size);
104104

105105
/** Set a device key into the NVStore
106106
* @param input Input buffer contain the key.
@@ -109,7 +109,7 @@ class DeviceKey : private mbed::NonCopyable<DeviceKey> {
109109
*/
110110
int write_key_to_nvstore(uint32_t *input, size_t isize);
111111

112-
/** Get a derived key base on a salt string. The methods implements Section 5.1
112+
/** Get a derived key base on a salt string. The methods implements Section 5.1
113113
* in NIST SP 800-108, Recommendation for Key Derivation Using Pseudorandom Functions
114114
* @param ikey_buff Input buffer holding the ROT key
115115
* @param ikey_size Size of the input key. Must be 16 bytes or 32 bytes.

0 commit comments

Comments
 (0)