@@ -40,20 +40,19 @@ CHIP_ERROR OtaTlvEncryptionKey::Import(const uint8_t * key, size_t key_len)
40
40
psa_set_key_type (&attributes, PSA_KEY_TYPE_AES);
41
41
psa_set_key_bits (&attributes, 128 );
42
42
psa_set_key_algorithm (&attributes, PSA_ALG_CTR);
43
- psa_set_key_usage_flags (
44
- &attributes, PSA_KEY_USAGE_DECRYPT);
43
+ psa_set_key_usage_flags (&attributes, PSA_KEY_USAGE_DECRYPT);
45
44
46
45
status = psa_import_key (&attributes, key, key_len, &key_id);
47
- if (status != PSA_SUCCESS) {
46
+ if (status != PSA_SUCCESS)
47
+ {
48
48
printf (" Failed to import a key error:%ld\n " , status);
49
49
return CHIP_ERROR_INTERNAL;
50
50
}
51
51
52
52
return CHIP_NO_ERROR;
53
-
54
53
}
55
54
56
- CHIP_ERROR OtaTlvEncryptionKey::Decrypt (MutableByteSpan & block, uint32_t &mIVOffset )
55
+ CHIP_ERROR OtaTlvEncryptionKey::Decrypt (MutableByteSpan & block, uint32_t & mIVOffset )
57
56
{
58
57
constexpr uint8_t au8Iv[] = { 0x00 , 0x00 , 0x00 , 0x10 , 0x11 , 0x12 , 0x13 , 0x14 , 0x15 , 0x16 , 0x17 , 0x18 , 0x00 , 0x00 , 0x00 , 0x00 };
59
58
uint8_t iv[16 ];
@@ -65,7 +64,6 @@ CHIP_ERROR OtaTlvEncryptionKey::Decrypt(MutableByteSpan & block, uint32_t &mIVOf
65
64
uint32_t u32IVCount;
66
65
uint32_t Offset = 0 ;
67
66
68
-
69
67
memcpy (iv, au8Iv, sizeof (au8Iv));
70
68
71
69
u32IVCount = (((uint32_t ) iv[12 ]) << 24 ) | (((uint32_t ) iv[13 ]) << 16 ) | (((uint32_t ) iv[14 ]) << 8 ) | (iv[15 ]);
@@ -79,20 +77,22 @@ CHIP_ERROR OtaTlvEncryptionKey::Decrypt(MutableByteSpan & block, uint32_t &mIVOf
79
77
while (Offset + 16 <= block.size ())
80
78
{
81
79
status = psa_cipher_decrypt_setup (&operation, static_cast <psa_key_id_t >(mId ), PSA_ALG_CTR);
82
- if (status != PSA_SUCCESS) {
80
+ if (status != PSA_SUCCESS)
81
+ {
83
82
printf (" Failed to begin cipher operation error:%ld\n " , status);
84
83
return CHIP_ERROR_INTERNAL;
85
84
}
86
85
87
86
status = psa_cipher_set_iv (&operation, iv, sizeof (iv));
88
- if (status != PSA_SUCCESS) {
87
+ if (status != PSA_SUCCESS)
88
+ {
89
89
printf (" Failed to set IV error:%ld\n " , status);
90
90
return CHIP_ERROR_INTERNAL;
91
91
}
92
92
93
- status = psa_cipher_update (&operation, static_cast <uint8_t *>(&block[Offset]), 16 ,
94
- output, sizeof (output), &output_len);
95
- if (status != PSA_SUCCESS) {
93
+ status = psa_cipher_update (&operation, static_cast <uint8_t *>(&block[Offset]), 16 , output, sizeof (output), &output_len);
94
+ if (status != PSA_SUCCESS)
95
+ {
96
96
printf (" Failed to update cipher operation error:%ld\n " , status);
97
97
return CHIP_ERROR_INTERNAL;
98
98
}
@@ -109,13 +109,12 @@ CHIP_ERROR OtaTlvEncryptionKey::Decrypt(MutableByteSpan & block, uint32_t &mIVOf
109
109
110
110
Offset += 16 ; /* increment the buffer offset */
111
111
mIVOffset += 16 ;
112
- status = psa_cipher_finish (&operation, output + total_output,
113
- sizeof (output) - total_output, &total_output);
114
- if (status != PSA_SUCCESS) {
115
- printf (" Failed to finish cipher operation\n " );
116
- return CHIP_ERROR_INTERNAL;
112
+ status = psa_cipher_finish (&operation, output + total_output, sizeof (output) - total_output, &total_output);
113
+ if (status != PSA_SUCCESS)
114
+ {
115
+ printf (" Failed to finish cipher operation\n " );
116
+ return CHIP_ERROR_INTERNAL;
117
117
}
118
-
119
118
}
120
119
121
120
printf (" Decrypted ciphertext\n " );
@@ -125,8 +124,7 @@ CHIP_ERROR OtaTlvEncryptionKey::Decrypt(MutableByteSpan & block, uint32_t &mIVOf
125
124
return CHIP_NO_ERROR;
126
125
}
127
126
128
-
129
- } // namespace Provision
127
+ } // namespace OtaTlvEncryptionKey
130
128
} // namespace Silabs
131
129
} // namespace DeviceLayer
132
130
} // namespace chip
0 commit comments