~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/mac80211/aes_gmac.c

Version: ~ [ linux-5.11.2 ] ~ [ linux-5.10.19 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.101 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.177 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.222 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.258 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.258 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  * AES-GMAC for IEEE 802.11 BIP-GMAC-128 and BIP-GMAC-256
  3  * Copyright 2015, Qualcomm Atheros, Inc.
  4  *
  5  * This program is free software; you can redistribute it and/or modify
  6  * it under the terms of the GNU General Public License version 2 as
  7  * published by the Free Software Foundation.
  8  */
  9 
 10 #include <linux/kernel.h>
 11 #include <linux/types.h>
 12 #include <linux/err.h>
 13 #include <crypto/aead.h>
 14 #include <crypto/aes.h>
 15 
 16 #include <net/mac80211.h>
 17 #include "key.h"
 18 #include "aes_gmac.h"
 19 
 20 #define GMAC_MIC_LEN 16
 21 #define GMAC_NONCE_LEN 12
 22 #define AAD_LEN 20
 23 
 24 int ieee80211_aes_gmac(struct crypto_aead *tfm, const u8 *aad, u8 *nonce,
 25                        const u8 *data, size_t data_len, u8 *mic)
 26 {
 27         struct scatterlist sg[4];
 28         char aead_req_data[sizeof(struct aead_request) +
 29                            crypto_aead_reqsize(tfm)]
 30                 __aligned(__alignof__(struct aead_request));
 31         struct aead_request *aead_req = (void *)aead_req_data;
 32         u8 zero[GMAC_MIC_LEN], iv[AES_BLOCK_SIZE];
 33 
 34         if (data_len < GMAC_MIC_LEN)
 35                 return -EINVAL;
 36 
 37         memset(aead_req, 0, sizeof(aead_req_data));
 38 
 39         memset(zero, 0, GMAC_MIC_LEN);
 40         sg_init_table(sg, 4);
 41         sg_set_buf(&sg[0], aad, AAD_LEN);
 42         sg_set_buf(&sg[1], data, data_len - GMAC_MIC_LEN);
 43         sg_set_buf(&sg[2], zero, GMAC_MIC_LEN);
 44         sg_set_buf(&sg[3], mic, GMAC_MIC_LEN);
 45 
 46         memcpy(iv, nonce, GMAC_NONCE_LEN);
 47         memset(iv + GMAC_NONCE_LEN, 0, sizeof(iv) - GMAC_NONCE_LEN);
 48         iv[AES_BLOCK_SIZE - 1] = 0x01;
 49 
 50         aead_request_set_tfm(aead_req, tfm);
 51         aead_request_set_crypt(aead_req, sg, sg, 0, iv);
 52         aead_request_set_ad(aead_req, AAD_LEN + data_len);
 53 
 54         crypto_aead_encrypt(aead_req);
 55 
 56         return 0;
 57 }
 58 
 59 struct crypto_aead *ieee80211_aes_gmac_key_setup(const u8 key[],
 60                                                  size_t key_len)
 61 {
 62         struct crypto_aead *tfm;
 63         int err;
 64 
 65         tfm = crypto_alloc_aead("gcm(aes)", 0, CRYPTO_ALG_ASYNC);
 66         if (IS_ERR(tfm))
 67                 return tfm;
 68 
 69         err = crypto_aead_setkey(tfm, key, key_len);
 70         if (!err)
 71                 err = crypto_aead_setauthsize(tfm, GMAC_MIC_LEN);
 72         if (!err)
 73                 return tfm;
 74 
 75         crypto_free_aead(tfm);
 76         return ERR_PTR(err);
 77 }
 78 
 79 void ieee80211_aes_gmac_key_free(struct crypto_aead *tfm)
 80 {
 81         crypto_free_aead(tfm);
 82 }
 83 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp