Keem Bay OCS ECC crypto driver
Subsystems (6)
cover Keem Bay OCS ECC crypto driver
Hi,
I'm posting this patch series as RFC since there are a few open points on which I'd like to have the opinion of the crypto maintainers and the rest of kernel community.
The patch series adds the Intel Keem Bay OCS ECC crypto driver, which enables hardware-accelerated ECDH on the Intel Keem Bay SoC.
The open points are the followings:
1. The OCS ECC HW supports the NIST P-384 curve, which, however, is not supported by Linux ECDH software implementation ('crypto/ecdh.c'). Support for P-384 is added to the driver anyway by reserving a curve id for P-384 in 'include/crypto/ecdh.h' and defining the cure parameters in 'drivers/crypto/keembay/ocs-ecc-curve-defs.h'. Is this reasonable?
2. The OCS ECC HW does not support the NIST P-192 curve. We were planning to add SW fallback for P-192 in the driver, but the Intel Crypto team (which, internally, has to approve any code involving cryptography) advised against it, because they consider P-192 weak. As a result, the driver is not passing crypto self-tests. Is there any possible solution to this? Is it reasonable to change the self-tests to only test the curves actually supported by the tested driver? (not fully sure how to do that).
3. Another request from our crypto team was to make private key generation optional in the driver, since they advice against automatic key generation. As a result, the driver passes the P-256 self test only when CONFIG_CRYPTO_DEV_KEEMBAY_OCS_ECDH_GEN_PRIV_KEY_SUPPORT=y. Is that acceptable?
Daniele Alessandrelli (2):
crypto: ecc - Move ecc.h to include/crypto/internal
crypto: ecc - Export additional helper functions
Prabhjot Khurana (4):
crypto: engine - Add KPP Support to Crypto Engine
crypto: ecdh - Add Curve ID for NIST P-384
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 | 27 +
crypto/ecc.c | 18 +-
crypto/ecdh.c | 2 +-
crypto/ecrdsa.c | 2 +-
crypto/ecrdsa_defs.h | 2 +-
drivers/crypto/keembay/Kconfig | 31 +
drivers/crypto/keembay/Makefile | 2 +
drivers/crypto/keembay/keembay-ocs-ecc.c | 1003 +++++++++++++++++
drivers/crypto/keembay/ocs-ecc-curve-defs.h | 68 ++
include/crypto/ecdh.h | 1 +
include/crypto/engine.h | 5 +
{crypto => include/crypto/internal}/ecc.h | 44 +
15 files changed, 1257 insertions(+), 10 deletions(-)
create mode 100644 Documentation/devicetree/bindings/crypto/intel,keembay-ocs-ecc.yaml
create mode 100644 drivers/crypto/keembay/keembay-ocs-ecc.c
create mode 100644 drivers/crypto/keembay/ocs-ecc-curve-defs.h
rename {crypto => include/crypto/internal}/ecc.h (87%)base-commit: 90cc8cf2d1ab87d708ebc311ac104ccbbefad9fc
Signature · 1 line
2.26.2
RFC PATCH 1/6 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 | 27 ++++++++++++++++++++++++++ include/crypto/engine.h | 5 +++++ 3 files changed, 36 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 +27 -0
@@ -340,6 +340,19 @@ int crypto_transfer_skcipher_request_to_engine(struct crypto_engine *engine, }EXPORT_SYMBOL_GPL (crypto_transfer_skcipher_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_finalize_aead_request - finalize one aead_request if * the request is done
@@ -396,6 +409,20 @@ void crypto_finalize_skcipher_request(struct crypto_engine *engine, }EXPORT_SYMBOL_GPL (crypto_finalize_skcipher_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_engine_start - start the hardware engine * @engine: the hardware engine need to be started
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/*
@@ -98,6 +99,8 @@ int crypto_transfer_hash_request_to_engine(struct crypto_engine *engine, struct ahash_request *req);int crypto_transfer_skcipher_request_to_engine (struct crypto_engine *engine,struct skcipher_request *req); +int crypto_transfer_kpp_request_to_engine (struct crypto_engine *engine, +struct kpp_request *req);void crypto_finalize_aead_request (struct crypto_engine *engine,struct aead_request *req,int err); void crypto_finalize_akcipher_request(struct crypto_engine *engine,
@@ -106,6 +109,8 @@ void crypto_finalize_hash_request(struct crypto_engine *engine, struct ahash_request *req, int err);void crypto_finalize_skcipher_request (struct crypto_engine *engine,struct skcipher_request *req,int err); +void crypto_finalize_kpp_request (struct crypto_engine *engine, +struct kpp_request *req,int err);int crypto_engine_start (struct crypto_engine *engine);int crypto_engine_stop (struct crypto_engine *engine);struct crypto_engine *crypto_engine_alloc_init (struct device *dev,bool rt);
Signature · 1 line
2.26.2
RFC PATCH 2/6 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/ecrdsa.c | 2 +-
crypto/ecrdsa_defs.h | 2 +-
{crypto => include/crypto/internal}/ecc.h | 0
5 files changed, 4 insertions(+), 4 deletions(-)
rename {crypto => include/crypto/internal}/ecc.h (100%)crypto/ecc.c +1 -1
@@ -31,10 +31,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/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.26.2
RFC PATCH 3/6 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()
- 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.
--- crypto/ecc.c | 16 ++++++++----- include/crypto/internal/ecc.h | 44 +++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 6 deletions(-)
crypto/ecc.c +10 -6
@@ -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)
include/crypto/internal/ecc.h +44 -0
54 lines not on this page · raw message
Signature · 1 line
2.26.2
RFC PATCH 4/6 crypto: ecdh - Add Curve ID for NIST P-384
In reply to Daniele AlessandrelliFrom: Prabhjot Khurana <[email protected]>
Reserve ECC curve id for NIST P-384 curve.
This is done to prepare for future support of the P-384 curve by KPP device drivers.
--- include/crypto/ecdh.h | 1 + 1 file changed, 1 insertion(+)
include/crypto/ecdh.h +1 -0
@@ -25,6 +25,7 @@/* Curves IDs */ #define ECC_CURVE_NIST_P192 0x0001#define ECC_CURVE_NIST_P256 0x0002 +#define ECC_CURVE_NIST_P384 0x0003/** * struct ecdh - define an ECDH private key
Signature · 1 line
2.26.2
RFC PATCH 5/6 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
@@ -9070,6 +9070,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 MANAGEMENT ENGINE (mei) M: Tomas Winkler <[email protected]> L: [email protected]
Signature · 1 line
2.26.2
Re: [RFC PATCH 5/6] 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
RFC PATCH 6/6 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 | 31 + drivers/crypto/keembay/Makefile | 2 + drivers/crypto/keembay/keembay-ocs-ecc.c | 1003 +++++++++++++++++++ drivers/crypto/keembay/ocs-ecc-curve-defs.h | 68 ++ 5 files changed, 1108 insertions(+) create mode 100644 drivers/crypto/keembay/keembay-ocs-ecc.c create mode 100644 drivers/crypto/keembay/ocs-ecc-curve-defs.h
MAINTAINERS +4 -0
@@ -9076,6 +9076,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 MANAGEMENT ENGINE (mei) M: Tomas Winkler <[email protected]>
drivers/crypto/keembay/Kconfig +31 -0
@@ -37,3 +37,34 @@ config CRYPTO_DEV_KEEMBAY_OCS_AES_SM4_CTS Provides OCS version of cts(cbc(aes)) and cts(cbc(sm4)). 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, 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_ECDH_GEN_PRIV_KEY_SUPPORT + bool "Add ECDH private key generation in Keem Bay OCS ECC driver" + depends on CRYPTO_DEV_KEEMBAY_OCS_ECC + help + Add ECDH private key generation in the Intel Keem Bay OCS ECC driver. + + Intel does not recommend use of private key generation for ECDH + computations, which, however, is required to pass crypto self-tests. + + Say Y if you need the driver to pass crypto self-tests. If unsure, + say N.
drivers/crypto/keembay/Makefile +2 -0
@@ -3,3 +3,5 @@ # 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
drivers/crypto/keembay/keembay-ocs-ecc.c new file +1003 -0
1,003 lines not on this page · raw message
drivers/crypto/keembay/ocs-ecc-curve-defs.h new file +68 -0
68 lines not on this page · raw message
Signature · 1 line
2.26.2
Quoted 8 lines
2. The OCS ECC HW does not support the NIST P-192 curve. We were planning to add SW fallback for P-192 in the driver, but the Intel Crypto team (which, internally, has to approve any code involving cryptography) advised against it, because they consider P-192 weak. As a result, the driver is not passing crypto self-tests. Is there any possible solution to this? Is it reasonable to change the self-tests to only test the curves actually supported by the tested driver? (not fully sure how to do that).
An additional reason against the P-192 SW fallback is the fact that it can potentially trigger unsafe behavior which is not even "visible" to the end user of the ECC functionality. If I request (by my developer mistake) a P-192 weaker curve from ECC Keem Bay HW driver, it is much safer to return a "not supported" error that proceed behind my back with a SW code implementation making me believe that I am actually getting a HW-backed up functionality (since I don't think there is a way for me to check that I am using SW fallback).
Best Regards,
Elena
Herbert Xu
maintainerQuoted 9 lines · Elena
Quoted 8 lines
2. The OCS ECC HW does not support the NIST P-192 curve. We were planning to add SW fallback for P-192 in the driver, but the Intel Crypto team (which, internally, has to approve any code involving cryptography) advised against it, because they consider P-192 weak. As a result, the driver is not passing crypto self-tests. Is there any possible solution to this? Is it reasonable to change the self-tests to only test the curves actually supported by the tested driver? (not fully sure how to do that).
Quoted 8 lines
An additional reason against the P-192 SW fallback is the fact that it can potentially trigger unsafe behavior which is not even "visible" to the end user of the ECC functionality. If I request (by my developer mistake) a P-192 weaker curve from ECC Keem Bay HW driver, it is much safer to return a "not supported" error that proceed behind my back with a SW code implementation making me believe that I am actually getting a HW-backed up functionality (since I don't think there is a way for me to check that I am using SW fallback).
Sorry, but if you break the Crypto API requirement then your driver isn't getting merged.
Cheers,
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
Quoted 19 lines · Elena
Quoted 9 lines
Quoted 8 lines
2. The OCS ECC HW does not support the NIST P-192 curve. We were planning to add SW fallback for P-192 in the driver, but the Intel Crypto team (which, internally, has to approve any code involving cryptography) advised against it, because they consider P-192 weak. As a result, the driver is not passing crypto self-tests. Is there any possible solution to this? Is it reasonable to change the self-tests to only test the curves actually supported by the tested driver? (not fully sure how to do that).
Quoted 8 lines
An additional reason against the P-192 SW fallback is the fact that it can potentially trigger unsafe behavior which is not even "visible" to the end user of the ECC functionality. If I request (by my developer mistake) a P-192 weaker curve from ECC Keem Bay HW driver, it is much safer to return a "not supported" error that proceed behind my back with a SW code implementation making me believe that I am actually getting a HW-backed up functionality (since I don't think there is a way for me to check that I am using SW fallback).
Quoted 2 lines
Sorry, but if you break the Crypto API requirement then your driver isn't getting merged.
But should not we think what behavior would make sense for good crypto drivers in future? As cryptography moves forward (especially for the post quantum era), we will have lengths for all existing algorithms increased (in addition to having a bunch of new ones), and we surely should not expect the new generation of HW drivers to implement
the old/weaker lengths, so why there the requirement to support them? It is not a part of crypto API definition on what bit lengths should be supported, because it cannot be part of API to begin with since it is always changing parameter (algorithms and attacks develop all the time).
Best Regards,
Elena.
Quoted 23 lines
Quoted 2 lines · Elena
Quoted 1 line
Quoted 1 line
2. The OCS ECC HW does not support the NIST P-192 curve. We were planning
to
Quoted 17 lines
Quoted 8 lines
Quoted 7 lines
add SW fallback for P-192 in the driver, but the Intel Crypto team (which, internally, has to approve any code involving cryptography) advised against it, because they consider P-192 weak. As a result, the driver is not passing crypto self-tests. Is there any possible solution to this? Is it reasonable to change the self-tests to only test the curves actually supported by the tested driver? (not fully sure how to do that).
Quoted 8 lines
An additional reason against the P-192 SW fallback is the fact that it can potentially trigger unsafe behavior which is not even "visible" to the end user of the ECC functionality. If I request (by my developer mistake) a P-192 weaker curve from ECC Keem Bay HW driver, it is much safer to return a "not supported" error that proceed behind my back with a SW code implementation making me believe that I am actually getting a HW-backed up functionality (since I don't think there is a way for me to check that I am using SW fallback).
Quoted 2 lines
Sorry, but if you break the Crypto API requirement then your driver isn't getting merged.
Quoted 11 lines
But should not we think what behavior would make sense for good crypto drivers in future?
As cryptography moves forward (especially for the post quantum era), we will have lengths for all existing algorithms increased (in addition to having a bunch of new ones),
and we surely should not expect the new generation of HW drivers to implement the old/weaker lengths, so why there the requirement to support them? It is not a part of crypto API definition on what bit lengths should be supported, because it cannot be part of API to begin with since it is always changing parameter (algorithms and attacks
develop all the time).
I would really appreciate, if someone helps us to understand here. Maybe there is a correct way to address this, but we just don't see it. The question is not even about this particular crypto driver and the fact whenever it gests merged or not, but the logic of the crypto API subsystem.
As far as I understand the implementations that are provided by the specialized drivers (like our Keem Bay OCS ECC driver example here) have a higher priority vs. generic Implementations that exists in kernel, which makes sense because we expect these drivers (and the security HW they talk to) to provide both more efficient and more secure implementations than a pure SW implementation in kernel can do (even if it utilizes special instructions, like SIMD, AESNI, etc.). However, naturally these drivers are bound by what security HW can do, and if it does not support a certain size/param of the algorithm (P-192 curve in our case), it is pointless and wrong for them to reimplement what SW is already doing in kernel, so they should not do so and currently they re-direct to core kernel implementation. So far good.
But now comes my biggest worry is that this redirection as far
as I can see is *internal to driver itself*, i.e. it does a callback to these core functions from the driver code, which again, unless I misunderstand smth, leads to the fact that the end user gets P-192 curve ECC implementation from the core kernel that has been "promoted" to a highest priority (given that ECC KeemBay driver for example got priority 300 to begin with). So, if we say we have another HW Driver 'Foo', which happens to implement P-192 curves more securely, but happens to have a lower priority than ECC KeemBay driver, its implementation would never be chosen, but core kernel implementation will be used (via SW fallback internal to ECC Keem Bay driver).
Another problem is that for a user of crypto API I don't see a way (and perhaps I am wrong here) to guarantee that all my calls to perform crypto operations will end up being performed on a security HW I want (maybe because this is the only thing I trust). It seems to be possible in theory, but in practice would require careful evaluation of a kernel setup and a sync between what end user requests and what driver can provide. Let me try to explain a potential scenario. Lets say we had an end user that used to ask for both P-192 and P-384 curve-based ECC operations and let's say we had a driver and security HW that implemented it. The end user made sure that this driver implementation is always preferred vs. other existing implementations. Now, time moves, a new security HW comes instead that only supports P-384, and the driver now has been updated to support P-192 via the SW fallback (like we are asked now).
Now, how does an end user notice that when it asks for a P-192 based operations, his operations are not done in security HW anymore? The only way seems to be
is to know that driver and security HW has been updated, algorithms and sizes changed, etc. It might take a while before the end user realizes this and for example stops using P-192 altogether, but what if this silent redirect by the driver actually breaks some security assumptions (side-channel resistance being one potential example) made by this end user? The consequences can be very bad. You might say: "this is the end user problem to verify this", but shouldn't we do smth to prevent or at least indicate such potential issues to them?
Best Regards,
Elena.
Quoted 52 lines · Elena
Quoted 24 lines
Quoted 3 lines · Elena
Quoted 1 line
Quoted 1 line
2. The OCS ECC HW does not support the NIST P-192 curve. We were planning
to
Quoted 17 lines
Quoted 8 lines
Quoted 7 lines
add SW fallback for P-192 in the driver, but the Intel Crypto team (which, internally, has to approve any code involving cryptography) advised against it, because they consider P-192 weak. As a result, the driver is not passing crypto self-tests. Is there any possible solution to this? Is it reasonable to change the self-tests to only test the curves actually supported by the tested driver? (not fully sure how to do that).
Quoted 8 lines
An additional reason against the P-192 SW fallback is the fact that it can potentially trigger unsafe behavior which is not even "visible" to the end user of the ECC functionality. If I request (by my developer mistake) a P-192 weaker curve from ECC Keem Bay HW driver, it is much safer to return a "not supported" error that proceed behind my back with a SW code implementation making me believe that I am actually getting a HW-backed up functionality (since I don't think there is a way for me to check that I am using SW fallback).
Quoted 2 lines
Sorry, but if you break the Crypto API requirement then your driver isn't getting merged.
Quoted 11 lines
But should not we think what behavior would make sense for good crypto drivers in future?
As cryptography moves forward (especially for the post quantum era), we will have lengths for all existing algorithms increased (in addition to having a bunch of new ones),
and we surely should not expect the new generation of HW drivers to implement the old/weaker lengths, so why there the requirement to support them? It is not a part of crypto API definition on what bit lengths should be supported, because it cannot be part of API to begin with since it is always changing parameter (algorithms and attacks
develop all the time).I would really appreciate, if someone helps us to understand here. Maybe there is a correct way to address this, but we just don't see it. The question is not even about this particular crypto driver and the fact whenever it gests merged or not, but the logic of the crypto API subsystem.
As far as I understand the implementations that are provided by the specialized drivers (like our Keem Bay OCS ECC driver example here) have a higher priority vs. generic Implementations that exists in kernel, which makes sense because we expect these drivers (and the security HW they talk to) to provide both more efficient and more secure implementations than a pure SW implementation in kernel can do (even if it utilizes special instructions, like SIMD, AESNI, etc.). However, naturally these drivers are bound by what security HW can do, and if it does not support a certain size/param of the algorithm (P-192 curve in our case), it is pointless and wrong for them to reimplement what SW is already doing in kernel, so they should not do so and currently they re-direct to core kernel implementation. So far good.
Quoted 10 lines
But now comes my biggest worry is that this redirection as far
as I can see is *internal to driver itself*, i.e. it does a callback to these core functions from the driver code, which again, unless I misunderstand smth, leads to the fact that the end user gets P-192 curve ECC implementation from the core kernel that has been "promoted" to a highest priority (given that ECC KeemBay driver for example got priority 300 to begin with). So, if we say we have another HW Driver 'Foo', which happens to implement P-192 curves more securely, but happens to have a lower priority than ECC KeemBay driver, its implementation would never be chosen, but core kernel implementation will be used (via SW fallback internal to ECC Keem Bay driver).
No, this is incorrect. If you allocate a fallback algorithm in the correct way, the crypto API will resolve the allocation in the usual manner, and select whichever of the remaining implementations has the highest priority (provided that it does not require a fallback itself).
Quoted 10 lines
Another problem is that for a user of crypto API I don't see a way (and perhaps I am wrong here) to guarantee that all my calls to perform crypto operations will end up being performed on a security HW I want (maybe because this is the only thing I trust). It seems to be possible in theory, but in practice would require careful evaluation of a kernel setup and a sync between what end user requests and what driver can provide. Let me try to explain a potential scenario. Lets say we had an end user that used to ask for both P-192 and P-384 curve-based ECC operations and let's say we had a driver and security HW that implemented it. The end user made sure that this driver implementation is always preferred vs. other existing implementations. Now, time moves, a new security HW comes instead that only supports P-384, and the driver now has been updated to support P-192 via the SW fallback (like we are asked now).
Quoted 9 lines
Now, how does an end user notice that when it asks for a P-192 based operations, his operations are not done in security HW anymore? The only way seems to be
is to know that driver and security HW has been updated, algorithms and sizes changed, etc. It might take a while before the end user realizes this and for example stops using P-192 altogether, but what if this silent redirect by the driver actually breaks some security assumptions (side-channel resistance being one potential example) made by this end user? The consequences can be very bad. You might say: "this is the end user problem to verify this", but shouldn't we do smth to prevent or at least indicate such potential issues to them?
I don't think it is possible at the API level to define rules that will always produce the most secure combination of drivers. The priority fields are only used to convey relative performance (which is already semantically murky, given the lack of distinction between hardware with a single queue vs software algorithms that can be executed by all CPUs in parallel).
When it comes to comparative security, trustworthiness or robustness of implementations, it is simply left up to the user to blacklist modules that they prefer not to use. When fallback allocations are made in the correct way, the remaining available implementations will be used in priority order.
Quoted 80 lines
Quoted 3 lines · Elena
Quoted 3 lines
Quoted 3 lines · Elena
Quoted 1 line
Quoted 1 line
2. The OCS ECC HW does not support the NIST P-192 curve. We were
planning
Quoted 18 lines
Quoted 18 lines
to
Quoted 17 lines
Quoted 16 lines
Quoted 7 lines
add SW fallback for P-192 in the driver, but the Intel Crypto team (which, internally, has to approve any code involving cryptography) advised against it, because they consider P-192 weak. As a result, the driver is not passing crypto self-tests. Is there any possible solution to this? Is it reasonable to change the self-tests to only test the curves actually supported by the tested driver? (not fully sure how to do that).
An additional reason against the P-192 SW fallback is the fact that it can potentially trigger unsafe behavior which is not even "visible" to the end user of the ECC functionality. If I request (by my developer mistake) a P-192 weaker curve from ECC Keem Bay HW driver, it is much safer to return a "not supported" error that proceed behind my back with a SW code implementation making me believe that I am actually getting a HW-backed up functionality (since I don't think there is a way for me to check that I am using SW fallback).
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Sorry, but if you break the Crypto API requirement then your driver isn't getting merged.
But should not we think what behavior would make sense for good crypto drivers
in
Quoted 2 lines
Quoted 2 lines
future?
As cryptography moves forward (especially for the post quantum era), we willhave
Quoted 4 lines
Quoted 4 lines
lengths for all existing algorithms increased (in addition to having a bunch of new ones),
and we surely should not expect the new generation of HW drivers to implement the old/weaker lengths, so why there the requirement to support them? It is nota
Quoted 2 lines
Quoted 2 lines
part of crypto API definition on what bit lengths should be supported, because it cannot be part of API to begin with since it is always changing parameter
(algorithms
Quoted 9 lines
Quoted 2 lines
and attacks
develop all the time).I would really appreciate, if someone helps us to understand here. Maybe there is a correct way to address this, but we just don't see it. The question is not even about this particular crypto driver and the fact whenever it gests merged or not, but the logic of the crypto API subsystem.
As far as I understand the implementations that are provided by the specialized
drivers
Quoted 2 lines
(like our Keem Bay OCS ECC driver example here) have a higher priority vs. generic Implementations that exists in kernel, which makes sense because we expect these
drivers
Quoted 2 lines
(and the security HW they talk to) to provide both more efficient and more secure implementations than a pure SW implementation in kernel can do (even if it utilizes
special
Quoted 2 lines
instructions, like SIMD, AESNI, etc.). However, naturally these drivers are bound by what security HW can do, and if it does not support a certain size/param of the
algorithm
Quoted 1 line
(P-192 curve in our case), it is pointless and wrong for them to reimplement what
SW is
Quoted 1 line
already doing in kernel, so they should not do so and currently they re-direct to
core kernel
Quoted 4 lines
implementation. So far good.
But now comes my biggest worry is that this redirection as far
as I can see is *internal to driver itself*, i.e. it does a callback to these corefunctions from the driver
Quoted 1 line
code, which again, unless I misunderstand smth, leads to the fact that the end user
gets
Quoted 1 line
P-192 curve ECC implementation from the core kernel that has been "promoted"
to a highest
Quoted 1 line
priority (given that ECC KeemBay driver for example got priority 300 to begin with).
So, if
Quoted 1 line
we say we have another HW Driver 'Foo', which happens to implement P-192
curves more securely,
Quoted 1 line
but happens to have a lower priority than ECC KeemBay driver, its implementation
would never
Quoted 1 line
be chosen, but core kernel implementation will be used (via SW fallback internal to
ECC Keem
Quoted 8 lines
Quoted 2 lines
Bay driver).
No, this is incorrect. If you allocate a fallback algorithm in the correct way, the crypto API will resolve the allocation in the usual manner, and select whichever of the remaining implementations has the highest priority (provided that it does not require a fallback itself).
Thank you very much Ard for the important correction here!
See below if I got it now correctly to the end for the use case in question.
Quoted 43 lines
Quoted 2 lines
Another problem is that for a user of crypto API I don't see a way (and perhaps I
am wrong here)
Quoted 1 line
to guarantee that all my calls to perform crypto operations will end up being
performed on a
Quoted 1 line
security HW I want (maybe because this is the only thing I trust). It seems to be
possible in theory,
Quoted 1 line
but in practice would require careful evaluation of a kernel setup and a sync
between what
Quoted 1 line
end user requests and what driver can provide. Let me try to explain a potential
scenario.
Quoted 1 line
Lets say we had an end user that used to ask for both P-192 and P-384 curve-based
ECC operations
Quoted 1 line
and let's say we had a driver and security HW that implemented it. The end user
made sure that
Quoted 1 line
this driver implementation is always preferred vs. other existing implementations.
Now, time moves, a new
Quoted 1 line
security HW comes instead that only supports P-384, and the driver now has been
updated to
Quoted 2 lines
support P-192 via the SW fallback (like we are asked now).
Now, how does an end user notice that when it asks for a P-192 based operations,his operations
Quoted 2 lines
are not done in security HW anymore? The only way seems to be
is to know that driver and security HW has been updated, algorithms and sizeschanged, etc.
Quoted 1 line
It might take a while before the end user realizes this and for example stops using
P-192 altogether,
Quoted 1 line
but what if this silent redirect by the driver actually breaks some security
assumptions (side-channel
Quoted 1 line
resistance being one potential example) made by this end user? The consequences
can be very bad.
Quoted 1 line
You might say: "this is the end user problem to verify this", but shouldn't we do
smth to prevent or
Quoted 2 lines
at least indicate such potential issues to them?
I don't think it is possible at the API level to define rules that will always produce the most secure combination of drivers. The priority fields are only used to convey relative performance (which is already semantically murky, given the lack of distinction between hardware with a single queue vs software algorithms that can be executed by all CPUs in parallel).
Quoted 5 lines
When it comes to comparative security, trustworthiness or robustness of implementations, it is simply left up to the user to blacklist modules that they prefer not to use. When fallback allocations are made in the correct way, the remaining available implementations will be used in priority order.
So, let me see if I understand the full picture correctly now and how to utilize the blacklisting of modules as a user. Suppose I want to blacklist everything but my OSC driver module. So, if I am as a user refer to a specific driver implementation using a unique driver name (ecdh-keembay-ocs in our case), then regardless of the fact that a driver implements this SW fallback for P-192 curve, if I am as a user to ask for P-192 curve (or any other param that results in SW fallback), I will be notified that this requested implementation does not provide it?
Best Regards,
Elena.
Quoted 142 lines · Elena
Quoted 81 lines
Quoted 3 lines · Elena
Quoted 3 lines
Quoted 3 lines · Elena
Quoted 1 line
Quoted 1 line
2. The OCS ECC HW does not support the NIST P-192 curve. We were
planning
Quoted 18 lines
Quoted 18 lines
to
Quoted 17 lines
Quoted 16 lines
Quoted 7 lines
add SW fallback for P-192 in the driver, but the Intel Crypto team (which, internally, has to approve any code involving cryptography) advised against it, because they consider P-192 weak. As a result, the driver is not passing crypto self-tests. Is there any possible solution to this? Is it reasonable to change the self-tests to only test the curves actually supported by the tested driver? (not fully sure how to do that).
An additional reason against the P-192 SW fallback is the fact that it can potentially trigger unsafe behavior which is not even "visible" to the end user of the ECC functionality. If I request (by my developer mistake) a P-192 weaker curve from ECC Keem Bay HW driver, it is much safer to return a "not supported" error that proceed behind my back with a SW code implementation making me believe that I am actually getting a HW-backed up functionality (since I don't think there is a way for me to check that I am using SW fallback).
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines
Sorry, but if you break the Crypto API requirement then your driver isn't getting merged.
But should not we think what behavior would make sense for good crypto drivers
in
Quoted 2 lines
Quoted 2 lines
future?
As cryptography moves forward (especially for the post quantum era), we willhave
Quoted 4 lines
Quoted 4 lines
lengths for all existing algorithms increased (in addition to having a bunch of new ones),
and we surely should not expect the new generation of HW drivers to implement the old/weaker lengths, so why there the requirement to support them? It is nota
Quoted 2 lines
Quoted 2 lines
part of crypto API definition on what bit lengths should be supported, because it cannot be part of API to begin with since it is always changing parameter
(algorithms
Quoted 9 lines
Quoted 2 lines
and attacks
develop all the time).I would really appreciate, if someone helps us to understand here. Maybe there is a correct way to address this, but we just don't see it. The question is not even about this particular crypto driver and the fact whenever it gests merged or not, but the logic of the crypto API subsystem.
As far as I understand the implementations that are provided by the specialized
drivers
Quoted 2 lines
(like our Keem Bay OCS ECC driver example here) have a higher priority vs. generic Implementations that exists in kernel, which makes sense because we expect these
drivers
Quoted 2 lines
(and the security HW they talk to) to provide both more efficient and more secure implementations than a pure SW implementation in kernel can do (even if it utilizes
special
Quoted 2 lines
instructions, like SIMD, AESNI, etc.). However, naturally these drivers are bound by what security HW can do, and if it does not support a certain size/param of the
algorithm
Quoted 1 line
(P-192 curve in our case), it is pointless and wrong for them to reimplement what
SW is
Quoted 1 line
already doing in kernel, so they should not do so and currently they re-direct to
core kernel
Quoted 4 lines
implementation. So far good.
But now comes my biggest worry is that this redirection as far
as I can see is *internal to driver itself*, i.e. it does a callback to these corefunctions from the driver
Quoted 1 line
code, which again, unless I misunderstand smth, leads to the fact that the end user
gets
Quoted 1 line
P-192 curve ECC implementation from the core kernel that has been "promoted"
to a highest
Quoted 1 line
priority (given that ECC KeemBay driver for example got priority 300 to begin with).
So, if
Quoted 1 line
we say we have another HW Driver 'Foo', which happens to implement P-192
curves more securely,
Quoted 1 line
but happens to have a lower priority than ECC KeemBay driver, its implementation
would never
Quoted 1 line
be chosen, but core kernel implementation will be used (via SW fallback internal to
ECC Keem
Quoted 8 lines
Quoted 2 lines
Bay driver).
No, this is incorrect. If you allocate a fallback algorithm in the correct way, the crypto API will resolve the allocation in the usual manner, and select whichever of the remaining implementations has the highest priority (provided that it does not require a fallback itself).
Thank you very much Ard for the important correction here!
See below if I got it now correctly to the end for the use case in question.Quoted 43 lines
Quoted 2 lines
Another problem is that for a user of crypto API I don't see a way (and perhaps I
am wrong here)
Quoted 1 line
to guarantee that all my calls to perform crypto operations will end up being
performed on a
Quoted 1 line
security HW I want (maybe because this is the only thing I trust). It seems to be
possible in theory,
Quoted 1 line
but in practice would require careful evaluation of a kernel setup and a sync
between what
Quoted 1 line
end user requests and what driver can provide. Let me try to explain a potential
scenario.
Quoted 1 line
Lets say we had an end user that used to ask for both P-192 and P-384 curve-based
ECC operations
Quoted 1 line
and let's say we had a driver and security HW that implemented it. The end user
made sure that
Quoted 1 line
this driver implementation is always preferred vs. other existing implementations.
Now, time moves, a new
Quoted 1 line
security HW comes instead that only supports P-384, and the driver now has been
updated to
Quoted 2 lines
support P-192 via the SW fallback (like we are asked now).
Now, how does an end user notice that when it asks for a P-192 based operations,his operations
Quoted 2 lines
are not done in security HW anymore? The only way seems to be
is to know that driver and security HW has been updated, algorithms and sizeschanged, etc.
Quoted 1 line
It might take a while before the end user realizes this and for example stops using
P-192 altogether,
Quoted 1 line
but what if this silent redirect by the driver actually breaks some security
assumptions (side-channel
Quoted 1 line
resistance being one potential example) made by this end user? The consequences
can be very bad.
Quoted 1 line
You might say: "this is the end user problem to verify this", but shouldn't we do
smth to prevent or
Quoted 2 lines
at least indicate such potential issues to them?
I don't think it is possible at the API level to define rules that will always produce the most secure combination of drivers. The priority fields are only used to convey relative performance (which is already semantically murky, given the lack of distinction between hardware with a single queue vs software algorithms that can be executed by all CPUs in parallel).
Quoted 5 lines
When it comes to comparative security, trustworthiness or robustness of implementations, it is simply left up to the user to blacklist modules that they prefer not to use. When fallback allocations are made in the correct way, the remaining available implementations will be used in priority order.
Quoted 8 lines
So, let me see if I understand the full picture correctly now and how to utilize the blacklisting of modules as a user. Suppose I want to blacklist everything but my OSC driver module. So, if I am as a user refer to a specific driver implementation using a unique driver name (ecdh-keembay-ocs in our case), then regardless of the fact that a driver implements this SW fallback for P-192 curve, if I am as a user to ask for P-192 curve (or any other param that results in SW fallback), I will be notified that this requested implementation does not provide it?
This is rather unusual compared with how the crypto API is typically used, but if this is really what you want to implement, you can do so by:
- having a "ecdh" implementation that implements the entire range, and uses a fallback for curves that it does not implement
- export the same implementation again as "ecdh" and with a known driver name "ecdh-keembay-ocs", but with a slightly lower priority, and in this case, return an error when the unimplemented curve is requested.
That way, you fully adhere to the API, by providing implementations of all curves by default. And if a user requests "ecdh-keembay-ocs" explicitly, it will not be able to use the P192 curve inadvertently.
But policing which curves are secure and which are not is really not the job of the API. We have implementations of MD5 and RC4 in the kernel that we would *love* to remove but we simply cannot do so as long as they are still being used. The same applies to P192: we simply cannot fail requests for that curve for use cases that were previously deemed valid. It is perfectly reasonable to omit the implementation from your hardware, but banning its use outright on the grounds that is no longer secure conflicts with our requirement not to break existing use cases.
Quoted 180 lines
Quoted 6 lines · Elena
Quoted 6 lines
Quoted 3 lines · Elena
Quoted 3 lines
Quoted 3 lines · Elena
Quoted 1 line
Quoted 1 line
2. The OCS ECC HW does not support the NIST P-192 curve. We were
Quoted 8 lines
Quoted 8 lines
planning
Quoted 7 lines
Quoted 7 lines
to
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
add SW fallback for P-192 in the driver, but the Intel Crypto team (which, internally, has to approve any code involving cryptography) advised against it, because they consider P-192 weak. As a result, the driver is not passing crypto self-tests. Is there any possible solution to this? Is it reasonable to change the self-tests to only test the curves actually supported by the tested driver? (not fully sure how to
do
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 1 line
that).An additional reason against the P-192 SW fallback is the fact that it can potentially trigger unsafe behavior which is not even "visible" to the end
user
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
of the ECC functionality. If I request (by my developer mistake) a P-192 weaker curve from ECC Keem Bay HW driver, it is much safer to return a "not supported" error that proceed behind my back with a SW code implementation making me believe that I am actually getting a HW-
backed up
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
functionality (since I don't think there is a way for me to check that I am
using
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
SW fallback).
Sorry, but if you break the Crypto API requirement then your driver isn't getting merged.
But should not we think what behavior would make sense for good crypto
drivers
Quoted 5 lines
Quoted 5 lines
in
Quoted 2 lines
Quoted 2 lines
future?
As cryptography moves forward (especially for the post quantum era), we willhave
Quoted 1 line
Quoted 1 line
lengths for all existing algorithms increased (in addition to having a bunch of
new
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
ones),
and we surely should not expect the new generation of HW drivers toimplement
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
the old/weaker lengths, so why there the requirement to support them? It is
not
Quoted 2 lines
Quoted 2 lines
a
Quoted 1 line
Quoted 1 line
part of crypto API definition on what bit lengths should be supported,
because it
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
Quoted 1 line
cannot be part of API to begin with since it is always changing parameter
(algorithms
Quoted 4 lines
Quoted 2 lines
and attacks
develop all the time).I would really appreciate, if someone helps us to understand here. Maybe there
is a
Quoted 1 line
Quoted 1 line
Quoted 1 line
correct way to address this, but we just don't see it. The question is not even
about
Quoted 1 line
Quoted 1 line
Quoted 1 line
this particular crypto driver and the fact whenever it gests merged or not, but
the
Quoted 5 lines
Quoted 5 lines
Quoted 3 lines
logic of the crypto API subsystem.
As far as I understand the implementations that are provided by the specialized
drivers
Quoted 1 line
(like our Keem Bay OCS ECC driver example here) have a higher priority vs.
generic
Quoted 1 line
Quoted 1 line
Quoted 1 line
Implementations that exists in kernel, which makes sense because we expect
these
Quoted 2 lines
Quoted 2 lines
drivers
Quoted 1 line
(and the security HW they talk to) to provide both more efficient and more
secure
Quoted 1 line
Quoted 1 line
Quoted 1 line
implementations than a pure SW implementation in kernel can do (even if it
utilizes
Quoted 2 lines
Quoted 2 lines
special
Quoted 1 line
instructions, like SIMD, AESNI, etc.). However, naturally these drivers are bound
by
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
what security HW can do, and if it does not support a certain size/param of the
algorithm
Quoted 1 line
(P-192 curve in our case), it is pointless and wrong for them to reimplement
what
Quoted 9 lines
Quoted 9 lines
SW is
Quoted 1 line
already doing in kernel, so they should not do so and currently they re-direct to
core kernel
Quoted 4 lines
implementation. So far good.
But now comes my biggest worry is that this redirection as far
as I can see is *internal to driver itself*, i.e. it does a callback to these corefunctions from the driver
Quoted 1 line
code, which again, unless I misunderstand smth, leads to the fact that the end
user
Quoted 2 lines
Quoted 2 lines
gets
Quoted 1 line
P-192 curve ECC implementation from the core kernel that has been
"promoted"
Quoted 2 lines
Quoted 2 lines
to a highest
Quoted 1 line
priority (given that ECC KeemBay driver for example got priority 300 to begin
with).
Quoted 4 lines
Quoted 4 lines
So, if
Quoted 1 line
we say we have another HW Driver 'Foo', which happens to implement P-192
curves more securely,
Quoted 1 line
but happens to have a lower priority than ECC KeemBay driver, its
implementation
Quoted 2 lines
Quoted 2 lines
would never
Quoted 1 line
be chosen, but core kernel implementation will be used (via SW fallback
internal to
Quoted 4 lines
Quoted 4 lines
ECC Keem
Quoted 2 lines
Bay driver).
Quoted 21 lines
Quoted 5 lines
No, this is incorrect. If you allocate a fallback algorithm in the correct way, the crypto API will resolve the allocation in the usual manner, and select whichever of the remaining implementations has the highest priority (provided that it does not require a fallback itself).
Thank you very much Ard for the important correction here!
See below if I got it now correctly to the end for the use case in question.Quoted 12 lines
Quoted 2 lines
Another problem is that for a user of crypto API I don't see a way (and perhaps I
am wrong here)
Quoted 1 line
to guarantee that all my calls to perform crypto operations will end up being
performed on a
Quoted 1 line
security HW I want (maybe because this is the only thing I trust). It seems to be
possible in theory,
Quoted 1 line
but in practice would require careful evaluation of a kernel setup and a sync
between what
Quoted 1 line
end user requests and what driver can provide. Let me try to explain a potential
scenario.
Quoted 1 line
Lets say we had an end user that used to ask for both P-192 and P-384 curve-
based
Quoted 4 lines
Quoted 4 lines
ECC operations
Quoted 1 line
and let's say we had a driver and security HW that implemented it. The end user
made sure that
Quoted 1 line
this driver implementation is always preferred vs. other existing
implementations.
Quoted 2 lines
Quoted 2 lines
Now, time moves, a new
Quoted 1 line
security HW comes instead that only supports P-384, and the driver now has
been
Quoted 3 lines
Quoted 3 lines
updated to
Quoted 2 lines
support P-192 via the SW fallback (like we are asked now). Now, how does an end user notice that when it asks for a P-192 based
operations,
Quoted 5 lines
Quoted 5 lines
his operations
Quoted 2 lines
are not done in security HW anymore? The only way seems to be
is to know that driver and security HW has been updated, algorithms and sizeschanged, etc.
Quoted 1 line
It might take a while before the end user realizes this and for example stops
using
Quoted 4 lines
Quoted 4 lines
P-192 altogether,
Quoted 1 line
but what if this silent redirect by the driver actually breaks some security
assumptions (side-channel
Quoted 1 line
resistance being one potential example) made by this end user? The
consequences
Quoted 19 lines
Quoted 13 lines
can be very bad.
Quoted 1 line
You might say: "this is the end user problem to verify this", but shouldn't we do
smth to prevent or
Quoted 2 lines
at least indicate such potential issues to them?
I don't think it is possible at the API level to define rules that will always produce the most secure combination of drivers. The priority fields are only used to convey relative performance (which is already semantically murky, given the lack of distinction between hardware with a single queue vs software algorithms that can be executed by all CPUs in parallel).
Quoted 5 lines
When it comes to comparative security, trustworthiness or robustness of implementations, it is simply left up to the user to blacklist modules that they prefer not to use. When fallback allocations are made in the correct way, the remaining available implementations will be used in priority order.
Quoted 3 lines
So, let me see if I understand the full picture correctly now and how to utilize the blacklisting of modules as a user. Suppose I want to blacklist everything but my OSC driver module. So, if I am as a user refer to a specific driver
implementation
Quoted 3 lines
using a unique driver name (ecdh-keembay-ocs in our case), then regardless of the fact that a driver implements this SW fallback for P-192 curve, if I am as a user to ask for P-192 curve (or any other param that results in SW fallback), I will be
Quoted 6 lines
notified
Quoted 2 lines
that this requested implementation does not provide it?
This is rather unusual compared with how the crypto API is typically used,
The interesting part here is that I think the use case I am describing is pretty generic, it is strange to see why noone has raised this before. One would think that this is the purpose of having these more secure crypto HW implementations supported via drivers to make sure that the users that care about high-grade security actually get what they expect and the risk of mistakes is minimized.
but if this is really what you want to implement, you can do so
Quoted 11 lines
by:
- having a "ecdh" implementation that implements the entire range, and uses a fallback for curves that it does not implement
- export the same implementation again as "ecdh" and with a known driver name "ecdh-keembay-ocs", but with a slightly lower priority, and in this case, return an error when the unimplemented curve is requested.That way, you fully adhere to the API, by providing implementations of all curves by default. And if a user requests "ecdh-keembay-ocs" explicitly, it will not be able to use the P192 curve inadvertently.
Thank you very much Ard for this explanation! We will see how such implementation definition would look in practice first before thinking on the way to proceed. It might end up looking strange and confusing, and if so, it would at the end destroy the original idea to make "it simple and secure for the driver users to use the provided functionality". I have not seen this being done at all before at any existing crypto drivers, that's why I was thinking this is not supported to begin with.
Quoted 10 lines
But policing which curves are secure and which are not is really not the job of the API. We have implementations of MD5 and RC4 in the kernel that we would *love* to remove but we simply cannot do so as long as they are still being used. The same applies to P192: we simply cannot fail requests for that curve for use cases that were previously deemed valid. It is perfectly reasonable to omit the implementation from your hardware, but banning its use outright on the grounds that is no longer secure conflicts with our requirement not to break existing use cases.
I agree with the above logic. In the light that the crypto API is a toolbox for the crypto and not the security subsystem that aims to make any guarantees on the end security properties it all makes sense. I guess I was only asking if this toolbox can help its users to minimize potential mistakes and be configurable enough to support different usage scenarios. But if the above works, I guess it supports it, just hope the end declaration is not too messy to create other (different) usage problems.
Best Regards,
Elena.
Hi Ard,
Thank you very much for your valuable feedback.
Quoted 10 lines · Ard Biesheuvel
This is rather unusual compared with how the crypto API is typically used, but if this is really what you want to implement, you can do so by:
- having a "ecdh" implementation that implements the entire range, and uses a fallback for curves that it does not implement
- export the same implementation again as "ecdh" and with a known driver name "ecdh-keembay-ocs", but with a slightly lower priority, and in this case, return an error when the unimplemented curve is requested.
Quoted 3 lines
That way, you fully adhere to the API, by providing implementations of all curves by default. And if a user requests "ecdh-keembay-ocs" explicitly, it will not be able to use the P192 curve inadvertently.
I tried to implement this, but it looks like the driver name is mandatory, so I specified one also for the first implementation.
Basically I defined two 'struct kpp_alg' variables; both with cra_name = "ecdh", but with different 'cra_driver_name' (one with cra_driver_name = "ecdh-keembay-ocs-fallback" and the other one with cra_driver_name = "ecdh-keembay-ocs").
Is this what you were suggesting?
Anyway, that works (i.e., 'ecdh-keembay-ocs' returns an error when the unimplemented curve is requested; while 'ecdh-keembay-ocs' and 'ecdh' work fine with any curve), but I have to set the priority of 'ecdh- keembay-ocs' to something lower than the 'ecdh_generic' priority. Otherwise the implementation with fallback ends up using my "ecdh- keembay-ocs" as fallback (so it ends up using a fallback that still does not support the P-192 curve).
Also, the implementation without fallback is still failing crypto self- tests (as expected I guess).
Therefore, I tried with a slightly different solution. Still two implementations, but with different cra_names (one with cra_name = "ecdh" and the other one with cra_name = "ecdh-keembay"). This solution seems to be working, since, the "ecdh-keembay" is not tested by the self tests and is not picked up as fallback for "ecdh" (since, if I understand it correctly, it's like if I'm defining a new kind of kpp algorithm), but it's still picked when calling crypto_alloc_kpp("ecdh- keembay").
Does this second solution looks okay to you? Or does it have some pitfall that I'm missing?
Regards,
Daniele
Quoted 50 lines · Daniele
Hi Ard,
Thank you very much for your valuable feedback.
Quoted 10 lines · Ard Biesheuvel
This is rather unusual compared with how the crypto API is typically used, but if this is really what you want to implement, you can do so by:
- having a "ecdh" implementation that implements the entire range, and uses a fallback for curves that it does not implement
- export the same implementation again as "ecdh" and with a known driver name "ecdh-keembay-ocs", but with a slightly lower priority, and in this case, return an error when the unimplemented curve is requested.Quoted 3 lines
That way, you fully adhere to the API, by providing implementations of all curves by default. And if a user requests "ecdh-keembay-ocs" explicitly, it will not be able to use the P192 curve inadvertently.
I tried to implement this, but it looks like the driver name is mandatory, so I specified one also for the first implementation.
Basically I defined two 'struct
kpp_alg' variables; both withcra_name= "ecdh", but with different 'cra_driver_name' (one withcra_driver_name= "ecdh-keembay-ocs-fallback" and the other one withcra_driver_name= "ecdh-keembay-ocs").Is this what you were suggesting?
Anyway, that works (i.e., 'ecdh-keembay-ocs' returns an error when the unimplemented curve is requested; while 'ecdh-keembay-ocs' and 'ecdh' work fine with any curve), but I have to set the priority of 'ecdh- keembay-ocs' to something lower than the '
ecdh_generic' priority. Otherwise the implementation with fallback ends up using my "ecdh- keembay-ocs" as fallback (so it ends up using a fallback that still does not support the P-192 curve).Also, the implementation without fallback is still failing crypto self- tests (as expected I guess).
Therefore, I tried with a slightly different solution. Still two implementations, but with different
cra_names(one withcra_name= "ecdh" and the other one withcra_name= "ecdh-keembay"). This solution seems to be working, since, the "ecdh-keembay" is not tested by the self tests and is not picked up as fallback for "ecdh" (since, if I understand it correctly, it's like if I'm defining a new kind of kpp algorithm), but it's still picked when callingcrypto_alloc_kpp("ecdh- keembay").
Quoted 3 lines
Does this second solution looks okay to you? Or does it have some pitfall that I'm missing?
You should set the CRYPTO_ALG_NEED_FALLBACK flag on both implementations, to ensure that neither of them are considered as fallbacks themselves.
Quoted 65 lines · Ard Biesheuvel
Quoted 63 lines · Daniele
Hi Ard,
Thank you very much for your valuable feedback.
Quoted 14 lines · Ard Biesheuvel
This is rather unusual compared with how the crypto API is typically
used, but if this is really what you want to implement, you can do so
by:
- having a "ecdh" implementation that implements the entire range, and
uses a fallback for curves that it does not implement
- export the same implementation again as "ecdh" and with a known driver name "ecdh-keembay-ocs", but with a slightly lower priority,
and in this case, return an error when the unimplemented curve is requested.Quoted 5 lines
That way, you fully adhere to the API, by providing implementations of
all curves by default. And if a user requests "ecdh-keembay-ocs" explicitly, it will not be able to use the P192 curve inadvertently.I tried to implement this, but it looks like the driver name is mandatory, so I specified one also for the first implementation.
Basically I defined two 'struct
kpp_alg' variables; both withcra_name
= "ecdh", but with different 'cra_driver_name' (one withcra_driver_name= "ecdh-keembay-ocs-fallback" and the other one withcra_driver_name= "ecdh-keembay-ocs").Is this what you were suggesting?
Anyway, that works (i.e., 'ecdh-keembay-ocs' returns an error when the
unimplemented curve is requested; while 'ecdh-keembay-ocs' and 'ecdh'
work fine with any curve), but I have to set the priority of 'ecdh- keembay-ocs' to something lower than the 'ecdh_generic' priority. Otherwise the implementation with fallback ends up using my "ecdh- keembay-ocs" as fallback (so it ends up using a fallback that still does not support the P-192 curve).Also, the implementation without fallback is still failing crypto self-
tests (as expected I guess).Therefore, I tried with a slightly different solution. Still two implementations, but with different
cra_names(one withcra_name= "ecdh" and the other one withcra_name= "ecdh-keembay"). This solution
seems to be working, since, the "ecdh-keembay" is not tested by the self tests and is not picked up as fallback for "ecdh" (since, if I understand it correctly, it's like if I'm defining a new kind of kpp
algorithm), but it's still picked when calling crypto_alloc_kpp("ecdh-
keembay").
Quoted 7 lines
Quoted 3 lines
Does this second solution looks okay to you? Or does it have some pitfall that I'm missing?
You should set the
CRYPTO_ALG_NEED_FALLBACKflag on both implementations, to ensure that neither of them are considered as fallbacks themselves.
Thanks again!
I was setting that flag only for the first implementation (the one with fallback), but I see now how it's needed for the second one as well.
With that, the second implementation (i.e., the one without fallback) is not used anymore as a fallback for the first one.
As expected, the second implementation does not pass self-tests and crypto_alloc_kpp() returns -ELIBBAD when trying to allocate it, but I've seen that I can avoid the error (and have it allocated properly) by passing the CRYPTO_ALG_TESTED flag in the 'type' argument, like below:
crypto_alloc_kpp("ecdh-keembay-ocs", CRYPTO_ALG_TESTED, 0);Is that the right way to tell crypto_alloc_kpp() that we are fine using an implementation that fails self-tests?
Herbert Xu
maintainerQuoted 6 lines · Daniele
As expected, the second implementation does not pass self-tests and
crypto_alloc_kpp()returns-ELIBBADwhen trying to allocate it, but I've seen that I can avoid the error (and have it allocated properly) by passing theCRYPTO_ALG_TESTEDflag in the 'type' argument, like below:
Did you set your algorithm's name to ecdh? I think Ard was suggesting you to not do that. As long as you're not using the same name as a recognised algorithm, then you won't need to pass any self-tests at all.
Cheers,
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
Quoted 9 lines · Herbert Xu
Quoted 6 lines · Daniele
As expected, the second implementation does not pass self-tests and
crypto_alloc_kpp()returns-ELIBBADwhen trying to allocate it, but I've seen that I can avoid the error (and have it allocated properly)
by passing theCRYPTO_ALG_TESTEDflag in the 'type' argument, like below:
Quoted 5 lines
Did you set your algorithm's name to ecdh? I think Ard was suggesting you to not do that. As long as you're not using the same name as a recognised algorithm, then you won't need to pass any self-tests at all.
Oh, looks like I misunderstood Ard suggestion.
I will change the second implementation to use a different algorithm name (cra_name), something like 'ecdh-keembay-ocs'.
Thanks,
Daniele