linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Daniele Alessandrelli <daniele.alessandrelli@linux.intel.com>
To: linux-crypto@vger.kernel.org,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>
Cc: devicetree@vger.kernel.org, Rob Herring <robh+dt@kernel.org>,
	Daniele Alessandrelli <daniele.alessandrelli@intel.com>,
	Mark Gross <mgross@linux.intel.com>,
	Prabhjot Khurana <prabhjot.khurana@intel.com>,
	Elena Reshetova <elena.reshetova@intel.com>
Subject: [RFC PATCH 3/6] crypto: ecc - Export additional helper functions
Date: Thu, 17 Dec 2020 17:20:58 +0000	[thread overview]
Message-ID: <20201217172101.381772-4-daniele.alessandrelli@linux.intel.com> (raw)
In-Reply-To: <20201217172101.381772-1-daniele.alessandrelli@linux.intel.com>

From: Daniele Alessandrelli <daniele.alessandrelli@intel.com>

Export the following additional ECC helper functions:
- ecc_alloc_point()
- ecc_free_point()
- vli_num_bits()
- ecc_point_is_zero()
- ecc_swap_digits()

This is done to allow future KPP 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 crypto/ecc.h.

Signed-off-by: Daniele Alessandrelli <daniele.alessandrelli@intel.com>
---
 crypto/ecc.c                  | 16 ++++++++-----
 include/crypto/internal/ecc.h | 44 +++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 6 deletions(-)

diff --git a/crypto/ecc.c b/crypto/ecc.c
index 9aa801315a32..e8176db071d8 100644
--- a/crypto/ecc.c
+++ b/crypto/ecc.c
@@ -70,7 +70,7 @@ static void ecc_free_digits_space(u64 *space)
 	kfree_sensitive(space);
 }
 
-static struct ecc_point *ecc_alloc_point(unsigned int ndigits)
+struct ecc_point *ecc_alloc_point(unsigned int ndigits)
 {
 	struct ecc_point *p = kmalloc(sizeof(*p), GFP_KERNEL);
 
@@ -95,8 +95,9 @@ static struct ecc_point *ecc_alloc_point(unsigned int ndigits)
 	kfree(p);
 	return NULL;
 }
+EXPORT_SYMBOL(ecc_alloc_point);
 
-static void ecc_free_point(struct ecc_point *p)
+void ecc_free_point(struct ecc_point *p)
 {
 	if (!p)
 		return;
@@ -105,6 +106,7 @@ static void ecc_free_point(struct ecc_point *p)
 	kfree_sensitive(p->y);
 	kfree_sensitive(p);
 }
+EXPORT_SYMBOL(ecc_free_point);
 
 static void vli_clear(u64 *vli, unsigned int ndigits)
 {
@@ -154,7 +156,7 @@ static unsigned int vli_num_digits(const u64 *vli, unsigned int ndigits)
 }
 
 /* Counts the number of bits required for vli. */
-static unsigned int vli_num_bits(const u64 *vli, unsigned int ndigits)
+unsigned int vli_num_bits(const u64 *vli, unsigned int ndigits)
 {
 	unsigned int i, num_digits;
 	u64 digit;
@@ -169,6 +171,7 @@ static unsigned int vli_num_bits(const u64 *vli, unsigned int ndigits)
 
 	return ((num_digits - 1) * 64 + i);
 }
+EXPORT_SYMBOL(vli_num_bits);
 
 /* Set dest from unaligned bit string src. */
 void vli_from_be64(u64 *dest, const void *src, unsigned int ndigits)
@@ -933,11 +936,12 @@ EXPORT_SYMBOL(vli_mod_inv);
 /* ------ Point operations ------ */
 
 /* Returns true if p_point is the point at infinity, false otherwise. */
-static bool ecc_point_is_zero(const struct ecc_point *point)
+bool ecc_point_is_zero(const struct ecc_point *point)
 {
 	return (vli_is_zero(point->x, point->ndigits) &&
 		vli_is_zero(point->y, point->ndigits));
 }
