crypto/krb5: Add some constants out of sunrpc headers
Subsystems (7)
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/29 crypto/krb5: Add some constants out of sunrpc headers
From: David Howells <[email protected]>
Add 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 */
Signature · 1 line
2.50.1
PATCH 2/29 crypto/krb5: Implement Kerberos crypto core
In reply to a message not in the archiveFrom: David Howells <[email protected]>
Provide 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
@@ -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 +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
64 lines not on this page · raw message
Signature · 1 line
2.50.1
PATCH 3/29 crypto/krb5: Add an API to query the layout of the crypto section
In reply to a message not in the archiveFrom: David Howells <[email protected]>
Provide 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,5 +101,14 @@ 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);#endif /* _CRYPTO_KRB5_H */
Signature · 1 line
2.50.1
PATCH 4/29 crypto/krb5: Add an API to alloc and prepare a crypto object
In reply to a message not in the archiveFrom: David Howells <[email protected]>
Add 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,5 +111,11 @@ 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);#endif /* _CRYPTO_KRB5_H */
Signature · 1 line
2.50.1
PATCH 5/29 crypto/krb5: Add an API to perform requests
In reply to a message not in the archiveFrom: David Howells <[email protected]>
Add 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,5 +117,26 @@ 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);#endif /* _CRYPTO_KRB5_H */
Signature · 1 line
2.50.1
PATCH 6/29 crypto/krb5: Provide infrastructure and key derivation
In reply to a message not in the archiveFrom: David Howells <[email protected]>
Provide 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,4 +139,14 @@ 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); +#endif /* _CRYPTO_KRB5_H */
Signature · 1 line
2.50.1
PATCH 7/29 crypto/krb5: Implement the Kerberos5 rfc3961 key derivation
In reply to a message not in the archiveFrom: David Howells <[email protected]>
Implement 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
Signature · 1 line
2.50.1
PATCH 8/29 crypto/krb5: Provide RFC3961 setkey packaging functions
In reply to a message not in the archiveFrom: David Howells <[email protected]>
Provide 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 | 122 ++++++++++++++++++++++++++++++- 2 files changed, 138 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 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); +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 +118 -4
133 lines not on this page · raw message
Signature · 1 line
2.50.1
PATCH 9/29 crypto/krb5: Implement the Kerberos5 rfc3961 encrypt and decrypt functions
In reply to a message not in the archiveFrom: David Howells <[email protected]>
Add 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 authenc_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
Signature · 1 line
2.50.1
PATCH 10/29 crypto/krb5: Implement the Kerberos5 rfc3961 get_mic and verify_mic
In reply to a message not in the archiveFrom: David Howells <[email protected]>
Add 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
Signature · 1 line
2.50.1
PATCH 11/29 crypto/krb5: Implement the AES enctypes from rfc3962
In reply to a message not in the archiveFrom: David Howells <[email protected]>
Implement 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
Signature · 1 line
2.50.1
PATCH 12/29 crypto/krb5: Implement the AES enctypes from rfc8009
In reply to a message not in the archiveFrom: David Howells <[email protected]>
Implement 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 | 6 + crypto/krb5/krb5_api.c | 2 + crypto/krb5/rfc8009_aes2.c | 362 +++++++++++++++++++++++++++++++++++++ include/crypto/krb5.h | 4 + 6 files changed, 378 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 +6 -0
@@ -185,3 +185,9 @@ 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;
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 +362 -0
362 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 */ /*
Signature · 1 line
2.50.1
PATCH 13/29 crypto/krb5: Implement the Camellia enctypes from rfc6803
In reply to a message not in the archiveFrom: David Howells <[email protected]>
Implement 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 +++++++++++++++++++++++++++++++++ include/crypto/krb5.h | 4 + 6 files changed, 252 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 obj-$(CONFIG_CRYPTO_KRB5) += krb5.o
crypto/krb5/internal.h +6 -0
@@ -186,6 +186,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
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 */
Signature · 1 line
2.50.1
PATCH 14/29 crypto/krb5: Implement crypto self-testing
In reply to a message not in the archiveFrom: David Howells <[email protected]>
Implement self-testing infrastructure to test the pseudo-random function, key derivation, encryption and checksumming.
Add the testing data from rfc8009 to test AES + HMAC-SHA2.
Add the testing data from rfc6803 to test Camellia. Note some encryption test vectors here 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 | 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 | 291 +++++++++++++++++++ 6 files changed, 905 insertions(+) create mode 100644 crypto/krb5/selftest.c create mode 100644 crypto/krb5/selftest_data.c
crypto/krb5/Kconfig +7 -0
@@ -17,3 +17,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
@@ -11,4 +11,8 @@ krb5-y += \ 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 +48 -0
57 lines not on this page · raw message
crypto/krb5/krb5_api.c +11 -0
@@ -439,3 +439,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 +291 -0
291 lines not on this page · raw message
Signature · 1 line
2.50.1
PATCH 19/29 crypto/krb5: Add API Documentation
In reply to a message not in the archiveFrom: David Howells <[email protected]>
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
Signature · 1 line
2.50.1
PATCH 21/29 crypto: krb5 - filter out async aead implementations at alloc
In reply to a message not in the archiveFrom: Michael Bommarito <[email protected]>
commit 6c9dddeb582fde005360f4fe02c760d45ca05fb5 upstream.
krb5_aead_encrypt(), krb5_aead_decrypt() in rfc3961_simplified.c and rfc8009_encrypt(), rfc8009_decrypt() in rfc8009_aes2.c set a NULL completion callback and treat any negative return from crypto_aead_{encrypt,decrypt}() as terminal, falling through to kfree_sensitive(buffer). When the encrypt_name resolves to an async AEAD instance the request returns -EINPROGRESS, the buffer is freed while the backend's worker still holds a pointer, and the worker dereferences the freed slab on completion.
KASAN report under UML+SLUB with a synthetic async aead backend bound to krb5->encrypt_name:
BUG: KASAN: slab-use-after-free in t5_stub_complete+0x7d/0xc7
The helpers were written synchronously, so filter the async instances out at allocation time instead of plumbing crypto_wait_req() through every call site.
Reachable via net/rxrpc/rxgk.c, fs/afs/cm_security.c and net/ceph/crypto.c on systems with an async AEAD provider bound to the krb5 enctype name.
--- crypto/krb5/krb5_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
crypto/krb5/krb5_api.c +1 -1
@@ -207,7 +207,7 @@ struct crypto_aead *krb5_prepare_encryption(const struct krb5_enctype *krb5,struct crypto_aead *ci =NULL ;int ret = -ENOMEM ; - ci =crypto_alloc_aead (krb5->encrypt_name,0 ,0 ); + ci =crypto_alloc_aead (krb5->encrypt_name,0 ,CRYPTO_ALG_ASYNC );if (IS_ERR (ci)) { ret =PTR_ERR (ci);if (ret == -ENOENT )
Signature · 1 line
2.50.1
PATCH 22/29 crypto: krb5 - use kfree_sensitive() for derived key buffers
In reply to a message not in the archiveFrom: Jan Sebastian Götte <[email protected]>
commit f7d53dd3f267e46a784f219a75072f2f400d42b9 upstream.
crypto_krb5_prepare_encryption() and crypto_krb5_prepare_checksum() free the buffer holding the freshly derived keys with plain kfree(), leaving the key material behind in the freed slab object.
--- crypto/krb5/krb5_api.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
crypto/krb5/krb5_api.c +4 -4
@@ -263,10 +263,10 @@ struct crypto_aead *crypto_krb5_prepare_encryption(const struct krb5_enctype *kr goto err; } -kfree (keys.data); +kfree_sensitive (keys.data);return ci; err: -kfree (keys.data); +kfree_sensitive (keys.data);return ERR_PTR (ret); }EXPORT_SYMBOL (crypto_krb5_prepare_encryption);
@@ -333,10 +333,10 @@ struct crypto_shash *crypto_krb5_prepare_checksum(const struct krb5_enctype *krb goto err; } -kfree (keys.data); +kfree_sensitive (keys.data);return ci; err: -kfree (keys.data); +kfree_sensitive (keys.data);return ERR_PTR (ret); }EXPORT_SYMBOL (crypto_krb5_prepare_checksum);
Signature · 1 line
2.50.1