User API for KPP
Subsystems (2)
cover User API for KPP
This patchset adds a dedicated user interface for the Key-agreement Protocol Primitive (KPP).
From user applications, we can now use the following specification for AF_ALG sockets:
struct sockaddr_alg sa = {
.salg_family = AF_ALG,
.salg_type = "kpp",
.salg_name = "ecdh-nist-p256",
};Once the private key is set with ALG_SET_KEY or (preferably) ALG_SET_KEY_BY_KEY_SERIAL, the user program reads its public key from the socket and then writes the peer's public key to the socket.
The shared secret calculated by the selected kernel algorithm is then available for reading.
For example, if we create a trusted key like this:
kpriv_id=$(keyctl add trusted kpriv "new 32" @u)
A simple example code is as follows:
key_serial_t key_id;
/* Generate the socket for KPP operation */
sk_fd = socket(AF_ALG, SOCK_SEQPACKET, 0);
bind(sk_fd, (struct sockaddr *)&sa, sizeof(sa));
/* kpriv_id holds the trusted key ID */
setsockopt(sk_fd, SOL_ALG, ALG_SET_KEY_BY_KEY_SERIAL,
&key_id, sizeof(key_id));
/* Get the operational socket */
op_fd = accept(sk_fd, NULL, 0);
/* Read our public key */
recv(op_fd, pubkey, pubkey_len, 0);
/* Write the peer's public key */
send(op_fd, peer_pubkey, peer_pubkey_len, 0);
/* Read the shared secret */
len = recv(op_fd, secret, secret_len, 0);Each time we write a peer's public key, we can read a different shared secret.
Rodolfo Giometti (4):
crypto ecdh.h: set key memory region as const crypto kpp.h: add new method set_secret_raw in struct kpp_alg crypto ecdh.c: define the ECDH set_secret_raw method
crypto: add user-space interface for KPP algorithms
crypto/Kconfig | 8 ++ crypto/Makefile | 1 + crypto/algif_kpp.c | 286 ++++++++++++++++++++++++++++++++++++++++++ crypto/ecdh.c | 31 +++++ include/crypto/ecdh.h | 2 +- include/crypto/kpp.h | 29 +++++ 6 files changed, 356 insertions(+), 1 deletion(-) create mode 100644 crypto/algif_kpp.c
Signature · 1 line
2.34.1
PATCH 1/4 crypto ecdh.h: set key memory region as const
As in include/crypto/dh.h the memory region of a private key must be set as constant.
--- include/crypto/ecdh.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/crypto/ecdh.h +1 -1
@@ -35,7 +35,7 @@* @key_size: Size of the private ECDH key */ struct ecdh { -char *key; +const char *key;unsigned short key_size; };
Signature · 1 line
2.34.1
kernel test robot
build botRe: [V1 1/4] crypto ecdh.h: set key memory region as const
kernel test robot noticed the following build errors:
Hi Rodolfo,
kernel test robot noticed the following build errors:
[auto build test ERROR on herbert-cryptodev-2.6/master]
[also build test ERROR on herbert-crypto-2.6/master linus/master v6.17-rc6 next-20250915] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Rodolfo-Giometti/crypto-ecdh-h-set-key-memory-region-as-const/20250915-164558 base: https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git master patch link: https://lore.kernel.org/r/20250915084039.2848952-2-giometti%40enneenne.com patch subject: [V1 1/4] crypto ecdh.h: set key memory region as const config: riscv-randconfig-001-20250916 (https://download.01.org/0day-ci/archive/20250916/[email protected]/config) compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project 65ad21d730d25789454d18e811f8ff5db79cb5d4) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250916/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> drivers/crypto/hisilicon/hpre/hpre_crypto.c:1430:23: error: passing 'const char *' to parameter of type 'char *' discards qualifiers [-Werror,-Wincompatible-pointer-types-discards-qualifiers]
1430 | if (hpre_key_is_zero(params.key, params.key_size)) {
| ^~~~~~~~~~ drivers/crypto/hisilicon/hpre/hpre_crypto.c:1369:36: note: passing argument to parameter 'key' here
1369 | static bool hpre_key_is_zero(char *key, unsigned short key_sz)
| ^
1 error generated.
vim +1430 drivers/crypto/hisilicon/hpre/hpre_crypto.c
1e609f5fb73b6b1 Hui Tang 2021-05-29 1399
05e7b906aa7c869 Meng Yu 2021-03-04 1400 static int hpre_ecdh_set_secret(struct crypto_kpp *tfm, const void *buf,
05e7b906aa7c869 Meng Yu 2021-03-04 1401 unsigned int len)
05e7b906aa7c869 Meng Yu 2021-03-04 1402 {
05e7b906aa7c869 Meng Yu 2021-03-04 1403 struct hpre_ctx *ctx = kpp_tfm_ctx(tfm);
b0ab0797f7ab74b Weili Qian 2023-07-07 1404 unsigned int sz, sz_shift, curve_sz;
b94c910afda050a Hui Tang 2021-05-12 1405 struct device *dev = ctx->dev;
1e609f5fb73b6b1 Hui Tang 2021-05-29 1406 char key[HPRE_ECC_MAX_KSZ];
05e7b906aa7c869 Meng Yu 2021-03-04 1407 struct ecdh params;
05e7b906aa7c869 Meng Yu 2021-03-04 1408 int ret;
05e7b906aa7c869 Meng Yu 2021-03-04 1409
05e7b906aa7c869 Meng Yu 2021-03-04 1410 if (crypto_ecdh_decode_key(buf, len, ¶ms) < 0) {
05e7b906aa7c869 Meng Yu 2021-03-04 1411 dev_err(dev, "failed to decode ecdh key!\n");
05e7b906aa7c869 Meng Yu 2021-03-04 1412 return -EINVAL;
05e7b906aa7c869 Meng Yu 2021-03-04 1413 }
05e7b906aa7c869 Meng Yu 2021-03-04 1414
1e609f5fb73b6b1 Hui Tang 2021-05-29 1415 /* Use stdrng to generate private key */
1e609f5fb73b6b1 Hui Tang 2021-05-29 1416 if (!params.key || !params.key_size) {
1e609f5fb73b6b1 Hui Tang 2021-05-29 1417 params.key = key;
b0ab0797f7ab74b Weili Qian 2023-07-07 1418 curve_sz = hpre_ecdh_get_curvesz(ctx->curve_id);
b0ab0797f7ab74b Weili Qian 2023-07-07 1419 if (!curve_sz) {
b0ab0797f7ab74b Weili Qian 2023-07-07 1420 dev_err(dev, "Invalid curve size!\n");
b0ab0797f7ab74b Weili Qian 2023-07-07 1421 return -EINVAL;
b0ab0797f7ab74b Weili Qian 2023-07-07 1422 }
b0ab0797f7ab74b Weili Qian 2023-07-07 1423
b0ab0797f7ab74b Weili Qian 2023-07-07 1424 params.key_size = curve_sz - 1;
1e609f5fb73b6b1 Hui Tang 2021-05-29 1425 ret = ecdh_gen_privkey(ctx, ¶ms);
1e609f5fb73b6b1 Hui Tang 2021-05-29 1426 if (ret)
1e609f5fb73b6b1 Hui Tang 2021-05-29 1427 return ret;
1e609f5fb73b6b1 Hui Tang 2021-05-29 1428 }
1e609f5fb73b6b1 Hui Tang 2021-05-29 1429
05e7b906aa7c869 Meng Yu 2021-03-04 @1430 if (hpre_key_is_zero(params.key, params.key_size)) {
05e7b906aa7c869 Meng Yu 2021-03-04 1431 dev_err(dev, "Invalid hpre key!\n");
05e7b906aa7c869 Meng Yu 2021-03-04 1432 return -EINVAL;
05e7b906aa7c869 Meng Yu 2021-03-04 1433 }
05e7b906aa7c869 Meng Yu 2021-03-04 1434
05e7b906aa7c869 Meng Yu 2021-03-04 1435 hpre_ecc_clear_ctx(ctx, false, true);
05e7b906aa7c869 Meng Yu 2021-03-04 1436
05e7b906aa7c869 Meng Yu 2021-03-04 1437 ret = hpre_ecdh_set_param(ctx, ¶ms);
05e7b906aa7c869 Meng Yu 2021-03-04 1438 if (ret < 0) {
05e7b906aa7c869 Meng Yu 2021-03-04 1439 dev_err(dev, "failed to set hpre param, ret = %d!\n", ret);
05e7b906aa7c869 Meng Yu 2021-03-04 1440 return ret;
05e7b906aa7c869 Meng Yu 2021-03-04 1441 }
05e7b906aa7c869 Meng Yu 2021-03-04 1442
05e7b906aa7c869 Meng Yu 2021-03-04 1443 sz = ctx->key_sz;
05e7b906aa7c869 Meng Yu 2021-03-04 1444 sz_shift = (sz << 1) + sz - params.key_size;
05e7b906aa7c869 Meng Yu 2021-03-04 1445 memcpy(ctx->ecdh.p + sz_shift, params.key, params.key_size);
05e7b906aa7c869 Meng Yu 2021-03-04 1446
05e7b906aa7c869 Meng Yu 2021-03-04 1447 return 0;
05e7b906aa7c869 Meng Yu 2021-03-04 1448 }
05e7b906aa7c869 Meng Yu 2021-03-04 1449 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [V1 1/4] crypto ecdh.h: set key memory region as const
In reply to Rodolfo Giomettikernel test robot noticed the following build warnings:
Hi Rodolfo,
kernel test robot noticed the following build warnings:
[auto build test WARNING on herbert-cryptodev-2.6/master]
[also build test WARNING on herbert-crypto-2.6/master linus/master v6.17-rc6 next-20250916] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Rodolfo-Giometti/crypto-ecdh-h-set-key-memory-region-as-const/20250915-164558 base: https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git master patch link: https://lore.kernel.org/r/20250915084039.2848952-2-giometti%40enneenne.com patch subject: [V1 1/4] crypto ecdh.h: set key memory region as const config: arm64-defconfig (https://download.01.org/0day-ci/archive/20250917/[email protected]/config) compiler: aarch64-linux-gcc (GCC) 15.1.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250917/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
drivers/crypto/hisilicon/hpre/hpre_crypto.c: In function 'hpre_ecdh_set_secret':
>> drivers/crypto/hisilicon/hpre/hpre_crypto.c:1430:36: warning: passing argument 1 of 'hpre_key_is_zero' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
1430 | if (hpre_key_is_zero(params.key, params.key_size)) {
| ~~~~~~^~~~ drivers/crypto/hisilicon/hpre/hpre_crypto.c:1369:36: note: expected 'char *' but argument is of type 'const char *'
1369 | static bool hpre_key_is_zero(char *key, unsigned short key_sz)
| ~~~~~~^~~
vim +1430 drivers/crypto/hisilicon/hpre/hpre_crypto.c
1e609f5fb73b6b Hui Tang 2021-05-29 1399
05e7b906aa7c86 Meng Yu 2021-03-04 1400 static int hpre_ecdh_set_secret(struct crypto_kpp *tfm, const void *buf,
05e7b906aa7c86 Meng Yu 2021-03-04 1401 unsigned int len)
05e7b906aa7c86 Meng Yu 2021-03-04 1402 {
05e7b906aa7c86 Meng Yu 2021-03-04 1403 struct hpre_ctx *ctx = kpp_tfm_ctx(tfm);
b0ab0797f7ab74 Weili Qian 2023-07-07 1404 unsigned int sz, sz_shift, curve_sz;
b94c910afda050 Hui Tang 2021-05-12 1405 struct device *dev = ctx->dev;
1e609f5fb73b6b Hui Tang 2021-05-29 1406 char key[HPRE_ECC_MAX_KSZ];
05e7b906aa7c86 Meng Yu 2021-03-04 1407 struct ecdh params;
05e7b906aa7c86 Meng Yu 2021-03-04 1408 int ret;
05e7b906aa7c86 Meng Yu 2021-03-04 1409
05e7b906aa7c86 Meng Yu 2021-03-04 1410 if (crypto_ecdh_decode_key(buf, len, ¶ms) < 0) {
05e7b906aa7c86 Meng Yu 2021-03-04 1411 dev_err(dev, "failed to decode ecdh key!\n");
05e7b906aa7c86 Meng Yu 2021-03-04 1412 return -EINVAL;
05e7b906aa7c86 Meng Yu 2021-03-04 1413 }
05e7b906aa7c86 Meng Yu 2021-03-04 1414
1e609f5fb73b6b Hui Tang 2021-05-29 1415 /* Use stdrng to generate private key */
1e609f5fb73b6b Hui Tang 2021-05-29 1416 if (!params.key || !params.key_size) {
1e609f5fb73b6b Hui Tang 2021-05-29 1417 params.key = key;
b0ab0797f7ab74 Weili Qian 2023-07-07 1418 curve_sz = hpre_ecdh_get_curvesz(ctx->curve_id);
b0ab0797f7ab74 Weili Qian 2023-07-07 1419 if (!curve_sz) {
b0ab0797f7ab74 Weili Qian 2023-07-07 1420 dev_err(dev, "Invalid curve size!\n");
b0ab0797f7ab74 Weili Qian 2023-07-07 1421 return -EINVAL;
b0ab0797f7ab74 Weili Qian 2023-07-07 1422 }
b0ab0797f7ab74 Weili Qian 2023-07-07 1423
b0ab0797f7ab74 Weili Qian 2023-07-07 1424 params.key_size = curve_sz - 1;
1e609f5fb73b6b Hui Tang 2021-05-29 1425 ret = ecdh_gen_privkey(ctx, ¶ms);
1e609f5fb73b6b Hui Tang 2021-05-29 1426 if (ret)
1e609f5fb73b6b Hui Tang 2021-05-29 1427 return ret;
1e609f5fb73b6b Hui Tang 2021-05-29 1428 }
1e609f5fb73b6b Hui Tang 2021-05-29 1429
05e7b906aa7c86 Meng Yu 2021-03-04 @1430 if (hpre_key_is_zero(params.key, params.key_size)) {
05e7b906aa7c86 Meng Yu 2021-03-04 1431 dev_err(dev, "Invalid hpre key!\n");
05e7b906aa7c86 Meng Yu 2021-03-04 1432 return -EINVAL;
05e7b906aa7c86 Meng Yu 2021-03-04 1433 }
05e7b906aa7c86 Meng Yu 2021-03-04 1434
05e7b906aa7c86 Meng Yu 2021-03-04 1435 hpre_ecc_clear_ctx(ctx, false, true);
05e7b906aa7c86 Meng Yu 2021-03-04 1436
05e7b906aa7c86 Meng Yu 2021-03-04 1437 ret = hpre_ecdh_set_param(ctx, ¶ms);
05e7b906aa7c86 Meng Yu 2021-03-04 1438 if (ret < 0) {
05e7b906aa7c86 Meng Yu 2021-03-04 1439 dev_err(dev, "failed to set hpre param, ret = %d!\n", ret);
05e7b906aa7c86 Meng Yu 2021-03-04 1440 return ret;
05e7b906aa7c86 Meng Yu 2021-03-04 1441 }
05e7b906aa7c86 Meng Yu 2021-03-04 1442
05e7b906aa7c86 Meng Yu 2021-03-04 1443 sz = ctx->key_sz;
05e7b906aa7c86 Meng Yu 2021-03-04 1444 sz_shift = (sz << 1) + sz - params.key_size;
05e7b906aa7c86 Meng Yu 2021-03-04 1445 memcpy(ctx->ecdh.p + sz_shift, params.key, params.key_size);
05e7b906aa7c86 Meng Yu 2021-03-04 1446
05e7b906aa7c86 Meng Yu 2021-03-04 1447 return 0;
05e7b906aa7c86 Meng Yu 2021-03-04 1448 }
05e7b906aa7c86 Meng Yu 2021-03-04 1449 Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH 2/4 crypto kpp.h: add new method set_secret_raw in struct kpp_alg
In reply to Rodolfo GiomettiThis method can be used to correctly set the private key from a binary data buffer. This function class should encode the key and then simply call the specific set_secret() function based on the corresponding algorithm.
--- include/crypto/kpp.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+)
include/crypto/kpp.h +29 -0
@@ -54,6 +54,9 @@ struct crypto_kpp {/** * struct kpp_alg - generic key-agreement protocol primitives * +* @set_secret_raw: Function invokes the protocol specific function to +* encode and set the secret private key in a raw +* binary format. * @set_secret: Function invokes the protocol specific function to * store the secret private key along with parameters. * The implementation knows how to decode the buffer
@@ -75,6 +78,8 @@ struct crypto_kpp {* @base: Common crypto API algorithm data structure */ struct kpp_alg { +int (*set_secret_raw)(struct crypto_kpp *tfm,const u8 *key, +unsigned int len);int (*set_secret)(struct crypto_kpp *tfm,const void *buffer,unsigned int len);int (*generate_public_key)(struct kpp_request *req);
@@ -293,6 +298,30 @@ static inline int crypto_kpp_set_secret(struct crypto_kpp *tfm,return crypto_kpp_alg (tfm)->set_secret (tfm, buffer, len); } +/** +* crypto_kpp_set_secret_raw() - Invoke kpp operation +* +* Function that works as crypto_kpp_set_secret() but on a non-encoded key +* (aka raw binary data). +* +* @tfm: tfm handle +* @buffer: Buffer holding the raw representation of the private +* key as raw binary data. +* @len: Length of the private key buffer. +* +* Return: zero on success; error code in case of error +*/ +static inline int crypto_kpp_set_secret_raw (struct crypto_kpp *tfm, +const u8 *key,unsigned int len) +{ +struct kpp_alg *alg =crypto_kpp_alg (tfm); + +if (!alg->set_secret_raw) +return -EOPNOTSUPP ; + +return alg->set_secret_raw (tfm, key, len); +} +/** * crypto_kpp_generate_public_key() - Invoke kpp operation *
Signature · 1 line
2.34.1
PATCH 3/4 crypto ecdh.c: define the ECDH set_secret_raw method
In reply to Rodolfo GiomettiAdds new function ecdh_set_secret_raw() and sets it as set_secret_raw method for ecdh_nist_(p192|p256|p384) algorithms.
--- crypto/ecdh.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
crypto/ecdh.c +31 -0
@@ -52,6 +52,34 @@ static int ecdh_set_secret(struct crypto_kpp *tfm, const void *buf,return ret; } +static int ecdh_set_secret_raw (struct crypto_kpp *tfm,const u8 *key, +unsigned int len) +{ +struct ecdh params = { + .key = key, + .key_size = len, + }; +u8 *buf; +unsigned int buf_len; +int err; + + buf_len =crypto_ecdh_key_len (¶ms); + buf =kmalloc (buf_len,GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + + err =crypto_ecdh_encode_key (buf, buf_len, ¶ms); +if (err) + goto free_buf; + + err =ecdh_set_secret (tfm, buf, buf_len); + fallthrough; +free_buf: +kfree_sensitive (buf); + +return err; +} +static int ecdh_compute_value (struct kpp_request *req) {struct crypto_kpp *tfm =crypto_kpp_reqtfm (req);
@@ -139,6 +167,7 @@ static int ecdh_nist_p192_init_tfm(struct crypto_kpp *tfm) }static struct kpp_alg ecdh_nist_p192 = { + .set_secret_raw = ecdh_set_secret_raw, .set_secret = ecdh_set_secret, .generate_public_key = ecdh_compute_value, .compute_shared_secret = ecdh_compute_value,
@@ -164,6 +193,7 @@ static int ecdh_nist_p256_init_tfm(struct crypto_kpp *tfm) }static struct kpp_alg ecdh_nist_p256 = { + .set_secret_raw = ecdh_set_secret_raw, .set_secret = ecdh_set_secret, .generate_public_key = ecdh_compute_value, .compute_shared_secret = ecdh_compute_value,
@@ -189,6 +219,7 @@ static int ecdh_nist_p384_init_tfm(struct crypto_kpp *tfm) }static struct kpp_alg ecdh_nist_p384 = { + .set_secret_raw = ecdh_set_secret_raw, .set_secret = ecdh_set_secret, .generate_public_key = ecdh_compute_value, .compute_shared_secret = ecdh_compute_value,
Signature · 1 line
2.34.1
kernel test robot
build botRe: [V1 3/4] crypto ecdh.c: define the ECDH set_secret_raw method
kernel test robot noticed the following build errors:
Hi Rodolfo,
kernel test robot noticed the following build errors:
[auto build test ERROR on herbert-cryptodev-2.6/master]
[also build test ERROR on herbert-crypto-2.6/master linus/master v6.17-rc6 next-20250912] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Rodolfo-Giometti/crypto-ecdh-h-set-key-memory-region-as-const/20250915-164558 base: https://git.kernel.org/pub/scm/linux/kernel/git/herbert/cryptodev-2.6.git master patch link: https://lore.kernel.org/r/20250915084039.2848952-4-giometti%40enneenne.com patch subject: [V1 3/4] crypto ecdh.c: define the ECDH set_secret_raw method config: i386-buildonly-randconfig-002-20250915 (https://download.01.org/0day-ci/archive/20250915/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250915/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from include/linux/compiler_types.h:89,
from <command-line>:
crypto/ecdh.c: In function 'ecdh_set_secret_raw':
>> include/linux/compiler_attributes.h:214:41: error: invalid use of attribute 'fallthrough'
214 | # define fallthrough __attribute__((__fallthrough__))
| ^~~~~~~~~~~~~
crypto/ecdh.c:76:9: note: in expansion of macro 'fallthrough'
76 | fallthrough;
| ^~~~~~~~~~~--
In file included from include/linux/compiler_types.h:89,
from <command-line>:
ecdh.c: In function 'ecdh_set_secret_raw':
>> include/linux/compiler_attributes.h:214:41: error: invalid use of attribute 'fallthrough'
214 | # define fallthrough __attribute__((__fallthrough__))
| ^~~~~~~~~~~~~
ecdh.c:76:9: note: in expansion of macro 'fallthrough'
76 | fallthrough;
| ^~~~~~~~~~~vim +/fallthrough +214 include/linux/compiler_attributes.h
294f69e662d1570 Joe Perches 2019-10-05 201 294f69e662d1570 Joe Perches 2019-10-05 202 /* 294f69e662d1570 Joe Perches 2019-10-05 203 * Add the pseudo keyword 'fallthrough' so case statement blocks 294f69e662d1570 Joe Perches 2019-10-05 204 * must end with any of these keywords: 294f69e662d1570 Joe Perches 2019-10-05 205 * break; 294f69e662d1570 Joe Perches 2019-10-05 206 * fallthrough; ca0760e7d79e2bb Wei Ming Chen 2021-05-06 207 * continue; 294f69e662d1570 Joe Perches 2019-10-05 208 * goto <label>; 294f69e662d1570 Joe Perches 2019-10-05 209 * return [expression]; 294f69e662d1570 Joe Perches 2019-10-05 210 * 294f69e662d1570 Joe Perches 2019-10-05 211 * gcc: https://gcc.gnu.org/onlinedocs/gcc/Statement-Attributes.html#Statement-Attributes 294f69e662d1570 Joe Perches 2019-10-05 212 */ 294f69e662d1570 Joe Perches 2019-10-05 213 #if __has_attribute(__fallthrough__) 294f69e662d1570 Joe Perches 2019-10-05 @214 # define fallthrough __attribute__((__fallthrough__)) 294f69e662d1570 Joe Perches 2019-10-05 215 #else 294f69e662d1570 Joe Perches 2019-10-05 216 # define fallthrough do {} while (0) /* fallthrough */ a3f8a30f3f0079c Miguel Ojeda 2018-08-30 217 #endif a3f8a30f3f0079c Miguel Ojeda 2018-08-30 218
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH 4/4 crypto: add user-space interface for KPP algorithms
In reply to Rodolfo GiomettiIt adds a dedicated user interface for the Key-agreement Protocol Primitive (KPP).
Now, from user applications, we can use the following specification for AF_ALG sockets:
struct sockaddr_alg sa = {
.salg_family = AF_ALG,
.salg_type = "kpp",
.salg_name = "ecdh-nist-p256",
};Once the private key is set with ALG_SET_KEY or (better by) ALG_SET_KEY_BY_KEY_SERIAL, the user program should write the peer's public key to the socket and then receive its public key followed by the shared secret calculated by the selected kernel algorithm.
--- crypto/Kconfig | 8 ++ crypto/Makefile | 1 + crypto/algif_kpp.c | 286 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 295 insertions(+) create mode 100644 crypto/algif_kpp.c
crypto/Kconfig +8 -0
@@ -1412,6 +1412,14 @@ config CRYPTO_USER_API_AEAD See Documentation/crypto/userspace-if.rst and https://www.chronox.de/libkcapi/html/index.html +config CRYPTO_USER_API_KPP + tristate "Key-agreement Protocol Primitive" + depends on NET + select CRYPTO_KPP + select CRYPTO_USER_API + help + Enable the userspace interface for Key-agreement Protocol Primitive. + config CRYPTO_USER_API_ENABLE_OBSOLETE bool "Obsolete cryptographic algorithms" depends on CRYPTO_USER_API
crypto/Makefile +1 -0
@@ -179,6 +179,7 @@ obj-$(CONFIG_CRYPTO_USER_API_HASH) += algif_hash.o obj-$(CONFIG_CRYPTO_USER_API_SKCIPHER) += algif_skcipher.o obj-$(CONFIG_CRYPTO_USER_API_RNG) += algif_rng.o obj-$(CONFIG_CRYPTO_USER_API_AEAD) += algif_aead.o +obj-$(CONFIG_CRYPTO_USER_API_KPP) += algif_kpp.o obj-$(CONFIG_CRYPTO_ZSTD) += zstd.o obj-$(CONFIG_CRYPTO_ECC) += ecc.o obj-$(CONFIG_CRYPTO_ESSIV) += essiv.o
crypto/algif_kpp.c new file +286 -0
286 lines not on this page · raw message
Signature · 1 line
2.34.1
Quoted 56 lines · Rodolfo Giometti
This patchset adds a dedicated user interface for the Key-agreement Protocol Primitive (KPP).
From user applications, we can now use the following specification for
AF_ALGsockets:struct sockaddr_alg sa = { .salg_family = AF_ALG, .salg_type = "kpp", .salg_name = "ecdh-nist-p256", };Once the private key is set with
ALG_SET_KEYor (preferably)ALG_SET_KEY_BY_KEY_SERIAL, the user program reads its public key from the socket and then writes the peer's public key to the socket.The shared secret calculated by the selected kernel algorithm is then available for reading.
For example, if we create a trusted key like this:
kpriv_id=$(keyctl add trusted kpriv "new 32" @u)A simple example code is as follows:
key_serial_t key_id; /* Generate the socket for KPP operation */ sk_fd = socket(AF_ALG, SOCK_SEQPACKET, 0); bind(sk_fd, (struct sockaddr *)&sa, sizeof(sa)); /* kpriv_id holds the trusted key ID */ setsockopt(sk_fd, SOL_ALG, ALG_SET_KEY_BY_KEY_SERIAL, &key_id, sizeof(key_id)); /* Get the operational socket */ op_fd = accept(sk_fd, NULL, 0); /* Read our public key */ recv(op_fd, pubkey, pubkey_len, 0); /* Write the peer's public key */ send(op_fd, peer_pubkey, peer_pubkey_len, 0); /* Read the shared secret */ len = recv(op_fd, secret, secret_len, 0);Each time we write a peer's public key, we can read a different shared secret.
Rodolfo Giometti (4):
cryptoecdh.h: set key memory region as const cryptokpp.h: add new methodset_secret_rawin structkpp_algcryptoecdh.c: define the ECDHset_secret_rawmethod
crypto: add user-space interface for KPP algorithms
Quoted 8 lines
crypto/Kconfig | 8 ++ crypto/Makefile | 1 + crypto/algif_kpp.c | 286 ++++++++++++++++++++++++++++++++++++++++++ crypto/ecdh.c | 31 +++++ include/crypto/ecdh.h | 2 +- include/crypto/kpp.h | 29 +++++ 6 files changed, 356 insertions(+), 1 deletion(-) create mode 100644 crypto/algif_kpp.c
First, this lacks any description of a use case.
Second, *if* this is done at all, then it must give access to hardware drivers *only*. We've had way too many problems with userspace software inappropriately depending on the in-kernel software crypto code via AF_ALG, when it should just be doing the crypto in userspace.
The asymmetric algorithms are especially bad because the in-kernel implementations of most of them (all except Curve25519, I think) have known timing attack vulnerabilities. Implementing these algorithms is really hard, and the in-kernel implementations just haven't had the same level of care applied to them as userspace implementations.
We've seen time and time again that if a UAPI is offered, then userspace will use it, even when it's not the appropriate solution. Then it can't be fixed, and everyone ends up worse off.
- Eric
Quoted 66 lines · Eric Biggers
Quoted 56 lines · Rodolfo Giometti
This patchset adds a dedicated user interface for the Key-agreement Protocol Primitive (KPP).
From user applications, we can now use the following specification for
AF_ALGsockets:struct sockaddr_alg sa = { .salg_family = AF_ALG, .salg_type = "kpp", .salg_name = "ecdh-nist-p256", };Once the private key is set with
ALG_SET_KEYor (preferably)ALG_SET_KEY_BY_KEY_SERIAL, the user program reads its public key from the socket and then writes the peer's public key to the socket.The shared secret calculated by the selected kernel algorithm is then available for reading.
For example, if we create a trusted key like this:
kpriv_id=$(keyctl add trusted kpriv "new 32" @u)A simple example code is as follows:
key_serial_t key_id; /* Generate the socket for KPP operation */ sk_fd = socket(AF_ALG, SOCK_SEQPACKET, 0); bind(sk_fd, (struct sockaddr *)&sa, sizeof(sa)); /* kpriv_id holds the trusted key ID */ setsockopt(sk_fd, SOL_ALG, ALG_SET_KEY_BY_KEY_SERIAL, &key_id, sizeof(key_id)); /* Get the operational socket */ op_fd = accept(sk_fd, NULL, 0); /* Read our public key */ recv(op_fd, pubkey, pubkey_len, 0); /* Write the peer's public key */ send(op_fd, peer_pubkey, peer_pubkey_len, 0); /* Read the shared secret */ len = recv(op_fd, secret, secret_len, 0);Each time we write a peer's public key, we can read a different shared secret.
Rodolfo Giometti (4):
cryptoecdh.h: set key memory region as const cryptokpp.h: add new methodset_secret_rawin structkpp_algcryptoecdh.c: define the ECDHset_secret_rawmethod
crypto: add user-space interface for KPP algorithmsQuoted 8 lines
crypto/Kconfig | 8 ++ crypto/Makefile | 1 + crypto/algif_kpp.c | 286 ++++++++++++++++++++++++++++++++++++++++++ crypto/ecdh.c | 31 +++++ include/crypto/ecdh.h | 2 +- include/crypto/kpp.h | 29 +++++ 6 files changed, 356 insertions(+), 1 deletion(-)create mode 100644
crypto/algif_kpp.c
Quoted 1 line
First, this lacks any description of a use case.
The main purpose of using this implementation is to be able to use the kernel's trusted keys as private keys. Trusted keys are protected by a TPM or other hardware device, and being able to generate private keys that can only be (de)encapsulated within them is (IMHO) a very useful and secure mechanism for storing a private key.
Quoted 4 lines
Second, *if* this is done at all, then it must give access to hardware drivers *only*. We've had way too many problems with userspace software inappropriately depending on the in-kernel software crypto code via
AF_ALG, when it should just be doing the crypto in userspace.
I see, but in userspace there is no better way to protect a private key than using trusted keys.
Quoted 5 lines
The asymmetric algorithms are especially bad because the in-kernel implementations of most of them (all except Curve25519, I think) have known timing attack vulnerabilities. Implementing these algorithms is really hard, and the in-kernel implementations just haven't had the same level of care applied to them as userspace implementations.
I think this is true when talking about kernel software implementations, but is it the same when we consider possible hardware implementations?
Quoted 3 lines
We've seen time and time again that if a UAPI is offered, then userspace will use it, even when it's not the appropriate solution. Then it can't be fixed, and everyone ends up worse off.
I understand your point, so please let me know if I have any chance of this patch set (once fixed and revised) being merged into the kernel; otherwise, I'll give up right away. :)
Thanks for your considerations.
Ciao,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems phone: +39 349 2432127 UNIX programming
Herbert Xu
maintainerQuoted 6 lines · Rodolfo Giometti
The main purpose of using this implementation is to be able to use the kernel's trusted keys as private keys. Trusted keys are protected by a TPM or other hardware device, and being able to generate private keys that can only be (de)encapsulated within them is (IMHO) a very useful and secure mechanism for storing a private key.
If the issue is key management then you should be working with David Howell on creating an interface that sits on top of the keyring subsystem.
The Crypto API doesn't care about keys.
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 8 lines · Herbert Xu
Quoted 6 lines · Rodolfo Giometti
The main purpose of using this implementation is to be able to use the kernel's trusted keys as private keys. Trusted keys are protected by a TPM or other hardware device, and being able to generate private keys that can only be (de)encapsulated within them is (IMHO) a very useful and secure mechanism for storing a private key.
Quoted 5 lines
If the issue is key management then you should be working with David Howell on creating an interface that sits on top of the keyring subsystem.
The Crypto API doesn't care about keys.
No, the problem concerns the use of the Linux keyring (specifically, trusted keys and other hardware-managed keys) with cryptographic algorithms.
From a security standpoint, AF_ALG and keyctl's trusted keys are a perfect match to manage secure encryption and decryption, so why not do the same with KPP operations (or other cryptographic operations)?
I know there might be issues with allowing user space to use this interface, but:
1) I think this mechanism can get its best when implemented in hardware, and
2) (hey!) we're developers who know what they're doing! :)
This patch series is just a sample of the improvements I'd like to make on this front. Please tell me if you don't intend to add these mechanisms to the kernel at all, or if I have any chances, so I can decide whether to proceed or stop here.
Ciao,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems phone: +39 349 2432127 UNIX programming
Quoted 14 lines · Rodolfo Giometti
Quoted 12 lines · Herbert Xu
Quoted 6 lines · Rodolfo Giometti
The main purpose of using this implementation is to be able to use the kernel's trusted keys as private keys. Trusted keys are protected by a TPM or other hardware device, and being able to generate private keys that can only be (de)encapsulated within them is (IMHO) a very useful and secure mechanism for storing a private key.
If the issue is key management then you should be working with David Howell on creating an interface that sits on top of the keyring subsystem.
Quoted 8 lines
Quoted 1 line
The Crypto API doesn't care about keys.
No, the problem concerns the use of the Linux keyring (specifically, trusted keys and other hardware-managed keys) with cryptographic algorithms.
From a security standpoint,
AF_ALGand keyctl's trusted keys are a perfect
match to manage secure encryption and decryption, so why not do the same with KPP operations (or other cryptographic operations)?
I generally find the AF_ALG API ugly to use, but I can see the use case for symmetric algorithms, where one needs to encrypt/decrypt a large stream in chunks. For asymmetric operations, like signing and KPP it doesn't make much sense to go through the socket API. In fact we already have an established interface through keyctl(2).
Now, in my opinion, the fundamental problem here is that we want to use trusted keys as asymmetric keys, where currently they are just binary blobs from a kernel perspective (so suitable only for symmetric use). So instead of the AF_ALG extension we need a way to "cast" a trusted key to an asymmetric key and once it is "cast" (or type changed somehow) - we can use the established keyring interfaces both for signatures and KPP. For example, what if we somehow extend the add_key(2)/request_key(2) syscalls to be able to initialise an asymmetric key from a trusted key payload instead of providing the payload directly via a buffer (similar to how ALG_SET_KEY_BY_KEY_SERIAL does it for symmetric keys for socket crypto API)?
Ignat
Quoted 19 lines
I know there might be issues with allowing user space to use this interface, but:
1) I think this mechanism can get its best when implemented in hardware, and
2) (hey!) we're developers who know what they're doing! :)
This patch series is just a sample of the improvements I'd like to make on this front. Please tell me if you don't intend to add these mechanisms to the kernel at all, or if I have any chances, so I can decide whether to proceed or stop here.
Ciao,
Rodolfo
--
GNU/Linux Solutions e-mail: [email protected]
Linux Device Driver [email protected]
Embedded Systems phone: +39 349 2432127
UNIX programming
Quoted 24 lines · Ignat Korchagin
Quoted 14 lines · Rodolfo Giometti
Quoted 12 lines · Herbert Xu
Quoted 6 lines · Rodolfo Giometti
The main purpose of using this implementation is to be able to use the kernel's trusted keys as private keys. Trusted keys are protected by a TPM or other hardware device, and being able to generate private keys that can only be (de)encapsulated within them is (IMHO) a very useful and secure mechanism for storing a private key.
If the issue is key management then you should be working with David Howell on creating an interface that sits on top of the keyring subsystem.
Quoted 8 lines
Quoted 1 line
The Crypto API doesn't care about keys.
No, the problem concerns the use of the Linux keyring (specifically, trusted keys and other hardware-managed keys) with cryptographic algorithms.
From a security standpoint,
AF_ALGand keyctl's trusted keys are a perfect
match to manage secure encryption and decryption, so why not do the same with KPP operations (or other cryptographic operations)?
Quoted 5 lines
I generally find the
AF_ALGAPI ugly to use, but I can see the use case for symmetric algorithms, where one needs to encrypt/decrypt a large stream in chunks. For asymmetric operations, like signing and KPP it doesn't make much sense to go through the socket API. In fact we already have an established interface through keyctl(2).
I see, but if we consider shared secret support, for example, keyctl doesn't support ECDH, while AF_ALG allows you to choose whether to use DH or ECDH. Furthermore, AF_ALG allows us to choose which driver actually performs the encryption operation!
In my opinion, keyctl is excellent for managing key generation and access, but using AF_ALG for using them isn't entirely wrong even in the case of asymmetric keys and, in my opinion, is much more versatile.
Quoted 7 lines
Now, in my opinion, the fundamental problem here is that we want to use trusted keys as asymmetric keys, where currently they are just binary blobs from a kernel perspective (so suitable only for symmetric use). So instead of the
AF_ALGextension we need a way to "cast" a trusted key to an asymmetric key and once it is "cast" (or type changed somehow) - we can use the established keyring interfaces both for signatures and KPP.
IMHO the fact that trusted keys are binary blobs is perfect for use with AF_ALG, where we can specify different algorithms to operate on. :)
Ciao,
Rodolfo
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems phone: +39 349 2432127 UNIX programming
Quoted 26 lines · Rodolfo Giometti
Quoted 24 lines · Ignat Korchagin
Quoted 22 lines · Rodolfo Giometti
Quoted 8 lines · Herbert Xu
Quoted 6 lines · Rodolfo Giometti
The main purpose of using this implementation is to be able to use the kernel's trusted keys as private keys. Trusted keys are protected by a TPM or other hardware device, and being able to generate private keys that can only be (de)encapsulated within them is (IMHO) a very useful and secure mechanism for storing a private key.
Quoted 5 lines
If the issue is key management then you should be working with David Howell on creating an interface that sits on top of the keyring subsystem.
The Crypto API doesn't care about keys.
No, the problem concerns the use of the Linux keyring (specifically, trusted keys and other hardware-managed keys) with cryptographic algorithms.
From a security standpoint,
AF_ALGand keyctl's trusted keys are a perfect
match to manage secure encryption and decryption, so why not do the same with KPP operations (or other cryptographic operations)?
Quoted 8 lines
Quoted 5 lines
I generally find the
AF_ALGAPI ugly to use, but I can see the use case for symmetric algorithms, where one needs to encrypt/decrypt a large stream in chunks. For asymmetric operations, like signing and KPP it doesn't make much sense to go through the socket API. In fact we already have an established interface through keyctl(2).I see, but if we consider shared secret support, for example, keyctl doesn't support ECDH, while
AF_ALGallows you to choose whether to use DH or ECDH.
But this is exactly the point: unlike symmetric algorithms, where you can just use any blob with any algorithm, you can't use an RSA key for ECDH for example. That is, you cannot arbitrarily select an algorithm for any key and the algorithm is a property attached to the key itself. So if you "cast" a blob to an EC key, you would need to select the algorithm at cast time and the implementation should validate if the blob actually represents a valid EC key (with all the proper checks, like if the key is an a big in and is less than the order group etc). With AF_ALG you would need to do this validation for every crypto operation, which is not very efficient at the very least.
Quoted 2 lines
Furthermore,
AF_ALGallows us to choose which driver actually performs the encryption operation!
This is indeed a limitation of the current keyctl interface, but again
- we probably should not select the algorithm here, but we should consider extending it so the user can specify a particular crypto driver/implementation.
Quoted 24 lines
In my opinion, keyctl is excellent for managing key generation and access, but using
AF_ALGfor using them isn't entirely wrong even in the case of asymmetric keys and, in my opinion, is much more versatile.Quoted 7 lines
Now, in my opinion, the fundamental problem here is that we want to use trusted keys as asymmetric keys, where currently they are just binary blobs from a kernel perspective (so suitable only for symmetric use). So instead of the
AF_ALGextension we need a way to "cast" a trusted key to an asymmetric key and once it is "cast" (or type changed somehow) - we can use the established keyring interfaces both for signatures and KPP.IMHO the fact that trusted keys are binary blobs is perfect for use with
AF_ALG, where we can specify different algorithms to operate on. :)Ciao,
Rodolfo
--
GNU/Linux Solutions e-mail: [email protected]
Linux Device Driver [email protected]
Embedded Systems phone: +39 349 2432127
UNIX programming
Quoted 36 lines · Ignat Korchagin
Quoted 26 lines · Rodolfo Giometti
Quoted 24 lines · Ignat Korchagin
Quoted 22 lines · Rodolfo Giometti
Quoted 8 lines · Herbert Xu
Quoted 6 lines · Rodolfo Giometti
The main purpose of using this implementation is to be able to use the kernel's trusted keys as private keys. Trusted keys are protected by a TPM or other hardware device, and being able to generate private keys that can only be (de)encapsulated within them is (IMHO) a very useful and secure mechanism for storing a private key.
Quoted 5 lines
If the issue is key management then you should be working with David Howell on creating an interface that sits on top of the keyring subsystem.
The Crypto API doesn't care about keys.
No, the problem concerns the use of the Linux keyring (specifically, trusted keys and other hardware-managed keys) with cryptographic algorithms.
From a security standpoint,
AF_ALGand keyctl's trusted keys are a perfect
match to manage secure encryption and decryption, so why not do the same with KPP operations (or other cryptographic operations)?Quoted 8 lines
Quoted 5 lines
I generally find the
AF_ALGAPI ugly to use, but I can see the use case for symmetric algorithms, where one needs to encrypt/decrypt a large stream in chunks. For asymmetric operations, like signing and KPP it doesn't make much sense to go through the socket API. In fact we already have an established interface through keyctl(2).I see, but if we consider shared secret support, for example, keyctl doesn't support ECDH, while
AF_ALGallows you to choose whether to use DH or ECDH.
Quoted 9 lines
But this is exactly the point: unlike symmetric algorithms, where you can just use any blob with any algorithm, you can't use an RSA key for ECDH for example. That is, you cannot arbitrarily select an algorithm for any key and the algorithm is a property attached to the key itself. So if you "cast" a blob to an EC key, you would need to select the algorithm at cast time and the implementation should validate if the blob actually represents a valid EC key (with all the proper checks, like if the key is an a big in and is less than the order group etc).
I understand your point; however, I believe that allowing the AF_ALG developer to use a generic data blob (of the appropriate size, of course) as a key is more versatile and allows for easier implementation of future extensions.
Quoted 2 lines
With
AF_ALGyou would need to do this validation for every crypto operation, which is not very efficient at the very least.
I think this might be acceptable if we consider the security we gain compared to using any existing user-space implementation!
Quoted 7 lines
Quoted 2 lines
Furthermore,
AF_ALGallows us to choose which driver actually performs the encryption operation!This is indeed a limitation of the current keyctl interface, but again
- we probably should not select the algorithm here, but we should consider extending it so the user can specify a particular crypto driver/implementation.
Furthermore, I think one solution isn't mutually exclusive. So, why not give the developer the freedom to choose which interface to use? ;)
Furthermore, there's nothing stopping us from strengthening the current AF_ALG support so that it can also be used well with asymmetric keys.
Quoted 24 lines
Quoted 24 lines
In my opinion, keyctl is excellent for managing key generation and access, but using
AF_ALGfor using them isn't entirely wrong even in the case of asymmetric keys and, in my opinion, is much more versatile.Quoted 7 lines
Now, in my opinion, the fundamental problem here is that we want to use trusted keys as asymmetric keys, where currently they are just binary blobs from a kernel perspective (so suitable only for symmetric use). So instead of the
AF_ALGextension we need a way to "cast" a trusted key to an asymmetric key and once it is "cast" (or type changed somehow) - we can use the established keyring interfaces both for signatures and KPP.IMHO the fact that trusted keys are binary blobs is perfect for use with
AF_ALG, where we can specify different algorithms to operate on. :)Ciao,
Rodolfo
--
GNU/Linux Solutions e-mail: [email protected]
Linux Device Driver [email protected]
Embedded Systems phone: +39 349 2432127
UNIX programming
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems phone: +39 349 2432127 UNIX programming
Quoted 52 lines · Rodolfo Giometti
Quoted 36 lines · Ignat Korchagin
Quoted 26 lines · Rodolfo Giometti
Quoted 24 lines · Ignat Korchagin
Quoted 22 lines · Rodolfo Giometti
Quoted 8 lines · Herbert Xu
Quoted 6 lines · Rodolfo Giometti
The main purpose of using this implementation is to be able to use the kernel's trusted keys as private keys. Trusted keys are protected by a TPM or other hardware device, and being able to generate private keys that can only be (de)encapsulated within them is (IMHO) a very useful and secure mechanism for storing a private key.
Quoted 5 lines
If the issue is key management then you should be working with David Howell on creating an interface that sits on top of the keyring subsystem.
The Crypto API doesn't care about keys.
No, the problem concerns the use of the Linux keyring (specifically, trusted keys and other hardware-managed keys) with cryptographic algorithms.
From a security standpoint,
AF_ALGand keyctl's trusted keys are a perfect
match to manage secure encryption and decryption, so why not do the same with KPP operations (or other cryptographic operations)?Quoted 8 lines
Quoted 5 lines
I generally find the
AF_ALGAPI ugly to use, but I can see the use case for symmetric algorithms, where one needs to encrypt/decrypt a large stream in chunks. For asymmetric operations, like signing and KPP it doesn't make much sense to go through the socket API. In fact we already have an established interface through keyctl(2).I see, but if we consider shared secret support, for example, keyctl doesn't support ECDH, while
AF_ALGallows you to choose whether to use DH or ECDH.Quoted 9 lines
But this is exactly the point: unlike symmetric algorithms, where you can just use any blob with any algorithm, you can't use an RSA key for ECDH for example. That is, you cannot arbitrarily select an algorithm for any key and the algorithm is a property attached to the key itself. So if you "cast" a blob to an EC key, you would need to select the algorithm at cast time and the implementation should validate if the blob actually represents a valid EC key (with all the proper checks, like if the key is an a big in and is less than the order group etc).
I understand your point; however, I believe that allowing the
AF_ALGdeveloper to use a generic data blob (of the appropriate size, of course) as a key is more versatile and allows for easier implementation of future extensions.
Quoted 5 lines
Quoted 2 lines
With
AF_ALGyou would need to do this validation for every crypto operation, which is not very efficient at the very least.I think this might be acceptable if we consider the security we gain compared to using any existing user-space implementation!
I don't think the alternative approach I proposed compromises on security. That is it has the same security level (using a trusted key to do ECDH without exposing it to userspace). Unless I'm missing something?
Quoted 45 lines
Quoted 7 lines
Quoted 2 lines
Furthermore,
AF_ALGallows us to choose which driver actually performs the encryption operation!This is indeed a limitation of the current keyctl interface, but again
- we probably should not select the algorithm here, but we should consider extending it so the user can specify a particular crypto driver/implementation.Furthermore, I think one solution isn't mutually exclusive. So, why not give the developer the freedom to choose which interface to use? ;)
Furthermore, there's nothing stopping us from strengthening the current
AF_ALGsupport so that it can also be used well with asymmetric keys.Quoted 17 lines
Quoted 17 lines
In my opinion, keyctl is excellent for managing key generation and access, but using
AF_ALGfor using them isn't entirely wrong even in the case of asymmetric keys and, in my opinion, is much more versatile.Quoted 7 lines
Now, in my opinion, the fundamental problem here is that we want to use trusted keys as asymmetric keys, where currently they are just binary blobs from a kernel perspective (so suitable only for symmetric use). So instead of the
AF_ALGextension we need a way to "cast" a trusted key to an asymmetric key and once it is "cast" (or type changed somehow) - we can use the established keyring interfaces both for signatures and KPP.IMHO the fact that trusted keys are binary blobs is perfect for use with
AF_ALG, where we can specify different algorithms to operate on. :)Ciao,
Quoted 7 lines
Quoted 7 lines
Rodolfo
--
GNU/Linux Solutions e-mail: [email protected]
Linux Device Driver [email protected]
Embedded Systems phone: +39 349 2432127
UNIX programming--
GNU/Linux Solutions e-mail: [email protected]
Linux Device Driver [email protected]
Embedded Systems phone: +39 349 2432127
UNIX programming
Quoted 56 lines · Ignat Korchagin
Quoted 55 lines · Rodolfo Giometti
Quoted 36 lines · Ignat Korchagin
Quoted 26 lines · Rodolfo Giometti
Quoted 24 lines · Ignat Korchagin
Quoted 22 lines · Rodolfo Giometti
Quoted 8 lines · Herbert Xu
Quoted 6 lines · Rodolfo Giometti
The main purpose of using this implementation is to be able to use the kernel's trusted keys as private keys. Trusted keys are protected by a TPM or other hardware device, and being able to generate private keys that can only be (de)encapsulated within them is (IMHO) a very useful and secure mechanism for storing a private key.
Quoted 5 lines
If the issue is key management then you should be working with David Howell on creating an interface that sits on top of the keyring subsystem.
The Crypto API doesn't care about keys.
No, the problem concerns the use of the Linux keyring (specifically, trusted keys and other hardware-managed keys) with cryptographic algorithms.
From a security standpoint,
AF_ALGand keyctl's trusted keys are a perfect
match to manage secure encryption and decryption, so why not do the same with KPP operations (or other cryptographic operations)?Quoted 8 lines
Quoted 5 lines
I generally find the
AF_ALGAPI ugly to use, but I can see the use case for symmetric algorithms, where one needs to encrypt/decrypt a large stream in chunks. For asymmetric operations, like signing and KPP it doesn't make much sense to go through the socket API. In fact we already have an established interface through keyctl(2).I see, but if we consider shared secret support, for example, keyctl doesn't support ECDH, while
AF_ALGallows you to choose whether to use DH or ECDH.Quoted 9 lines
But this is exactly the point: unlike symmetric algorithms, where you can just use any blob with any algorithm, you can't use an RSA key for ECDH for example. That is, you cannot arbitrarily select an algorithm for any key and the algorithm is a property attached to the key itself. So if you "cast" a blob to an EC key, you would need to select the algorithm at cast time and the implementation should validate if the blob actually represents a valid EC key (with all the proper checks, like if the key is an a big in and is less than the order group etc).
I understand your point; however, I believe that allowing the
AF_ALGdeveloper to use a generic data blob (of the appropriate size, of course) as a key is more versatile and allows for easier implementation of future extensions.Quoted 2 lines
With
AF_ALGyou would need to do this validation for every crypto operation, which is not very efficient at the very least.
Quoted 7 lines
Quoted 2 lines
I think this might be acceptable if we consider the security we gain compared to using any existing user-space implementation!
I don't think the alternative approach I proposed compromises on security. That is it has the same security level (using a trusted key to do ECDH without exposing it to userspace). Unless I'm missing something?
Sorry, my bad. I wasn't referring to your suggestion but to any other user-space only KPP (or signature) implementation that doesn't use trusted keys (e.g., OpenSSL, etc.).
Quoted 45 lines
Quoted 45 lines
Quoted 7 lines
Quoted 2 lines
Furthermore,
AF_ALGallows us to choose which driver actually performs the encryption operation!This is indeed a limitation of the current keyctl interface, but again
- we probably should not select the algorithm here, but we should consider extending it so the user can specify a particular crypto driver/implementation.Furthermore, I think one solution isn't mutually exclusive. So, why not give the developer the freedom to choose which interface to use? ;)
Furthermore, there's nothing stopping us from strengthening the current
AF_ALGsupport so that it can also be used well with asymmetric keys.Quoted 17 lines
Quoted 17 lines
In my opinion, keyctl is excellent for managing key generation and access, but using
AF_ALGfor using them isn't entirely wrong even in the case of asymmetric keys and, in my opinion, is much more versatile.Quoted 7 lines
Now, in my opinion, the fundamental problem here is that we want to use trusted keys as asymmetric keys, where currently they are just binary blobs from a kernel perspective (so suitable only for symmetric use). So instead of the
AF_ALGextension we need a way to "cast" a trusted key to an asymmetric key and once it is "cast" (or type changed somehow) - we can use the established keyring interfaces both for signatures and KPP.IMHO the fact that trusted keys are binary blobs is perfect for use with
AF_ALG, where we can specify different algorithms to operate on. :)Ciao,
Quoted 7 lines
Quoted 7 lines
Rodolfo
--
GNU/Linux Solutions e-mail: [email protected]
Linux Device Driver [email protected]
Embedded Systems phone: +39 349 2432127
UNIX programming--
GNU/Linux Solutions e-mail: [email protected]
Linux Device Driver [email protected]
Embedded Systems phone: +39 349 2432127
UNIX programming
Signature · 4 lines
GNU/Linux Solutions e-mail: [email protected] Linux Device Driver [email protected] Embedded Systems phone: +39 349 2432127 UNIX programming
Quoted 3 lines · Rodolfo Giometti
I understand your point; however, I believe that allowing the
AF_ALGdeveloper to use a generic data blob (of the appropriate size, of course) as a key is more versatile and allows for easier implementation of future extensions.
The only thing something like this allow is huge foot guns.
The current trend in cryptography circles is the exact opposite, ie strong typing where keys are defined such that they can be used for a single purpose even when the general mechanisms allows different operations.
Ie even if an algorithm that allows both encryption and signing the key is specified to be used only for one or the other operation with metadata that accompanies they key itself at all times
so the cryptographic implementation can enforce the binding and fail the un-permitted operation.
In general using random blobs as asymmetric keys is just not possible, the size alone is no guarantee you have a valid key, so you would have to spend significant amount of CPU cycles to validate that the blob is a valid key for the given algorithm, rendering any HW acceleration effectively pointless by the time you cross all the layers, context switch back and forth from the kernel, validate the blobs and all.
Signature · 4 lines
Simo Sorce Distinguished Engineer RHEL Crypto Team Red Hat, Inc