@@ -904,7 +904,7 @@ static inline void ecc_swap_digits(const u64 *in, u64 *out,
904904}
905905
906906int ecc_is_key_valid (unsigned int curve_id , unsigned int ndigits ,
907- const u8 * private_key , unsigned int private_key_len )
907+ const u64 * private_key , unsigned int private_key_len )
908908{
909909 int nbytes ;
910910 const struct ecc_curve * curve = ecc_get_curve (curve_id );
@@ -917,31 +917,30 @@ int ecc_is_key_valid(unsigned int curve_id, unsigned int ndigits,
917917 if (private_key_len != nbytes )
918918 return - EINVAL ;
919919
920- if (vli_is_zero (( const u64 * ) & private_key [ 0 ] , ndigits ))
920+ if (vli_is_zero (private_key , ndigits ))
921921 return - EINVAL ;
922922
923923 /* Make sure the private key is in the range [1, n-1]. */
924- if (vli_cmp (curve -> n , ( const u64 * ) & private_key [ 0 ] , ndigits ) != 1 )
924+ if (vli_cmp (curve -> n , private_key , ndigits ) != 1 )
925925 return - EINVAL ;
926926
927927 return 0 ;
928928}
929929
930930int ecdh_make_pub_key (unsigned int curve_id , unsigned int ndigits ,
931- const u8 * private_key , u8 * public_key )
931+ const u64 * private_key , u64 * public_key )
932932{
933933 int ret = 0 ;
934934 struct ecc_point * pk ;
935935 u64 priv [ndigits ];
936- unsigned int nbytes ;
937936 const struct ecc_curve * curve = ecc_get_curve (curve_id );
938937
939938 if (!private_key || !curve ) {
940939 ret = - EINVAL ;
941940 goto out ;
942941 }
943942
944- ecc_swap_digits (( const u64 * ) private_key , priv , ndigits );
943+ ecc_swap_digits (private_key , priv , ndigits );
945944
946945 pk = ecc_alloc_point (ndigits );
947946 if (!pk ) {
@@ -955,9 +954,8 @@ int ecdh_make_pub_key(unsigned int curve_id, unsigned int ndigits,
955954 goto err_free_point ;
956955 }
957956
958- nbytes = ndigits << ECC_DIGITS_TO_BYTES_SHIFT ;
959- ecc_swap_digits (pk -> x , (u64 * )public_key , ndigits );
960- ecc_swap_digits (pk -> y , (u64 * )& public_key [nbytes ], ndigits );
957+ ecc_swap_digits (pk -> x , public_key , ndigits );
958+ ecc_swap_digits (pk -> y , & public_key [ndigits ], ndigits );
961959
962960err_free_point :
963961 ecc_free_point (pk );
@@ -966,8 +964,8 @@ int ecdh_make_pub_key(unsigned int curve_id, unsigned int ndigits,
966964}
967965
968966int crypto_ecdh_shared_secret (unsigned int curve_id , unsigned int ndigits ,
969- const u8 * private_key , const u8 * public_key ,
970- u8 * secret )
967+ const u64 * private_key , const u64 * public_key ,
968+ u64 * secret )
971969{
972970 int ret = 0 ;
973971 struct ecc_point * product , * pk ;
@@ -997,13 +995,13 @@ int crypto_ecdh_shared_secret(unsigned int curve_id, unsigned int ndigits,
997995 goto err_alloc_product ;
998996 }
999997
1000- ecc_swap_digits (( const u64 * ) public_key , pk -> x , ndigits );
1001- ecc_swap_digits (( const u64 * ) & public_key [nbytes ], pk -> y , ndigits );
1002- ecc_swap_digits (( const u64 * ) private_key , priv , ndigits );
998+ ecc_swap_digits (public_key , pk -> x , ndigits );
999+ ecc_swap_digits (& public_key [ndigits ], pk -> y , ndigits );
1000+ ecc_swap_digits (private_key , priv , ndigits );
10031001
10041002 ecc_point_mult (product , pk , priv , rand_z , curve -> p , ndigits );
10051003
1006- ecc_swap_digits (product -> x , ( u64 * ) secret , ndigits );
1004+ ecc_swap_digits (product -> x , secret , ndigits );
10071005
10081006 if (ecc_point_is_zero (product ))
10091007 ret = - EFAULT ;
0 commit comments