| @@ -737,14 +737,7 @@ void aes_cbcmac_final(struct aes_cbcmac_ctx *ctx, u8 out[AES_BLOCK_SIZE]) · 736 unmodified lines |
| 737 | 737 | } |
| 738 | 738 | EXPORT_SYMBOL_NS_GPL(aes_cbcmac_final, "CRYPTO_INTERNAL"); |
| 739 | 739 | |
| 740 | | −/* |
| 741 | | − * FIPS cryptographic algorithm self-test for AES-CMAC. As per the FIPS 140-3 |
| 742 | | − * Implementation Guidance, a cryptographic algorithm self-test for at least one |
| 743 | | − * of AES-GCM, AES-CCM, AES-CMAC, or AES-GMAC is required if any of those modes |
| 744 | | − * is implemented. This fulfills that requirement via AES-CMAC. |
| 745 | | − * |
| 746 | | − * This is just for FIPS. The full tests are in the KUnit test suite. |
| 747 | | − */ |
| 740 | +/* FIPS cryptographic algorithm self-test for AES-CMAC */ |
| 748 | 741 | static void __init aes_cmac_fips_test(void) |
| 749 | 742 | { |
| 750 | 743 | struct aes_cmac_key key; |
| @@ -1745,7 +1738,37 @@ int aes_gcm_decrypt(u8 *dst, const u8 *src, size_t data_len, const u8 *authtag, · 994 unmodified lines |
| 1745 | 1738 | } |
| 1746 | 1739 | EXPORT_SYMBOL_GPL(aes_gcm_decrypt); |
| 1747 | 1740 | |
| 1748 | | −#endif /* CONFIG_CRYPTO_LIB_AES_GCM */ |
| 1741 | +/* FIPS cryptographic algorithm self-test for AES-GCM */ |
| 1742 | +static void __init aes_gcm_fips_test(void) |
| 1743 | +{ |
| 1744 | + const size_t data_len = sizeof(fips_test_data); |
| 1745 | + u8 buf[sizeof(fips_test_data) + AES_BLOCK_SIZE]; |
| 1746 | + struct aes_gcm_key key; |
| 1747 | + int err; |
| 1748 | + |
| 1749 | + if (aes_gcm_preparekey(&key, fips_test_key, sizeof(fips_test_key), |
| 1750 | + AES_BLOCK_SIZE) != 0) |
| 1751 | + panic("aes: GCM FIPS self-test failed (preparekey)\n"); |
| 1752 | + |
| 1753 | + aes_gcm_encrypt(buf, fips_test_data, data_len, &buf[data_len], |
| 1754 | + fips_test_ad, sizeof(fips_test_ad), fips_test_iv, &key); |
| 1755 | + if (memcmp(fips_test_aes_gcm_ctext_and_tag, buf, sizeof(buf)) != 0) |
| 1756 | + panic("aes: GCM FIPS self-test failed (wrong ciphertext and/or tag)\n"); |
| 1757 | + |
| 1758 | + err = aes_gcm_decrypt(buf, buf, data_len, &buf[data_len], fips_test_ad, |
| 1759 | + sizeof(fips_test_ad), fips_test_iv, &key); |
| 1760 | + if (err != 0) |
| 1761 | + panic("aes: GCM FIPS self-test failed (decryption failed)\n"); |
| 1762 | + if (memcmp(fips_test_data, buf, data_len) != 0) |
| 1763 | + panic("aes: GCM FIPS self-test failed (wrong plaintext)\n"); |
| 1764 | + |
| 1765 | + memzero_explicit(&key, sizeof(key)); |
| 1766 | +} |
| 1767 | +#else /* CONFIG_CRYPTO_LIB_AES_GCM */ |
| 1768 | +static inline void aes_gcm_fips_test(void) |
| 1769 | +{ |
| 1770 | +} |
| 1771 | +#endif /* !CONFIG_CRYPTO_LIB_AES_GCM */ |
| 1749 | 1772 | |
| 1750 | 1773 | #if IS_ENABLED(CONFIG_CRYPTO_LIB_AES_CCM) |
| 1751 | 1774 | int aes_ccm_preparekey(struct aes_ccm_key *key, const u8 *in_key, |
| @@ -2057,7 +2080,43 @@ int aes_ccm_decrypt(u8 *dst, const u8 *src, size_t data_len, const u8 *authtag, · 305 unmodified lines |
| 2057 | 2080 | return err; |
| 2058 | 2081 | } |
| 2059 | 2082 | EXPORT_SYMBOL_GPL(aes_ccm_decrypt); |
| 2060 | | −#endif /* CONFIG_CRYPTO_LIB_AES_CCM */ |
| 2083 | + |
| 2084 | +/* FIPS cryptographic algorithm self-test for AES-CCM */ |
| 2085 | +static void __init aes_ccm_fips_test(void) |
| 2086 | +{ |
| 2087 | + const size_t data_len = sizeof(fips_test_data); |
| 2088 | + const size_t nonce_len = 13; |
| 2089 | + u8 buf[sizeof(fips_test_data) + AES_BLOCK_SIZE]; |
| 2090 | + struct aes_ccm_key key; |
| 2091 | + int err; |
| 2092 | + |
| 2093 | + if (aes_ccm_preparekey(&key, fips_test_key, sizeof(fips_test_key), |
| 2094 | + AES_BLOCK_SIZE) != 0) |
| 2095 | + panic("aes: CCM FIPS self-test failed (preparekey)\n"); |
| 2096 | + |
| 2097 | + err = aes_ccm_encrypt(buf, fips_test_data, data_len, &buf[data_len], |
| 2098 | + fips_test_ad, sizeof(fips_test_ad), fips_test_iv, |
| 2099 | + nonce_len, &key); |
| 2100 | + if (err != 0) |
| 2101 | + panic("aes: CCM FIPS self-test failed (encryption failed)\n"); |
| 2102 | + if (memcmp(fips_test_aes_ccm_ctext_and_tag, buf, sizeof(buf)) != 0) |
| 2103 | + panic("aes: CCM FIPS self-test failed (wrong ciphertext and/or tag)\n"); |
| 2104 | + |
| 2105 | + err = aes_ccm_decrypt(buf, buf, data_len, &buf[data_len], fips_test_ad, |
| 2106 | + sizeof(fips_test_ad), fips_test_iv, nonce_len, |
| 2107 | + &key); |
| 2108 | + if (err != 0) |
| 2109 | + panic("aes: CCM FIPS self-test failed (decryption failed)\n"); |
| 2110 | + if (memcmp(fips_test_data, buf, data_len) != 0) |
| 2111 | + panic("aes: CCM FIPS self-test failed (wrong plaintext)\n"); |
| 2112 | + |
| 2113 | + memzero_explicit(&key, sizeof(key)); |
| 2114 | +} |
| 2115 | +#else /* CONFIG_CRYPTO_LIB_AES_CCM */ |
| 2116 | +static inline void aes_ccm_fips_test(void) |
| 2117 | +{ |
| 2118 | +} |
| 2119 | +#endif /* !CONFIG_CRYPTO_LIB_AES_CCM */ |
| 2061 | 2120 | |
| 2062 | 2121 | static int __init aes_mod_init(void) |
| 2063 | 2122 | { |
| @@ -2072,6 +2131,8 @@ static int __init aes_mod_init(void) · 8 unmodified lines |
| 2072 | 2131 | aes_cbc_cts_fips_test(); |
| 2073 | 2132 | aes_ctr_fips_test(); |
| 2074 | 2133 | aes_xts_fips_test(); |
| 2134 | + aes_gcm_fips_test(); |
| 2135 | + aes_ccm_fips_test(); |
| 2075 | 2136 | } |
| 2076 | 2137 | return 0; |
| 2077 | 2138 | } |