crypto: Add generic Kerberos library with AEAD template for hash-then-crypt
Subsystems (12)
David Howells
maintainercover crypto: Add generic Kerberos library with AEAD template for hash-then-crypt
Hi Herbert, Chuck,
Here's yet another 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.
I added an addition AEAD template type, derived from authenc, that does hash-then-crypt rather than crypt-then-hash as authenc does. I called it "krb5enc" for want of a better name. Possibly I should call it "hashenc" or something like that.
I went back to my previous more library-based approach, but for encrypt mode, I replaced the separate skcipher and shash objects with a single templated AEAD object - either krb5enc (AES+SHA1 and Camellia) or authenc (AES+SHA2).
Apart from that, things are much as they were previously from the point of view of someone using the API. There's a new pair of functions that, given an encoding type, a key and a usage value, will derive the necessary keys and return an AEAD or hash handle. These handles can then be passed to operation functions that will do the actual work of performing an encryption, a decryption, MIC generation or MIC verification.
Querying functions are also available to look up an encoding type table by kerberos protocol number and to help manage message layout.
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, though these have to be provisioned with the intermediate subkeys rather than the transport key.
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 (24):
crypto/krb5: Add API Documentation
crypto/krb5: Add some constants out of sunrpc headers
crypto: Add 'krb5enc' hash and cipher AEAD algorithm crypto/krb5: Test manager data
crypto/krb5: Implement Kerberos crypto core
crypto/krb5: Add an API to query the layout of the crypto section crypto/krb5: Add an API to alloc and prepare a crypto object crypto/krb5: Add an API to perform requests
crypto/krb5: Provide infrastructure and key derivation crypto/krb5: Implement the Kerberos5 rfc3961 key derivation crypto/krb5: Provide RFC3961 setkey packaging functions crypto/krb5: Implement the Kerberos5 rfc3961 encrypt and decrypt
functions
crypto/krb5: Implement the Kerberos5 rfc3961 get_mic and verify_mic crypto/krb5: Implement the AES enctypes from rfc3962 crypto/krb5: Implement the AES enctypes from rfc8009 crypto/krb5: Implement the AES encrypt/decrypt from rfc8009 crypto/krb5: Implement crypto self-testing
crypto/krb5: Add the AES self-testing data from rfc8009 crypto/krb5: Implement the Camellia enctypes from rfc6803
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
Documentation/crypto/index.rst | 1 + Documentation/crypto/krb5.rst | 262 +++++++ crypto/Kconfig | 13 + crypto/Makefile | 3 + crypto/krb5/Kconfig | 26 + crypto/krb5/Makefile | 18 + crypto/krb5/internal.h | 257 +++++++ crypto/krb5/krb5_api.c | 452 ++++++++++++ crypto/krb5/krb5_kdf.c | 145 ++++ crypto/krb5/rfc3961_simplified.c | 791 ++++++++++++++++++++ crypto/krb5/rfc3962_aes.c | 115 +++ crypto/krb5/rfc6803_camellia.c | 237 ++++++ crypto/krb5/rfc8009_aes2.c | 431 +++++++++++ crypto/krb5/selftest.c | 544 ++++++++++++++ crypto/krb5/selftest_data.c | 291 ++++++++ crypto/krb5enc.c | 491 +++++++++++++ crypto/testmgr.c | 16 + crypto/testmgr.h | 401 ++++++++++ fs/afs/misc.c | 13 + include/crypto/krb5.h | 167 +++++ 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 | 1170 ++++++++++++++++++++++++++++++ net/rxrpc/rxgk_app.c | 284 ++++++++ net/rxrpc/rxgk_common.h | 140 ++++ net/rxrpc/rxgk_kdf.c | 287 ++++++++ net/rxrpc/rxkad.c | 6 +- net/rxrpc/security.c | 3 + 37 files changed, 6874 insertions(+), 5 deletions(-) create mode 100644 Documentation/crypto/krb5.rst create mode 100644 crypto/krb5/Kconfig create mode 100644 crypto/krb5/Makefile create mode 100644 crypto/krb5/internal.h create mode 100644 crypto/krb5/krb5_api.c create mode 100644 crypto/krb5/krb5_kdf.c create mode 100644 crypto/krb5/rfc3961_simplified.c create mode 100644 crypto/krb5/rfc3962_aes.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 crypto/krb5enc.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/24 crypto/krb5: Add API Documentation
Add API documentation for the kerberos crypto library.
--- Documentation/crypto/index.rst | 1 + Documentation/crypto/krb5.rst | 262 +++++++++++++++++++++++++++++++++ 2 files changed, 263 insertions(+) create mode 100644 Documentation/crypto/krb5.rst
Documentation/crypto/index.rst +1 -0
@@ -26,3 +26,4 @@ for cryptographic use cases, as well as programming examples. api-samples descore-readme device_drivers/index + krb5
Documentation/crypto/krb5.rst new file +262 -0
262 lines not on this page · raw message
David Howells
maintainerRFC PATCH 2/24 crypto/krb5: Add some constants out of sunrpc headers
In reply to David HowellsAdd some constants from the sunrpc headers.
--- include/crypto/krb5.h | 51 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 include/crypto/krb5.h
include/crypto/krb5.h new file +51 -0
@@ -0,0 +1,51 @@ +/* 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 3/24 crypto: Add 'krb5enc' hash and cipher AEAD algorithm
In reply to David HowellsAdd an AEAD template that does hash-then-cipher (unlike authenc that does cipher-then-hash). This is required for a number of Kerberos 5 encoding types.
[!] Note that the net/sunrpc/auth_gss/ implementation gets a pair of ciphers, one non-CTS and one CTS, using the former to do all the aligned blocks and the latter to do the last two blocks if they aren't also aligned. It may be necessary to do this here too for performance reasons - but there are considerations both ways:
(1) firstly, there is an optimised assembly version of cts(cbc(aes)) on
x86_64 that should be used instead of having two ciphers;
(2) secondly, none of the hardware offload drivers seem to offer CTS support (Intel QAT does not, for instance).
However, I don't know if it's possible to query the crypto API to find out whether there's an optimised CTS algorithm available.
--- crypto/Kconfig | 12 ++ crypto/Makefile | 1 + crypto/krb5enc.c | 491 ++++++++++++++++++++++++++++++++++++++++++ include/crypto/krb5.h | 7 + 4 files changed, 511 insertions(+) create mode 100644 crypto/krb5enc.c
crypto/Kconfig +12 -0
@@ -228,6 +228,18 @@ config CRYPTO_AUTHENC This is required for IPSec ESP (XFRM_ESP). +config CRYPTO_KRB5ENC + tristate "Kerberos 5 combined hash+cipher support" + select CRYPTO_AEAD + select CRYPTO_SKCIPHER + select CRYPTO_MANAGER + select CRYPTO_HASH + select CRYPTO_NULL + help + Combined hash and cipher support for Kerberos 5 RFC3961 simplified + profile. This is required for Kerberos 5-style encryption, used by + sunrpc/NFS and rxrpc/AFS. + config CRYPTO_TEST tristate "Testing module" depends on m || EXPERT
crypto/Makefile +1 -0
@@ -160,6 +160,7 @@ CFLAGS_crc32_generic.o += -DARCH=$(ARCH) obj-$(CONFIG_CRYPTO_CRCT10DIF) += crct10dif_common.o crct10dif_generic.o obj-$(CONFIG_CRYPTO_CRC64_ROCKSOFT) += crc64_rocksoft_generic.o obj-$(CONFIG_CRYPTO_AUTHENC) += authenc.o authencesn.o +obj-$(CONFIG_CRYPTO_KRB5ENC) += krb5enc.o obj-$(CONFIG_CRYPTO_LZO) += lzo.o lzo-rle.o obj-$(CONFIG_CRYPTO_LZ4) += lz4.o obj-$(CONFIG_CRYPTO_LZ4HC) += lz4hc.o
crypto/krb5enc.c new file +491 -0
491 lines not on this page · raw message
include/crypto/krb5.h +7 -0
@@ -48,4 +48,11 @@#define KEY_USAGE_SEED_ENCRYPTION (0xAA)#define KEY_USAGE_SEED_INTEGRITY (0x55) +/* +* krb5enc.c +*/ +struct crypto_authenc_keys ; +int crypto_krb5enc_extractkeys (struct crypto_authenc_keys *keys,const u8 *key, +unsigned int keylen); +#endif /* _CRYPTO_KRB5_H */
Simon Horman
reviewerRe: [RFC PATCH 03/24] crypto: Add 'krb5enc' hash and cipher AEAD algorithm
Quoted 20 lines · David Howells
Add an AEAD template that does hash-then-cipher (unlike authenc that does cipher-then-hash). This is required for a number of Kerberos 5 encoding types.
[!] Note that the
net/sunrpc/auth_gss/implementation gets a pair of ciphers, one non-CTS and one CTS, using the former to do all the aligned blocks and the latter to do the last two blocks if they aren't also aligned. It may be necessary to do this here too for performance reasons - but there are considerations both ways:(1) firstly, there is an optimised assembly version of cts(cbc(aes)) on
x86_64 that should be used instead of having two ciphers;(2) secondly, none of the hardware offload drivers seem to offer CTS support (Intel QAT does not, for instance).
However, I don't know if it's possible to query the crypto API to find out whether there's an optimised CTS algorithm available.
Signed-off-by David Howells <[email protected]>
...
Quoted 1 line
crypto/krb5enc.c +0
-0
...
Quoted 15 lines
crypto/krb5enc.c +15
-0+static int krb5enc_verify_hash (struct aead_request *req,void *hash) +{ +struct crypto_aead *krb5enc =crypto_aead_reqtfm (req); +struct aead_instance *inst =aead_alg_instance (krb5enc); +struct krb5enc_instance_ctx *ictx =aead_instance_ctx (inst); +struct krb5enc_request_ctx *areq_ctx =aead_request_ctx (req); +struct ahash_request *ahreq = (void *)(areq_ctx->tail + ictx->reqoff); +unsigned int authsize =crypto_aead_authsize (krb5enc); +u8 *ihash = ahreq->result + authsize; + +scatterwalk_map_and_copy (ihash, req->src, ahreq->nbytes, authsize,0 ); + +if (crypto_memneq (ihash, ahreq->result, authsize)) +return -EBADMSG ; +return 0 ;
crypto/krb5enc.c line 257
Quoted 10 lines
crypto/krb5enc.c +10
-0+} + +static void krb5enc_decrypt_hash_done (void *data,int err) +{ +struct aead_request *req = data; + +if (err) +return krb5enc_request_complete (req, err); + + err =krb5enc_verify_hash (req,0 );
Hi David,
Sparse complains that the second argument to krb5enc_verify_hash should be a pointer rather than an integer. So perhaps this would be slightly better expressed as (completely untested!):
err = krb5enc_verify_hash(req, NULL);
Quoted 1 line
crypto/krb5enc.c +1
-0+krb5enc_request_complete (req, err);
...
Quoted 1 line
+}
David Howells
maintainerRe: [RFC PATCH 03/24] crypto: Add 'krb5enc' hash and cipher AEAD algorithm
Quoted 11 lines · Simon Horman
crypto/krb5enc.c line 257
Quoted 8 lines
crypto/krb5enc.c new file +8
-0+static void krb5enc_decrypt_hash_done (void *data,int err) +{ +struct aead_request *req = data; + +if (err) +return krb5enc_request_complete (req, err); + + err =krb5enc_verify_hash (req,0 );Hi David,
Quoted 5 lines
Sparse complains that the second argument to
krb5enc_verify_hashshould be a pointer rather than an integer. So perhaps this would be slightly better expressed as (completely untested!):err = krb5enc_verify_hash(req, NULL);
Actually, no. It should be "ahreq->result + authsize" and krb5enc_verify_hash() shouldn't calculate ihash, but use its hash parameter.
I wonder if the testmgr driver tests running the algorithms asynchronously...
Thanks,
David
Re: [RFC PATCH 03/24] crypto: Add 'krb5enc' hash and cipher AEAD algorithm
Quoted 3 lines · David Howells
I wonder if the testmgr driver tests running the algorithms asynchronously...
Multiple requests in parallel, I think you mean? No, it doesn't, but it should.
- Eric
David Howells
maintainerRe: [RFC PATCH 03/24] crypto: Add 'krb5enc' hash and cipher AEAD algorithm
Quoted 2 lines · Eric Biggers
Multiple requests in parallel, I think you mean? No, it doesn't, but it should.
Not so much. This bug is on the asynchronous path and not tested by my rxrpc/rxgk code which only exercises the synchronous path. I haven't tried to make that asynchronous yet. I presume testmgr also only tests the sync path.
David
Re: [RFC PATCH 03/24] crypto: Add 'krb5enc' hash and cipher AEAD algorithm
Quoted 11 lines · David Howells
Quoted 2 lines · Eric Biggers
Multiple requests in parallel, I think you mean? No, it doesn't, but it should.
Not so much. This bug is on the asynchronous path and not tested by my rxrpc/rxgk code which only exercises the synchronous path. I haven't tried to make that asynchronous yet. I presume testmgr also only tests the sync path.
David
I'm not sure I understand your question. Users of the crypto API can exclude asynchronous algorithms when selecting one, but the self-tests do not do that.
In any case, why would you need anything to do asynchronous at all here?
- Eric
David Howells
maintainerRe: [RFC PATCH 03/24] crypto: Add 'krb5enc' hash and cipher AEAD algorithm
Quoted 1 line · Eric Biggers
In any case, why would you need anything to do asynchronous at all here?
Because authenc, which I copied, passes the asynchronocity mode onto the two algos it runs (one encrypt, one hash). If authenc is run synchronously, then the algos are run synchronously and serially; but if authenc is run async, then the algos are run asynchronously - but they may still have to be run serially[*] and the second is dispatched from the completion handler of the first. So two different paths through the code exist, and rxgk and testmgr only test the synchronous path.
[*] Because in authenc-compatible encoding types, the output of the encryption is hashed. Older krb5 encodings hash the plaintext and the hash generation and the encrypt can be run in parallel. For decrypting, the reverse is true; authenc may be able to do the decrypt and the hash in parallel... But parallellisation also requires that the input and output buffers are not the same.
Anyway. If it can be done asynchronously, that should probably be tested.
David
Re: [RFC PATCH 03/24] crypto: Add 'krb5enc' hash and cipher AEAD algorithm
Quoted 11 lines · David Howells
Quoted 1 line · Eric Biggers
In any case, why would you need anything to do asynchronous at all here?
Because authenc, which I copied, passes the asynchronocity mode onto the two algos it runs (one encrypt, one hash). If authenc is run synchronously, then the algos are run synchronously and serially; but if authenc is run async, then the algos are run asynchronously - but they may still have to be run serially[*] and the second is dispatched from the completion handler of the first. So two different paths through the code exist, and rxgk and testmgr only test the synchronous path.
No, it goes in the other direction. The underlying algorithms decide whether they are asynchronous or not, and that gets passed up. It sounds like what you want to do is test your template in the case where the underlying algorithms are asynchronous. There is a way to do that by wrapping the underlying algorithms with cryptd. For example the following works with gcm:
python3 <<EOF
import socket
s = socket.socket(socket.AF_ALG, 5, 0)s.bind(("aead", "gcm_base(cryptd(ctr(aes-generic)),cryptd(ghash-generic))")) EOF
This really should just be thought of as complying with the outdated design of the crypto API, though. In practice synchronous is the only case that really matters.
Quoted 6 lines
[*] Because in authenc-compatible encoding types, the output of the encryption is hashed. Older krb5 encodings hash the plaintext and the hash generation and the encrypt can be run in parallel. For decrypting, the reverse is true; authenc may be able to do the decrypt and the hash in parallel... But parallellisation also requires that the input and output buffers are not the same.
The right way to optimize cases like that is to interleave the two computations. Look at how the AES-GCM assembly code interleaves AES-CTR and GHASH for example. Doing something with async threads is the completely wrong solution here and would be much slower. The amount of time needed to process a single message is simply far too short for multithreading to be appropriate on a per message basis.
- Eric
David Howells
maintainerRe: [RFC PATCH 03/24] crypto: Add 'krb5enc' hash and cipher AEAD algorithm
In reply to David HowellsQuoted 8 lines · David Howells
Quoted 5 lines
Sparse complains that the second argument to
krb5enc_verify_hashshould be a pointer rather than an integer. So perhaps this would be slightly better expressed as (completely untested!):err = krb5enc_verify_hash(req, NULL);Actually, no. It should be "
ahreq->result+ authsize" andkrb5enc_verify_hash()shouldn't calculate ihash, but use its hash parameter.
Ah. That's wrong also. I'm going to drop the second parameter and just calculate the hash pointers directly.
David
---
crypto/krb5enc.c +8 -7
@@ -230,7 +230,7 @@ static int krb5enc_encrypt(struct aead_request *req)return krb5enc_dispatch_encrypt (req,aead_request_flags (req)); } -static int krb5enc_verify_hash (struct aead_request *req,void *hash) +static int krb5enc_verify_hash (struct aead_request *req) {struct crypto_aead *krb5enc =crypto_aead_reqtfm (req);struct aead_instance *inst =aead_alg_instance (krb5enc);
@@ -238,11 +238,12 @@ static int krb5enc_verify_hash(struct aead_request *req, void *hash)struct krb5enc_request_ctx *areq_ctx =aead_request_ctx (req);struct ahash_request *ahreq = (void *)(areq_ctx->tail + ictx->reqoff);unsigned int authsize =crypto_aead_authsize (krb5enc); -u8 *ihash = ahreq->result + authsize; +u8 *calc_hash = areq_ctx->tail; +u8 *msg_hash = areq_ctx->tail + authsize; -scatterwalk_map_and_copy (ihash, req->src, ahreq->nbytes, authsize,0 ); +scatterwalk_map_and_copy (msg_hash, req->src, ahreq->nbytes, authsize,0 ); -if (crypto_memneq (ihash, ahreq->result, authsize)) +if (crypto_memneq (msg_hash, calc_hash, authsize))return -EBADMSG ;return 0 ; }
@@ -254,7 +255,7 @@ static void krb5enc_decrypt_hash_done(void *data, int err)if (err)return krb5enc_request_complete (req, err); - err =krb5enc_verify_hash (req,0 ); + err =krb5enc_verify_hash (req);krb5enc_request_complete (req, err); }
@@ -284,7 +285,7 @@ static int krb5enc_dispatch_decrypt_hash(struct aead_request *req)if (err <0 )return err; -return krb5enc_verify_hash (req, hash); +return krb5enc_verify_hash (req); }/*
@@ -352,7 +353,7 @@ static int krb5enc_init_tfm(struct crypto_aead *tfm)crypto_aead_set_reqsize ( tfm,sizeof (struct krb5enc_request_ctx ) + - ictx->reqoff + + ictx->reqoff +/* Space for two checksums */ umax (sizeof (struct ahash_request ) +crypto_ahash_reqsize (auth),sizeof (struct skcipher_request ) +crypto_skcipher_reqsize (enc)));
David Howells
maintainerRFC PATCH 4/24 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.
--- crypto/testmgr.c | 16 ++ crypto/testmgr.h | 401 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 417 insertions(+)
crypto/testmgr.c +16 -0
@@ -4515,6 +4515,12 @@ static const struct alg_test_desc alg_test_descs[] = { .alg = "authenc(hmac(sha256),ctr(aes))", .test = alg_test_null, .fips_allowed = 1, + }, { + .alg = "authenc(hmac(sha256),cts(cbc(aes)))", + .test = alg_test_aead, + .suite = { + .aead = __VECS(krb5_test_aes128_cts_hmac_sha256_128) + } }, { .alg = "authenc(hmac(sha256),rfc3686(ctr(aes)))", .test = alg_test_null,
@@ -4535,6 +4541,12 @@ static const struct alg_test_desc alg_test_descs[] = { .alg = "authenc(hmac(sha384),ctr(aes))", .test = alg_test_null, .fips_allowed = 1, + }, { + .alg = "authenc(hmac(sha384),cts(cbc(aes)))", + .test = alg_test_aead, + .suite = { + .aead = __VECS(krb5_test_aes256_cts_hmac_sha384_192) + } }, { .alg = "authenc(hmac(sha384),rfc3686(ctr(aes)))", .test = alg_test_null,
@@ -5408,6 +5420,10 @@ static const struct alg_test_desc alg_test_descs[] = { .alg = "jitterentropy_rng", .fips_allowed = 1, .test = alg_test_null, + }, { + .alg = "krb5enc(cmac(camellia),cts(cbc(camellia)))", + .test = alg_test_aead, + .suite.aead =__VECS (krb5_test_camellia_cts_cmac) }, { .alg = "kw(aes)", .test = alg_test_skcipher,
crypto/testmgr.h +401 -0
405 lines not on this page · raw message
David Howells
maintainerRFC PATCH 5/24 crypto/krb5: Implement Kerberos crypto core
In reply to David HowellsProvide core structures, an encoding-type registry and basic module and config bits for a generic Kerberos crypto library.
--- crypto/Kconfig | 1 + crypto/Makefile | 2 + crypto/krb5/Kconfig | 14 ++++++ crypto/krb5/Makefile | 9 ++++ crypto/krb5/internal.h | 112 +++++++++++++++++++++++++++++++++++++++++ crypto/krb5/krb5_api.c | 42 ++++++++++++++++ include/crypto/krb5.h | 54 ++++++++++++++++++++ 7 files changed, 234 insertions(+) create mode 100644 crypto/krb5/Kconfig create mode 100644 crypto/krb5/Makefile create mode 100644 crypto/krb5/internal.h create mode 100644 crypto/krb5/krb5_api.c
crypto/Kconfig +1 -0
@@ -1489,5 +1489,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
@@ -214,3 +214,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 +14 -0
@@ -0,0 +1,14 @@ +config CRYPTO_KRB5 + tristate "Kerberos 5 crypto" + select CRYPTO_MANAGER + select CRYPTO_KRB5ENC + select CRYPTO_AUTHENC + select CRYPTO_SKCIPHER + select CRYPTO_HASH_INFO + select CRYPTO_SHA1 + select CRYPTO_CBC + select CRYPTO_CTS + select CRYPTO_AES + help + Provide a library for provision of Kerberos-5-based crypto. This is + intended for network filesystems to use.
crypto/krb5/Makefile new file +9 -0
@@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for asymmetric cryptographic keys +# + +krb5-y += \ + krb5_api.o + +obj-$(CONFIG_CRYPTO_KRB5) += krb5.o
crypto/krb5/internal.h new file +112 -0
112 lines not on this page · raw message
crypto/krb5/krb5_api.c new file +42 -0
42 lines not on this page · raw message
include/crypto/krb5.h +54 -0
66 lines not on this page · raw message
David Howells
maintainerRFC PATCH 6/24 crypto/krb5: Add an API to query the layout of the crypto section
In reply to David HowellsProvide some functions to allow the called to find out about the layout of the crypto section:
(1) Calculate, for a given size of data, how big a buffer will be required to hold it and where the data will be within it.
(2) Calculate, for an amount of buffer, what's the maximum size of data that will fit therein, and where it will start.
(3) Determine where the data will be in a received message.
--- crypto/krb5/krb5_api.c | 108 +++++++++++++++++++++++++++++++++++++++++ include/crypto/krb5.h | 9 ++++ 2 files changed, 117 insertions(+)
crypto/krb5/krb5_api.c +108 -0
@@ -40,3 +40,111 @@ const struct krb5_enctype *crypto_krb5_find_enctype(u32 enctype)return NULL ; }EXPORT_SYMBOL (crypto_krb5_find_enctype); + +/** +* crypto_krb5_how_much_buffer - Work out how much buffer is required for an amount of data +* @krb5: The encoding to use. +* @mode: The mode in which to operated (checksum/encrypt) +* @data_size: How much data we want to allow for +* @_offset: Where to place the offset into the buffer +* +* Calculate how much buffer space is required to wrap a given amount of data. +* This allows for a confounder, padding and checksum as appropriate. The +* amount of buffer required is returned and the offset into the buffer at +* which the data will start is placed in *_offset. +*/ +size_t crypto_krb5_how_much_buffer (const struct krb5_enctype *krb5, +enum krb5_crypto_mode mode, +size_t data_size,size_t *_offset) +{ +switch (mode) { +case KRB5_CHECKSUM_MODE : + *_offset = krb5->cksum_len; +return krb5->cksum_len + data_size; + +case KRB5_ENCRYPT_MODE : + *_offset = krb5->conf_len; +return krb5->conf_len + data_size + krb5->cksum_len; + +default : +WARN_ON (1 ); + *_offset =0 ; +return 0 ; + } +} +EXPORT_SYMBOL (crypto_krb5_how_much_buffer); + +/** +* crypto_krb5_how_much_data - Work out how much data can fit in an amount of buffer +* @krb5: The encoding to use. +* @mode: The mode in which to operated (checksum/encrypt) +* @_buffer_size: How much buffer we want to allow for (may be reduced) +* @_offset: Where to place the offset into the buffer +* +* Calculate how much data can be fitted into given amount of buffer. This +* allows for a confounder, padding and checksum as appropriate. The amount of +* data that will fit is returned, the amount of buffer required is shrunk to +* allow for alignment and the offset into the buffer at which the data will +* start is placed in *_offset. +*/ +size_t crypto_krb5_how_much_data (const struct krb5_enctype *krb5, +enum krb5_crypto_mode mode, +size_t *_buffer_size,size_t *_offset) +{ +size_t buffer_size = *_buffer_size, data_size; + +switch (mode) { +case KRB5_CHECKSUM_MODE : +if (WARN_ON (buffer_size < krb5->cksum_len +1 )) + goto bad; + *_offset = krb5->cksum_len; +return buffer_size - krb5->cksum_len; + +case KRB5_ENCRYPT_MODE : +if (WARN_ON (buffer_size < krb5->conf_len +1 + krb5->cksum_len)) + goto bad; + data_size = buffer_size - krb5->cksum_len; + *_offset = krb5->conf_len; +return data_size - krb5->conf_len; + +default : +WARN_ON (1 ); + goto bad; + } + +bad: + *_offset =0 ; +return 0 ; +} +EXPORT_SYMBOL (crypto_krb5_how_much_data); + +/** +* crypto_krb5_where_is_the_data - Find the data in a decrypted message +* @krb5: The encoding to use. +* @mode: Mode of operation +* @_offset: Offset of the secure blob in the buffer; updated to data offset. +* @_len: The length of the secure blob; updated to data length. +* +* Find the offset and size of the data in a secure message so that this +* information can be used in the metadata buffer which will get added to the +* digest by crypto_krb5_verify_mic(). +*/ +void crypto_krb5_where_is_the_data (const struct krb5_enctype *krb5, +enum krb5_crypto_mode mode, +size_t *_offset,size_t *_len) +{ +switch (mode) { +case KRB5_CHECKSUM_MODE : + *_offset += krb5->cksum_len; + *_len -= krb5->cksum_len; +return ; +case KRB5_ENCRYPT_MODE : + *_offset += krb5->conf_len; + *_len -= krb5->conf_len + krb5->cksum_len; +return ; +default : +WARN_ON_ONCE (1 ); +return ; + } +} +EXPORT_SYMBOL (crypto_krb5_where_is_the_data);
include/crypto/krb5.h +9 -0
@@ -101,6 +101,15 @@ struct krb5_enctype {* krb5_api.c */ const struct krb5_enctype *crypto_krb5_find_enctype (u32 enctype); +size_t crypto_krb5_how_much_buffer (const struct krb5_enctype *krb5, +enum krb5_crypto_mode mode, +size_t data_size,size_t *_offset); +size_t crypto_krb5_how_much_data (const struct krb5_enctype *krb5, +enum krb5_crypto_mode mode, +size_t *_buffer_size,size_t *_offset); +void crypto_krb5_where_is_the_data (const struct krb5_enctype *krb5, +enum krb5_crypto_mode mode, +size_t *_offset,size_t *_len);/* * krb5enc.c
David Howells
maintainerRFC PATCH 7/24 crypto/krb5: Add an API to alloc and prepare a crypto object
In reply to David HowellsAdd an API by which users of the krb5 crypto library can get an allocated and keyed crypto object.
For encryption-mode operation, an AEAD object is returned; for checksum-mode operation, a synchronous hash object is returned.
--- crypto/krb5/internal.h | 10 +++ crypto/krb5/krb5_api.c | 144 +++++++++++++++++++++++++++++++++++++++++ include/crypto/krb5.h | 7 ++ 3 files changed, 161 insertions(+)
crypto/krb5/internal.h +10 -0
@@ -110,3 +110,13 @@ struct krb5_crypto_profile {#define krb5_digest_size (TFM ) \ crypto_roundup(crypto_shash_digestsize(TFM))#define round16 (x) (((x) + 15) & ~15) + +/* +* krb5_api.c +*/ +struct crypto_aead *krb5_prepare_encryption (const struct krb5_enctype *krb5, +const struct krb5_buffer *keys, +gfp_t gfp); +struct crypto_shash *krb5_prepare_checksum (const struct krb5_enctype *krb5, +const struct krb5_buffer *Kc, +gfp_t gfp);
crypto/krb5/krb5_api.c +144 -0
147 lines not on this page · raw message
include/crypto/krb5.h +7 -0
@@ -10,6 +10,7 @@#include <linux/crypto.h> #include <crypto/aead.h> +#include <crypto/hash.h> struct crypto_shash ;struct scatterlist ;
@@ -110,6 +111,12 @@ size_t crypto_krb5_how_much_data(const struct krb5_enctype *krb5,void crypto_krb5_where_is_the_data (const struct krb5_enctype *krb5,enum krb5_crypto_mode mode,size_t *_offset,size_t *_len); +struct crypto_aead *crypto_krb5_prepare_encryption (const struct krb5_enctype *krb5, +const struct krb5_buffer *TK , +u32 usage,gfp_t gfp); +struct crypto_shash *crypto_krb5_prepare_checksum (const struct krb5_enctype *krb5, +const struct krb5_buffer *TK , +u32 usage,gfp_t gfp);/* * krb5enc.c
David Howells
maintainerRFC PATCH 8/24 crypto/krb5: Add an API to perform requests
In reply to David HowellsAdd an API by which users of the krb5 crypto library can perform crypto requests, such as encrypt, decrypt, get_mic and verify_mic. These functions take the previously prepared crypto objects to work on.
--- crypto/krb5/krb5_api.c | 141 +++++++++++++++++++++++++++++++++++++++++ include/crypto/krb5.h | 21 ++++++ 2 files changed, 162 insertions(+)
crypto/krb5/krb5_api.c +141 -0
@@ -292,3 +292,144 @@ struct crypto_shash *crypto_krb5_prepare_checksum(const struct krb5_enctype *krbreturn ERR_PTR (ret); }EXPORT_SYMBOL (crypto_krb5_prepare_checksum); + +/** +* crypto_krb5_encrypt - Apply Kerberos encryption and integrity. +* @krb5: The encoding to use. +* @aead: The keyed crypto object to use. +* @sg: Scatterlist defining the crypto buffer. +* @nr_sg: The number of elements in @sg. +* @sg_len: The size of the buffer. +* @data_offset: The offset of the data in the @sg buffer. +* @data_len: The length of the data. +* @preconfounded: True if the confounder is already inserted. +* +* Using the specified Kerberos encoding, insert a confounder and padding as +* needed, encrypt this and the data in place and insert an integrity checksum +* into the buffer. +* +* The buffer must include space for the confounder, the checksum and any +* padding required. The caller can preinsert the confounder into the buffer +* (for testing, for example). +* +* The resulting secured blob may be less than the size of the buffer. +* +* Returns the size of the secure blob if successful, -ENOMEM on an allocation +* failure, -EFAULT if there is insufficient space, -EMSGSIZE if the confounder +* is too short or the data is misaligned. Other errors may also be returned +* from the crypto layer. +*/ +ssize_t crypto_krb5_encrypt (const struct krb5_enctype *krb5, +struct crypto_aead *aead, +struct scatterlist *sg,unsigned int nr_sg, +size_t sg_len, +size_t data_offset,size_t data_len, +bool preconfounded) +{ +if (WARN_ON (data_offset > sg_len || + data_len > sg_len || + data_offset > sg_len - data_len)) +return -EMSGSIZE ; +return krb5->profile->encrypt (krb5, aead, sg, nr_sg, sg_len, + data_offset, data_len, preconfounded); +} +EXPORT_SYMBOL (crypto_krb5_encrypt); + +/** +* crypto_krb5_decrypt - Validate and remove Kerberos encryption and integrity. +* @krb5: The encoding to use. +* @aead: The keyed crypto object to use. +* @sg: Scatterlist defining the crypto buffer. +* @nr_sg: The number of elements in @sg. +* @_offset: Offset of the secure blob in the buffer; updated to data offset. +* @_len: The length of the secure blob; updated to data length. +* +* Using the specified Kerberos encoding, check and remove the integrity +* checksum and decrypt the secure region, stripping off the confounder. +* +* If successful, @_offset and @_len are updated to outline the region in which +* the data plus the trailing padding are stored. The caller is responsible +* for working out how much padding there is and removing it. +* +* Returns the 0 if successful, -ENOMEM on an allocation failure; sets +* *_error_code and returns -EPROTO if the data cannot be parsed, or -EBADMSG +* if the integrity checksum doesn't match). Other errors may also be returned +* from the crypto layer. +*/ +int crypto_krb5_decrypt (const struct krb5_enctype *krb5, +struct crypto_aead *aead, +struct scatterlist *sg,unsigned int nr_sg, +size_t *_offset,size_t *_len) +{ +return krb5->profile->decrypt (krb5, aead, sg, nr_sg, _offset, _len); +} +EXPORT_SYMBOL (crypto_krb5_decrypt); + +/** +* crypto_krb5_get_mic - Apply Kerberos integrity checksum. +* @krb5: The encoding to use. +* @shash: The keyed hash to use. +* @metadata: Metadata to add into the hash before adding the data. +* @sg: Scatterlist defining the crypto buffer. +* @nr_sg: The number of elements in @sg. +* @sg_len: The size of the buffer. +* @data_offset: The offset of the data in the @sg buffer. +* @data_len: The length of the data. +* +* Using the specified Kerberos encoding, calculate and insert an integrity +* checksum into the buffer. +* +* The buffer must include space for the checksum at the front. +* +* Returns the size of the secure blob if successful, -ENOMEM on an allocation +* failure, -EFAULT if there is insufficient space, -EMSGSIZE if the gap for +* the checksum is too short. Other errors may also be returned from the +* crypto layer. +*/ +ssize_t crypto_krb5_get_mic (const struct krb5_enctype *krb5, +struct crypto_shash *shash, +const struct krb5_buffer *metadata, +struct scatterlist *sg,unsigned int nr_sg, +size_t sg_len, +size_t data_offset,size_t data_len) +{ +if (WARN_ON (data_offset > sg_len || + data_len > sg_len || + data_offset > sg_len - data_len)) +return -EMSGSIZE ; +return krb5->profile->get_mic (krb5, shash, metadata, sg, nr_sg, sg_len, + data_offset, data_len); +} +EXPORT_SYMBOL (crypto_krb5_get_mic); + +/** +* crypto_krb5_verify_mic - Validate and remove Kerberos integrity checksum. +* @krb5: The encoding to use. +* @shash: The keyed hash to use. +* @metadata: Metadata to add into the hash before adding the data. +* @sg: Scatterlist defining the crypto buffer. +* @nr_sg: The number of elements in @sg. +* @_offset: Offset of the secure blob in the buffer; updated to data offset. +* @_len: The length of the secure blob; updated to data length. +* +* Using the specified Kerberos encoding, check and remove the integrity +* checksum. +* +* If successful, @_offset and @_len are updated to outline the region in which +* the data is stored. +* +* Returns the 0 if successful, -ENOMEM on an allocation failure; sets +* *_error_code and returns -EPROTO if the data cannot be parsed, or -EBADMSG +* if the checksum doesn't match). Other errors may also be returned from the +* crypto layer. +*/ +int crypto_krb5_verify_mic (const struct krb5_enctype *krb5, +struct crypto_shash *shash, +const struct krb5_buffer *metadata, +struct scatterlist *sg,unsigned int nr_sg, +size_t *_offset,size_t *_len) +{ +return krb5->profile->verify_mic (krb5, shash, metadata, sg, nr_sg, + _offset, _len); +} +EXPORT_SYMBOL (crypto_krb5_verify_mic);
include/crypto/krb5.h +21 -0
@@ -117,6 +117,27 @@ struct crypto_aead *crypto_krb5_prepare_encryption(const struct krb5_enctype *krstruct crypto_shash *crypto_krb5_prepare_checksum (const struct krb5_enctype *krb5,const struct krb5_buffer *TK ,u32 usage,gfp_t gfp); +ssize_t crypto_krb5_encrypt (const struct krb5_enctype *krb5, +struct crypto_aead *aead, +struct scatterlist *sg,unsigned int nr_sg, +size_t sg_len, +size_t data_offset,size_t data_len, +bool preconfounded); +int crypto_krb5_decrypt (const struct krb5_enctype *krb5, +struct crypto_aead *aead, +struct scatterlist *sg,unsigned int nr_sg, +size_t *_offset,size_t *_len); +ssize_t crypto_krb5_get_mic (const struct krb5_enctype *krb5, +struct crypto_shash *shash, +const struct krb5_buffer *metadata, +struct scatterlist *sg,unsigned int nr_sg, +size_t sg_len, +size_t data_offset,size_t data_len); +int crypto_krb5_verify_mic (const struct krb5_enctype *krb5, +struct crypto_shash *shash, +const struct krb5_buffer *metadata, +struct scatterlist *sg,unsigned int nr_sg, +size_t *_offset,size_t *_len);/* * krb5enc.c
David Howells
maintainerRFC PATCH 9/24 crypto/krb5: Provide infrastructure and key derivation
In reply to David HowellsProvide key derivation interface functions and a helper to implement the PRF+ function from rfc4402.
--- crypto/krb5/Makefile | 1 + crypto/krb5/internal.h | 10 +++ crypto/krb5/krb5_kdf.c | 145 +++++++++++++++++++++++++++++++++++++++++ include/crypto/krb5.h | 10 +++ 4 files changed, 166 insertions(+) create mode 100644 crypto/krb5/krb5_kdf.c
crypto/krb5/Makefile +1 -0
@@ -4,6 +4,7 @@ # krb5-y += \ + krb5_kdf.o \ krb5_api.o obj-$(CONFIG_CRYPTO_KRB5) += krb5.o
crypto/krb5/internal.h +10 -0
@@ -120,3 +120,13 @@ struct crypto_aead *krb5_prepare_encryption(const struct krb5_enctype *krb5,struct crypto_shash *krb5_prepare_checksum (const struct krb5_enctype *krb5,const struct krb5_buffer *Kc,gfp_t gfp); + +/* +* krb5_kdf.c +*/ +int krb5_derive_Kc (const struct krb5_enctype *krb5,const struct krb5_buffer *TK , +u32 usage,struct krb5_buffer *key,gfp_t gfp); +int krb5_derive_Ke (const struct krb5_enctype *krb5,const struct krb5_buffer *TK , +u32 usage,struct krb5_buffer *key,gfp_t gfp); +int krb5_derive_Ki (const struct krb5_enctype *krb5,const struct krb5_buffer *TK , +u32 usage,struct krb5_buffer *key,gfp_t gfp);
crypto/krb5/krb5_kdf.c new file +145 -0
145 lines not on this page · raw message
include/crypto/krb5.h +10 -0
@@ -139,6 +139,16 @@ int crypto_krb5_verify_mic(const struct krb5_enctype *krb5, struct scatterlist *sg, unsigned int nr_sg, size_t *_offset, size_t *_len); +/* +* krb5_kdf.c +*/ +int crypto_krb5_calc_PRFplus (const struct krb5_enctype *krb5, +const struct krb5_buffer *K , +unsigned int L , +const struct krb5_buffer *S , +struct krb5_buffer *result, +gfp_t gfp); +/* * krb5enc.c */
David Howells
maintainerRFC PATCH 10/24 crypto/krb5: Implement the Kerberos5 rfc3961 key derivation
In reply to David HowellsImplement the 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.
--- crypto/krb5/Makefile | 3 +- crypto/krb5/internal.h | 6 + crypto/krb5/rfc3961_simplified.c | 407 +++++++++++++++++++++++++++++++ 3 files changed, 415 insertions(+), 1 deletion(-) create mode 100644 crypto/krb5/rfc3961_simplified.c
crypto/krb5/Makefile +2 -1
@@ -5,6 +5,7 @@ krb5-y += \ krb5_kdf.o \ - krb5_api.o + krb5_api.o \ + rfc3961_simplified.o obj-$(CONFIG_CRYPTO_KRB5) += krb5.o
crypto/krb5/internal.h +6 -0
@@ -5,6 +5,7 @@* Written by David Howells ([email protected]) */ +#include <linux/scatterlist.h> #include <crypto/krb5.h> /*
@@ -130,3 +131,8 @@ int krb5_derive_Ke(const struct krb5_enctype *krb5, const struct krb5_buffer *TK u32 usage, struct krb5_buffer *key, gfp_t gfp);int krb5_derive_Ki (const struct krb5_enctype *krb5,const struct krb5_buffer *TK ,u32 usage,struct krb5_buffer *key,gfp_t gfp); + +/* +* rfc3961_simplified.c +*/ +extern const struct krb5_crypto_profile rfc3961_simplified_profile;
crypto/krb5/rfc3961_simplified.c new file +407 -0
407 lines not on this page · raw message
David Howells
maintainerRFC PATCH 11/24 crypto/krb5: Provide RFC3961 setkey packaging functions
In reply to David HowellsProvide functions to derive keys according to RFC3961 (or load the derived keys for the selftester where only derived keys are available) and to package them up appropriately for passing to a krb5enc AEAD setkey or a hash setkey function.
--- crypto/krb5/internal.h | 20 ++++++ crypto/krb5/rfc3961_simplified.c | 116 +++++++++++++++++++++++++++++-- 2 files changed, 132 insertions(+), 4 deletions(-)
crypto/krb5/internal.h +20 -0
@@ -136,3 +136,23 @@ int krb5_derive_Ki(const struct krb5_enctype *krb5, const struct krb5_buffer *TK* rfc3961_simplified.c */ extern const struct krb5_crypto_profile rfc3961_simplified_profile; + +int krb5enc_derive_encrypt_keys (const struct krb5_enctype *krb5, +const struct krb5_buffer *TK , +unsigned int usage, +struct krb5_buffer *setkey, +gfp_t gfp); +int krb5enc_load_encrypt_keys (const struct krb5_enctype *krb5, +const struct krb5_buffer *Ke, +const struct krb5_buffer *Ki, +struct krb5_buffer *setkey, +gfp_t gfp); +int rfc3961_derive_checksum_key (const struct krb5_enctype *krb5, +const struct krb5_buffer *TK , +unsigned int usage, +struct krb5_buffer *setkey, +gfp_t gfp); +int rfc3961_load_checksum_key (const struct krb5_enctype *krb5, +const struct krb5_buffer *Kc, +struct krb5_buffer *setkey, +gfp_t gfp);
crypto/krb5/rfc3961_simplified.c +112 -4
121 lines not on this page · raw message
David Howells
maintainerRFC PATCH 12/24 crypto/krb5: Implement the Kerberos5 rfc3961 encrypt and decrypt functions
In reply to David HowellsAdd functions that encrypt and decrypt a message according to rfc3961 sec 5.3, using Ki to checksum the data to be secured and Ke to encrypt it during the encryption phase, then decrypting with Ke and verifying the checksum with Ki in the decryption phase.
--- crypto/krb5/internal.h | 13 +++ crypto/krb5/rfc3961_simplified.c | 146 +++++++++++++++++++++++++++++++ 2 files changed, 159 insertions(+)
crypto/krb5/internal.h +13 -0
@@ -7,6 +7,8 @@#include <linux/scatterlist.h> #include <crypto/krb5.h> +#include <crypto/hash.h> +#include <crypto/skcipher.h> /* * Profile used for key derivation and encryption.
@@ -137,6 +139,8 @@ int krb5_derive_Ki(const struct krb5_enctype *krb5, const struct krb5_buffer *TK*/ extern const struct krb5_crypto_profile rfc3961_simplified_profile; +int crypto_shash_update_sg (struct shash_desc *desc,struct scatterlist *sg, +size_t offset,size_t len); int krb5enc_derive_encrypt_keys(const struct krb5_enctype *krb5, const struct krb5_buffer *TK, unsigned int usage,
@@ -156,3 +160,12 @@ int rfc3961_load_checksum_key(const struct krb5_enctype *krb5,const struct krb5_buffer *Kc, struct krb5_buffer *setkey, gfp_t gfp); +ssize_t krb5_aead_encrypt (const struct krb5_enctype *krb5, +struct crypto_aead *aead, +struct scatterlist *sg,unsigned int nr_sg,size_t sg_len, +size_t data_offset,size_t data_len, +bool preconfounded); +int krb5_aead_decrypt (const struct krb5_enctype *krb5, +struct crypto_aead *aead, +struct scatterlist *sg,unsigned int nr_sg, +size_t *_offset,size_t *_len);
crypto/krb5/rfc3961_simplified.c +146 -0
169 lines not on this page · raw message
David Howells
maintainerRFC PATCH 13/24 crypto/krb5: Implement the Kerberos5 rfc3961 get_mic and verify_mic
In reply to David HowellsAdd functions that sign and verify a message according to rfc3961 sec 5.4, using Kc to generate a checksum and insert it into the MIC field in the skbuff in the sign phase then checksum the data and compare it to the MIC in the verify phase.
--- crypto/krb5/internal.h | 10 +++ crypto/krb5/rfc3961_simplified.c | 130 +++++++++++++++++++++++++++++++ 2 files changed, 140 insertions(+)
crypto/krb5/internal.h +10 -0
@@ -169,3 +169,13 @@ int krb5_aead_decrypt(const struct krb5_enctype *krb5,struct crypto_aead *aead, struct scatterlist *sg, unsigned int nr_sg, size_t *_offset, size_t *_len); +ssize_t rfc3961_get_mic (const struct krb5_enctype *krb5, +struct crypto_shash *shash, +const struct krb5_buffer *metadata, +struct scatterlist *sg,unsigned int nr_sg,size_t sg_len, +size_t data_offset,size_t data_len); +int rfc3961_verify_mic (const struct krb5_enctype *krb5, +struct crypto_shash *shash, +const struct krb5_buffer *metadata, +struct scatterlist *sg,unsigned int nr_sg, +size_t *_offset,size_t *_len);
crypto/krb5/rfc3961_simplified.c +130 -0
140 lines not on this page · raw message
David Howells
maintainerRFC PATCH 14/24 crypto/krb5: Implement the AES enctypes from rfc3962
In reply to David HowellsImplement the aes128-cts-hmac-sha1-96 and aes256-cts-hmac-sha1-96 enctypes from rfc3962, using the rfc3961 kerberos 5 simplified crypto scheme.
--- crypto/krb5/Kconfig | 1 + crypto/krb5/Makefile | 3 +- crypto/krb5/internal.h | 6 ++ crypto/krb5/krb5_api.c | 2 + crypto/krb5/rfc3962_aes.c | 115 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 crypto/krb5/rfc3962_aes.c
crypto/krb5/Kconfig +1 -0
@@ -5,6 +5,7 @@ config CRYPTO_KRB5 select CRYPTO_AUTHENC select CRYPTO_SKCIPHER select CRYPTO_HASH_INFO + select CRYPTO_HMAC select CRYPTO_SHA1 select CRYPTO_CBC select CRYPTO_CTS
crypto/krb5/Makefile +2 -1
@@ -6,6 +6,7 @@ krb5-y += \ krb5_kdf.o \ krb5_api.o \ - rfc3961_simplified.o + rfc3961_simplified.o \ + rfc3962_aes.o obj-$(CONFIG_CRYPTO_KRB5) += krb5.o
crypto/krb5/internal.h +6 -0
@@ -179,3 +179,9 @@ int rfc3961_verify_mic(const struct krb5_enctype *krb5,const struct krb5_buffer *metadata, struct scatterlist *sg, unsigned int nr_sg, size_t *_offset, size_t *_len); + +/* +* rfc3962_aes.c +*/ +extern const struct krb5_enctype krb5_aes128_cts_hmac_sha1_96; +extern const struct krb5_enctype krb5_aes256_cts_hmac_sha1_96;
crypto/krb5/krb5_api.c +2 -0
@@ -17,6 +17,8 @@ MODULE_AUTHOR("Red Hat, Inc.");MODULE_LICENSE ("GPL" );static const struct krb5_enctype *const krb5_supported_enctypes[] = { + &krb5_aes128_cts_hmac_sha1_96, + &krb5_aes256_cts_hmac_sha1_96, };/**
crypto/krb5/rfc3962_aes.c new file +115 -0
115 lines not on this page · raw message
David Howells
maintainerRFC PATCH 15/24 crypto/krb5: Implement the AES enctypes from rfc8009
In reply to David HowellsImplement the aes128-cts-hmac-sha256-128 and aes256-cts-hmac-sha384-192 enctypes from rfc8009, overriding the rfc3961 kerberos 5 simplified crypto scheme.
--- crypto/krb5/Kconfig | 2 + crypto/krb5/Makefile | 3 +- crypto/krb5/internal.h | 16 ++ crypto/krb5/krb5_api.c | 2 + crypto/krb5/rfc8009_aes2.c | 296 +++++++++++++++++++++++++++++++++++++ include/crypto/krb5.h | 4 + 6 files changed, 322 insertions(+), 1 deletion(-) create mode 100644 crypto/krb5/rfc8009_aes2.c
crypto/krb5/Kconfig +2 -0
@@ -7,6 +7,8 @@ config CRYPTO_KRB5 select CRYPTO_HASH_INFO select CRYPTO_HMAC select CRYPTO_SHA1 + select CRYPTO_SHA256 + select CRYPTO_SHA512 select CRYPTO_CBC select CRYPTO_CTS select CRYPTO_AES
crypto/krb5/Makefile +2 -1
@@ -7,6 +7,7 @@ krb5-y += \ krb5_kdf.o \ krb5_api.o \ rfc3961_simplified.o \ - rfc3962_aes.o + rfc3962_aes.o \ + rfc8009_aes2.o obj-$(CONFIG_CRYPTO_KRB5) += krb5.o
crypto/krb5/internal.h +16 -0
@@ -185,3 +185,19 @@ int rfc3961_verify_mic(const struct krb5_enctype *krb5,*/ extern const struct krb5_enctype krb5_aes128_cts_hmac_sha1_96;extern const struct krb5_enctype krb5_aes256_cts_hmac_sha1_96; + +/* +* rfc8009_aes2.c +*/ +extern const struct krb5_enctype krb5_aes128_cts_hmac_sha256_128; +extern const struct krb5_enctype krb5_aes256_cts_hmac_sha384_192; +int authenc_derive_encrypt_keys (const struct krb5_enctype *krb5, +const struct krb5_buffer *TK , +unsigned int usage, +struct krb5_buffer *setkey, +gfp_t gfp); +int authenc_load_encrypt_keys (const struct krb5_enctype *krb5, +const struct krb5_buffer *Ke, +const struct krb5_buffer *Ki, +struct krb5_buffer *setkey, +gfp_t gfp);
crypto/krb5/krb5_api.c +2 -0
@@ -19,6 +19,8 @@ MODULE_LICENSE("GPL");static const struct krb5_enctype *const krb5_supported_enctypes[] = { &krb5_aes128_cts_hmac_sha1_96, &krb5_aes256_cts_hmac_sha1_96, + &krb5_aes128_cts_hmac_sha256_128, + &krb5_aes256_cts_hmac_sha384_192, };/**
crypto/krb5/rfc8009_aes2.c new file +296 -0
296 lines not on this page · raw message
include/crypto/krb5.h +4 -0
@@ -31,6 +31,8 @@ struct scatterlist;#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_AES128_CTS_HMAC_SHA256_128 0x0013 +#define KRB5_ENCTYPE_AES256_CTS_HMAC_SHA384_192 0x0014#define KRB5_ENCTYPE_ARCFOUR_HMAC 0x0017#define KRB5_ENCTYPE_ARCFOUR_HMAC_EXP 0x0018#define KRB5_ENCTYPE_UNKNOWN 0x01ff
@@ -45,6 +47,8 @@ struct scatterlist;#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_SHA256_128_AES128 0x0013 +#define KRB5_CKSUMTYPE_HMAC_SHA384_192_AES256 0x0014#define KRB5_CKSUMTYPE_HMAC_MD5_ARCFOUR -138/* Microsoft md5 hmac cksumtype */ /*
David Howells
maintainerRFC PATCH 16/24 crypto/krb5: Implement the AES encrypt/decrypt from rfc8009
In reply to David HowellsImplement encryption and decryption functions for AES + HMAC-SHA2 as described in rfc8009 sec 5.
--- crypto/krb5/rfc8009_aes2.c | 139 ++++++++++++++++++++++++++++++++++++- 1 file changed, 137 insertions(+), 2 deletions(-)
crypto/krb5/rfc8009_aes2.c +137 -2
@@ -234,6 +234,141 @@ int authenc_load_encrypt_keys(const struct krb5_enctype *krb5,return 0 ; } +/* +* Apply encryption and checksumming functions to a message. Unlike for +* RFC3961, for RFC8009, we have to chuck the starting IV into the hash first. +*/ +static ssize_t rfc8009_encrypt (const struct krb5_enctype *krb5, +struct crypto_aead *aead, +struct scatterlist *sg,unsigned int nr_sg,size_t sg_len, +size_t data_offset,size_t data_len, +bool preconfounded) +{ +struct aead_request *req; +struct scatterlist bsg[2 ]; +ssize_t ret, done; +size_t bsize, base_len, secure_offset, secure_len, pad_len, cksum_offset; +void *buffer; +u8 *iv, *ad; + +if (WARN_ON (data_offset != krb5->conf_len)) +return -EINVAL ;/* Data is in wrong place */ + + secure_offset =0 ; + base_len = krb5->conf_len + data_len; + pad_len =0 ; + secure_len = base_len + pad_len; + cksum_offset = secure_len; +if (WARN_ON (cksum_offset + krb5->cksum_len > sg_len)) +return -EFAULT ; + + bsize =krb5_aead_size (aead) + +krb5_aead_ivsize (aead) *2 ; + buffer =kzalloc (bsize,GFP_NOFS ); +if (!buffer) +return -ENOMEM ; + + req = buffer; + iv = buffer +krb5_aead_size (aead); + ad = buffer +krb5_aead_size (aead) +krb5_aead_ivsize (aead); + +/* Insert the confounder into the buffer */ + ret = -EFAULT ; +if (!preconfounded) { +get_random_bytes (buffer, krb5->conf_len); + done =sg_pcopy_from_buffer (sg, nr_sg, buffer, krb5->conf_len, + secure_offset); +if (done != krb5->conf_len) + goto error; + } + +/* We may need to pad out to the crypto blocksize. */ +if (pad_len) { + done =sg_zero_buffer (sg, nr_sg, pad_len, data_offset + data_len); +if (done != pad_len) + goto error; + } + +/* We need to include the starting IV in the hash. */ +sg_init_table (bsg,2 ); +sg_set_buf (&bsg[0 ], ad,krb5_aead_ivsize (aead)); +sg_chain (bsg,2 , sg); + +/* Hash and encrypt the message. */ +aead_request_set_tfm (req, aead); +aead_request_set_callback (req,0 ,NULL ,NULL ); +aead_request_set_ad (req,krb5_aead_ivsize (aead)); +aead_request_set_crypt (req, bsg, bsg, secure_len, iv); + ret =crypto_aead_encrypt (req); +if (ret <0 ) + goto error; + + ret = secure_len + krb5->cksum_len; + +error: +kfree_sensitive (buffer); +return ret; +} + +/* +* Apply decryption and checksumming functions to a message. Unlike for +* RFC3961, for RFC8009, we have to chuck the starting IV into the hash first. +* +* The offset and length are updated to reflect the actual content of the +* encrypted region. +*/ +static int rfc8009_decrypt (const struct krb5_enctype *krb5, +struct crypto_aead *aead, +struct scatterlist *sg,unsigned int nr_sg, +size_t *_offset,size_t *_len) +{ +struct aead_request *req; +struct scatterlist bsg[2 ]; +size_t bsize; +void *buffer; +int ret; +u8 *iv, *ad; + +if (WARN_ON (*_offset !=0 )) +return -EINVAL ;/* Can't set offset on aead */ + +if (*_len < krb5->conf_len + krb5->cksum_len) +return -EPROTO ; + + bsize =krb5_aead_size (aead) + +krb5_aead_ivsize (aead) *2 ; + buffer =kzalloc (bsize,GFP_NOFS ); +if (!buffer) +return -ENOMEM ; + + req = buffer; + iv = buffer +krb5_aead_size (aead); + ad = buffer +krb5_aead_size (aead) +krb5_aead_ivsize (aead); + +/* We need to include the starting IV in the hash. */ +sg_init_table (bsg,2 ); +sg_set_buf (&bsg[0 ], ad,krb5_aead_ivsize (aead)); +sg_chain (bsg,2 , sg); + +/* Decrypt the message and verify its checksum. */ +aead_request_set_tfm (req, aead); +aead_request_set_callback (req,0 ,NULL ,NULL ); +aead_request_set_ad (req,krb5_aead_ivsize (aead)); +aead_request_set_crypt (req, bsg, bsg, *_len, iv); + ret =crypto_aead_decrypt (req); +if (ret <0 ) + goto error; + +/* Adjust the boundaries of the data. */ + *_offset += krb5->conf_len; + *_len -= krb5->conf_len + krb5->cksum_len; + ret =0 ; + +error: +kfree_sensitive (buffer); +return ret; +} +static const struct krb5_crypto_profile rfc8009_crypto_profile = { .calc_PRF = rfc8009_calc_PRF, .calc_Kc = rfc8009_calc_Ki,
@@ -243,8 +378,8 @@ static const struct krb5_crypto_profile rfc8009_crypto_profile = { .load_encrypt_keys = authenc_load_encrypt_keys, .derive_checksum_key = rfc3961_derive_checksum_key, .load_checksum_key = rfc3961_load_checksum_key, - .encrypt = NULL, //rfc8009_encrypt, - .decrypt = NULL, //rfc8009_decrypt, + .encrypt = rfc8009_encrypt, + .decrypt = rfc8009_decrypt, .get_mic = rfc3961_get_mic, .verify_mic = rfc3961_verify_mic, };
David Howells
maintainerRFC PATCH 17/24 crypto/krb5: Implement crypto self-testing
In reply to David HowellsImplement self-testing infrastructure to test the pseudo-random function, key derivation, encryption and checksumming.
--- crypto/krb5/Kconfig | 7 + crypto/krb5/Makefile | 4 + crypto/krb5/internal.h | 48 ++++ crypto/krb5/krb5_api.c | 11 + crypto/krb5/selftest.c | 544 ++++++++++++++++++++++++++++++++++++ crypto/krb5/selftest_data.c | 38 +++ 6 files changed, 652 insertions(+) create mode 100644 crypto/krb5/selftest.c create mode 100644 crypto/krb5/selftest_data.c
crypto/krb5/Kconfig +7 -0
@@ -15,3 +15,10 @@ config CRYPTO_KRB5 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 +4 -0
@@ -10,4 +10,8 @@ krb5-y += \ rfc3962_aes.o \ rfc8009_aes2.o +krb5-$(CONFIG_CRYPTO_KRB5_SELFTESTS) += \ + selftest.o \ + selftest_data.o + obj-$(CONFIG_CRYPTO_KRB5) += krb5.o
crypto/krb5/internal.h +48 -0
57 lines not on this page · raw message
crypto/krb5/krb5_api.c +11 -0
@@ -437,3 +437,14 @@ int crypto_krb5_verify_mic(const struct krb5_enctype *krb5, _offset, _len); }EXPORT_SYMBOL (crypto_krb5_verify_mic); + +static int __init crypto_krb5_init (void ) +{ +return krb5_selftest (); +} +module_init (crypto_krb5_init); + +static void __exit crypto_krb5_exit(void) +{ +} +module_exit (crypto_krb5_exit);
crypto/krb5/selftest.c new file +544 -0
544 lines not on this page · raw message
crypto/krb5/selftest_data.c new file +38 -0
@@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* Data for Kerberos library self-testing +* +* Copyright (C) 2025 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +*/ + +#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt + +#include "internal.h" + +/* +* Pseudo-random function tests. +*/ +const struct krb5_prf_test krb5_prf_tests[] = { + {/* END */ } +}; + +/* +* Key derivation tests. +*/ +const struct krb5_key_test krb5_key_tests[] = { + {/* END */ } +}; + +/* +* Encryption tests. +*/ +const struct krb5_enc_test krb5_enc_tests[] = { + {/* END */ } +}; + +/* +* Checksum generation tests. +*/ +const struct krb5_mic_test krb5_mic_tests[] = { + {/* END */ } +};
David Howells
maintainerRFC PATCH 18/24 crypto/krb5: Add the AES self-testing data from rfc8009
In reply to David HowellsAdd the self-testing data from rfc8009 to test AES + HMAC-SHA2.
--- crypto/krb5/selftest_data.c | 118 ++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+)
crypto/krb5/selftest_data.c +118 -0
@@ -13,6 +13,22 @@* Pseudo-random function tests. */ const struct krb5_prf_test krb5_prf_tests[] = { +/* rfc8009 Appendix A */ + { + .etype =KRB5_ENCTYPE_AES128_CTS_HMAC_SHA256_128 , + .name ="prf" , + .key ="3705D96080C17728A0E800EAB6E0D23C" , + .octet ="74657374" , + .prf ="9D188616F63852FE86915BB840B4A886FF3E6BB0F819B49B893393D393854295" , + }, { + .etype =KRB5_ENCTYPE_AES256_CTS_HMAC_SHA384_192 , + .name ="prf" , + .key ="6D404D37FAF79F9DF0D33568D320669800EB4836472EA8A026D16B7182460C52" , + .octet ="74657374" , + .prf = +"9801F69A368C2BF675E59521E177D9A07F67EFE1CFDE8D3C8D6F6A0256E3B17D" +"B3C1B62AD1B8553360D17367EB1514D2" , + }, {/* END */ } };
@@ -20,6 +36,28 @@ const struct krb5_prf_test krb5_prf_tests[] = {* Key derivation tests. */ const struct krb5_key_test krb5_key_tests[] = { +/* rfc8009 Appendix A */ + { + .etype =KRB5_ENCTYPE_AES128_CTS_HMAC_SHA256_128 , + .name ="key" , + .key ="3705D96080C17728A0E800EAB6E0D23C" , + .Kc.use =0x00000002 , + .Kc.key ="B31A018A48F54776F403E9A396325DC3" , + .Ke.use =0x00000002 , + .Ke.key ="9B197DD1E8C5609D6E67C3E37C62C72E" , + .Ki.use =0x00000002 , + .Ki.key ="9FDA0E56AB2D85E1569A688696C26A6C" , + }, { + .etype =KRB5_ENCTYPE_AES256_CTS_HMAC_SHA384_192 , + .name ="key" , + .key ="6D404D37FAF79F9DF0D33568D320669800EB4836472EA8A026D16B7182460C52" , + .Kc.use =0x00000002 , + .Kc.key ="EF5718BE86CC84963D8BBB5031E9F5C4BA41F28FAF69E73D" , + .Ke.use =0x00000002 , + .Ke.key ="56AB22BEE63D82D7BC5227F6773F8EA7A5EB1C825160C38312980C442E5C7E49" , + .Ki.use =0x00000002 , + .Ki.key ="69B16514E3CD8E56B82010D5C73012B622C4D00FFC23ED1F" , + }, {/* END */ } };
@@ -27,6 +65,72 @@ const struct krb5_key_test krb5_key_tests[] = {* Encryption tests. */ const struct krb5_enc_test krb5_enc_tests[] = { +/* rfc8009 Appendix A */ + { + .etype =KRB5_ENCTYPE_AES128_CTS_HMAC_SHA256_128 , + .name ="enc no plain" , + .plain ="" , + .conf ="7E5895EAF2672435BAD817F545A37148" , + .Ke ="9B197DD1E8C5609D6E67C3E37C62C72E" , + .Ki ="9FDA0E56AB2D85E1569A688696C26A6C" , + .ct ="EF85FB890BB8472F4DAB20394DCA781DAD877EDA39D50C870C0D5A0A8E48C718" , + }, { + .etype =KRB5_ENCTYPE_AES128_CTS_HMAC_SHA256_128 , + .name ="enc plain<block" , + .plain ="000102030405" , + .conf ="7BCA285E2FD4130FB55B1A5C83BC5B24" , + .Ke ="9B197DD1E8C5609D6E67C3E37C62C72E" , + .Ki ="9FDA0E56AB2D85E1569A688696C26A6C" , + .ct ="84D7F30754ED987BAB0BF3506BEB09CFB55402CEF7E6877CE99E247E52D16ED4421DFDF8976C" , + }, { + .etype =KRB5_ENCTYPE_AES128_CTS_HMAC_SHA256_128 , + .name ="enc plain==block" , + .plain ="000102030405060708090A0B0C0D0E0F" , + .conf ="56AB21713FF62C0A1457200F6FA9948F" , + .Ke ="9B197DD1E8C5609D6E67C3E37C62C72E" , + .Ki ="9FDA0E56AB2D85E1569A688696C26A6C" , + .ct ="3517D640F50DDC8AD3628722B3569D2AE07493FA8263254080EA65C1008E8FC295FB4852E7D83E1E7C48C37EEBE6B0D3" , + }, { + .etype =KRB5_ENCTYPE_AES128_CTS_HMAC_SHA256_128 , + .name ="enc plain>block" , + .plain ="000102030405060708090A0B0C0D0E0F1011121314" , + .conf ="A7A4E29A4728CE10664FB64E49AD3FAC" , + .Ke ="9B197DD1E8C5609D6E67C3E37C62C72E" , + .Ki ="9FDA0E56AB2D85E1569A688696C26A6C" , + .ct ="720F73B18D9859CD6CCB4346115CD336C70F58EDC0C4437C5573544C31C813BCE1E6D072C186B39A413C2F92CA9B8334A287FFCBFC" , + }, { + .etype =KRB5_ENCTYPE_AES256_CTS_HMAC_SHA384_192 , + .name ="enc no plain" , + .plain ="" , + .conf ="F764E9FA15C276478B2C7D0C4E5F58E4" , + .Ke ="56AB22BEE63D82D7BC5227F6773F8EA7A5EB1C825160C38312980C442E5C7E49" , + .Ki ="69B16514E3CD8E56B82010D5C73012B622C4D00FFC23ED1F" , + .ct ="41F53FA5BFE7026D91FAF9BE959195A058707273A96A40F0A01960621AC612748B9BBFBE7EB4CE3C" , + }, { + .etype =KRB5_ENCTYPE_AES256_CTS_HMAC_SHA384_192 , + .name ="enc plain<block" , + .plain ="000102030405" , + .conf ="B80D3251C1F6471494256FFE712D0B9A" , + .Ke ="56AB22BEE63D82D7BC5227F6773F8EA7A5EB1C825160C38312980C442E5C7E49" , + .Ki ="69B16514E3CD8E56B82010D5C73012B622C4D00FFC23ED1F" , + .ct ="4ED7B37C2BCAC8F74F23C1CF07E62BC7B75FB3F637B9F559C7F664F69EAB7B6092237526EA0D1F61CB20D69D10F2" , + }, { + .etype =KRB5_ENCTYPE_AES256_CTS_HMAC_SHA384_192 , + .name ="enc plain==block" , + .plain ="000102030405060708090A0B0C0D0E0F" , + .conf ="53BF8A0D105265D4E276428624CE5E63" , + .Ke ="56AB22BEE63D82D7BC5227F6773F8EA7A5EB1C825160C38312980C442E5C7E49" , + .Ki ="69B16514E3CD8E56B82010D5C73012B622C4D00FFC23ED1F" , + .ct ="BC47FFEC7998EB91E8115CF8D19DAC4BBBE2E163E87DD37F49BECA92027764F68CF51F14D798C2273F35DF574D1F932E40C4FF255B36A266" , + }, { + .etype =KRB5_ENCTYPE_AES256_CTS_HMAC_SHA384_192 , + .name ="enc plain>block" , + .plain ="000102030405060708090A0B0C0D0E0F1011121314" , + .conf ="763E65367E864F02F55153C7E3B58AF1" , + .Ke ="56AB22BEE63D82D7BC5227F6773F8EA7A5EB1C825160C38312980C442E5C7E49" , + .Ki ="69B16514E3CD8E56B82010D5C73012B622C4D00FFC23ED1F" , + .ct ="40013E2DF58E8751957D2878BCD2D6FE101CCFD556CB1EAE79DB3C3EE86429F2B2A602AC86FEF6ECB647D6295FAE077A1FEB517508D2C16B4192E01F62" , + }, {/* END */ } };
@@ -34,5 +138,19 @@ const struct krb5_enc_test krb5_enc_tests[] = {* Checksum generation tests. */ const struct krb5_mic_test krb5_mic_tests[] = { +/* rfc8009 Appendix A */ + { + .etype =KRB5_ENCTYPE_AES128_CTS_HMAC_SHA256_128 , + .name ="mic" , + .plain ="000102030405060708090A0B0C0D0E0F1011121314" , + .Kc ="B31A018A48F54776F403E9A396325DC3" , + .mic ="D78367186643D67B411CBA9139FC1DEE" , + }, { + .etype =KRB5_ENCTYPE_AES256_CTS_HMAC_SHA384_192 , + .name ="mic" , + .plain ="000102030405060708090A0B0C0D0E0F1011121314" , + .Kc ="EF5718BE86CC84963D8BBB5031E9F5C4BA41F28FAF69E73D" , + .mic ="45EE791567EEFCA37F4AC1E0222DE80D43C3BFA06699672A" , + }, {/* END */ } };
David Howells
maintainerRFC PATCH 19/24 crypto/krb5: Implement the Camellia enctypes from rfc6803
In reply to David HowellsImplement 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
--- crypto/krb5/Kconfig | 2 + crypto/krb5/Makefile | 1 + crypto/krb5/internal.h | 6 + crypto/krb5/krb5_api.c | 2 + crypto/krb5/rfc6803_camellia.c | 237 +++++++++++++++++++++++++++++++++ crypto/krb5/selftest_data.c | 135 +++++++++++++++++++ include/crypto/krb5.h | 4 + 7 files changed, 387 insertions(+) create mode 100644 crypto/krb5/rfc6803_camellia.c
crypto/krb5/Kconfig +2 -0
@@ -6,12 +6,14 @@ config CRYPTO_KRB5 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.
crypto/krb5/Makefile +1 -0
@@ -8,6 +8,7 @@ krb5-y += \ krb5_api.o \ rfc3961_simplified.o \ rfc3962_aes.o \ + rfc6803_camellia.o \ rfc8009_aes2.o krb5-$(CONFIG_CRYPTO_KRB5_SELFTESTS) += \
crypto/krb5/internal.h +6 -0
@@ -217,6 +217,12 @@ int rfc3961_verify_mic(const struct krb5_enctype *krb5,extern const struct krb5_enctype krb5_aes128_cts_hmac_sha1_96;extern const struct krb5_enctype krb5_aes256_cts_hmac_sha1_96; +/* +* rfc6803_camellia.c +*/ +extern const struct krb5_enctype krb5_camellia128_cts_cmac; +extern const struct krb5_enctype krb5_camellia256_cts_cmac; +/* * rfc8009_aes2.c */
crypto/krb5/krb5_api.c +2 -0
@@ -21,6 +21,8 @@ static const struct krb5_enctype *const krb5_supported_enctypes[] = { &krb5_aes256_cts_hmac_sha1_96, &krb5_aes128_cts_hmac_sha256_128, &krb5_aes256_cts_hmac_sha384_192, + &krb5_camellia128_cts_cmac, + &krb5_camellia256_cts_cmac, };/**
crypto/krb5/rfc6803_camellia.c new file +237 -0
237 lines not on this page · raw message
crypto/krb5/selftest_data.c +135 -0
152 lines not on this page · raw message
include/crypto/krb5.h +4 -0
@@ -35,6 +35,8 @@ struct scatterlist;#define KRB5_ENCTYPE_AES256_CTS_HMAC_SHA384_192 0x0014#define KRB5_ENCTYPE_ARCFOUR_HMAC 0x0017#define KRB5_ENCTYPE_ARCFOUR_HMAC_EXP 0x0018 +#define KRB5_ENCTYPE_CAMELLIA128_CTS_CMAC 0x0019 +#define KRB5_ENCTYPE_CAMELLIA256_CTS_CMAC 0x001a#define KRB5_ENCTYPE_UNKNOWN 0x01ff#define KRB5_CKSUMTYPE_CRC32 0x0001
@@ -47,6 +49,8 @@ struct scatterlist;#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_CMAC_CAMELLIA128 0x0011 +#define KRB5_CKSUMTYPE_CMAC_CAMELLIA256 0x0012#define KRB5_CKSUMTYPE_HMAC_SHA256_128_AES128 0x0013#define KRB5_CKSUMTYPE_HMAC_SHA384_192_AES256 0x0014#define KRB5_CKSUMTYPE_HMAC_MD5_ARCFOUR -138/* Microsoft md5 hmac cksumtype */
David Howells
maintainerRFC PATCH 20/24 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 21/24 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 22/24 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 | 48 +++++++ net/rxrpc/rxgk_kdf.c | 287 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 350 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 +48 -0
48 lines not on this page · raw message
net/rxrpc/rxgk_kdf.c new file +287 -0
287 lines not on this page · raw message
David Howells
maintainerRFC PATCH 23/24 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 | 1026 ++++++++++++++++++++++++++++++++++ net/rxrpc/rxgk_app.c | 284 ++++++++++ net/rxrpc/rxgk_common.h | 92 +++ net/rxrpc/rxkad.c | 6 +- net/rxrpc/security.c | 3 + 11 files changed, 1485 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 +1026 -0
1,026 lines not on this page · raw message
net/rxrpc/rxgk_app.c new file +284 -0
284 lines not on this page · raw message
net/rxrpc/rxgk_common.h +92 -0
101 lines not on this page · raw message
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 24/24 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
Quoted 12 lines · David Howells
Hi Herbert, Chuck,
Here's yet another 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.
I added an addition AEAD template type, derived from authenc, that does hash-then-crypt rather than crypt-then-hash as authenc does. I called it "krb5enc" for want of a better name. Possibly I should call it "hashenc" or something like that.
Quoted 4 lines
I went back to my previous more library-based approach, but for encrypt mode, I replaced the separate skcipher and shash objects with a single templated AEAD object - either krb5enc (AES+SHA1 and Camellia) or authenc (AES+SHA2).
I'm philosophically in favor of sharing this code. One of the biggest benefits will be making review/audit easier. Another will be the opportunities for more hardware acceleration.
But I can't tell if the library API as laid out here will be a good fit for SunRPC and our kernel XDR implementation until I actually try to use the API, which I don't have time for right now. The set of enctypes indeed seems sufficient to support GSS-API Kerberos, and that is a fundamental requirement for us.
The Linux in-kernel SMB community might be interested in sharing some of this too, though they seem to have grown their own enctypes. The Cc list on the thread is already substantial, but they should be included.
I think it would be fine to merge this, as long as the crypto folks are happy with it, with its current single consumer (RxRPC), and then we can explore broader sharing.
Quoted 113 lines
Apart from that, things are much as they were previously from the point of view of someone using the API. There's a new pair of functions that, given an encoding type, a key and a usage value, will derive the necessary keys and return an AEAD or hash handle. These handles can then be passed to operation functions that will do the actual work of performing an encryption, a decryption, MIC generation or MIC verification.
Querying functions are also available to look up an encoding type table by kerberos protocol number and to help manage message layout.
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, though these have to be provisioned with the intermediate subkeys rather than the transport key.
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 (24):
crypto/krb5: Add API Documentation
crypto/krb5: Add some constants out of sunrpc headers
crypto: Add 'krb5enc' hash and cipher AEAD algorithmcrypto/krb5: Test manager data
crypto/krb5: Implement Kerberos crypto core
crypto/krb5: Add an API to query the layout of the crypto sectioncrypto/krb5: Add an API to alloc and prepare a crypto objectcrypto/krb5: Add an API to perform requests
crypto/krb5: Provide infrastructure and key derivationcrypto/krb5: Implement the Kerberos5 rfc3961 key derivationcrypto/krb5: Provide RFC3961 setkey packaging functionscrypto/krb5: Implement the Kerberos5 rfc3961 encrypt and decrypt
functions
crypto/krb5: Implement the Kerberos5 rfc3961get_micandverify_miccrypto/krb5: Implement the AES enctypes from rfc3962crypto/krb5: Implement the AES enctypes from rfc8009crypto/krb5: Implement the AES encrypt/decrypt from rfc8009crypto/krb5: Implement crypto self-testing
crypto/krb5: Add the AES self-testing data from rfc8009crypto/krb5: Implement the Camellia enctypes from rfc6803
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 rekeyingDocumentation/crypto/index.rst | 1 + Documentation/crypto/krb5.rst | 262 +++++++ crypto/Kconfig | 13 + crypto/Makefile | 3 + crypto/krb5/Kconfig | 26 + crypto/krb5/Makefile | 18 + crypto/krb5/internal.h | 257 +++++++ crypto/krb5/krb5_api.c | 452 ++++++++++++ crypto/krb5/krb5_kdf.c | 145 ++++ crypto/krb5/rfc3961_simplified.c | 791 ++++++++++++++++++++ crypto/krb5/rfc3962_aes.c | 115 +++ crypto/krb5/rfc6803_camellia.c | 237 ++++++ crypto/krb5/rfc8009_aes2.c | 431 +++++++++++ crypto/krb5/selftest.c | 544 ++++++++++++++ crypto/krb5/selftest_data.c | 291 ++++++++ crypto/krb5enc.c | 491 +++++++++++++ crypto/testmgr.c | 16 + crypto/testmgr.h | 401 ++++++++++ fs/afs/misc.c | 13 + include/crypto/krb5.h | 167 +++++ 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 | 1170 ++++++++++++++++++++++++++++++ net/rxrpc/rxgk_app.c | 284 ++++++++ net/rxrpc/rxgk_common.h | 140 ++++ net/rxrpc/rxgk_kdf.c | 287 ++++++++ net/rxrpc/rxkad.c | 6 +- net/rxrpc/security.c | 3 + 37 files changed, 6874 insertions(+), 5 deletions(-)create mode 100644
Documentation/crypto/krb5.rstcreate mode 100644crypto/krb5/Kconfigcreate mode 100644crypto/krb5/Makefilecreate mode 100644crypto/krb5/internal.hcreate mode 100644crypto/krb5/krb5_api.ccreate mode 100644crypto/krb5/krb5_kdf.ccreate mode 100644crypto/krb5/rfc3961_simplified.ccreate mode 100644crypto/krb5/rfc3962_aes.ccreate mode 100644crypto/krb5/rfc6803_camellia.ccreate mode 100644crypto/krb5/rfc8009_aes2.ccreate mode 100644crypto/krb5/selftest.ccreate mode 100644crypto/krb5/selftest_data.ccreate mode 100644crypto/krb5enc.c
create mode 100644include/crypto/krb5.hcreate mode 100644net/rxrpc/rxgk.c
create mode 100644net/rxrpc/rxgk_app.ccreate mode 100644net/rxrpc/rxgk_common.hcreate mode 100644net/rxrpc/rxgk_kdf.c
Signature · 1 line
Chuck Lever