+EXPORT_SYMBOL(ecc_point_is_zero);
 
 /* Point multiplication algorithm using Montgomery's ladder with co-Z
  * coordinates. From https://eprint.iacr.org/2011/338.pdf
@@ -1281,8 +1285,7 @@ void ecc_point_mult_shamir(const struct ecc_point *result,
 }
 EXPORT_SYMBOL(ecc_point_mult_shamir);
 
-static inline void ecc_swap_digits(const u64 *in, u64 *out,
-				   unsigned int ndigits)
+void ecc_swap_digits(const u64 *in, u64 *out, unsigned int ndigits)
 {
 	const __be64 *src = (__force __be64 *)in;
 	int i;
@@ -1290,6 +1293,7 @@ static inline void ecc_swap_digits(const u64 *in, u64 *out,
 	for (i = 0; i < ndigits; i++)
 		out[i] = be64_to_cpu(src[ndigits - 1 - i]);
 }
+EXPORT_SYMBOL(ecc_swap_digits);
 
 static int __ecc_is_key_valid(const struct ecc_curve *curve,
 			      const u64 *private_key, unsigned int ndigits)
diff --git a/include/crypto/internal/ecc.h b/include/crypto/internal/ecc.h
index d4e546b9ad79..2f6ac78b64f3 100644
--- a/include/crypto/internal/ecc.h
+++ b/include/crypto/internal/ecc.h
@@ -239,6 +239,41 @@ void vli_mod_inv(u64 *result, const u64 *input, const u64 *mod,
 void vli_mod_mult_slow(u64 *result, const u64 *left, const u64 *right,
 		       const u64 *mod, unsigned int ndigits);
 
+/**
+ * vli_num_bits() - Counts the number of bits required for vli.
+ *
+ * @vli:		vli to check.
+ * @ndigits:		Length of the @vli
+ *
+ * Return: The number of bits required to represent @vli.
+ */
+unsigned int vli_num_bits(const u64 *vli, unsigned int ndigits);
+
+/**
+ * ecc_aloc_point() - Allocate ECC point.
+ *
+ * @ndigits:		Length of vlis in u64 qwords.
+ *
+ * Return: Pointer to the allocated point or NULL if allocation failed.
+ */
+struct ecc_point *ecc_alloc_point(unsigned int ndigits);
+
+/**
+ * ecc_free_point() - Free ECC point.
+ *
+ * @p:			The point to free.
+ */
+void ecc_free_point(struct ecc_point *p);
+
+/**
+ * ecc_point_is_zero() - Check if point is zero.
+ *
+ * @p:			Point to check for zero.
+ *
+ * Return: true if point is the point at infinity, false otherwise.
+ */
+bool ecc_point_is_zero(const struct ecc_point *point);
+
 /**
  * ecc_point_mult_shamir() - Add two points multiplied by scalars
  *
@@ -256,4 +291,13 @@ void ecc_point_mult_shamir(const struct ecc_point *result,
 			   const u64 *x, const struct ecc_point *p,
 			   const u64 *y, const struct ecc_point *q,
 			   const struct ecc_curve *curve);
+
+/**
+ * ecc_swap_digits() - Swap digits in vli.
+ *
+ * @in:			The input vli (whose digits will be swapped).
+ * @out:		The output vli (where swapped digits will be saved).
+ * @ndigits:		Length of vli to be swapped.
+ */
+void ecc_swap_digits(const u64 *in, u64 *out, unsigned int ndigits);
 #endif
-- 
2.26.2


  parent reply	other threads:[~2020-12-17 17:24 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-17 17:20 [RFC PATCH 0/6] Keem Bay OCS ECC crypto driver Daniele Alessandrelli
2020-12-17 17:20 ` [RFC PATCH 1/6] crypto: engine - Add KPP Support to Crypto Engine Daniele Alessandrelli
2020-12-17 17:20 ` [RFC PATCH 2/6] crypto: ecc - Move ecc.h to include/crypto/internal Daniele Alessandrelli
2020-12-17 17:20 ` Daniele Alessandrelli [this message]
2020-12-17 17:20 ` [RFC PATCH 4/6] crypto: ecdh - Add Curve ID for NIST P-384 Daniele Alessandrelli
2020-12-17 17:21 ` [RFC PATCH 5/6] dt-bindings: crypto: Add Keem Bay ECC bindings Daniele Alessandrelli
2020-12-21 22:52   ` Rob Herring
2020-12-17 17:21 ` [RFC PATCH 6/6] crypto: keembay-ocs-ecc - Add Keem Bay OCS ECC Driver Daniele Alessandrelli
2021-01-04  8:04 ` [RFC PATCH 0/6] Keem Bay OCS ECC crypto driver Reshetova, Elena
2021-01-04 11:31   ` Herbert Xu
2021-01-04 14:40     ` Reshetova, Elena
2021-01-14 10:25       ` Reshetova, Elena
2021-01-14 18:26         ` Ard Biesheuvel
2021-01-18 11:55           ` Reshetova, Elena
2021-01-18 12:09             ` Ard Biesheuvel
2021-01-19 10:47               ` Reshetova, Elena
2021-01-20 19:00               ` Alessandrelli, Daniele
2021-01-21  9:52                 ` Ard Biesheuvel
2021-01-21 16:13                   ` Alessandrelli, Daniele
2021-01-21 20:02                     ` Herbert Xu
2021-01-22 12:07                       ` Alessandrelli, Daniele

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201217172101.381772-4-daniele.alessandrelli@linux.intel.com \
    --to=daniele.alessandrelli@linux.intel.com \
    --cc=daniele.alessandrelli@intel.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=elena.reshetova@intel.com \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    --cc=mgross@linux.intel.com \
    --cc=prabhjot.khurana@intel.com \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).