1111#include <wolfssl/wolfcrypt/settings.h>
1212#include <wolfssl/wolfcrypt/types.h>
1313
14- int wh_Client_KeyWrapRequest (whClientContext * ctx , enum wc_CipherType cipherType ,
14+ int wh_Client_KeyWrapRequest (whClientContext * ctx ,
15+ enum wc_CipherType cipherType ,
1516 uint16_t serverKeyId , void * key , uint16_t keySz ,
1617 whNvmMetadata * metadata )
1718{
18- uint16_t group = WH_MESSAGE_GROUP_KEY ;
19- uint16_t action = WH_KEY_WRAP ;
19+ uint16_t group = WH_MESSAGE_GROUP_KEY ;
20+ uint16_t action = WH_KEY_WRAP ;
2021 whMessageKeystore_WrapRequest * req = NULL ;
21- uint8_t * reqData ;
22+ uint8_t * reqData ;
2223
2324 if (ctx == NULL || key == NULL || metadata == NULL ) {
2425 return WH_ERROR_BADARGS ;
@@ -45,15 +46,16 @@ int wh_Client_KeyWrapRequest(whClientContext* ctx, enum wc_CipherType cipherType
4546 (uint8_t * )req );
4647}
4748
48- int wh_Client_KeyWrapResponse (whClientContext * ctx , enum wc_CipherType cipherType ,
49+ int wh_Client_KeyWrapResponse (whClientContext * ctx ,
50+ enum wc_CipherType cipherType ,
4951 void * wrappedKeyOut , uint16_t wrappedKeySz )
5052{
51- int ret ;
52- uint16_t group ;
53- uint16_t action ;
54- uint16_t size ;
53+ int ret ;
54+ uint16_t group ;
55+ uint16_t action ;
56+ uint16_t size ;
5557 whMessageKeystore_WrapResponse * resp = NULL ;
56- uint8_t * respData ;
58+ uint8_t * respData ;
5759
5860 if (ctx == NULL || wrappedKeyOut == NULL ) {
5961 return WH_ERROR_BADARGS ;
@@ -71,12 +73,9 @@ int wh_Client_KeyWrapResponse(whClientContext* ctx, enum wc_CipherType cipherTyp
7173 return ret ;
7274 }
7375
74- if (group != WH_MESSAGE_GROUP_KEY ||
75- action != WH_KEY_WRAP ||
76- size < sizeof (* resp ) ||
77- size > sizeof (* resp ) + wrappedKeySz ||
78- resp -> wrappedKeySz != wrappedKeySz ||
79- resp -> cipherType != cipherType ) {
76+ if (group != WH_MESSAGE_GROUP_KEY || action != WH_KEY_WRAP ||
77+ size < sizeof (* resp ) || size > sizeof (* resp ) + wrappedKeySz ||
78+ resp -> wrappedKeySz != wrappedKeySz || resp -> cipherType != cipherType ) {
8079 return WH_ERROR_ABORTED ;
8180 }
8281
@@ -91,9 +90,8 @@ int wh_Client_KeyWrapResponse(whClientContext* ctx, enum wc_CipherType cipherTyp
9190 return WH_ERROR_OK ;
9291}
9392
94- int wh_Client_KeyWrap (whClientContext * ctx , enum wc_CipherType cipherType ,
95- uint16_t serverKeyId ,
96- void * keyIn , uint16_t keySz ,
93+ int wh_Client_KeyWrap (whClientContext * ctx , enum wc_CipherType cipherType ,
94+ uint16_t serverKeyId , void * keyIn , uint16_t keySz ,
9795 whNvmMetadata * metadataIn , void * wrappedKeyOut ,
9896 uint16_t wrappedKeySz )
9997{
@@ -111,28 +109,32 @@ int wh_Client_KeyWrap(whClientContext* ctx, enum wc_CipherType cipherType,
111109 }
112110
113111 do {
114- ret = wh_Client_KeyWrapResponse (ctx , cipherType , wrappedKeyOut , wrappedKeySz );
112+ ret = wh_Client_KeyWrapResponse (ctx , cipherType , wrappedKeyOut ,
113+ wrappedKeySz );
115114 } while (ret == WH_ERROR_NOTREADY );
116115
117116 return ret ;
118117}
119118
120- int wh_Client_KeyUnwrapAndExportRequest (whClientContext * ctx , enum wc_CipherType cipherType ,
121- uint16_t serverKeyId ,
122- void * wrappedKeyIn , uint16_t wrappedKeySz )
119+ int wh_Client_KeyUnwrapAndExportRequest (whClientContext * ctx ,
120+ enum wc_CipherType cipherType ,
121+ uint16_t serverKeyId ,
122+ void * wrappedKeyIn ,
123+ uint16_t wrappedKeySz )
123124
124125{
125- uint16_t group = WH_MESSAGE_GROUP_KEY ;
126- uint16_t action = WH_KEY_UNWRAPEXPORT ;
126+ uint16_t group = WH_MESSAGE_GROUP_KEY ;
127+ uint16_t action = WH_KEY_UNWRAPEXPORT ;
127128 whMessageKeystore_UnwrapAndExportRequest * req = NULL ;
128- uint8_t * reqData ;
129+ uint8_t * reqData ;
129130
130131 if (ctx == NULL || wrappedKeyIn == NULL ) {
131132 return WH_ERROR_BADARGS ;
132133 }
133134
134135 /* Set the request pointer to the shared comm data memory region */
135- req = (whMessageKeystore_UnwrapAndExportRequest * )wh_CommClient_GetDataPtr (ctx -> comm );
136+ req = (whMessageKeystore_UnwrapAndExportRequest * )wh_CommClient_GetDataPtr (
137+ ctx -> comm );
136138 if (req == NULL ) {
137139 return WH_ERROR_BADARGS ;
138140 }
@@ -150,24 +152,25 @@ int wh_Client_KeyUnwrapAndExportRequest(whClientContext* ctx, enum wc_CipherType
150152 sizeof (* req ) + wrappedKeySz , (uint8_t * )req );
151153}
152154
153- int wh_Client_KeyUnwrapAndExportResponse (whClientContext * ctx , enum wc_CipherType cipherType ,
154- whNvmMetadata * metadataOut , void * keyOut ,
155- uint16_t keySz )
155+ int wh_Client_KeyUnwrapAndExportResponse (whClientContext * ctx ,
156+ enum wc_CipherType cipherType ,
157+ whNvmMetadata * metadataOut ,
158+ void * keyOut , uint16_t keySz )
156159{
157- int ret ;
158- uint16_t group ;
159- uint16_t action ;
160- uint16_t size ;
160+ int ret ;
161+ uint16_t group ;
162+ uint16_t action ;
163+ uint16_t size ;
161164 whMessageKeystore_UnwrapAndExportResponse * resp = NULL ;
162- uint8_t * respData ;
165+ uint8_t * respData ;
163166
164167 if (ctx == NULL || metadataOut == NULL || keyOut == NULL ) {
165168 return WH_ERROR_BADARGS ;
166169 }
167170
168171 /* Set the response pointer to the shared comm data memory region */
169- resp =
170- ( whMessageKeystore_UnwrapAndExportResponse * ) wh_CommClient_GetDataPtr ( ctx -> comm );
172+ resp = ( whMessageKeystore_UnwrapAndExportResponse * ) wh_CommClient_GetDataPtr (
173+ ctx -> comm );
171174 if (resp == NULL ) {
172175 return WH_ERROR_BADARGS ;
173176 }
@@ -178,12 +181,10 @@ int wh_Client_KeyUnwrapAndExportResponse(whClientContext* ctx, enum wc_CipherTyp
178181 return ret ;
179182 }
180183
181- if (group != WH_MESSAGE_GROUP_KEY ||
182- action != WH_KEY_UNWRAPEXPORT ||
184+ if (group != WH_MESSAGE_GROUP_KEY || action != WH_KEY_UNWRAPEXPORT ||
183185 size < sizeof (* resp ) ||
184186 size > sizeof (* resp ) + sizeof (* metadataOut ) + keySz ||
185- resp -> keySz != keySz ||
186- resp -> cipherType != cipherType ) {
187+ resp -> keySz != keySz || resp -> cipherType != cipherType ) {
187188 return WH_ERROR_ABORTED ;
188189 }
189190
@@ -200,9 +201,10 @@ int wh_Client_KeyUnwrapAndExportResponse(whClientContext* ctx, enum wc_CipherTyp
200201 return WH_ERROR_OK ;
201202}
202203
203- int wh_Client_KeyUnwrapAndExport (whClientContext * ctx , enum wc_CipherType cipherType ,
204- uint16_t serverKeyId ,
205- void * wrappedKeyIn , uint16_t wrappedKeySz ,
204+ int wh_Client_KeyUnwrapAndExport (whClientContext * ctx ,
205+ enum wc_CipherType cipherType ,
206+ uint16_t serverKeyId , void * wrappedKeyIn ,
207+ uint16_t wrappedKeySz ,
206208 whNvmMetadata * metadataOut , void * keyOut ,
207209 uint16_t keySz )
208210{
@@ -212,37 +214,37 @@ int wh_Client_KeyUnwrapAndExport(whClientContext* ctx, enum wc_CipherType cipher
212214 keyOut == NULL )
213215 return WH_ERROR_BADARGS ;
214216
215- ret = wh_Client_KeyUnwrapAndExportRequest (ctx , cipherType , serverKeyId , wrappedKeyIn ,
216- wrappedKeySz );
217+ ret = wh_Client_KeyUnwrapAndExportRequest (ctx , cipherType , serverKeyId ,
218+ wrappedKeyIn , wrappedKeySz );
217219 if (ret != WH_ERROR_OK ) {
218220 return ret ;
219221 }
220222
221223 do {
222- ret =
223- wh_Client_KeyUnwrapAndExportResponse ( ctx , cipherType , metadataOut , keyOut , keySz );
224+ ret = wh_Client_KeyUnwrapAndExportResponse ( ctx , cipherType , metadataOut ,
225+ keyOut , keySz );
224226 } while (ret == WH_ERROR_NOTREADY );
225227
226228 return ret ;
227229}
228230
229- int wh_Client_KeyUnwrapAndCacheRequest (whClientContext * ctx ,
231+ int wh_Client_KeyUnwrapAndCacheRequest (whClientContext * ctx ,
230232 enum wc_CipherType cipherType ,
231- uint16_t serverKeyId ,
232- void * wrappedKeyIn ,
233- uint16_t wrappedKeySz )
233+ uint16_t serverKeyId , void * wrappedKeyIn ,
234+ uint16_t wrappedKeySz )
234235{
235236 uint16_t group = WH_MESSAGE_GROUP_KEY ;
236237 uint16_t action = WH_KEY_UNWRAPCACHE ;
237238
238239 whMessageKeystore_UnwrapAndCacheRequest * req = NULL ;
239- uint8_t * reqData ;
240+ uint8_t * reqData ;
240241
241242 if (ctx == NULL || wrappedKeyIn == NULL )
242243 return WH_ERROR_BADARGS ;
243244
244245 /* Set the request pointer to the shared comm data memory region */
245- req = (whMessageKeystore_UnwrapAndCacheRequest * )wh_CommClient_GetDataPtr (ctx -> comm );
246+ req = (whMessageKeystore_UnwrapAndCacheRequest * )wh_CommClient_GetDataPtr (
247+ ctx -> comm );
246248 if (req == NULL ) {
247249 return WH_ERROR_BADARGS ;
248250 }
@@ -260,21 +262,22 @@ int wh_Client_KeyUnwrapAndCacheRequest(whClientContext* ctx,
260262 sizeof (* req ) + wrappedKeySz , (uint8_t * )req );
261263}
262264
263- int wh_Client_KeyUnwrapAndCacheResponse (whClientContext * ctx ,
265+ int wh_Client_KeyUnwrapAndCacheResponse (whClientContext * ctx ,
264266 enum wc_CipherType cipherType ,
265- uint16_t * keyIdOut )
267+ uint16_t * keyIdOut )
266268{
267- int ret ;
268- uint16_t group ;
269- uint16_t action ;
270- uint16_t size ;
269+ int ret ;
270+ uint16_t group ;
271+ uint16_t action ;
272+ uint16_t size ;
271273 whMessageKeystore_UnwrapAndCacheResponse * resp = NULL ;
272274
273275 if (ctx == NULL || keyIdOut == NULL )
274276 return WH_ERROR_BADARGS ;
275277
276278 /* Set the response pointer to the shared comm data memory region */
277- resp = (whMessageKeystore_UnwrapAndCacheResponse * )wh_CommClient_GetDataPtr (ctx -> comm );
279+ resp = (whMessageKeystore_UnwrapAndCacheResponse * )wh_CommClient_GetDataPtr (
280+ ctx -> comm );
278281 if (resp == NULL ) {
279282 return WH_ERROR_BADARGS ;
280283 }
@@ -285,10 +288,8 @@ int wh_Client_KeyUnwrapAndCacheResponse(whClientContext* ctx,
285288 return ret ;
286289 }
287290
288- if (group != WH_MESSAGE_GROUP_KEY ||
289- action != WH_KEY_UNWRAPCACHE ||
290- size < sizeof (* resp ) ||
291- resp -> cipherType != cipherType ) {
291+ if (group != WH_MESSAGE_GROUP_KEY || action != WH_KEY_UNWRAPCACHE ||
292+ size < sizeof (* resp ) || resp -> cipherType != cipherType ) {
292293 return WH_ERROR_ABORTED ;
293294 }
294295
@@ -301,18 +302,18 @@ int wh_Client_KeyUnwrapAndCacheResponse(whClientContext* ctx,
301302 return WH_ERROR_OK ;
302303}
303304
304- int wh_Client_KeyUnwrapAndCache (whClientContext * ctx , enum wc_CipherType cipherType ,
305- uint16_t serverKeyId ,
306- void * wrappedKeyIn , uint16_t wrappedKeySz ,
307- uint16_t * keyIdOut )
305+ int wh_Client_KeyUnwrapAndCache (whClientContext * ctx ,
306+ enum wc_CipherType cipherType ,
307+ uint16_t serverKeyId , void * wrappedKeyIn ,
308+ uint16_t wrappedKeySz , uint16_t * keyIdOut )
308309{
309310 int ret = WH_ERROR_OK ;
310311
311312 if (ctx == NULL || wrappedKeyIn == NULL || keyIdOut == NULL )
312313 return WH_ERROR_BADARGS ;
313314
314- ret = wh_Client_KeyUnwrapAndCacheRequest (ctx , cipherType , serverKeyId , wrappedKeyIn ,
315- wrappedKeySz );
315+ ret = wh_Client_KeyUnwrapAndCacheRequest (ctx , cipherType , serverKeyId ,
316+ wrappedKeyIn , wrappedKeySz );
316317 if (ret != WH_ERROR_OK ) {
317318 return ret ;
318319 }
0 commit comments