diff --git a/include/openssl/bn.h b/include/openssl/bn.h index c3acc8f911..16c85440e0 100644 --- a/include/openssl/bn.h +++ b/include/openssl/bn.h @@ -975,10 +975,9 @@ OPENSSL_EXPORT unsigned BN_num_bits_word(BN_ULONG l); #define BN_FLG_STATIC_DATA 0x02 // |BN_FLG_CONSTTIME| has been removed and intentionally omitted so code relying -// on it will not compile unless the flag above is set. Consumers should use the -// higher-level cryptographic algorithms exposed by other modules. Consumers -// within the library should call the appropriate timing-sensitive algorithm -// directly. +// on it will not compile. External consumers should use the higher-level +// cryptographic algorithms exposed by other modules. Consumers within the +// library should call the appropriate timing-sensitive algorithm directly. #if defined(__cplusplus) diff --git a/include/openssl/modes.h b/include/openssl/modes.h index 83c016a2c8..c3899d423c 100644 --- a/include/openssl/modes.h +++ b/include/openssl/modes.h @@ -29,10 +29,10 @@ typedef void (*cbc128_f)(const uint8_t *in, uint8_t *out, size_t len, const AES_KEY *key, uint8_t ivec[16], int enc); // CRYPTO_cts128_encrypt encrypts |len| bytes from |in| to |out| in CBC -// Ciphertext Stealing (CTS) mode (CS1 / RFC 2040 convention: the last two -// ciphertext blocks are unconditionally swapped, and an exact-block-multiple -// input is handled as a 16-byte residue). The IV is updated in |ivec|. |key| -// must have been set up for encryption. +// Ciphertext Stealing (CTS) mode (CS3 / NIST SP 800-38A Addendum convention: +// the last two ciphertext blocks are unconditionally swapped, and an +// exact-block-multiple input is handled as a 16-byte residue). The IV is +// updated in |ivec|. |key| must have been set up for encryption. // // Returns the number of bytes written, equal to |len|, on success. Returns // zero if |len| <= 16; for inputs of one block or fewer use plain CBC. diff --git a/tests/ci/integration/krb5_patch/0002-Gate-K5_OPENSSL_CAMELLIA-on-OPENSSL_NO_CAMELLIA.patch b/tests/ci/integration/krb5_patch/0002-Gate-K5_OPENSSL_CAMELLIA-on-OPENSSL_NO_CAMELLIA.patch deleted file mode 100644 index f841650edb..0000000000 --- a/tests/ci/integration/krb5_patch/0002-Gate-K5_OPENSSL_CAMELLIA-on-OPENSSL_NO_CAMELLIA.patch +++ /dev/null @@ -1,249 +0,0 @@ -From: AWS-LC integration CI -Subject: [PATCH] Disable Camellia enctypes when OPENSSL_NO_CAMELLIA is defined - -AWS-LC does not implement Camellia and defines OPENSSL_NO_CAMELLIA in -. Gate the K5_OPENSSL_CAMELLIA macro, all -Camellia enctype/checksum table entries, and Camellia references in -the crypto test suite on !OPENSSL_NO_CAMELLIA so the build succeeds, -`make check` passes, and krb5 simply omits Camellia enctypes at -runtime. AES-CTS is the mandatory-to-implement Kerberos enctype, so -this is safe. - ---- -diff --git a/src/lib/crypto/crypto_tests/camellia-test.c b/src/lib/crypto/crypto_tests/camellia-test.c -index ca6579f..494ceac 100644 ---- a/src/lib/crypto/crypto_tests/camellia-test.c -+++ b/src/lib/crypto/crypto_tests/camellia-test.c -@@ -28,6 +28,10 @@ - */ - - #include -+#include -+#ifdef OPENSSL_NO_CAMELLIA -+int main(void) { return 0; } -+#else - #include "crypto_int.h" - - static char key[32]; -@@ -139,3 +143,4 @@ int main (int argc, char *argv[]) - vt_test(); - return 0; - } -+#endif -diff --git a/src/lib/crypto/crypto_tests/t_cksums.c b/src/lib/crypto/crypto_tests/t_cksums.c -index 557340e..6f9b5b3 100644 ---- a/src/lib/crypto/crypto_tests/t_cksums.c -+++ b/src/lib/crypto/crypto_tests/t_cksums.c -@@ -102,6 +102,7 @@ struct test { - { KV5M_DATA, 16, - "\xEB\x38\xCC\x97\xE2\x23\x0F\x59\xDA\x41\x17\xDC\x58\x59\xD7\xEC" } - }, -+#if defined(K5_OPENSSL_CAMELLIA) || defined(K5_BUILTIN_CAMELLIA) - { - { KV5M_DATA, 11, "abcdefghijk" }, - CKSUMTYPE_CMAC_CAMELLIA128, ENCTYPE_CAMELLIA128_CTS_CMAC, 7, -@@ -136,6 +137,7 @@ struct test { - { KV5M_DATA, 16, - "\x3F\xA0\xB4\x23\x55\xE5\x2B\x18\x91\x87\x29\x4A\xA2\x52\xAB\x64" } - }, -+#endif - { - { KV5M_DATA, 21, - "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F" -diff --git a/src/lib/crypto/crypto_tests/t_cmac.c b/src/lib/crypto/crypto_tests/t_cmac.c -index 565c35d..4cc3e58 100644 ---- a/src/lib/crypto/crypto_tests/t_cmac.c -+++ b/src/lib/crypto/crypto_tests/t_cmac.c -@@ -40,6 +40,10 @@ - - #include "crypto_int.h" - -+#if !defined(K5_OPENSSL_CAMELLIA) && !defined(K5_BUILTIN_CAMELLIA) -+int main(void) { return 0; } -+#else -+ - /* All examples use the following Camellia-128 key. */ - static unsigned char keybytes[] = { - 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, -@@ -145,3 +149,4 @@ main(int argc, char **argv) - krb5_k_free_key(context, key); - return 0; - } -+#endif -diff --git a/src/lib/crypto/crypto_tests/t_decrypt.c b/src/lib/crypto/crypto_tests/t_decrypt.c -index a40a855..d508173 100644 ---- a/src/lib/crypto/crypto_tests/t_decrypt.c -+++ b/src/lib/crypto/crypto_tests/t_decrypt.c -@@ -300,6 +300,7 @@ struct test { - "\xB7\x34\xD4\xD4\x98\xB6\x71\x4F\x1C\x1D" } - }, - -+#if defined(K5_OPENSSL_CAMELLIA) || defined(K5_BUILTIN_CAMELLIA) - { - ENCTYPE_CAMELLIA128_CTS_CMAC, - { KV5M_DATA, 0, "", }, 0, -@@ -406,6 +407,7 @@ struct test { - "\xF3\x4A\xD1\x25\x5A\x34\x49\x99\xAD\x37\x14\x68\x87\xA6\xC6\x84" - "\x57\x31\xAC\x7F\x46\x37\x6A\x05\x04\xCD\x06\x57\x14\x74" } - }, -+#endif - - { - ENCTYPE_AES128_CTS_HMAC_SHA256_128, -@@ -529,8 +531,10 @@ enctypes[] = { - ENCTYPE_ARCFOUR_HMAC_EXP, - ENCTYPE_AES128_CTS_HMAC_SHA1_96, - ENCTYPE_AES256_CTS_HMAC_SHA1_96, -+#if defined(K5_OPENSSL_CAMELLIA) || defined(K5_BUILTIN_CAMELLIA) - ENCTYPE_CAMELLIA128_CTS_CMAC, - ENCTYPE_CAMELLIA256_CTS_CMAC, -+#endif - ENCTYPE_AES128_CTS_HMAC_SHA256_128, - ENCTYPE_AES256_CTS_HMAC_SHA384_192 - }; -diff --git a/src/lib/crypto/crypto_tests/t_derive.c b/src/lib/crypto/crypto_tests/t_derive.c -index afbf747..e7a1ce3 100644 ---- a/src/lib/crypto/crypto_tests/t_derive.c -+++ b/src/lib/crypto/crypto_tests/t_derive.c -@@ -138,6 +138,7 @@ struct test { - }, - - /* Kc, Ke, Ki for a Camellia-128 key */ -+#if defined(K5_OPENSSL_CAMELLIA) || defined(K5_BUILTIN_CAMELLIA) - { - ENCTYPE_CAMELLIA128_CTS_CMAC, - { KV5M_DATA, 16, -@@ -200,6 +201,7 @@ struct test { - "\xFA\x62\x4F\xA0\xE5\x23\x99\x3F\xA3\x88\xAE\xFD\xC6\x7E\x67\xEB" - "\xCD\x8C\x08\xE8\xA0\x24\x6B\x1D\x73\xB0\xD1\xDD\x9F\xC5\x82\xB0" } - }, -+#endif - - /* Kc, Ke, Ki for an aes128-sha2 key. */ - { -@@ -289,8 +291,10 @@ get_enc_provider(krb5_enctype enctype) - case ENCTYPE_DES3_CBC_SHA1: return &krb5int_enc_des3; - case ENCTYPE_AES128_CTS_HMAC_SHA1_96: return &krb5int_enc_aes128; - case ENCTYPE_AES256_CTS_HMAC_SHA1_96: return &krb5int_enc_aes256; -+#if defined(K5_OPENSSL_CAMELLIA) || defined(K5_BUILTIN_CAMELLIA) - case ENCTYPE_CAMELLIA128_CTS_CMAC: return &krb5int_enc_camellia128; - case ENCTYPE_CAMELLIA256_CTS_CMAC: return &krb5int_enc_camellia256; -+#endif - case ENCTYPE_AES128_CTS_HMAC_SHA256_128: return &krb5int_enc_aes128; - case ENCTYPE_AES256_CTS_HMAC_SHA384_192: return &krb5int_enc_aes256; - } -diff --git a/src/lib/crypto/crypto_tests/t_encrypt.c b/src/lib/crypto/crypto_tests/t_encrypt.c -index 64092ef..5d38fdc 100644 ---- a/src/lib/crypto/crypto_tests/t_encrypt.c -+++ b/src/lib/crypto/crypto_tests/t_encrypt.c -@@ -42,8 +42,10 @@ krb5_enctype interesting_enctypes[] = { - ENCTYPE_ARCFOUR_HMAC_EXP, - ENCTYPE_AES256_CTS_HMAC_SHA1_96, - ENCTYPE_AES128_CTS_HMAC_SHA1_96, -+#if defined(K5_OPENSSL_CAMELLIA) || defined(K5_BUILTIN_CAMELLIA) - ENCTYPE_CAMELLIA128_CTS_CMAC, - ENCTYPE_CAMELLIA256_CTS_CMAC, -+#endif - ENCTYPE_AES128_CTS_HMAC_SHA256_128, - ENCTYPE_AES256_CTS_HMAC_SHA384_192, - 0 -diff --git a/src/lib/crypto/crypto_tests/t_short.c b/src/lib/crypto/crypto_tests/t_short.c -index d4c2b97..e0095d1 100644 ---- a/src/lib/crypto/crypto_tests/t_short.c -+++ b/src/lib/crypto/crypto_tests/t_short.c -@@ -39,8 +39,10 @@ krb5_enctype interesting_enctypes[] = { - ENCTYPE_ARCFOUR_HMAC_EXP, - ENCTYPE_AES256_CTS_HMAC_SHA1_96, - ENCTYPE_AES128_CTS_HMAC_SHA1_96, -+#if defined(K5_OPENSSL_CAMELLIA) || defined(K5_BUILTIN_CAMELLIA) - ENCTYPE_CAMELLIA128_CTS_CMAC, - ENCTYPE_CAMELLIA256_CTS_CMAC, -+#endif - ENCTYPE_AES128_CTS_HMAC_SHA256_128, - ENCTYPE_AES256_CTS_HMAC_SHA384_192, - 0 -diff --git a/src/lib/crypto/crypto_tests/t_str2key.c b/src/lib/crypto/crypto_tests/t_str2key.c -index cdb1acc..3f30673 100644 ---- a/src/lib/crypto/crypto_tests/t_str2key.c -+++ b/src/lib/crypto/crypto_tests/t_str2key.c -@@ -250,6 +250,7 @@ struct test { - }, - - /* The same inputs applied to Camellia enctypes. */ -+#if defined(K5_OPENSSL_CAMELLIA) || defined(K5_BUILTIN_CAMELLIA) - { - ENCTYPE_CAMELLIA128_CTS_CMAC, - "password", -@@ -410,6 +411,7 @@ struct test { - KRB5_ERR_BAD_S2K_PARAMS, - FALSE - }, -+#endif - - { - ENCTYPE_AES128_CTS_HMAC_SHA256_128, -diff --git a/src/lib/crypto/krb/cksumtypes.c b/src/lib/crypto/krb/cksumtypes.c -index f7ba322..2a536c5 100644 ---- a/src/lib/crypto/krb/cksumtypes.c -+++ b/src/lib/crypto/krb/cksumtypes.c -@@ -83,6 +83,7 @@ const struct krb5_cksumtypes krb5int_cksumtypes_list[] = { - krb5int_hmacmd5_checksum, NULL, - 16, 16, 0 }, - -+#if defined(K5_OPENSSL_CAMELLIA) || defined(K5_BUILTIN_CAMELLIA) - { CKSUMTYPE_CMAC_CAMELLIA128, - "cmac-camellia128", { 0 }, "CMAC Camellia128 key", - &krb5int_enc_camellia128, NULL, -@@ -94,6 +95,7 @@ const struct krb5_cksumtypes krb5int_cksumtypes_list[] = { - &krb5int_enc_camellia256, NULL, - krb5int_dk_cmac_checksum, NULL, - 16, 16, 0 }, -+#endif - - { CKSUMTYPE_HMAC_SHA256_128_AES128, - "hmac-sha256-128-aes128", { 0 }, "HMAC-SHA256 AES128 key", -diff --git a/src/lib/crypto/krb/crypto_int.h b/src/lib/crypto/krb/crypto_int.h -index 3629616..c83ee13 100644 ---- a/src/lib/crypto/krb/crypto_int.h -+++ b/src/lib/crypto/krb/crypto_int.h -@@ -62,7 +62,9 @@ - #endif - - #define K5_OPENSSL_AES -+#ifndef OPENSSL_NO_CAMELLIA - #define K5_OPENSSL_CAMELLIA -+#endif - #define K5_OPENSSL_DES - #define K5_OPENSSL_HMAC - #define K5_OPENSSL_MD5 -@@ -474,8 +476,10 @@ extern const struct krb5_enc_provider krb5int_enc_aes128; - extern const struct krb5_enc_provider krb5int_enc_aes256; - extern const struct krb5_enc_provider krb5int_enc_aes128_ctr; - extern const struct krb5_enc_provider krb5int_enc_aes256_ctr; -+#if defined(K5_OPENSSL_CAMELLIA) || defined(K5_BUILTIN_CAMELLIA) - extern const struct krb5_enc_provider krb5int_enc_camellia128; - extern const struct krb5_enc_provider krb5int_enc_camellia256; -+#endif - - extern const struct krb5_hash_provider krb5int_hash_md4; - extern const struct krb5_hash_provider krb5int_hash_md5; -diff --git a/src/lib/crypto/krb/etypes.c b/src/lib/crypto/krb/etypes.c -index fc27878..8aa85b2 100644 ---- a/src/lib/crypto/krb/etypes.c -+++ b/src/lib/crypto/krb/etypes.c -@@ -103,6 +103,7 @@ const struct krb5_keytypes krb5int_enctypes_list[] = { - CKSUMTYPE_HMAC_SHA1_96_AES256, - 0 /*flags*/, 256 }, - -+#if defined(K5_OPENSSL_CAMELLIA) || defined(K5_BUILTIN_CAMELLIA) - { ENCTYPE_CAMELLIA128_CTS_CMAC, - "camellia128-cts-cmac", { "camellia128-cts" }, - "Camellia-128 CTS mode with CMAC", -@@ -125,6 +126,7 @@ const struct krb5_keytypes krb5int_enctypes_list[] = { - krb5int_dk_cmac_prf, - CKSUMTYPE_CMAC_CAMELLIA256, - 0 /*flags */, 256 }, -+#endif - - { ENCTYPE_AES128_CTS_HMAC_SHA256_128, - "aes128-cts-hmac-sha256-128", { "aes128-sha2" }, diff --git a/tests/ci/integration/krb5_patch/0002-Use-built-in-Camellia-when-building-against-AWS-LC.patch b/tests/ci/integration/krb5_patch/0002-Use-built-in-Camellia-when-building-against-AWS-LC.patch new file mode 100644 index 0000000000..7487ee2f49 --- /dev/null +++ b/tests/ci/integration/krb5_patch/0002-Use-built-in-Camellia-when-building-against-AWS-LC.patch @@ -0,0 +1,33 @@ +From: AWS-LC integration CI +Subject: [PATCH] Use built-in Camellia when building against AWS-LC + +AWS-LC does not implement Camellia, so krb5's OpenSSL Camellia +enc_provider (guarded on K5_OPENSSL_CAMELLIA) cannot link against it. +Rather than disabling the Camellia enctypes, select krb5's own built-in +Camellia implementation (K5_BUILTIN_CAMELLIA) when building against +AWS-LC, detected via OPENSSL_IS_AWSLC from (already +included by crypto_int.h under CRYPTO_OPENSSL). The built-in sources in +lib/crypto/builtin/ are always compiled on Unix, so this keeps all +Camellia enctypes and CMAC checksums fully functional with no changes to +the crypto test suite. + +This mirrors the approach suggested by the krb5 maintainers: +https://github.com/krb5/krb5/pull/1533#issuecomment-4974308880 + +--- +diff --git a/src/lib/crypto/krb/crypto_int.h b/src/lib/crypto/krb/crypto_int.h +index 3629616..fb30d1f 100644 +--- a/src/lib/crypto/krb/crypto_int.h ++++ b/src/lib/crypto/krb/crypto_int.h +@@ -62,7 +62,11 @@ + #endif + + #define K5_OPENSSL_AES ++#ifdef OPENSSL_IS_AWSLC ++#define K5_BUILTIN_CAMELLIA ++#else + #define K5_OPENSSL_CAMELLIA ++#endif + #define K5_OPENSSL_DES + #define K5_OPENSSL_HMAC + #define K5_OPENSSL_MD5 diff --git a/tests/ci/integration/run_krb5_integration.sh b/tests/ci/integration/run_krb5_integration.sh index 672a117470..faeea31327 100755 --- a/tests/ci/integration/run_krb5_integration.sh +++ b/tests/ci/integration/run_krb5_integration.sh @@ -82,10 +82,10 @@ function krb5_build() { # Run krb5's crypto unit tests. The full `make check` from the top of the tree # spins up KDCs and exercises end-to-end Kerberos flows, which requires Python -# and additional CI plumbing. We build the test binaries then run the subset -# that exercises the AWS-LC backend (AES-CTS, HMAC, SHA-2, PRF, key derivation) -# without relying on Camellia (which AWS-LC doesn't implement) or DES -# behaviours that differ from stock OpenSSL. +# and additional CI plumbing. We build the test binaries then run the crypto +# test subset, which exercises the AWS-LC backend (AES-CTS, HMAC, SHA-2, PRF, +# key derivation) alongside krb5's built-in primitives (Camellia is served by +# the built-in implementation when building against AWS-LC). function krb5_run_tests() { pushd "${KRB5_SRC_FOLDER}/src/lib/crypto" @@ -95,11 +95,6 @@ function krb5_run_tests() { ln -sf "${AWS_LC_INSTALL_FOLDER}/lib/libcrypto.so" "../../lib/libcrypto.so" ln -sf "${AWS_LC_INSTALL_FOLDER}/lib/libcrypto.so.1" "../../lib/libcrypto.so.1" - # The camellia-test binary is a no-op (exits 0) when Camellia is disabled, - # but `make check` compares its stdout to a golden file. Truncate the golden - # file so the comparison succeeds. - : > crypto_tests/camellia-expect-vt.txt - make -j "${NUM_CPU_THREADS}" check popd }