Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <daniele.alessandrelli@intel.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

authored by

Daniele Alessandrelli and committed by
Herbert Xu
eaffe377 a745d3ac

+44 -4
+8 -4
crypto/ecc.c
··· 81 81 kfree_sensitive(space); 82 82 } 83 83 84 - static struct ecc_point *ecc_alloc_point(unsigned int ndigits) 84 + struct ecc_point *ecc_alloc_point(unsigned int ndigits) 85 85 { 86 86 struct ecc_point *p = kmalloc(sizeof(*p), GFP_KERNEL); 87 87 ··· 106 106 kfree(p); 107 107 return NULL; 108 108 } 109 + EXPORT_SYMBOL(ecc_alloc_point); 109 110 110 - static void ecc_free_point(struct ecc_point *p) 111 + void ecc_free_point(struct ecc_point *p) 111 112 { 112 113 if (!p) 113 114 return; ··· 117 116 kfree_sensitive(p->y); 118 117 kfree_sensitive(p); 119 118 } 119 + EXPORT_SYMBOL(ecc_free_point); 120 120 121 121 static void vli_clear(u64 *vli, unsigned int ndigits) 122 122 { ··· 167 165 } 168 166 169 167 /* Counts the number of bits required for vli. */ 170 - static unsigned int vli_num_bits(const u64 *vli, unsigned int ndigits) 168 + unsigned int vli_num_bits(const u64 *vli, unsigned int ndigits) 171 169 { 172 170 unsigned int i, num_digits; 173 171 u64 digit; ··· 182 180 183 181 return ((num_digits - 1) * 64 + i); 184 182 } 183 + EXPORT_SYMBOL(vli_num_bits); 185 184 186 185 /* Set dest from unaligned bit string src. */ 187 186 void vli_from_be64(u64 *dest, const void *src, unsigned int ndigits) ··· 1065 1062 /* ------ Point operations ------ */ 1066 1063 1067 1064 /* Returns true if p_point is the point at infinity, false otherwise. */ 1068 - static bool ecc_point_is_zero(const struct ecc_point *point) 1065 + bool ecc_point_is_zero(const struct ecc_point *point) 1069 1066 { 1070 1067 return (vli_is_zero(point->x, point->ndigits) && 1071 1068 vli_is_zero(point->y, point->ndigits)); 1072 1069 } 1070 + EXPORT_SYMBOL(ecc_point_is_zero); 1073 1071 1074 1072 /* Point multiplication algorithm using Montgomery's ladder with co-Z 1075 1073 * coordinates. From https://eprint.iacr.org/2011/338.pdf
+36
include/crypto/internal/ecc.h
··· 226 226 const u64 *mod, unsigned int ndigits); 227 227 228 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 + 263 + /** 229 264 * ecc_point_mult_shamir() - Add two points multiplied by scalars 230 265 * 231 266 * @result: resulting point ··· 277 242 const u64 *x, const struct ecc_point *p, 278 243 const u64 *y, const struct ecc_point *q, 279 244 const struct ecc_curve *curve); 245 + 280 246 #endif