@@ -42,6 +42,7 @@ static int nx_xcbc_set_key(struct crypto_shash *desc,
4242 unsigned int key_len )
4343{
4444 struct nx_crypto_ctx * nx_ctx = crypto_shash_ctx (desc );
45+ struct nx_csbcpb * csbcpb = nx_ctx -> csbcpb ;
4546
4647 switch (key_len ) {
4748 case AES_KEYSIZE_128 :
@@ -51,7 +52,7 @@ static int nx_xcbc_set_key(struct crypto_shash *desc,
5152 return - EINVAL ;
5253 }
5354
54- memcpy (nx_ctx -> priv . xcbc .key , in_key , key_len );
55+ memcpy (csbcpb -> cpb . aes_xcbc .key , in_key , key_len );
5556
5657 return 0 ;
5758}
@@ -148,32 +149,29 @@ static int nx_xcbc_empty(struct shash_desc *desc, u8 *out)
148149 return rc ;
149150}
150151
151- static int nx_xcbc_init (struct shash_desc * desc )
152+ static int nx_crypto_ctx_aes_xcbc_init2 (struct crypto_tfm * tfm )
152153{
153- struct xcbc_state * sctx = shash_desc_ctx (desc );
154- struct nx_crypto_ctx * nx_ctx = crypto_tfm_ctx (& desc -> tfm -> base );
154+ struct nx_crypto_ctx * nx_ctx = crypto_tfm_ctx (tfm );
155155 struct nx_csbcpb * csbcpb = nx_ctx -> csbcpb ;
156- struct nx_sg * out_sg ;
157- int len ;
156+ int err ;
158157
159- nx_ctx_init (nx_ctx , HCOP_FC_AES );
158+ err = nx_crypto_ctx_aes_xcbc_init (tfm );
159+ if (err )
160+ return err ;
160161
161- memset ( sctx , 0 , sizeof * sctx );
162+ nx_ctx_init ( nx_ctx , HCOP_FC_AES );
162163
163164 NX_CPB_SET_KEY_SIZE (csbcpb , NX_KS_AES_128 );
164165 csbcpb -> cpb .hdr .mode = NX_MODE_AES_XCBC_MAC ;
165166
166- memcpy (csbcpb -> cpb .aes_xcbc .key , nx_ctx -> priv .xcbc .key , AES_BLOCK_SIZE );
167- memset (nx_ctx -> priv .xcbc .key , 0 , sizeof * nx_ctx -> priv .xcbc .key );
168-
169- len = AES_BLOCK_SIZE ;
170- out_sg = nx_build_sg_list (nx_ctx -> out_sg , (u8 * )sctx -> state ,
171- & len , nx_ctx -> ap -> sglen );
167+ return 0 ;
168+ }
172169
173- if (len != AES_BLOCK_SIZE )
174- return - EINVAL ;
170+ static int nx_xcbc_init (struct shash_desc * desc )
171+ {
172+ struct xcbc_state * sctx = shash_desc_ctx (desc );
175173
176- nx_ctx -> op . outlen = ( nx_ctx -> out_sg - out_sg ) * sizeof ( struct nx_sg );
174+ memset ( sctx , 0 , sizeof * sctx );
177175
178176 return 0 ;
179177}
@@ -186,6 +184,7 @@ static int nx_xcbc_update(struct shash_desc *desc,
186184 struct nx_crypto_ctx * nx_ctx = crypto_tfm_ctx (& desc -> tfm -> base );
187185 struct nx_csbcpb * csbcpb = nx_ctx -> csbcpb ;
188186 struct nx_sg * in_sg ;
187+ struct nx_sg * out_sg ;
189188 u32 to_process = 0 , leftover , total ;
190189 unsigned int max_sg_len ;
191190 unsigned long irq_flags ;
@@ -213,6 +212,17 @@ static int nx_xcbc_update(struct shash_desc *desc,
213212 max_sg_len = min_t (u64 , max_sg_len ,
214213 nx_ctx -> ap -> databytelen /NX_PAGE_SIZE );
215214
215+ data_len = AES_BLOCK_SIZE ;
216+ out_sg = nx_build_sg_list (nx_ctx -> out_sg , (u8 * )sctx -> state ,
217+ & len , nx_ctx -> ap -> sglen );
218+
219+ if (data_len != AES_BLOCK_SIZE ) {
220+ rc = - EINVAL ;
221+ goto out ;
222+ }
223+
224+ nx_ctx -> op .outlen = (nx_ctx -> out_sg - out_sg ) * sizeof (struct nx_sg );
225+
216226 do {
217227 to_process = total - to_process ;
218228 to_process = to_process & ~(AES_BLOCK_SIZE - 1 );
@@ -235,8 +245,10 @@ static int nx_xcbc_update(struct shash_desc *desc,
235245 (u8 * ) sctx -> buffer ,
236246 & data_len ,
237247 max_sg_len );
238- if (data_len != sctx -> count )
239- return - EINVAL ;
248+ if (data_len != sctx -> count ) {
249+ rc = - EINVAL ;
250+ goto out ;
251+ }
240252 }
241253
242254 data_len = to_process - sctx -> count ;
@@ -245,8 +257,10 @@ static int nx_xcbc_update(struct shash_desc *desc,
245257 & data_len ,
246258 max_sg_len );
247259
248- if (data_len != to_process - sctx -> count )
249- return - EINVAL ;
260+ if (data_len != to_process - sctx -> count ) {
261+ rc = - EINVAL ;
262+ goto out ;
263+ }
250264
251265 nx_ctx -> op .inlen = (nx_ctx -> in_sg - in_sg ) *
252266 sizeof (struct nx_sg );
@@ -325,15 +339,19 @@ static int nx_xcbc_final(struct shash_desc *desc, u8 *out)
325339 in_sg = nx_build_sg_list (nx_ctx -> in_sg , (u8 * )sctx -> buffer ,
326340 & len , nx_ctx -> ap -> sglen );
327341
328- if (len != sctx -> count )
329- return - EINVAL ;
342+ if (len != sctx -> count ) {
343+ rc = - EINVAL ;
344+ goto out ;
345+ }
330346
331347 len = AES_BLOCK_SIZE ;
332348 out_sg = nx_build_sg_list (nx_ctx -> out_sg , out , & len ,
333349 nx_ctx -> ap -> sglen );
334350
335- if (len != AES_BLOCK_SIZE )
336- return - EINVAL ;
351+ if (len != AES_BLOCK_SIZE ) {
352+ rc = - EINVAL ;
353+ goto out ;
354+ }
337355
338356 nx_ctx -> op .inlen = (nx_ctx -> in_sg - in_sg ) * sizeof (struct nx_sg );
339357 nx_ctx -> op .outlen = (nx_ctx -> out_sg - out_sg ) * sizeof (struct nx_sg );
@@ -372,7 +390,7 @@ struct shash_alg nx_shash_aes_xcbc_alg = {
372390 .cra_blocksize = AES_BLOCK_SIZE ,
373391 .cra_module = THIS_MODULE ,
374392 .cra_ctxsize = sizeof (struct nx_crypto_ctx ),
375- .cra_init = nx_crypto_ctx_aes_xcbc_init ,
393+ .cra_init = nx_crypto_ctx_aes_xcbc_init2 ,
376394 .cra_exit = nx_crypto_ctx_exit ,
377395 }
378396};
0 commit comments