mac80111: Add BIP-CMAC-256 cipher
authorJouni Malinen <jouni@qca.qualcomm.com>
Sat, 24 Jan 2015 17:52:08 +0000 (19:52 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Tue, 27 Jan 2015 10:09:13 +0000 (11:09 +0100)
This allows mac80211 to configure BIP-CMAC-256 to the driver and also
use software-implementation within mac80211 when the driver does not
support this with hardware accelaration.

Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
include/linux/ieee80211.h
net/mac80211/aes_cmac.c
net/mac80211/aes_cmac.h
net/mac80211/cfg.c
net/mac80211/debugfs_key.c
net/mac80211/key.c
net/mac80211/main.c
net/mac80211/rx.c
net/mac80211/tx.c
net/mac80211/wpa.c
net/mac80211/wpa.h

index dbf417b..b9c7897 100644 (file)
@@ -1017,6 +1017,15 @@ struct ieee80211_mmie {
        u8 mic[8];
 } __packed;
 
+/* Management MIC information element (IEEE 802.11w) for GMAC and CMAC-256 */
+struct ieee80211_mmie_16 {
+       u8 element_id;
+       u8 length;
+       __le16 key_id;
+       u8 sequence_number[6];
+       u8 mic[16];
+} __packed;
+
 struct ieee80211_vendor_ie {
        u8 element_id;
        u8 len;
index 9b9009f..4192806 100644 (file)
@@ -18,8 +18,8 @@
 #include "key.h"
 #include "aes_cmac.h"
 
-#define AES_CMAC_KEY_LEN 16
 #define CMAC_TLEN 8 /* CMAC TLen = 64 bits (8 octets) */
+#define CMAC_TLEN_256 16 /* CMAC TLen = 128 bits (16 octets) */
 #define AAD_LEN 20
 
 
@@ -35,9 +35,9 @@ static void gf_mulx(u8 *pad)
                pad[AES_BLOCK_SIZE - 1] ^= 0x87;
 }
 
-
-static void aes_128_cmac_vector(struct crypto_cipher *tfm, size_t num_elem,
-                               const u8 *addr[], const size_t *len, u8 *mac)
+static void aes_cmac_vector(struct crypto_cipher *tfm, size_t num_elem,
+                           const u8 *addr[], const size_t *len, u8 *mac,
+                           size_t mac_len)
 {
        u8 cbc[AES_BLOCK_SIZE], pad[AES_BLOCK_SIZE];
        const u8 *pos, *end;
@@ -88,7 +88,7 @@ static void aes_128_cmac_vector(struct crypto_cipher *tfm, size_t num_elem,
        for (i = 0; i < AES_BLOCK_SIZE; i++)
                pad[i] ^= cbc[i];
        crypto_cipher_encrypt_one(tfm, pad, pad);
-       memcpy(mac, pad, CMAC_TLEN);
+       memcpy(mac, pad, mac_len);
 }
 
 
@@ -107,17 +107,35 @@ void ieee80211_aes_cmac(struct crypto_cipher *tfm, const u8 *aad,
        addr[2] = zero;
        len[2] = CMAC_TLEN;
 
-       aes_128_cmac_vector(tfm, 3, addr, len, mic);
+       aes_cmac_vector(tfm, 3, addr, len, mic, CMAC_TLEN);
 }
 
+void ieee80211_aes_cmac_256(struct crypto_cipher *tfm, const u8 *aad,
+                           const u8 *data, size_t data_len, u8 *mic)
+{
+       const u8 *addr[3];
+       size_t len[3];
+       u8 zero[CMAC_TLEN_256];
+
+       memset(zero, 0, CMAC_TLEN_256);
+       addr[0] = aad;
+       len[0] = AAD_LEN;
+       addr[1] = data;
+       len[1] = data_len - CMAC_TLEN_256;
+       addr[2] = zero;
+       len[2] = CMAC_TLEN_256;
+
+       aes_cmac_vector(tfm, 3, addr, len, mic, CMAC_TLEN_256);
+}
 
-struct crypto_cipher *ieee80211_aes_cmac_key_setup(const u8 key[])
+struct crypto_cipher *ieee80211_aes_cmac_key_setup(const u8 key[],
+                                                  size_t key_len)
 {
        struct crypto_cipher *tfm;
 
        tfm = crypto_alloc_cipher("aes", 0, CRYPTO_ALG_ASYNC);
        if (!IS_ERR(tfm))
-               crypto_cipher_setkey(tfm, key, AES_CMAC_KEY_LEN);
+               crypto_cipher_setkey(tfm, key, key_len);
 
        return tfm;
 }
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge