@@ -186,7 +186,10 @@ static int atmel_ecc_init_ecdh_cmd(struct atmel_ecc_cmd *cmd,
186186 * always be the same. Use a macro for the key size to avoid unnecessary
187187 * computations.
188188 */
189- copied = sg_copy_to_buffer (pubkey , 1 , cmd -> data , ATMEL_ECC_PUBKEY_SIZE );
189+ copied = sg_copy_to_buffer (pubkey ,
190+ sg_nents_for_len (pubkey ,
191+ ATMEL_ECC_PUBKEY_SIZE ),
192+ cmd -> data , ATMEL_ECC_PUBKEY_SIZE );
190193 if (copied != ATMEL_ECC_PUBKEY_SIZE )
191194 return - EINVAL ;
192195
@@ -268,15 +271,17 @@ static void atmel_ecdh_done(struct atmel_ecc_work_data *work_data, void *areq,
268271 struct kpp_request * req = areq ;
269272 struct atmel_ecdh_ctx * ctx = work_data -> ctx ;
270273 struct atmel_ecc_cmd * cmd = & work_data -> cmd ;
271- size_t copied ;
272- size_t n_sz = ctx -> n_sz ;
274+ size_t copied , n_sz ;
273275
274276 if (status )
275277 goto free_work_data ;
276278
279+ /* might want less than we've got */
280+ n_sz = min_t (size_t , ctx -> n_sz , req -> dst_len );
281+
277282 /* copy the shared secret */
278- copied = sg_copy_from_buffer (req -> dst , 1 , & cmd -> data [ RSP_DATA_IDX ] ,
279- n_sz );
283+ copied = sg_copy_from_buffer (req -> dst , sg_nents_for_len ( req -> dst , n_sz ) ,
284+ & cmd -> data [ RSP_DATA_IDX ], n_sz );
280285 if (copied != n_sz )
281286 status = - EINVAL ;
282287
@@ -440,18 +445,22 @@ static int atmel_ecdh_generate_public_key(struct kpp_request *req)
440445{
441446 struct crypto_kpp * tfm = crypto_kpp_reqtfm (req );
442447 struct atmel_ecdh_ctx * ctx = kpp_tfm_ctx (tfm );
443- size_t copied ;
448+ size_t copied , nbytes ;
444449 int ret = 0 ;
445450
446451 if (ctx -> do_fallback ) {
447452 kpp_request_set_tfm (req , ctx -> fallback );
448453 return crypto_kpp_generate_public_key (req );
449454 }
450455
456+ /* might want less than we've got */
457+ nbytes = min_t (size_t , ATMEL_ECC_PUBKEY_SIZE , req -> dst_len );
458+
451459 /* public key was saved at private key generation */
452- copied = sg_copy_from_buffer (req -> dst , 1 , ctx -> public_key ,
453- ATMEL_ECC_PUBKEY_SIZE );
454- if (copied != ATMEL_ECC_PUBKEY_SIZE )
460+ copied = sg_copy_from_buffer (req -> dst ,
461+ sg_nents_for_len (req -> dst , nbytes ),
462+ ctx -> public_key , nbytes );
463+ if (copied != nbytes )
455464 ret = - EINVAL ;
456465
457466 return ret ;
@@ -470,6 +479,10 @@ static int atmel_ecdh_compute_shared_secret(struct kpp_request *req)
470479 return crypto_kpp_compute_shared_secret (req );
471480 }
472481
482+ /* must have exactly two points to be on the curve */
483+ if (req -> src_len != ATMEL_ECC_PUBKEY_SIZE )
484+ return - EINVAL ;
485+
473486 gfp = (req -> base .flags & CRYPTO_TFM_REQ_MAY_SLEEP ) ? GFP_KERNEL :
474487 GFP_ATOMIC ;
475488
@@ -554,10 +567,6 @@ static int atmel_ecdh_init_tfm(struct crypto_kpp *tfm)
554567 }
555568
556569 crypto_kpp_set_flags (fallback , crypto_kpp_get_flags (tfm ));
557-
558- dev_info (& ctx -> client -> dev , "Using '%s' as fallback implementation.\n" ,
559- crypto_tfm_alg_driver_name (crypto_kpp_tfm (fallback )));
560-
561570 ctx -> fallback = fallback ;
562571
563572 return 0 ;
0 commit comments