Skip to content

Commit eaffe37

Browse files
dalessanherbertx
authored andcommitted
crypto: ecc - Export additional helper functions
Export the following additional ECC helper functions: - ecc_alloc_point() - ecc_free_point() - vli_num_bits() - ecc_point_is_zero() This is done to allow future ECC device drivers to re-use existing code, thus simplifying their implementation. Functions are exported using EXPORT_SYMBOL() (instead of EXPORT_SYMBOL_GPL()) to be consistent with the functions already exported by crypto/ecc.c. Exported functions are documented in include/crypto/internal/ecc.h. Signed-off-by: Daniele Alessandrelli <[email protected]> Signed-off-by: Herbert Xu <[email protected]>
1 parent a745d3a commit eaffe37

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

crypto/ecc.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static void ecc_free_digits_space(u64 *space)
8181
kfree_sensitive(space);
8282
}
8383

84-
static struct ecc_point *ecc_alloc_point(unsigned int ndigits)
84+
struct ecc_point *ecc_alloc_point(unsigned int ndigits)
8585
{
8686
struct ecc_point *p = kmalloc(sizeof(*p), GFP_KERNEL);
8787

@@ -106,8 +106,9 @@ static struct ecc_point *ecc_alloc_point(unsigned int ndigits)
106106
kfree(p);
107107
return NULL;
108108
}
109+
EXPORT_SYMBOL(ecc_alloc_point);
109110

110-
static void ecc_free_point(struct ecc_point *p)
111+
void ecc_free_point(struct ecc_point *p)
111112
{
112113
if (!p)
113114
return;
@@ -116,6 +117,7 @@ static void ecc_free_point(struct ecc_point *p)
116117
kfree_sensitive(p->y);
117118
kfree_sensitive(p);
118119
}
120+
EXPORT_SYMBOL(ecc_free_point);
119121

120122
static void vli_clear(u64 *vli, unsigned int ndigits)
121123
{
@@ -165,7 +167,7 @@ static unsigned int vli_num_digits(const u64 *vli, unsigned int ndigits)
165167
}
166168

167169
/* Counts the number of bits required for vli. */
168-
static unsigned int vli_num_bits(const u64 *vli, unsigned int ndigits)
170+
unsigned int vli_num_bits(const u64 *vli, unsigned int ndigits)
169171
{
170172
unsigned int i, num_digits;
171173
u64 digit;
@@ -180,6 +182,7 @@ static unsigned int vli_num_bits(const u64 *vli, unsigned int ndigits)
180182

181183
return ((num_digits - 1) * 64 + i);
182184
}
185+
EXPORT_SYMBOL(vli_num_bits);
183186

184187
/* Set dest from unaligned bit string src. */
185188
void vli_from_be64(u64 *dest, const void *src, unsigned int ndigits)
@@ -1062,11 +1065,12 @@ EXPORT_SYMBOL(vli_mod_inv);
10621065
/* ------ Point operations ------ */
10631066

10641067
/* Returns true if p_point is the point at infinity, false otherwise. */
1065-
static bool ecc_point_is_zero(const struct ecc_point *point)
1068+
bool ecc_point_is_zero(const struct ecc_point *point)
10661069
{
10671070
return (vli_is_zero(point->x, point->ndigits) &&
10681071
vli_is_zero(point->y, point->ndigits));
10691072
}
1073+
EXPORT_SYMBOL(ecc_point_is_zero);
10701074

10711075
/* Point multiplication algorithm using Montgomery's ladder with co-Z
10721076
* coordinates. From https://eprint.iacr.org/2011/338.pdf

include/crypto/internal/ecc.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,41 @@ void vli_mod_inv(u64 *result, const u64 *input, const u64 *mod,
225225
void vli_mod_mult_slow(u64 *result, const u64 *left, const u64 *right,
226226
const u64 *mod, unsigned int ndigits);
227227

228+
/**
229+
* vli_num_bits() - Counts the number of bits required for vli.
230+
*
231+
* @vli: vli to check.
232+
* @ndigits: Length of the @vli
233+
*
234+
* Return: The number of bits required to represent @vli.
235+
*/
236+
unsigned int vli_num_bits(const u64 *vli, unsigned int ndigits);
237+
238+
/**
239+
* ecc_aloc_point() - Allocate ECC point.
240+
*
241+
* @ndigits: Length of vlis in u64 qwords.
242+
*
243+
* Return: Pointer to the allocated point or NULL if allocation failed.
244+
*/
245+
struct ecc_point *ecc_alloc_point(unsigned int ndigits);
246+
247+
/**
248+
* ecc_free_point() - Free ECC point.
249+
*
250+
* @p: The point to free.
251+
*/
252+
void ecc_free_point(struct ecc_point *p);
253+
254+
/**
255+
* ecc_point_is_zero() - Check if point is zero.
256+
*
257+
* @p: Point to check for zero.
258+
*
259+
* Return: true if point is the point at infinity, false otherwise.
260+
*/
261+
bool ecc_point_is_zero(const struct ecc_point *point);
262+
228263
/**
229264
* ecc_point_mult_shamir() - Add two points multiplied by scalars
230265
*
@@ -242,4 +277,5 @@ void ecc_point_mult_shamir(const struct ecc_point *result,
242277
const u64 *x, const struct ecc_point *p,
243278
const u64 *y, const struct ecc_point *q,
244279
const struct ecc_curve *curve);
280+
245281
#endif

0 commit comments

Comments
 (0)