lkml.org 
[lkml]   [2024]   [Feb]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v2 10/14] crypto: ecc - Implement ecc_digits_to_bytes to convert digits to byte array
Date
Implement ecc_digits_to_bytes to convert an array of digits into an
nbytes-sized byte array.

Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
---
include/crypto/internal/ecc.h | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)

diff --git a/include/crypto/internal/ecc.h b/include/crypto/internal/ecc.h
index b8ca5023b3b5..6229aa3f3218 100644
--- a/include/crypto/internal/ecc.h
+++ b/include/crypto/internal/ecc.h
@@ -75,6 +75,24 @@ static inline void ecc_digits_from_bytes(const u8 *in, unsigned int nbytes,
ecc_swap_digits(tmp, out, ndigits);
}

+/**
+ * ecc_digits_to_bytes() - Copy digits into a byte array of size nbytes
+ * @in: Input digits array
+ * @ndigits: Number of digits in input digits array
+ * @out: Output byte array
+ * @nbytes: Number of bytes to copy into byte array
+ */
+static inline void ecc_digits_to_bytes(const u64 *in, unsigned int ndigits,
+ u8 *out, unsigned int nbytes)
+{
+ unsigned int sz = ndigits << ECC_DIGITS_TO_BYTES_SHIFT;
+ u8 tmp[ECC_MAX_DIGITS << ECC_DIGITS_TO_BYTES_SHIFT];
+ unsigned int o = sz - nbytes;
+
+ ecc_swap_digits(in, (u64 *)tmp, ndigits);
+ memcpy(out, &tmp[o], nbytes);
+}
+
/**
* ecc_is_key_valid() - Validate a given ECDH private key
*
--
2.43.0

\
 
 \ /
  Last update: 2024-05-27 15:05    [W:0.136 / U:0.140 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site