crypto: Add generic Kerberos library with crypto as AEAD algorithms
Subsystems (11)
David Howells
maintainercover crypto: Add generic Kerberos library with crypto as AEAD algorithms
Hi Herbert, Chuck,
Here's my next go at a generic Kerberos crypto library in the kernel so that I can share code between rxrpc and sunrpc (and cifs?).
I derived some of the parts from the sunrpc gss library and added more advanced AES and Camellia crypto. The crypto bits are inside AEAD algorithms as Herbert required, but there's also a library of supplementary functions to aid in managing message layout.
You can use:
const struct krb5_enctype *crypto_krb5_find_enctype(u32 enctype);
to go and get an information table and this will also let you get at the name of the AEAD algorithm associated with that encoding type number.
Each AEAD algorithm is defined for a particular Kerberos 5 type by name (not by enctype number) and supports both encryption and checksumming (MIC) through the AEAD encrypt/decrypt request API.
Note that the plain text may be a different size to the cipher text and this causes the testmgr some issues as it thinks the extra data is an auth tag (but this doesn't want auth tags).
A kerberos AEAD object is configured through its setkey method and this takes a compound structure that indicates the mode of operation (encrypt or checksum), the usage type and either the transport key or the subkeys. The setkey method allocates and keys the constituent ciphers and hashes - but that's a detail hidden inside the object.
This library has its own self-testing framework that checks more things than is possible with the testmgr, including subkey derivation. It also checks things about the output of encrypt + decrypt that testmgr doesn't. That said, testmgr is also provisioned with some encryption and checksumming tests for Camilla and AES2.
Note that, for purposes of illustration, I've included some rxrpc patches that use this interface to implement the rxgk Rx security class. The branch also is based on net-next that carries some rxrpc patches that are a prerequisite for this, but the crypto patches don't need it.
---
The patches can be found here also:
http://git.kernel.org/cgit/linux/kernel/git/dhowells/linux-fs.git/log/?h=crypto-krb5
David
David Howells (8):
crypto/krb5: Add some constants out of sunrpc headers crypto/krb5: Provide Kerberos 5 crypto through AEAD API crypto/krb5: Test manager data
rxrpc: Add the security index for yfs-rxgk
rxrpc: Add YFS RxGK (GSSAPI) security class
rxrpc: rxgk: Provide infrastructure and key derivation
rxrpc: rxgk: Implement the yfs-rxgk security class (GSSAPI)
rxrpc: rxgk: Implement connection rekeying
crypto/Kconfig | 1 + crypto/Makefile | 2 + crypto/aead.c | 2 + crypto/krb5/Kconfig | 24 + crypto/krb5/Makefile | 17 + crypto/krb5/internal.h | 162 ++++ crypto/krb5/kdf.c | 334 ++++++++ crypto/krb5/krb5_aead.c | 462 +++++++++++ crypto/krb5/rfc3961_simplified.c | 815 +++++++++++++++++++ crypto/krb5/rfc6803_camellia.c | 190 +++++ crypto/krb5/rfc8009_aes2.c | 394 ++++++++++ crypto/krb5/selftest.c | 533 +++++++++++++ crypto/krb5/selftest_data.c | 370 +++++++++ crypto/testmgr.c | 24 + crypto/testmgr.h | 456 +++++++++++ fs/afs/misc.c | 13 + include/crypto/aead.h | 2 + include/crypto/krb5.h | 147 ++++ include/keys/rxrpc-type.h | 17 + include/trace/events/rxrpc.h | 36 + include/uapi/linux/rxrpc.h | 17 + net/rxrpc/Kconfig | 10 + net/rxrpc/Makefile | 5 +- net/rxrpc/ar-internal.h | 22 + net/rxrpc/conn_event.c | 2 +- net/rxrpc/conn_object.c | 1 + net/rxrpc/key.c | 183 +++++ net/rxrpc/output.c | 2 +- net/rxrpc/protocol.h | 20 + net/rxrpc/rxgk.c | 1244 ++++++++++++++++++++++++++++++ net/rxrpc/rxgk_app.c | 318 ++++++++ net/rxrpc/rxgk_common.h | 58 ++ net/rxrpc/rxgk_kdf.c | 260 +++++++ net/rxrpc/rxkad.c | 6 +- net/rxrpc/security.c | 3 + 35 files changed, 6147 insertions(+), 5 deletions(-) create mode 100644 crypto/krb5/Kconfig create mode 100644 crypto/krb5/Makefile create mode 100644 crypto/krb5/internal.h create mode 100644 crypto/krb5/kdf.c create mode 100644 crypto/krb5/krb5_aead.c create mode 100644 crypto/krb5/rfc3961_simplified.c create mode 100644 crypto/krb5/rfc6803_camellia.c create mode 100644 crypto/krb5/rfc8009_aes2.c create mode 100644 crypto/krb5/selftest.c create mode 100644 crypto/krb5/selftest_data.c create mode 100644 include/crypto/krb5.h create mode 100644 net/rxrpc/rxgk.c create mode 100644 net/rxrpc/rxgk_app.c create mode 100644 net/rxrpc/rxgk_common.h create mode 100644 net/rxrpc/rxgk_kdf.c
David Howells
maintainerRFC PATCH 1/8 crypto/krb5: Add some constants out of sunrpc headers
Add some constants from the sunrpc headers.
--- include/crypto/krb5.h | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 include/crypto/krb5.h
include/crypto/krb5.h new file +50 -0
@@ -0,0 +1,50 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* Kerberos 5 crypto +* +* Copyright (C) 2025 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +*/ + +#ifndef _CRYPTO_KRB5_H +#define _CRYPTO_KRB5_H + +/* per Kerberos v5 protocol spec crypto types from the wire. +* these get mapped to linux kernel crypto routines. +*/ +#define KRB5_ENCTYPE_NULL 0x0000 +#define KRB5_ENCTYPE_DES_CBC_CRC 0x0001/* DES cbc mode with CRC-32 */ +#define KRB5_ENCTYPE_DES_CBC_MD4 0x0002/* DES cbc mode with RSA-MD4 */ +#define KRB5_ENCTYPE_DES_CBC_MD5 0x0003/* DES cbc mode with RSA-MD5 */ +#define KRB5_ENCTYPE_DES_CBC_RAW 0x0004/* DES cbc mode raw */ +/* XXX deprecated? */ +#define KRB5_ENCTYPE_DES3_CBC_SHA 0x0005/* DES-3 cbc mode with NIST-SHA */ +#define KRB5_ENCTYPE_DES3_CBC_RAW 0x0006/* DES-3 cbc mode raw */ +#define KRB5_ENCTYPE_DES_HMAC_SHA1 0x0008 +#define KRB5_ENCTYPE_DES3_CBC_SHA1 0x0010 +#define KRB5_ENCTYPE_AES128_CTS_HMAC_SHA1_96 0x0011 +#define KRB5_ENCTYPE_AES256_CTS_HMAC_SHA1_96 0x0012 +#define KRB5_ENCTYPE_ARCFOUR_HMAC 0x0017 +#define KRB5_ENCTYPE_ARCFOUR_HMAC_EXP 0x0018 +#define KRB5_ENCTYPE_UNKNOWN 0x01ff + +#define KRB5_CKSUMTYPE_CRC32 0x0001 +#define KRB5_CKSUMTYPE_RSA_MD4 0x0002 +#define KRB5_CKSUMTYPE_RSA_MD4_DES 0x0003 +#define KRB5_CKSUMTYPE_DESCBC 0x0004 +#define KRB5_CKSUMTYPE_RSA_MD5 0x0007 +#define KRB5_CKSUMTYPE_RSA_MD5_DES 0x0008 +#define KRB5_CKSUMTYPE_NIST_SHA 0x0009 +#define KRB5_CKSUMTYPE_HMAC_SHA1_DES3 0x000c +#define KRB5_CKSUMTYPE_HMAC_SHA1_96_AES128 0x000f +#define KRB5_CKSUMTYPE_HMAC_SHA1_96_AES256 0x0010 +#define KRB5_CKSUMTYPE_HMAC_MD5_ARCFOUR -138/* Microsoft md5 hmac cksumtype */ + +/* +* Constants used for key derivation +*/ +/* from rfc3961 */ +#define KEY_USAGE_SEED_CHECKSUM (0x99) +#define KEY_USAGE_SEED_ENCRYPTION (0xAA) +#define KEY_USAGE_SEED_INTEGRITY (0x55) + +#endif /* _CRYPTO_KRB5_H */
David Howells
maintainerRFC PATCH 2/8 crypto/krb5: Provide Kerberos 5 crypto through AEAD API
In reply to David HowellsUse the AEAD crypto API to provide Kerberos 5 crypto, plus some supplementary library functions that lie outside of the AEAD API.
The crypto algorithms only perform the actual crypto operations; they do not do any laying out of the message and nor do they insert any metadata or padding. Everything is done by dead-reckoning as the AEAD API does not provide a useful way to pass the extra parameters required.
When setting the key on a crypto algorithm, setkey takes a composite structure consisting of an indication of the mode of transformation to be applied to the message (checksum only or full encryption); the usage type to be used in deriving the keys; an indicator indicating what key is being presented (K0 or Kc/Ke+Ki); and the material for those key(s). Based on this, the setkey code allocates and keys the appropriate ciphers and hashes.
When dispatching a request, both checksumming (MIC) and encryption use the encrypt and decrypt methods. A source message, prelaid out with confounders or other metadata inserted is provided in the source buffer. The cryptolen indicates the amount of source message data, not including the trailer after the data (which includes the integrity checksum) and not including any associated data.
Associated data is only used by checksumming encrypt/decrypt. The associated data is added to the checksum hash before the data in the message, but does not occupy any part of the output message.
Authentication tags are not used at all and should cause EINVAL if used (a later patch does that).
For the moment, the kerberos encryption algorithms use separate hash and cipher algorithms internally, but should really use dual hash+cipher and cipher+hash algorithms if possible to avoid doing these in series. Offload off this may be possible through something like the Intel QAT.
To help with managing the layout, a number of functions are also provided:
(1) crypto_krb5_find_enctype() - Find the definition of an encoding type by protocol number. This provides the name of the algorithm along with a host of parameter values, such as key sizes, block size, etc..
Note that the enctype wraps the aead_alg struct so that the crypto routines can use container_of() to find it.
(2) crypto_krb5_how_much_buffer() - Determine how much bufferage is needed for a certain amount of data.
(3) crypto_krb5_how_much_data() - Determine how much data will fit into a certain amount of buffer.
(4) crypto_krb5_where_is_the_data() - Determine where in a decrypted message the data is and how much data there is. This may, in future, need to access the contents of the decrypted message to access metadata.
(5) crypto_krb5_confound_buffer() - Insert the confounder in the buffer at the appropriate place - or generate one randomly. This may, in future, be combined with something that inserts padding and metadata.
And to help with key derivation:
(6) crypto_krb5_calc_PRFplus() - Calculate the PRF+ function.
This patch includes the following features:
(1) The PRF+ function from RFC4402 used in deriving keys.
(2) The RFC3961 simplified crypto profile for Kerberos 5 rfc3961 with the pseudo-random function, PRF(), from section 5.3 and the key derivation function, DK() from section 5.1.
(3) Message encryption and decryption according to RFC3961 sec 5.3.
(4) Message checksumming and verification according to RFC3961 sec 5.4.
(5) The aes128-cts-hmac-sha1-96 and aes256-cts-hmac-sha1-96 enctypes from RFC3962, using the RFC3961 kerberos 5 simplified crypto scheme.
(6) The aes128-cts-hmac-sha256-128 and aes256-cts-hmac-sha384-192 enctypes from RFC8009 (which override the rfc3961 kerberos 5 simplified crypto scheme).
(7) The camellia128-cts-cmac and camellia256-cts-cmac enctypes from RFC6803.
Note that the test vectors in rfc6803 for encryption are incomplete, lacking the key usage number needed to derive Ke and Ki, and there are errata for this:
https://www.rfc-editor.org/errata_search.php?rfc=6803
(8) Functions to find out about the layout of the crypto section. One calculates, for a given size of data, how big a buffer will be required to hold it and where the data will be within it. The other calculates, for an amount of buffer, what's the maximum size of data that will fit therein, and where it will start.
(9) Self-testing infrastructure to test the pseudo-random function, key derivation, encryption and checksumming.
--- crypto/Kconfig | 1 + crypto/Makefile | 2 + crypto/krb5/Kconfig | 24 + crypto/krb5/Makefile | 17 + crypto/krb5/internal.h | 162 ++++++ crypto/krb5/kdf.c | 334 +++++++++++++ crypto/krb5/krb5_aead.c | 456 +++++++++++++++++ crypto/krb5/rfc3961_simplified.c | 815 +++++++++++++++++++++++++++++++ crypto/krb5/rfc6803_camellia.c | 190 +++++++ crypto/krb5/rfc8009_aes2.c | 394 +++++++++++++++ crypto/krb5/selftest.c | 533 ++++++++++++++++++++ crypto/krb5/selftest_data.c | 370 ++++++++++++++ include/crypto/krb5.h | 101 +++- 13 files changed, 3397 insertions(+), 2 deletions(-) create mode 100644 crypto/krb5/Kconfig create mode 100644 crypto/krb5/Makefile create mode 100644 crypto/krb5/internal.h create mode 100644 crypto/krb5/kdf.c create mode 100644 crypto/krb5/krb5_aead.c create mode 100644 crypto/krb5/rfc3961_simplified.c create mode 100644 crypto/krb5/rfc6803_camellia.c create mode 100644 crypto/krb5/rfc8009_aes2.c create mode 100644 crypto/krb5/selftest.c create mode 100644 crypto/krb5/selftest_data.c
crypto/Kconfig +1 -0
@@ -1477,5 +1477,6 @@ endif source "drivers/crypto/Kconfig" source "crypto/asymmetric_keys/Kconfig" source "certs/Kconfig" +source "crypto/krb5/Kconfig" endif # if CRYPTO
crypto/Makefile +2 -0
@@ -213,3 +213,5 @@ obj-$(CONFIG_CRYPTO_SIMD) += crypto_simd.o # Key derivation function # obj-$(CONFIG_CRYPTO_KDF800108_CTR) += kdf_sp800108.o + +obj-$(CONFIG_CRYPTO_KRB5) += krb5/
crypto/krb5/Kconfig new file +24 -0
@@ -0,0 +1,24 @@ +config CRYPTO_KRB5 + tristate "Kerberos 5 crypto" + select CRYPTO_MANAGER + select CRYPTO_SKCIPHER + select CRYPTO_HASH_INFO + select CRYPTO_HMAC + select CRYPTO_CMAC + select CRYPTO_SHA1 + select CRYPTO_SHA256 + select CRYPTO_SHA512 + select CRYPTO_CBC + select CRYPTO_CTS + select CRYPTO_AES + select CRYPTO_CAMELLIA + help + Provide a library for provision of Kerberos-5-based crypto. This is + intended for network filesystems to use. + +config CRYPTO_KRB5_SELFTESTS + bool "Kerberos 5 crypto selftests" + depends on CRYPTO_KRB5 + help + Turn on some self-testing for the kerberos 5 crypto functions. These + will be performed on module load or boot, if compiled in.
crypto/krb5/Makefile new file +17 -0
@@ -0,0 +1,17 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for asymmetric cryptographic keys +# + +krb5-y += \ + kdf.o \ + krb5_aead.o \ + rfc3961_simplified.o \ + rfc6803_camellia.o \ + rfc8009_aes2.o + +krb5-$(CONFIG_CRYPTO_KRB5_SELFTESTS) += \ + selftest.o \ + selftest_data.o + +obj-$(CONFIG_CRYPTO_KRB5) += krb5.o
crypto/krb5/internal.h new file +162 -0
162 lines not on this page · raw message
crypto/krb5/kdf.c new file +334 -0
334 lines not on this page · raw message
crypto/krb5/krb5_aead.c new file +456 -0
456 lines not on this page · raw message
crypto/krb5/rfc3961_simplified.c new file +815 -0
815 lines not on this page · raw message
crypto/krb5/rfc6803_camellia.c new file +190 -0
190 lines not on this page · raw message
crypto/krb5/rfc8009_aes2.c new file +394 -0
394 lines not on this page · raw message
crypto/krb5/selftest.c new file +533 -0
533 lines not on this page · raw message
crypto/krb5/selftest_data.c new file +370 -0
64 lines not on this page · raw message
include/crypto/krb5.h +99 -2
101 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Part of the diff is not shown here. View the raw message.
David Howells
maintainerRFC PATCH 3/8 crypto/krb5: Test manager data
In reply to David HowellsAdd Kerberos crypto tests to the test manager database. This covers:
camellia128-cts-cmac samples from RFC6803 camellia256-cts-cmac samples from RFC6803 aes128-cts-hmac-sha256-128 samples from RFC8009 aes256-cts-hmac-sha384-192 samples from RFC8009
but not:
aes128-cts-hmac-sha1-96 aes256-cts-hmac-sha1-96
as the test samples in RFC3962 don't seem to be suitable.
Note that the test manager makes some assumptions about AEAD algorithm type that would otherwise prevent testing the kerberos algorithms. The problem is that the test manager assumes that if there's a difference between the length of the plain text and the cipher text supplied in the test vector, then the extra data is the authentication tag - but these aren't applicable here.
This is worked around by adding a flag in the AEAD algorithm definition that causes EINVAL be returned unconditionally if anyone tries to set the auth tag length.
--- crypto/aead.c | 2 + crypto/krb5/krb5_aead.c | 8 +- crypto/testmgr.c | 24 +++ crypto/testmgr.h | 456 ++++++++++++++++++++++++++++++++++++++++ include/crypto/aead.h | 2 + 5 files changed, 491 insertions(+), 1 deletion(-)
crypto/aead.c +2 -0
@@ -65,6 +65,8 @@ int crypto_aead_setauthsize(struct crypto_aead *tfm, unsigned int authsize) {int err; +if (crypto_aead_alg (tfm)->no_authtags) +return -EINVAL ;if ((!authsize &&crypto_aead_maxauthsize (tfm)) || authsize >crypto_aead_maxauthsize (tfm))return -EINVAL ;
crypto/krb5/krb5_aead.c +7 -1
@@ -201,6 +201,7 @@ static struct krb5_enctype krb5_enctypes[] = { .aead.ivsize = 0, .aead.maxauthsize = 0, .aead.chunksize = 16, + .aead.no_authtags = true, .aead.base.cra_flags = CRYPTO_ALG_ALLOCATES_MEMORY, .aead.base.cra_blocksize = 1,
@@ -238,6 +239,7 @@ static struct krb5_enctype krb5_enctypes[] = { .aead.ivsize = 0, .aead.maxauthsize = 0, .aead.chunksize = 16, + .aead.no_authtags = true, .aead.base.cra_flags = CRYPTO_ALG_ALLOCATES_MEMORY, .aead.base.cra_blocksize = 1,
@@ -275,6 +277,7 @@ static struct krb5_enctype krb5_enctypes[] = { .aead.ivsize = 0, .aead.maxauthsize = 0, .aead.chunksize = 16, + .aead.no_authtags = true, .aead.base.cra_flags = CRYPTO_ALG_ALLOCATES_MEMORY, .aead.base.cra_blocksize = 1,
@@ -312,6 +315,7 @@ static struct krb5_enctype krb5_enctypes[] = { .aead.ivsize = 0, .aead.maxauthsize = 0, .aead.chunksize = 16, + .aead.no_authtags = true, .aead.base.cra_flags = CRYPTO_ALG_ALLOCATES_MEMORY, .aead.base.cra_blocksize = 1,
@@ -349,6 +353,7 @@ static struct krb5_enctype krb5_enctypes[] = { .aead.ivsize = 0, .aead.maxauthsize = 0, .aead.chunksize = 16, + .aead.no_authtags = true, .aead.base.cra_flags = CRYPTO_ALG_ALLOCATES_MEMORY, .aead.base.cra_blocksize = 1,
@@ -356,7 +361,7 @@ static struct krb5_enctype krb5_enctypes[] = { .aead.base.cra_alignmask = 0, .aead.base.cra_priority = 100, .aead.base.cra_name = "krb5-aes128-cts-hmac-sha256-128", - .aead.base.cra_driver_name = "krb5-aes128-cts-hmac-sha256-128generic", + .aead.base.cra_driver_name = "krb5-aes128-cts-hmac-sha256-128-generic", .aead.base.cra_module = THIS_MODULE, }, { .etype = KRB5_ENCTYPE_AES256_CTS_HMAC_SHA384_192,
@@ -386,6 +391,7 @@ static struct krb5_enctype krb5_enctypes[] = { .aead.ivsize = 0, .aead.maxauthsize = 0, .aead.chunksize = 16, + .aead.no_authtags = true, .aead.base.cra_flags = CRYPTO_ALG_ALLOCATES_MEMORY, .aead.base.cra_blocksize = 1,
crypto/testmgr.c +24 -0
@@ -5408,6 +5408,30 @@ static const struct alg_test_desc alg_test_descs[] = { .alg = "jitterentropy_rng", .fips_allowed = 1, .test = alg_test_null, + }, { + .alg = "krb5-aes128-cts-hmac-sha256-128", + .test = alg_test_aead, + .suite = { + .aead = __VECS(krb5_test_aes128_cts_hmac_sha256_128) + } + }, { + .alg = "krb5-aes256-cts-hmac-sha384-192", + .test = alg_test_aead, + .suite = { + .aead = __VECS(krb5_test_aes256_cts_hmac_sha384_192) + } + }, { + .alg = "krb5-camellia128-cts-cmac", + .test = alg_test_aead, + .suite = { + .aead = __VECS(krb5_test_camellia128_cts_cmac) + } + }, { + .alg = "krb5-camellia256-cts-cmac", + .test = alg_test_aead, + .suite = { + .aead = __VECS(krb5_test_camellia256_cts_cmac) + } }, { .alg = "kw(aes)", .test = alg_test_skcipher,
crypto/testmgr.h +456 -0
460 lines not on this page · raw message
include/crypto/aead.h +2 -0
@@ -121,6 +121,7 @@ struct aead_request {* @decrypt: see struct skcipher_alg * @ivsize: see struct skcipher_alg * @chunksize: see struct skcipher_alg +* @no_authtags: This algo doesn't use authentication tags. * @init: Initialize the cryptographic transformation object. This function * is used to initialize the cryptographic transformation object. * This function is called only once at the instantiation time, right
@@ -148,6 +149,7 @@ struct aead_alg {unsigned int ivsize;unsigned int maxauthsize;unsigned int chunksize; +bool no_authtags;struct crypto_alg base; };
David Howells
maintainerRFC PATCH 4/8 rxrpc: Add the security index for yfs-rxgk
In reply to David HowellsAdd the security index and abort codes for the YFS variant of rxgk.
--- fs/afs/misc.c | 13 +++++++++++++ include/uapi/linux/rxrpc.h | 17 +++++++++++++++++ 2 files changed, 30 insertions(+)
fs/afs/misc.c +13 -0
@@ -103,6 +103,19 @@ int afs_abort_to_error(u32 abort_code)case RXKADDATALEN :return -EKEYREJECTED ;case RXKADILLEGALLEVEL :return -EKEYREJECTED ; +case RXGK_INCONSISTENCY :return -EPROTO ; +case RXGK_PACKETSHORT :return -EPROTO ; +case RXGK_BADCHALLENGE :return -EPROTO ; +case RXGK_BADETYPE :return -ENOPKG ; +case RXGK_BADLEVEL :return -EKEYREJECTED ; +case RXGK_BADKEYNO :return -EKEYREJECTED ; +case RXGK_EXPIRED :return -EKEYEXPIRED ; +case RXGK_NOTAUTH :return -EKEYREJECTED ; +case RXGK_BAD_TOKEN :return -EKEYREJECTED ; +case RXGK_SEALED_INCON :return -EKEYREJECTED ; +case RXGK_DATA_LEN :return -EPROTO ; +case RXGK_BAD_QOP :return -EKEYREJECTED ; +case RXGEN_OPCODE :return -ENOTSUPP ;default :return -EREMOTEIO ;
include/uapi/linux/rxrpc.h +17 -0
@@ -73,6 +73,7 @@ enum rxrpc_cmsg_type {#define RXRPC_SECURITY_RXKAD 2/* kaserver or kerberos 4 */ #define RXRPC_SECURITY_RXGK 4/* gssapi-based */ #define RXRPC_SECURITY_RXK5 5/* kerberos 5 */ +#define RXRPC_SECURITY_YFS_RXGK 6/* YFS gssapi-based */ /* * RxRPC-level abort codes
@@ -118,4 +119,20 @@ enum rxrpc_cmsg_type {#define RXKADDATALEN 19270411/* user data too long */ #define RXKADILLEGALLEVEL 19270412/* caller not authorised to use encrypted conns */ +/* +* RxGK GSSAPI security abort codes. +*/ +#define RXGK_INCONSISTENCY 1233242880/* Security module structure inconsistent */ +#define RXGK_PACKETSHORT 1233242881/* Packet too short for security challenge */ +#define RXGK_BADCHALLENGE 1233242882/* Invalid security challenge */ +#define RXGK_BADETYPE 1233242883/* Invalid or impermissible encryption type */ +#define RXGK_BADLEVEL 1233242884/* Invalid or impermissible security level */ +#define RXGK_BADKEYNO 1233242885/* Key version number not found */ +#define RXGK_EXPIRED 1233242886/* Token has expired */ +#define RXGK_NOTAUTH 1233242887/* Caller not authorized */ +#define RXGK_BAD_TOKEN 1233242888/* Security object was passed a bad token */ +#define RXGK_SEALED_INCON 1233242889/* Sealed data inconsistent */ +#define RXGK_DATA_LEN 1233242890/* User data too long */ +#define RXGK_BAD_QOP 1233242891/* Inadequate quality of protection available */ +#endif /* _UAPI_LINUX_RXRPC_H */
David Howells
maintainerRFC PATCH 5/8 rxrpc: Add YFS RxGK (GSSAPI) security class
In reply to David HowellsAdd support for the YFS-variant RxGK security class to support GSSAPI-derived authentication. This also allows the use of better crypto over the rxkad security class.
The key payload is XDR encoded of the form:
typedef int64_t opr_time;
const AFSTOKEN_RK_TIX_MAX = 12000; /* Matches entry in rxkad.h */
struct token_rxkad {
afs_int32 viceid;
afs_int32 kvno;
afs_int64 key;
afs_int32 begintime;
afs_int32 endtime;
afs_int32 primary_flag;
opaque ticket<AFSTOKEN_RK_TIX_MAX>;
};
struct token_rxgk {
opr_time begintime;
opr_time endtime;
afs_int64 level;
afs_int64 lifetime;
afs_int64 bytelife;
afs_int64 enctype;
opaque key<>;
opaque ticket<>;
};
const AFSTOKEN_UNION_NOAUTH = 0;
const AFSTOKEN_UNION_KAD = 2;
const AFSTOKEN_UNION_YFSGK = 6;
union ktc_tokenUnion switch (afs_int32 type) {
case AFSTOKEN_UNION_KAD:
token_rxkad kad;
case AFSTOKEN_UNION_YFSGK:
token_rxgk gk;
};
const AFSTOKEN_LENGTH_MAX = 16384;
typedef opaque token_opaque<AFSTOKEN_LENGTH_MAX>;
const AFSTOKEN_MAX = 8;
const AFSTOKEN_CELL_MAX = 64;
struct ktc_setTokenData {
afs_int32 flags;
string cell<AFSTOKEN_CELL_MAX>;
token_opaque tokens<AFSTOKEN_MAX>;
};The parser for the basic token struct is already present, as is the rxkad token type. This adds a parser for the rxgk token type.
--- include/keys/rxrpc-type.h | 17 ++++ net/rxrpc/key.c | 183 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 200 insertions(+)
include/keys/rxrpc-type.h +17 -0
@@ -9,6 +9,7 @@#define _KEYS_RXRPC_TYPE_H#include <linux/key.h> +#include <crypto/krb5.h> /* * key type for AF_RXRPC keys
@@ -31,6 +32,21 @@ struct rxkad_key {u8 ticket[];/* the encrypted ticket */ }; +/* +* RxRPC key for YFS-RxGK (type-6 security) +*/ +struct rxgk_key { +s64 begintime;/* Time at which the ticket starts */ +s64 endtime;/* Time at which the ticket ends */ +u64 lifetime;/* Maximum lifespan of a connection (seconds) */ +u64 bytelife;/* Maximum number of bytes on a connection */ +unsigned int enctype;/* Encoding type */ +s8 level;/* Negotiated security RXRPC_SECURITY_PLAIN/AUTH/ENCRYPT */ +struct krb5_buffer key;/* Master key, K0 */ +struct krb5_buffer ticket;/* Ticket to be passed to server */ +u8 _key[];/* Key storage */ +}; +/* * list of tokens attached to an rxrpc key */
@@ -40,6 +56,7 @@ struct rxrpc_key_token {struct rxrpc_key_token *next;/* the next token in the list */ union {struct rxkad_key *kad; +struct rxgk_key *rxgk; }; };
net/rxrpc/key.c +183 -0
219 lines not on this page · raw message
David Howells
maintainerRFC PATCH 6/8 rxrpc: rxgk: Provide infrastructure and key derivation
In reply to David HowellsProvide some infrastructure for implementing the RxGK transport security class:
(1) A definition of an encoding type, including:
- Relevant crypto-layer names
- Lengths of the crypto keys and checksums involved
- Crypto functions specific to the encoding type
- Crypto scheme used for that type
(2) A definition of a crypto scheme, including:
- Underlying crypto handlers
- The pseudo-random function, PRF, used in base key derivation
- Functions for deriving usage keys Kc, Ke and Ki
- Functions for en/decrypting parts of an sk_buff
(3) A key context, with the usage keys required for a derivative of a transport key for a specific key number. This includes keys for securing packets for transmission, extracting received packets and dealing with response packets.
(3) A function to look up an encoding type by number.
(4) A function to set up a key context and derive the keys.
(5) A function to set up the keys required to extract the ticket obtained from the GSS negotiation in the server.
(6) Miscellaneous functions for context handling.
The keys and key derivation functions are described in:
tools.ietf.org/html/draft-wilkinson-afs3-rxgk-11
--- net/rxrpc/Kconfig | 10 ++ net/rxrpc/Makefile | 3 +- net/rxrpc/ar-internal.h | 3 + net/rxrpc/rxgk_common.h | 44 +++++++ net/rxrpc/rxgk_kdf.c | 260 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 319 insertions(+), 1 deletion(-) create mode 100644 net/rxrpc/rxgk_common.h create mode 100644 net/rxrpc/rxgk_kdf.c
net/rxrpc/Kconfig +10 -0
@@ -67,6 +67,16 @@ config RXKAD See Documentation/networking/rxrpc.rst. +config RXGK + bool "RxRPC GSSAPI security" + depends on AF_RXRPC + depends on CRYPTO_KRB5 + help + Provide the GSSAPI-based RxGK security class for AFS. Keys are added + with add_key(). + + See Documentation/networking/rxrpc.rst. + config RXPERF tristate "RxRPC test service" help
net/rxrpc/Makefile +2 -1
@@ -39,6 +39,7 @@ rxrpc-y := \ rxrpc-$(CONFIG_PROC_FS) += proc.o rxrpc-$(CONFIG_RXKAD) += rxkad.o rxrpc-$(CONFIG_SYSCTL) += sysctl.o - +rxrpc-$(CONFIG_RXGK) += \ + rxgk_kdf.o obj-$(CONFIG_RXPERF) += rxperf.o
net/rxrpc/ar-internal.h +3 -0
@@ -526,6 +526,9 @@ struct rxrpc_connection {struct rxrpc_crypt csum_iv;/* packet checksum base */ u32 nonce;/* response re-use preventer */ } rxkad; +struct { +u64 start_time;/* The start time for TK derivation */ + } rxgk; };unsigned long flags;unsigned long events;
net/rxrpc/rxgk_common.h new file +44 -0
44 lines not on this page · raw message
net/rxrpc/rxgk_kdf.c new file +260 -0
260 lines not on this page · raw message
David Howells
maintainerRFC PATCH 7/8 rxrpc: rxgk: Implement the yfs-rxgk security class (GSSAPI)
In reply to David HowellsImplement the basic parts of the yfs-rxgk security class (security index 6) to support GSSAPI-negotiated security.
--- include/trace/events/rxrpc.h | 36 ++ net/rxrpc/Makefile | 2 + net/rxrpc/ar-internal.h | 16 + net/rxrpc/conn_event.c | 2 +- net/rxrpc/output.c | 2 +- net/rxrpc/protocol.h | 20 + net/rxrpc/rxgk.c | 1100 ++++++++++++++++++++++++++++++++++ net/rxrpc/rxgk_app.c | 318 ++++++++++ net/rxrpc/rxgk_common.h | 14 + net/rxrpc/rxkad.c | 6 +- net/rxrpc/security.c | 3 + 11 files changed, 1515 insertions(+), 4 deletions(-) create mode 100644 net/rxrpc/rxgk.c create mode 100644 net/rxrpc/rxgk_app.c
include/trace/events/rxrpc.h +36 -0
@@ -68,6 +68,38 @@ EM(rxkad_abort_resp_tkt_sname, "rxkad-resp-tk-sname") \ EM(rxkad_abort_resp_unknown_tkt, "rxkad-resp-unknown-tkt") \EM (rxkad_abort_resp_version,"rxkad-resp-version" ) \ + /* RxGK security errors */ \ + EM(rxgk_abort_1_verify_mic_eproto, "rxgk1-vfy-mic-eproto") \ + EM(rxgk_abort_2_decrypt_eproto, "rxgk2-dec-eproto") \ + EM(rxgk_abort_2_short_data, "rxgk2-short-data") \ + EM(rxgk_abort_2_short_encdata, "rxgk2-short-encdata") \ + EM(rxgk_abort_2_short_header, "rxgk2-short-hdr") \ + EM(rxgk_abort_bad_key_number, "rxgk-bad-key-num") \ + EM(rxgk_abort_chall_key_expired, "rxgk-chall-key-exp") \ + EM(rxgk_abort_chall_no_key, "rxgk-chall-nokey") \ + EM(rxgk_abort_chall_short, "rxgk-chall-short") \ + EM(rxgk_abort_resp_auth_dec, "rxgk-resp-auth-dec") \ + EM(rxgk_abort_resp_bad_callid, "rxgk-resp-bad-callid") \ + EM(rxgk_abort_resp_bad_nonce, "rxgk-resp-bad-nonce") \ + EM(rxgk_abort_resp_bad_param, "rxgk-resp-bad-param") \ + EM(rxgk_abort_resp_call_ctr, "rxgk-resp-call-ctr") \ + EM(rxgk_abort_resp_call_state, "rxgk-resp-call-state") \ + EM(rxgk_abort_resp_internal_error, "rxgk-resp-int-error") \ + EM(rxgk_abort_resp_nopkg, "rxgk-resp-nopkg") \ + EM(rxgk_abort_resp_short_applen, "rxgk-resp-short-applen") \ + EM(rxgk_abort_resp_short_auth, "rxgk-resp-short-auth") \ + EM(rxgk_abort_resp_short_call_list, "rxgk-resp-short-callls") \ + EM(rxgk_abort_resp_short_packet, "rxgk-resp-short-packet") \ + EM(rxgk_abort_resp_short_yfs_klen, "rxgk-resp-short-yfs-klen") \ + EM(rxgk_abort_resp_short_yfs_key, "rxgk-resp-short-yfs-key") \ + EM(rxgk_abort_resp_short_yfs_tkt, "rxgk-resp-short-yfs-tkt") \ + EM(rxgk_abort_resp_tok_dec, "rxgk-resp-tok-dec") \ + EM(rxgk_abort_resp_tok_internal_error, "rxgk-resp-tok-int-err") \ + EM(rxgk_abort_resp_tok_keyerr, "rxgk-resp-tok-keyerr") \ + EM(rxgk_abort_resp_tok_nokey, "rxgk-resp-tok-nokey") \ + EM(rxgk_abort_resp_tok_nopkg, "rxgk-resp-tok-nopkg") \ + EM(rxgk_abort_resp_tok_short, "rxgk-resp-tok-short") \ +EM (rxgk_abort_resp_xdr_align,"rxgk-resp-xdr-align" ) \ /* rxrpc errors */ \ EM(rxrpc_abort_call_improper_term, "call-improper-term") \EM (rxrpc_abort_call_reset,"call-reset" ) \
@@ -454,6 +486,8 @@ EM(rxrpc_tx_point_call_final_resend, "CallFinalResend") \ EM(rxrpc_tx_point_conn_abort, "ConnAbort") \ EM(rxrpc_tx_point_reject, "Reject") \ + EM(rxrpc_tx_point_rxgk_challenge, "RxGKChall") \ + EM(rxrpc_tx_point_rxgk_response, "RxGKResp") \ EM(rxrpc_tx_point_rxkad_challenge, "RxkadChall") \ EM(rxrpc_tx_point_rxkad_response, "RxkadResp") \EM (rxrpc_tx_point_version_keepalive,"VerKeepalive" ) \
@@ -472,6 +506,7 @@#define rxrpc_txbuf_traces \ EM(rxrpc_txbuf_alloc_data, "ALLOC DATA ") \ + EM(rxrpc_txbuf_alloc_response, "ALLOC RESP ") \ EM(rxrpc_txbuf_free, "FREE ") \ EM(rxrpc_txbuf_get_buffer, "GET BUFFER ") \ EM(rxrpc_txbuf_get_trans, "GET TRANS ") \
@@ -479,6 +514,7 @@ EM(rxrpc_txbuf_put_cleaned, "PUT CLEANED") \ EM(rxrpc_txbuf_put_nomem, "PUT NOMEM ") \ EM(rxrpc_txbuf_put_rotated, "PUT ROTATED") \ + EM(rxrpc_txbuf_put_response_tx, "PUT RESP TX") \ EM(rxrpc_txbuf_put_send_aborted, "PUT SEND-X ") \ EM(rxrpc_txbuf_put_trans, "PUT TRANS ") \EM (rxrpc_txbuf_see_lost,"SEE LOST " ) \
net/rxrpc/Makefile +2 -0
@@ -40,6 +40,8 @@ rxrpc-$(CONFIG_PROC_FS) += proc.o rxrpc-$(CONFIG_RXKAD) += rxkad.o rxrpc-$(CONFIG_SYSCTL) += sysctl.o rxrpc-$(CONFIG_RXGK) += \ + rxgk.o \ + rxgk_app.o \ rxgk_kdf.o obj-$(CONFIG_RXPERF) += rxperf.o
net/rxrpc/ar-internal.h +16 -0
@@ -31,6 +31,7 @@ struct key_preparsed_payload;struct rxrpc_connection ;struct rxrpc_txbuf ;struct rxrpc_txqueue ; +struct rxgk_context ;/* * Mark applied to socket buffers in skb->mark. skb->priority is used
@@ -280,6 +281,11 @@ struct rxrpc_security {/* clear connection security */ void (*clear)(struct rxrpc_connection *); + +/* Default ticket -> key decoder */ +int (*default_decode_ticket)(struct rxrpc_connection *conn,struct sk_buff *skb, +unsigned int ticket_offset,unsigned int ticket_len, +struct key **_key); };/*
@@ -527,7 +533,9 @@ struct rxrpc_connection {u32 nonce;/* response re-use preventer */ } rxkad;struct { +struct rxgk_context *keys[1 ];u64 start_time;/* The start time for TK derivation */ +u8 nonce[20 ];/* Response re-use preventer */ } rxgk; };unsigned long flags;
@@ -870,6 +878,8 @@ struct rxrpc_txbuf {unsigned short len;/* Amount of data in buffer */ unsigned short space;/* Remaining data space */ unsigned short offset;/* Offset of fill point */ +unsigned short crypto_header;/* Size of crypto header */ +unsigned short sec_header;/* Size of security header */ unsigned short pkt_len;/* Size of packet content */ unsigned short alloc_size;/* Amount of bufferage allocated */ unsigned int flags;
@@ -1295,6 +1305,7 @@ static inline struct rxrpc_net *rxrpc_net(struct net *net)/* * output.c */ +ssize_t do_udp_sendmsg (struct socket *socket,struct msghdr *msg,size_t len);void rxrpc_send_ACK (struct rxrpc_call *call,u8 ack_reason,rxrpc_serial_t serial,enum rxrpc_propose_ack_trace why);void rxrpc_send_probe_for_pmtud (struct rxrpc_call *call);
@@ -1366,6 +1377,11 @@ void rxrpc_call_add_rtt(struct rxrpc_call *call, enum rxrpc_rtt_rx_trace why,ktime_t rxrpc_get_rto_backoff (struct rxrpc_call *call,bool retrans);void rxrpc_call_init_rtt (struct rxrpc_call *call); +/* +* rxgk.c +*/ +extern const struct rxrpc_security rxgk_yfs; +/* * rxkad.c */
net/rxrpc/conn_event.c +1 -1
@@ -57,7 +57,7 @@ int rxrpc_abort_conn(struct rxrpc_connection *conn, struct sk_buff *skb, sp->hdr.seq, abort_code, err);rxrpc_poke_conn (conn, rxrpc_conn_get_poke_abort); } -return -EPROTO ; +return err; }/*
net/rxrpc/output.c +1 -1
@@ -18,7 +18,7 @@extern int udpv6_sendmsg (struct sock *sk,struct msghdr *msg,size_t len); -static ssize_t do_udp_sendmsg (struct socket *socket,struct msghdr *msg,size_t len) +ssize_t do_udp_sendmsg (struct socket *socket,struct msghdr *msg,size_t len) {struct sockaddr *sa = msg->msg_name;struct sock *sk = socket->sk;
net/rxrpc/protocol.h +20 -0
@@ -181,4 +181,24 @@ struct rxkad_response { __be32 ticket_len; /* Kerberos ticket length */ } __packed; +/* +* GSSAPI security type-4 and type-6 data header. +*/ +struct rxgk_header { +__be32 epoch; +__be32 cid; +__be32 call_number; +__be32 seq; +__be32 sec_index; +__be32 data_len; +} __packed; + +/* +* GSSAPI security type-4 and type-6 response packet header. +*/ +struct rxgk_response { +__be64 start_time; +__be32 token_len; +} __packed; +#endif /* _LINUX_RXRPC_PACKET_H */
net/rxrpc/rxgk.c new file +1100 -0
1,100 lines not on this page · raw message
net/rxrpc/rxgk_app.c new file +318 -0
318 lines not on this page · raw message
net/rxrpc/rxgk_common.h +14 -0
@@ -31,6 +31,20 @@ struct rxgk_context {struct crypto_aead *resp_crypto;/* Response key */ }; +#define xdr_round_up (x) (round_up((x), sizeof(__be32))) + +/* +* rxgk_app.c +*/ +int rxgk_yfs_decode_ticket (struct rxrpc_connection *conn,struct sk_buff *skb, +unsigned int ticket_offset,unsigned int ticket_len, +struct key **_key); +int rxgk_decrypt_skb (struct crypto_aead *token_enc,struct sk_buff *skb, +size_t *_offset,size_t *_len); +int rxgk_extract_token (struct rxrpc_connection *conn,struct sk_buff *skb, +unsigned int token_offset,unsigned int token_len, +struct key **_key); +/* * rxgk_kdf.c */
net/rxrpc/rxkad.c +4 -2
@@ -177,8 +177,10 @@ static struct rxrpc_txbuf *rxkad_alloc_txbuf(struct rxrpc_call *call, size_t remif (!txb)return NULL ; - txb->offset += shdr; - txb->space = part; + txb->crypto_header =0 ; + txb->sec_header = shdr; + txb->offset += shdr; + txb->space = part;return txb; }
net/rxrpc/security.c +3 -0
@@ -20,6 +20,9 @@ static const struct rxrpc_security *rxrpc_security_types[] = { #ifdef CONFIG_RXKAD [RXRPC_SECURITY_RXKAD ] = &rxkad, #endif +#ifdef CONFIG_RXGK + [RXRPC_SECURITY_YFS_RXGK] = &rxgk_yfs, +#endif };int __init rxrpc_init_security (void )
David Howells
maintainerRFC PATCH 8/8 rxrpc: rxgk: Implement connection rekeying
In reply to David HowellsImplement rekeying of connections with the RxGK security class. This involves regenerating the keys with a different key number as part of the input data after a certain amount of time or a certain amount of bytes encrypted. Rekeying may be triggered by either end.
The LSW of the key number is inserted into the security-specific field in the RX header, and we try and expand it to 32-bits to make it last longer.
--- net/rxrpc/ar-internal.h | 5 +- net/rxrpc/conn_object.c | 1 + net/rxrpc/rxgk.c | 156 ++++++++++++++++++++++++++++++++++++++-- 3 files changed, 155 insertions(+), 7 deletions(-)
net/rxrpc/ar-internal.h +4 -1
@@ -533,11 +533,14 @@ struct rxrpc_connection {u32 nonce;/* response re-use preventer */ } rxkad;struct { -struct rxgk_context *keys[1 ]; +struct rxgk_context *keys[4 ];/* (Re-)keying buffer */ u64 start_time;/* The start time for TK derivation */ u8 nonce[20 ];/* Response re-use preventer */ +u32 key_number;/* Current key number */ } rxgk; }; +rwlock_t security_use_lock;/* Security use/modification lock */ +unsigned long flags;unsigned long events;unsigned long idle_timestamp;/* Time at which last became idle */
net/rxrpc/conn_object.c +1 -0
@@ -72,6 +72,7 @@ struct rxrpc_connection *rxrpc_alloc_connection(struct rxrpc_net *rxnet,skb_queue_head_init (&conn->rx_queue); conn->rxnet = rxnet; conn->security = &rxrpc_no_security; +rwlock_init (&conn->security_use_lock);spin_lock_init (&conn->state_lock); conn->debug_id =atomic_inc_return (&rxrpc_debug_id); conn->idle_timestamp = jiffies;
net/rxrpc/rxgk.c +150 -6
178 lines not on this page · raw message
Re: [RFC PATCH 2/8] crypto/krb5: Provide Kerberos 5 crypto through AEAD API
In reply to David HowellsQuoted 27 lines · David Howells
Use the AEAD crypto API to provide Kerberos 5 crypto, plus some supplementary library functions that lie outside of the AEAD API.
The crypto algorithms only perform the actual crypto operations; they do not do any laying out of the message and nor do they insert any metadata or padding. Everything is done by dead-reckoning as the AEAD API does not provide a useful way to pass the extra parameters required.
When setting the key on a crypto algorithm, setkey takes a composite structure consisting of an indication of the mode of transformation to be applied to the message (checksum only or full encryption); the usage type to be used in deriving the keys; an indicator indicating what key is being presented (K0 or Kc/Ke+Ki); and the material for those key(s). Based on this, the setkey code allocates and keys the appropriate ciphers and hashes.
When dispatching a request, both checksumming (MIC) and encryption use the encrypt and decrypt methods. A source message, prelaid out with confounders or other metadata inserted is provided in the source buffer. The cryptolen indicates the amount of source message data, not including the trailer after the data (which includes the integrity checksum) and not including any associated data.
Associated data is only used by checksumming encrypt/decrypt. The associated data is added to the checksum hash before the data in the message, but does not occupy any part of the output message.
Quoted 7 lines
Authentication tags are not used at all and should cause EINVAL if used (a later patch does that).
For the moment, the kerberos encryption algorithms use separate hash and cipher algorithms internally, but should really use dual hash+cipher and cipher+hash algorithms if possible to avoid doing these in series. Offload off this may be possible through something like the Intel QAT.
It sounds like a lot of workarounds had to be implemented to fit these protocols into the crypto_aead API.
It also seems unlikely that there will be other implementations of these protocols added to the kernel, besides the one you're adding in crypto/krb5/.
Given that, providing this functionality as library functions instead would be much simpler. Take a look at how crypto/kdf_sp800108.c works, for example.
- Eric
David Howells
maintainerRe: [RFC PATCH 2/8] crypto/krb5: Provide Kerberos 5 crypto through AEAD API
Quoted 8 lines · Eric Biggers
It sounds like a lot of workarounds had to be implemented to fit these protocols into the
crypto_aeadAPI.It also seems unlikely that there will be other implementations of these protocols added to the kernel, besides the one you're adding in
crypto/krb5/.Given that, providing this functionality as library functions instead would be much simpler. Take a look at how
crypto/kdf_sp800108.cworks, for example.
Yes. That's how I did my first implementation. I basically took the code from net/sunrpc/auth_gss/ and made it more generic. Herbert wants it done this way, however. :-/
David
Re: [RFC PATCH 2/8] crypto/krb5: Provide Kerberos 5 crypto through AEAD API
Quoted 9 lines · David Howells
Quoted 6 lines · Eric Biggers
It sounds like a lot of workarounds had to be implemented to fit these protocols into the
crypto_aeadAPI.It also seems unlikely that there will be other implementations of these protocols added to the kernel, besides the one you're adding in
crypto/krb5/.
Quoted 7 lines
Quoted 2 lines
Given that, providing this functionality as library functions instead would be much simpler. Take a look at how
crypto/kdf_sp800108.cworks, for example.Yes. That's how I did my first implementation. I basically took the code from
net/sunrpc/auth_gss/and made it more generic. Herbert wants it done this way, however. :-/
What is the reason for shoehorning any of this into the crypto API?
I agree with Eric here: it seems both the user (Kerberos) and the crypto API are worse off here, due to mutual API incompatibilities that seem rather fundamental.
Are you anticipating other, accelerated implementations of the combined algorithms? Isn't it enough to rely on the existing Camellia and AES code? Mentioning 'something like the Intel QAT' doesn't suggest you have something specific in mind.
Also, this patch is rather big and therefore hard to review.
Herbert Xu
maintainerRe: [RFC PATCH 2/8] crypto/krb5: Provide Kerberos 5 crypto through AEAD API
In reply to David HowellsQuoted 15 lines · David Howells
crypto/krb5/krb5_aead.c new file +14
-0+ .etype = KRB5_ENCTYPE_AES128_CTS_HMAC_SHA256_128, + .ctype = KRB5_CKSUMTYPE_HMAC_SHA256_128_AES128, + .name = "aes128-cts-hmac-sha256-128", + .encrypt_name = "cts(cbc(aes))", + .cksum_name = "hmac(sha256)", + .hash_name = "sha256", + .key_bytes = 16, + .key_len = 16, + .Kc_len = 16, + .Ke_len = 16, + .Ki_len = 16, + .block_len = 16, + .conf_len = 16, + .cksum_len = 16,
crypto/krb5/krb5_aead.c line 348
Quoted 10 lines
crypto/krb5/krb5_aead.c new file +10
-0+ .hash_len = 20, + .prf_len = 32, + .keyed_cksum = true, + .random_to_key = NULL, /* Identity */ + .profile = &rfc8009_crypto_profile, + + .aead.setkey = krb5_setkey, + .aead.setauthsize = NULL, + .aead.encrypt = rfc8009_aead_encrypt, + .aead.decrypt = rfc8009_aead_decrypt,
rfc8009 is basically the same as authenc. So rather than being an AEAD algorithm it should really be an AEAD template which takes a cipher and and a hash as its parameters.
In fact, you could probably use authenc directly.
rfc3691 on the other hand is slightly different from authenc in that the integrity is computed on the plain text.
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
Herbert Xu
maintainerRe: [RFC PATCH 2/8] crypto/krb5: Provide Kerberos 5 crypto through AEAD API
In reply to David HowellsQuoted 3 lines · David Howells
Authentication tags are not used at all and should cause EINVAL if used (a later patch does that).
What do you mean by this? The authentication tag is the checksum that you're referring to and you appear to be using it in the rfc8009 encrypt/decrypt functions.
Quoted 4 lines
For the moment, the kerberos encryption algorithms use separate hash and cipher algorithms internally, but should really use dual hash+cipher and cipher+hash algorithms if possible to avoid doing these in series. Offload off this may be possible through something like the Intel QAT.
Please elaborate on what you mean by this. For IPsec, the main benefit with reframing cbc(aes)+hmac as aead is having a single code-path that supports both types of algorithms.
So does your use-case support both standard AEAD algorithms such as GCM as well as these legacy algorithms?
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
David Howells
maintainerRe: [RFC PATCH 2/8] crypto/krb5: Provide Kerberos 5 crypto through AEAD API
In reply to Herbert XuQuoted 3 lines · Herbert Xu
rfc8009 is basically the same as authenc. So rather than being an AEAD algorithm it should really be an AEAD template which takes a cipher and and a hash as its parameters.
That's only half true. If it's acting in checksum mode then it's not an authenc() algo.
Quoted 1 line
In fact, you could probably use authenc directly.
However the point of having a library is to abstract those details from the callers. You wanted me to rewrite the library as AEAD algorithms, which I have done as far as I can. This makes the object for each kerberos enctype look the same from the PoV of the clients.
I have plans to make the kerberos AEAD use an authenc behind the scenes rather than a cipher plus hash where appropriate as a future evolution, but the optimised authenc drivers (QAT for example) that I can find don't appear to support CTS.
So I'm not sure what it is you were envisioning.
David
Herbert Xu
maintainerRe: [RFC PATCH 2/8] crypto/krb5: Provide Kerberos 5 crypto through AEAD API
Quoted 5 lines · David Howells
However the point of having a library is to abstract those details from the callers. You wanted me to rewrite the library as AEAD algorithms, which I have done as far as I can. This makes the object for each kerberos enctype look the same from the PoV of the clients.
I think there is some misunderstanding here. For a library outside of the Crypto API you can do whatever you want.
I only suggested AEAD because I thought you wanted to bring this within the Crypto API.
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
David Howells
maintainerRe: [RFC PATCH 2/8] crypto/krb5: Provide Kerberos 5 crypto through AEAD API
In reply to Herbert XuQuoted 6 lines · Herbert Xu
Quoted 2 lines
Authentication tags are not used at all and should cause EINVAL if used (a later patch does that).
What do you mean by this? The authentication tag is the checksum that you're referring to and you appear to be using it in the rfc8009 encrypt/decrypt functions.
Is it? That's entirely unclear. The algorithm should deal with inserting the checksum in the appropriate place. The caller should not need to know about that or where the checksum is or about extra bits of metadata that may need to be inserted (as I think the extra gssapi layer does for sunrpc).
One of the reason the library has a number of layout functions is to handle that stuff transparently. Unfortunately, I couldn't make it work in the AEAD interface. The previous library implementation was better in that regard.
Quoted 8 lines
Quoted 4 lines
For the moment, the kerberos encryption algorithms use separate hash and cipher algorithms internally, but should really use dual hash+cipher and cipher+hash algorithms if possible to avoid doing these in series. Offload off this may be possible through something like the Intel QAT.
Please elaborate on what you mean by this. For IPsec, the main benefit with reframing cbc(aes)+hmac as aead is having a single code-path that supports both types of algorithms.
By "dual" I mean, for example, a piece of code that does the cipher and the hash concurrently. I think it may be possible to do this using x86 AES and SHA instructions - if there are sufficient registers. What I want to do is avoid having to call a cipher and a hash sequentially. It appears that the Intel QAT can actually do this with authenc combos - but the one I have doesn't offer CTS(CBC(AES)) but only CBC(AES).
Quoted 2 lines
So does your use-case support both standard AEAD algorithms such as GCM as well as these legacy algorithms?
At the moment AFS's rxgk does not support GCM. The same goes for sunrpc in the kernel.
David
Herbert Xu
maintainerRe: [RFC PATCH 2/8] crypto/krb5: Provide Kerberos 5 crypto through AEAD API
Quoted 5 lines · David Howells
Is it? That's entirely unclear. The algorithm should deal with inserting the checksum in the appropriate place. The caller should not need to know about that or where the checksum is or about extra bits of metadata that may need to be inserted (as I think the extra gssapi layer does for sunrpc).
The AEAD interface does not dictate where the authentication tag is. Most algorithms put it at the end, but it really could be anywhere.
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
David Howells
maintainerRe: [RFC PATCH 2/8] crypto/krb5: Provide Kerberos 5 crypto through AEAD API
In reply to Herbert XuQuoted 7 lines · Herbert Xu
Quoted 5 lines · David Howells
However the point of having a library is to abstract those details from the callers. You wanted me to rewrite the library as AEAD algorithms, which I have done as far as I can. This makes the object for each kerberos enctype look the same from the PoV of the clients.
Quoted 5 lines
I think there is some misunderstanding here. For a library outside of the Crypto API you can do whatever you want.
I only suggested AEAD because I thought you wanted to bring this within the Crypto API.
Not precisely. What I (and Chuck when I discussed it with him) were thinking is that the kerberos crypto stuff probably belongs in the crypto/ *directory* rather than in the net/ directory - but not necessarily as part of the crypto API. It mediates use of the crypto API on the part of its users (probably just sunrpc and rxrpc's rxgk).
That said, I kind of like the implementation of the pure crypto part as AEAD crypto algorithms as it provides a number of advantages:
(1) The client can be given a single AEAD object to use for each usage and call the encrypt and decrypt on that directly, no matter what enctype or mode of operation it is doing.
Of course, it's not quite so simple that I can just share the code for encrypt-mode and checksum-mode at the client level (eg. rxgk). In the former, some metadata is placed in the message; in the latter it's just added into the hash.
(2) The AEAD object looks after inserting the checksum into the right place for the enctype, which means the client doesn't have to do that and could therefore more easily asynchronise it through the crypto API.
(3) Since these do just the crypto and not the laying out, it may be feasible to substitute the AES2 encrypt-mode kerberos AEAD driver with an authenc() AEAD object.
(4) The possibility exists of providing optimised drivers to directly substitute the kerberos AEAD algorithms.
David
David Howells
maintainerRe: [RFC PATCH 2/8] crypto/krb5: Provide Kerberos 5 crypto through AEAD API
In reply to Ard BiesheuvelQuoted 1 line · Ard Biesheuvel
What is the reason for shoehorning any of this into the crypto API?
I was under the impression that that was what Herbert wanted.
Quoted 3 lines
I agree with Eric here: it seems both the user (Kerberos) and the crypto API are worse off here, due to mutual API incompatibilities that seem rather fundamental.
My original take on this was to take the sunrpc code and turn it into a library, placing that library in the crypto/ directory:
https://lore.kernel.org/linux-crypto/160518586534.2277919.14475638653680231924.stgit@warthog.procyon.org.uk/
The crypto/ dir seems the right home for it (and not net/ or lib/), but the way it's implemented here, it's a user of the crypto API, but does not itself implement it.
That said, it would be convenient if if *could* be part of the crypto API in some way. As I outlined in one of my responses to Herbert, there are a number of advantages to doing that.
Quoted 2 lines
Are you anticipating other, accelerated implementations of the combined algorithms?
I think one can be done with x86 AES and SHA instructions provided there are sufficient registers.
Quoted 1 line
Isn't it enough to rely on the existing Camellia and AES code?
The problem is that you have to do *two* crypto operations - and that it may not be possible to parallellise them. With AES+SHA1 and Camellia, they can be parallellised as both sides work on the plaintext; but with the AES+SHA2, the encryption is done and then the *encrypted* output is checksummed.
Note that "parallellising" might mean launching an async hash request and an async skcipher request and then waiting for both to finish. This can't, however, be done unless the output buffer is separate from the input buffer.
Quoted 2 lines
Mentioning 'something like the Intel QAT' doesn't suggest you have something specific in mind.
I have an Intel QAT card, and under some circumstances I could offload the crypto to it... But the only operations the driver currently makes available are:
authenc(hmac(sha1),cbc(aes)) authenc(hmac(sha256),cbc(aes)) authenc(hmac(sha512),cbc(aes))
The first one can't be used for kerberos's aes128-cts-hmac-sha1-96 as it hashes the ciphertext, not the plain text. I don't have anything that uses the third. The second is a possibility. I think that could probably do aes128-cts-hmac-sha256-128.
Now, it's possible that the QAT device range can do more than the driver offers. I'm presuming that the driver offers what IPsec wants to support. Also, waving these ideas in front of Intel devs might expand the range of what future QATs can do ;-)
Mostly, though, by "something like" I was just offering the possibility that other architectures or crypto cards may also offer usable services - but I haven't investigated.
Quoted 1 line
Also, this patch is rather big and therefore hard to review.
Yeah. Mostly I wanted to wave it in front of Herbert before expending the effort to slice it up. Sadly, it doesn't seem that what I came up with is what he wanted.
David
Re: [RFC PATCH 2/8] crypto/krb5: Provide Kerberos 5 crypto through AEAD API
In reply to Herbert XuQuoted 2 lines · Herbert Xu
So does your use-case support both standard AEAD algorithms such as GCM as well as these legacy algorithms?
RXGK is described by https://datatracker.ietf.org/doc/draft-wilkinson-afs3-rxgk/.
Any RFC3961 ("Encryption and Checksum Specifications for Kerberos 5") framework encryption algorithm can be used with it.
There have been proposals to add AEAD encryption types to RFC3961. For example, Luke Howard proposed
https://datatracker.ietf.org/doc/draft-howard-krb-aead/
The Security Considerations section describes the reasons that MIT's Kerberos team is reluctant to add AEAD algorithms to RFC3961. The primary one being that AEAD algorithms are not safe for all of the existing RFC3961 use cases and there is no means of ensuring that AEAD encryption types would not be misused.
Requests for the addition of AEAD to RFC3961 have come from both the NFSv4 community and those implementing RXGK. Alas, there has been no forward progress since the publication of Luke's draft.
Jeffrey Altman
David Howells
maintainerRe: [RFC PATCH 2/8] crypto/krb5: Provide Kerberos 5 crypto through AEAD API
In reply to Herbert XuQuoted 1 line · Herbert Xu
rfc8009 is basically the same as authenc.
Actually, it's not quite the same :-/
rfc8009 chucks the IV from the encryption into the hash first, but authenc() does not. It may be possible to arrange the buffer so that the assoc data is also the IV buffer.
David
David Howells
maintainerRe: [RFC PATCH 2/8] crypto/krb5: Provide Kerberos 5 crypto through AEAD API
Quoted 7 lines · David Howells
Quoted 1 line
rfc8009 is basically the same as authenc.
Actually, it's not quite the same :-/
rfc8009 chucks the IV from the encryption into the hash first, but
authenc()does not. It may be possible to arrange the buffer so that the assoc data is also the IV buffer.
Actually actually, it's the starting IV, so I just need to chuck in a block of zeroes.
David