ecc_curve.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* Copyright (c) 2021 HiSilicon */
  3. #ifndef _CRYTO_ECC_CURVE_H
  4. #define _CRYTO_ECC_CURVE_H
  5. #include <linux/types.h>
  6. /**
  7. * struct ecc_point - elliptic curve point in affine coordinates
  8. *
  9. * @x: X coordinate in vli form.
  10. * @y: Y coordinate in vli form.
  11. * @ndigits: Length of vlis in u64 qwords.
  12. */
  13. struct ecc_point {
  14. u64 *x;
  15. u64 *y;
  16. u8 ndigits;
  17. };
  18. /**
  19. * struct ecc_curve - definition of elliptic curve
  20. *
  21. * @name: Short name of the curve.
  22. * @nbits: The number of bits of a curve.
  23. * @g: Generator point of the curve.
  24. * @p: Prime number, if Barrett's reduction is used for this curve
  25. * pre-calculated value 'mu' is appended to the @p after ndigits.
  26. * Use of Barrett's reduction is heuristically determined in
  27. * vli_mmod_fast().
  28. * @n: Order of the curve group.
  29. * @a: Curve parameter a.
  30. * @b: Curve parameter b.
  31. */
  32. struct ecc_curve {
  33. char *name;
  34. u32 nbits;
  35. struct ecc_point g;
  36. u64 *p;
  37. u64 *n;
  38. u64 *a;
  39. u64 *b;
  40. };
  41. /**
  42. * ecc_get_curve() - get elliptic curve;
  43. * @curve_id: Curves IDs:
  44. * defined in 'include/crypto/ecdh.h';
  45. *
  46. * Returns curve if get curve succssful, NULL otherwise
  47. */
  48. const struct ecc_curve *ecc_get_curve(unsigned int curve_id);
  49. /**
  50. * ecc_get_curve25519() - get curve25519 curve;
  51. *
  52. * Returns curve25519
  53. */
  54. const struct ecc_curve *ecc_get_curve25519(void);
  55. #endif