@@ -34,7 +34,6 @@ static struct atmel_ecc_driver_data driver_data;
3434 * of the user to not call set_secret() while
3535 * generate_public_key() or compute_shared_secret() are in flight.
3636 * @curve_id : elliptic curve id
37- * @n_sz : size in bytes of the n prime
3837 * @do_fallback: true when the device doesn't support the curve or when the user
3938 * wants to use its own private key.
4039 */
@@ -43,23 +42,21 @@ struct atmel_ecdh_ctx {
4342 struct crypto_kpp * fallback ;
4443 const u8 * public_key ;
4544 unsigned int curve_id ;
46- size_t n_sz ;
4745 bool do_fallback ;
4846};
4947
5048static void atmel_ecdh_done (struct atmel_i2c_work_data * work_data , void * areq ,
5149 int status )
5250{
5351 struct kpp_request * req = areq ;
54- struct atmel_ecdh_ctx * ctx = work_data -> ctx ;
5552 struct atmel_i2c_cmd * cmd = & work_data -> cmd ;
5653 size_t copied , n_sz ;
5754
5855 if (status )
5956 goto free_work_data ;
6057
6158 /* might want less than we've got */
62- n_sz = min_t (size_t , ctx -> n_sz , req -> dst_len );
59+ n_sz = min_t (size_t , ATMEL_ECC_NIST_P256_N_SIZE , req -> dst_len );
6360
6461 /* copy the shared secret */
6562 copied = sg_copy_from_buffer (req -> dst , sg_nents_for_len (req -> dst , n_sz ),
@@ -73,14 +70,6 @@ static void atmel_ecdh_done(struct atmel_i2c_work_data *work_data, void *areq,
7370 kpp_request_complete (req , status );
7471}
7572
76- static unsigned int atmel_ecdh_supported_curve (unsigned int curve_id )
77- {
78- if (curve_id == ECC_CURVE_NIST_P256 )
79- return ATMEL_ECC_NIST_P256_N_SIZE ;
80-
81- return 0 ;
82- }
83-
8473/*
8574 * A random private key is generated and stored in the device. The device
8675 * returns the pair public key.
@@ -104,8 +93,7 @@ static int atmel_ecdh_set_secret(struct crypto_kpp *tfm, const void *buf,
10493 return - EINVAL ;
10594 }
10695
107- ctx -> n_sz = atmel_ecdh_supported_curve (params .curve_id );
108- if (!ctx -> n_sz || params .key_size ) {
96+ if (params .key_size ) {
10997 /* fallback to ecdh software implementation */
11098 ctx -> do_fallback = true;
11199 return crypto_kpp_set_secret (ctx -> fallback , buf , len );
@@ -125,7 +113,6 @@ static int atmel_ecdh_set_secret(struct crypto_kpp *tfm, const void *buf,
125113 goto free_cmd ;
126114
127115 ctx -> do_fallback = false;
128- ctx -> curve_id = params .curve_id ;
129116
130117 atmel_i2c_init_genkey_cmd (cmd , DATA_SLOT_2 );
131118
@@ -263,6 +250,7 @@ static int atmel_ecdh_init_tfm(struct crypto_kpp *tfm)
263250 struct crypto_kpp * fallback ;
264251 struct atmel_ecdh_ctx * ctx = kpp_tfm_ctx (tfm );
265252
253+ ctx -> curve_id = ECC_CURVE_NIST_P256 ;
266254 ctx -> client = atmel_ecc_i2c_client_alloc ();
267255 if (IS_ERR (ctx -> client )) {
268256 pr_err ("tfm - i2c_client binding failed\n" );
@@ -306,7 +294,7 @@ static unsigned int atmel_ecdh_max_size(struct crypto_kpp *tfm)
306294 return ATMEL_ECC_PUBKEY_SIZE ;
307295}
308296
309- static struct kpp_alg atmel_ecdh = {
297+ static struct kpp_alg atmel_ecdh_nist_p256 = {
310298 .set_secret = atmel_ecdh_set_secret ,
311299 .generate_public_key = atmel_ecdh_generate_public_key ,
312300 .compute_shared_secret = atmel_ecdh_compute_shared_secret ,
@@ -315,7 +303,7 @@ static struct kpp_alg atmel_ecdh = {
315303 .max_size = atmel_ecdh_max_size ,
316304 .base = {
317305 .cra_flags = CRYPTO_ALG_NEED_FALLBACK ,
318- .cra_name = "ecdh" ,
306+ .cra_name = "ecdh-nist-p256 " ,
319307 .cra_driver_name = "atmel-ecdh" ,
320308 .cra_priority = ATMEL_ECC_PRIORITY ,
321309 .cra_module = THIS_MODULE ,
@@ -340,14 +328,14 @@ static int atmel_ecc_probe(struct i2c_client *client,
340328 & driver_data .i2c_client_list );
341329 spin_unlock (& driver_data .i2c_list_lock );
342330
343- ret = crypto_register_kpp (& atmel_ecdh );
331+ ret = crypto_register_kpp (& atmel_ecdh_nist_p256 );
344332 if (ret ) {
345333 spin_lock (& driver_data .i2c_list_lock );
346334 list_del (& i2c_priv -> i2c_client_list_node );
347335 spin_unlock (& driver_data .i2c_list_lock );
348336
349337 dev_err (& client -> dev , "%s alg registration failed\n" ,
350- atmel_ecdh .base .cra_driver_name );
338+ atmel_ecdh_nist_p256 .base .cra_driver_name );
351339 } else {
352340 dev_info (& client -> dev , "atmel ecc algorithms registered in /proc/crypto\n" );
353341 }
@@ -365,7 +353,7 @@ static int atmel_ecc_remove(struct i2c_client *client)
365353 return - EBUSY ;
366354 }
367355
368- crypto_unregister_kpp (& atmel_ecdh );
356+ crypto_unregister_kpp (& atmel_ecdh_nist_p256 );
369357
370358 spin_lock (& driver_data .i2c_list_lock );
371359 list_del (& i2c_priv -> i2c_client_list_node );
0 commit comments