Keem Bay OCS ECC crypto driver
Subsystems (6)
cover Keem Bay OCS ECC crypto driver
Hi,
This patch series adds the Intel Keem Bay OCS ECC crypto driver, which enables hardware-accelerated 'ecdh-nist-p256' and 'ecdh-nist-p384' on the Intel Keem Bay SoC.
The following changes to core crypto code are also done:
- KPP support is added to the crypto engine (so that the new driver can use it).
- 'crypto/ecc.h' is moved to 'include/crypto/internal' (so that this and other drivers can use the symbols exported by 'crypto/ecc.c').
- A few additional functions from 'crypto/ecc.c' are exported (so that this and other drivers can use them and avoid code duplication).
The driver passes crypto manager self-tests.
A previous version of this patch series was submitted as an RFC:
https://lore.kernel.org/linux-crypto/[email protected]/
Changes from previous RFC submission (RFC-v1):
- Switched to the new 'ecdh-nist-p256' and 'ecdh-nist-p384' algorithm names
- Dropped the CONFIG_CRYPTO_DEV_KEEMBAY_OCS_ECDH_GEN_PRIV_KEY_SUPPORT Kconfig option
Daniele Alessandrelli (2):
crypto: ecc - Move ecc.h to include/crypto/internal
crypto: ecc - Export additional helper functions
Prabhjot Khurana (3):
crypto: engine - Add KPP Support to Crypto Engine
dt-bindings: crypto: Add Keem Bay ECC bindings
crypto: keembay-ocs-ecc - Add Keem Bay OCS ECC Driver
Documentation/crypto/crypto_engine.rst | 4 +
.../crypto/intel,keembay-ocs-ecc.yaml | 47 +
MAINTAINERS | 11 +
crypto/crypto_engine.c | 26 +
crypto/ecc.c | 14 +-
crypto/ecdh.c | 2 +-
crypto/ecdsa.c | 2 +-
crypto/ecrdsa.c | 2 +-
crypto/ecrdsa_defs.h | 2 +-
drivers/crypto/keembay/Kconfig | 19 +
drivers/crypto/keembay/Makefile | 2 +
drivers/crypto/keembay/keembay-ocs-ecc.c | 1017 +++++++++++++++++
include/crypto/engine.h | 5 +
{crypto => include/crypto/internal}/ecc.h | 36 +
14 files changed, 1180 insertions(+), 9 deletions(-)
create mode 100644 Documentation/devicetree/bindings/crypto/intel,keembay-ocs-ecc.yaml
create mode 100644 drivers/crypto/keembay/keembay-ocs-ecc.c
rename {crypto => include/crypto/internal}/ecc.h (90%)base-commit: 06f6e365e2ecf799c249bb464aa9d5f055e88b56
Signature · 1 line
2.31.1
PATCH 1/5 crypto: engine - Add KPP Support to Crypto Engine
From: Prabhjot Khurana <[email protected]>
Add KPP support to the crypto engine queue manager, so that it can be used to simplify the logic of KPP device drivers as done for other crypto drivers.
--- Documentation/crypto/crypto_engine.rst | 4 ++++ crypto/crypto_engine.c | 26 ++++++++++++++++++++++++++ include/crypto/engine.h | 5 +++++ 3 files changed, 35 insertions(+)
Documentation/crypto/crypto_engine.rst +4 -0
@@ -69,6 +69,8 @@ the crypto engine via one of: * crypto_transfer_hash_request_to_engine() +* crypto_transfer_kpp_request_to_engine() + * crypto_transfer_skcipher_request_to_engine() At the end of the request process, a call to one of the following functions is needed:
@@ -79,4 +81,6 @@ At the end of the request process, a call to one of the following functions is n * crypto_finalize_hash_request() +* crypto_finalize_kpp_request() + * crypto_finalize_skcipher_request()
crypto/crypto_engine.c +26 -0
@@ -327,6 +327,19 @@ int crypto_transfer_hash_request_to_engine(struct crypto_engine *engine, }EXPORT_SYMBOL_GPL (crypto_transfer_hash_request_to_engine); +/** +* crypto_transfer_kpp_request_to_engine - transfer one kpp_request to list +* into the engine queue +* @engine: the hardware engine +* @req: the request need to be listed into the engine queue +*/ +int crypto_transfer_kpp_request_to_engine (struct crypto_engine *engine, +struct kpp_request *req) +{ +return crypto_transfer_request_to_engine (engine, &req->base); +} +EXPORT_SYMBOL_GPL (crypto_transfer_kpp_request_to_engine); +/** * crypto_transfer_skcipher_request_to_engine - transfer one skcipher_request * to list into the engine queue
@@ -382,6 +395,19 @@ void crypto_finalize_hash_request(struct crypto_engine *engine, }EXPORT_SYMBOL_GPL (crypto_finalize_hash_request); +/** +* crypto_finalize_kpp_request - finalize one kpp_request if the request is done +* @engine: the hardware engine +* @req: the request need to be finalized +* @err: error number +*/ +void crypto_finalize_kpp_request (struct crypto_engine *engine, +struct kpp_request *req,int err) +{ +return crypto_finalize_request (engine, &req->base, err); +} +EXPORT_SYMBOL_GPL (crypto_finalize_kpp_request); +/** * crypto_finalize_skcipher_request - finalize one skcipher_request if * the request is done
include/crypto/engine.h +5 -0
@@ -16,6 +16,7 @@#include <crypto/akcipher.h> #include <crypto/hash.h> #include <crypto/skcipher.h> +#include <crypto/kpp.h> #define ENGINE_NAME_LEN 30/*
@@ -96,6 +97,8 @@ int crypto_transfer_akcipher_request_to_engine(struct crypto_engine *engine, struct akcipher_request *req);int crypto_transfer_hash_request_to_engine (struct crypto_engine *engine,struct ahash_request *req); +int crypto_transfer_kpp_request_to_engine (struct crypto_engine *engine, +struct kpp_request *req);int crypto_transfer_skcipher_request_to_engine (struct crypto_engine *engine,struct skcipher_request *req); void crypto_finalize_aead_request(struct crypto_engine *engine,
@@ -104,6 +107,8 @@ void crypto_finalize_akcipher_request(struct crypto_engine *engine, struct akcipher_request *req, int err);void crypto_finalize_hash_request (struct crypto_engine *engine,struct ahash_request *req,int err); +void crypto_finalize_kpp_request (struct crypto_engine *engine, +struct kpp_request *req,int err);void crypto_finalize_skcipher_request (struct crypto_engine *engine,struct skcipher_request *req,int err);int crypto_engine_start (struct crypto_engine *engine);
Signature · 1 line
2.31.1
PATCH 2/5 crypto: ecc - Move ecc.h to include/crypto/internal
In reply to Daniele AlessandrelliFrom: Daniele Alessandrelli <[email protected]>
Move ecc.h header file to 'include/crypto/internal' so that it can be easily imported from everywhere in the kernel tree.
This change is done to allow crypto device drivers to re-use the symbols exported by 'crypto/ecc.c', thus avoiding code duplication.
---
crypto/ecc.c | 2 +-
crypto/ecdh.c | 2 +-
crypto/ecdsa.c | 2 +-
crypto/ecrdsa.c | 2 +-
crypto/ecrdsa_defs.h | 2 +-
{crypto => include/crypto/internal}/ecc.h | 0
6 files changed, 5 insertions(+), 5 deletions(-)
rename {crypto => include/crypto/internal}/ecc.h (100%)crypto/ecc.c +1 -1
@@ -32,10 +32,10 @@#include <linux/fips.h> #include <crypto/ecdh.h> #include <crypto/rng.h> +#include <crypto/internal/ecc.h> #include <asm/unaligned.h> #include <linux/ratelimit.h> -#include "ecc.h" #include "ecc_curve_defs.h" typedef struct {
crypto/ecdh.c +1 -1
@@ -6,11 +6,11 @@*/ #include <linux/module.h> +#include <crypto/internal/ecc.h> #include <crypto/internal/kpp.h> #include <crypto/kpp.h> #include <crypto/ecdh.h> #include <linux/scatterlist.h> -#include "ecc.h" struct ecdh_ctx {unsigned int curve_id;
crypto/ecdsa.c +1 -1
@@ -5,12 +5,12 @@#include <linux/module.h> #include <crypto/internal/akcipher.h> +#include <crypto/internal/ecc.h> #include <crypto/akcipher.h> #include <crypto/ecdh.h> #include <linux/asn1_decoder.h> #include <linux/scatterlist.h> -#include "ecc.h" #include "ecdsasignature.asn1.h" struct ecc_ctx {
crypto/ecrdsa.c +1 -1
@@ -20,12 +20,12 @@#include <linux/crypto.h> #include <crypto/streebog.h> #include <crypto/internal/akcipher.h> +#include <crypto/internal/ecc.h> #include <crypto/akcipher.h> #include <linux/oid_registry.h> #include <linux/scatterlist.h> #include "ecrdsa_params.asn1.h" #include "ecrdsa_pub_key.asn1.h" -#include "ecc.h" #include "ecrdsa_defs.h" #define ECRDSA_MAX_SIG_SIZE (2 * 512 / 8)
crypto/ecrdsa_defs.h +1 -1
@@ -13,7 +13,7 @@#ifndef _CRYTO_ECRDSA_DEFS_H#define _CRYTO_ECRDSA_DEFS_H -#include "ecc.h" +#include <crypto/internal/ecc.h> #define ECRDSA_MAX_SIG_SIZE (2 * 512 / 8)#define ECRDSA_MAX_DIGITS (512 / 64)
include/crypto/internal/ecc.h renamed from crypto/ecc.h +0 -0
Signature · 1 line
2.31.1
PATCH 3/5 crypto: ecc - Export additional helper functions
In reply to Daniele AlessandrelliFrom: Daniele Alessandrelli <[email protected]>
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.
--- crypto/ecc.c | 12 ++++++++---- include/crypto/internal/ecc.h | 36 +++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-)
crypto/ecc.c +8 -4
@@ -81,7 +81,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 );
@@ -106,8 +106,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 ;
@@ -116,6 +117,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) {
@@ -165,7 +167,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;
@@ -180,6 +182,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)
@@ -1062,11 +1065,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
include/crypto/internal/ecc.h +36 -0
@@ -225,6 +225,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 *
@@ -242,4 +277,5 @@ 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); +#endif
Signature · 1 line
2.31.1
PATCH 4/5 dt-bindings: crypto: Add Keem Bay ECC bindings
In reply to Daniele AlessandrelliFrom: Prabhjot Khurana <[email protected]>
Add Keem Bay Offload and Crypto Subsystem (OCS) Elliptic Curve Cryptography (ECC) device tree bindings.
--- .../crypto/intel,keembay-ocs-ecc.yaml | 47 +++++++++++++++++++ MAINTAINERS | 7 +++ 2 files changed, 54 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/intel,keembay-ocs-ecc.yaml
Documentation/devicetree/bindings/crypto/intel,keembay-ocs-ecc.yaml new file +47 -0
@@ -0,0 +1,47 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/crypto/intel,keembay-ocs-ecc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Intel Keem Bay OCS ECC Device Tree Bindings + +maintainers: + - Daniele Alessandrelli <[email protected]> + - Prabhjot Khurana <[email protected]> + +description: + The Intel Keem Bay Offload and Crypto Subsystem (OCS) Elliptic Curve + Cryptography (ECC) device provides hardware acceleration for elliptic curve + cryptography using the NIST P-256 and NIST P-384 elliptic curves. + +properties: + compatible: + const: intel,keembay-ocs-ecc + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + +required: + - compatible + - reg + - interrupts + - clocks + +additionalProperties: false + +examples: + - | + #include <dt-bindings/interrupt-controller/arm-gic.h> + crypto@30001000 { + compatible = "intel,keembay-ocs-ecc"; + reg = <0x30001000 0x1000>; + interrupts = <GIC_SPI 120 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&scmi_clk 95>; + };
MAINTAINERS +7 -0
@@ -9512,6 +9512,13 @@ F: drivers/crypto/keembay/keembay-ocs-aes-core.c F: drivers/crypto/keembay/ocs-aes.c F: drivers/crypto/keembay/ocs-aes.h +INTEL KEEM BAY OCS ECC CRYPTO DRIVER +M: Daniele Alessandrelli <[email protected]> +M: Prabhjot Khurana <[email protected]> +M: Mark Gross <[email protected]> +S: Maintained +F: Documentation/devicetree/bindings/crypto/intel,keembay-ocs-ecc.yaml + INTEL KEEM BAY OCS HCU CRYPTO DRIVER M: Daniele Alessandrelli <[email protected]> M: Declan Murphy <[email protected]>
Signature · 1 line
2.31.1
Re: [PATCH 4/5] dt-bindings: crypto: Add Keem Bay ECC bindings
Quoted 5 lines · Daniele Alessandrelli
From: Prabhjot Khurana <[email protected]>
Add Keem Bay Offload and Crypto Subsystem (OCS) Elliptic Curve Cryptography (ECC) device tree bindings.
Quoted 8 lines
Signed-off-by Prabhjot Khurana <[email protected]>Signed-off-by Daniele Alessandrelli <[email protected]>--- .../crypto/intel,keembay-ocs-ecc.yaml | 47 +++++++++++++++++++ MAINTAINERS | 7 +++ 2 files changed, 54 insertions(+) create mode 100644 Documentation/devicetree/bindings/crypto/intel,keembay-ocs-ecc.yaml
PATCH 5/5 crypto: keembay-ocs-ecc - Add Keem Bay OCS ECC Driver
In reply to Daniele AlessandrelliFrom: Prabhjot Khurana <[email protected]>
The Intel Keem Bay SoC can provide hardware acceleration of Elliptic Curve Cryptography (ECC) by means of its Offload and Crypto Subsystem (OCS).
Add the Keem Bay OCS ECC driver which leverages such hardware capabilities to provide hardware-acceleration of ECDH-256 and ECDH-384.
--- MAINTAINERS | 4 + drivers/crypto/keembay/Kconfig | 19 + drivers/crypto/keembay/Makefile | 2 + drivers/crypto/keembay/keembay-ocs-ecc.c | 1017 ++++++++++++++++++++++ 4 files changed, 1042 insertions(+) create mode 100644 drivers/crypto/keembay/keembay-ocs-ecc.c
MAINTAINERS +4 -0
@@ -9518,6 +9518,10 @@ M: Prabhjot Khurana <[email protected]> M: Mark Gross <[email protected]> S: Maintained F: Documentation/devicetree/bindings/crypto/intel,keembay-ocs-ecc.yaml +F: drivers/crypto/keembay/Kconfig +F: drivers/crypto/keembay/Makefile +F: drivers/crypto/keembay/keembay-ocs-ecc.c +F: drivers/crypto/keembay/ocs-ecc-curve-defs.h INTEL KEEM BAY OCS HCU CRYPTO DRIVER M: Daniele Alessandrelli <[email protected]>
drivers/crypto/keembay/Kconfig +19 -0
@@ -39,6 +39,25 @@ config CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_CTS Intel does not recommend use of CTS mode with AES/SM4. +config CRYPTO_DEV_KEEMBAY_OCS_ECC + tristate "Support for Intel Keem Bay OCS ECC HW acceleration" + depends on ARCH_KEEMBAY || COMPILE_TEST + depends on OF || COMPILE_TEST + depends on HAS_IOMEM + select CRYPTO_ECDH + select CRYPTO_ENGINE + help + Support for Intel Keem Bay Offload and Crypto Subsystem (OCS) + Elliptic Curve Cryptography (ECC) hardware acceleration for use with + Crypto API. + + Provides OCS acceleration for ECDH-256 and ECDH-384. + + Say Y or M if you are compiling for the Intel Keem Bay SoC. The + module will be called keembay-ocs-ecc. + + If unsure, say N. + config CRYPTO_DEV_KEEMBAY_OCS_HCU tristate "Support for Intel Keem Bay OCS HCU HW acceleration" select CRYPTO_HASH
drivers/crypto/keembay/Makefile +2 -0
@@ -4,5 +4,7 @@ obj-$(CONFIG_CRYPTO_DEV_KEEMBAY_OCS_AES_SM4) += keembay-ocs-aes.o keembay-ocs-aes-objs := keembay-ocs-aes-core.o ocs-aes.o +obj-$(CONFIG_CRYPTO_DEV_KEEMBAY_OCS_ECC) += keembay-ocs-ecc.o + obj-$(CONFIG_CRYPTO_DEV_KEEMBAY_OCS_HCU) += keembay-ocs-hcu.o keembay-ocs-hcu-objs := keembay-ocs-hcu-core.o ocs-hcu.o
drivers/crypto/keembay/keembay-ocs-ecc.c new file +1017 -0
1,017 lines not on this page · raw message
Signature · 1 line
2.31.1
Herbert Xu
maintainerQuoted 54 lines · Daniele Alessandrelli
Hi,
This patch series adds the Intel Keem Bay OCS ECC crypto driver, which enables hardware-accelerated 'ecdh-nist-p256' and 'ecdh-nist-p384' on the Intel Keem Bay SoC.
The following changes to core crypto code are also done:
- KPP support is added to the crypto engine (so that the new driver can use it).
- 'crypto/ecc.h' is moved to 'include/crypto/internal' (so that this and other drivers can use the symbols exported by 'crypto/ecc.c').
- A few additional functions from 'crypto/ecc.c' are exported (so that this and other drivers can use them and avoid code duplication).The driver passes crypto manager self-tests.
A previous version of this patch series was submitted as an RFC:
https://lore.kernel.org/linux-crypto/[email protected]/Changes from previous RFC submission (RFC-v1):
- Switched to the new 'ecdh-nist-p256' and 'ecdh-nist-p384' algorithm names
- Dropped theCONFIG_CRYPTO_DEV_KEEMBAY_OCS_ECDH_GEN_PRIV_KEY_SUPPORTKconfigoptionDaniele Alessandrelli (2):
crypto: ecc - Moveecc.htoinclude/crypto/internal
crypto: ecc - Export additional helper functionsPrabhjot Khurana (3):
crypto: engine - Add KPP Support to Crypto Engine
dt-bindings: crypto: Add Keem Bay ECC bindings
crypto: keembay-ocs-ecc - Add Keem Bay OCS ECC DriverDocumentation/crypto/crypto_engine.rst | 4 + .../crypto/intel,keembay-ocs-ecc.yaml | 47 + MAINTAINERS | 11 + crypto/crypto_engine.c | 26 + crypto/ecc.c | 14 +- crypto/ecdh.c | 2 +- crypto/ecdsa.c | 2 +- crypto/ecrdsa.c | 2 +- crypto/ecrdsa_defs.h | 2 +- drivers/crypto/keembay/Kconfig | 19 + drivers/crypto/keembay/Makefile | 2 + drivers/crypto/keembay/keembay-ocs-ecc.c | 1017 +++++++++++++++++ include/crypto/engine.h | 5 + {crypto => include/crypto/internal}/ecc.h | 36 + 14 files changed, 1180 insertions(+), 9 deletions(-) create mode 100644 Documentation/devicetree/bindings/crypto/intel,keembay-ocs-ecc.yaml create mode 100644 drivers/crypto/keembay/keembay-ocs-ecc.c rename {crypto => include/crypto/internal}/ecc.h (90%)
Quoted 1 line
base-commit:
06f6e365e2ecf799c249bb464aa9d5f055e88b56
All applied. Thanks.
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt