|
@@ -1,6 +1,7 @@
|
|
/*
|
|
/*
|
|
* Copyright 2003-2004, Instant802 Networks, Inc.
|
|
* Copyright 2003-2004, Instant802 Networks, Inc.
|
|
* Copyright 2005-2006, Devicescape Software, Inc.
|
|
* Copyright 2005-2006, Devicescape Software, Inc.
|
|
|
|
+ * Copyright 2014-2015, Qualcomm Atheros, Inc.
|
|
*
|
|
*
|
|
* Rewrite: Copyright (C) 2013 Linaro Ltd <ard.biesheuvel@linaro.org>
|
|
* Rewrite: Copyright (C) 2013 Linaro Ltd <ard.biesheuvel@linaro.org>
|
|
*
|
|
*
|
|
@@ -12,30 +13,29 @@
|
|
#include <linux/kernel.h>
|
|
#include <linux/kernel.h>
|
|
#include <linux/types.h>
|
|
#include <linux/types.h>
|
|
#include <linux/err.h>
|
|
#include <linux/err.h>
|
|
|
|
+#include <linux/scatterlist.h>
|
|
#include <crypto/aead.h>
|
|
#include <crypto/aead.h>
|
|
|
|
|
|
-#include <net/mac80211.h>
|
|
|
|
-#include "key.h"
|
|
|
|
-#include "aes_ccm.h"
|
|
|
|
|
|
+#include "aead_api.h"
|
|
|
|
|
|
-int ieee80211_aes_ccm_encrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
|
|
|
|
- u8 *data, size_t data_len, u8 *mic,
|
|
|
|
- size_t mic_len)
|
|
|
|
|
|
+int aead_encrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad, size_t aad_len,
|
|
|
|
+ u8 *data, size_t data_len, u8 *mic)
|
|
{
|
|
{
|
|
|
|
+ size_t mic_len = tfm->authsize;
|
|
struct scatterlist sg[3];
|
|
struct scatterlist sg[3];
|
|
struct aead_request *aead_req;
|
|
struct aead_request *aead_req;
|
|
int reqsize = sizeof(*aead_req) + crypto_aead_reqsize(tfm);
|
|
int reqsize = sizeof(*aead_req) + crypto_aead_reqsize(tfm);
|
|
u8 *__aad;
|
|
u8 *__aad;
|
|
|
|
|
|
- aead_req = kzalloc(reqsize + CCM_AAD_LEN, GFP_ATOMIC);
|
|
|
|
|
|
+ aead_req = kzalloc(reqsize + aad_len, GFP_ATOMIC);
|
|
if (!aead_req)
|
|
if (!aead_req)
|
|
return -ENOMEM;
|
|
return -ENOMEM;
|
|
|
|
|
|
__aad = (u8 *)aead_req + reqsize;
|
|
__aad = (u8 *)aead_req + reqsize;
|
|
- memcpy(__aad, aad, CCM_AAD_LEN);
|
|
|
|
|
|
+ memcpy(__aad, aad, aad_len);
|
|
|
|
|
|
sg_init_table(sg, 3);
|
|
sg_init_table(sg, 3);
|
|
- sg_set_buf(&sg[0], &__aad[2], be16_to_cpup((__be16 *)__aad));
|
|
|
|
|
|
+ sg_set_buf(&sg[0], __aad, aad_len);
|
|
sg_set_buf(&sg[1], data, data_len);
|
|
sg_set_buf(&sg[1], data, data_len);
|
|
sg_set_buf(&sg[2], mic, mic_len);
|
|
sg_set_buf(&sg[2], mic, mic_len);
|
|
|
|
|
|
@@ -49,10 +49,10 @@ int ieee80211_aes_ccm_encrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
|
|
return 0;
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
|
|
-int ieee80211_aes_ccm_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
|
|
|
|
- u8 *data, size_t data_len, u8 *mic,
|
|
|
|
- size_t mic_len)
|
|
|
|
|
|
+int aead_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad, size_t aad_len,
|
|
|
|
+ u8 *data, size_t data_len, u8 *mic)
|
|
{
|
|
{
|
|
|
|
+ size_t mic_len = tfm->authsize;
|
|
struct scatterlist sg[3];
|
|
struct scatterlist sg[3];
|
|
struct aead_request *aead_req;
|
|
struct aead_request *aead_req;
|
|
int reqsize = sizeof(*aead_req) + crypto_aead_reqsize(tfm);
|
|
int reqsize = sizeof(*aead_req) + crypto_aead_reqsize(tfm);
|
|
@@ -62,15 +62,15 @@ int ieee80211_aes_ccm_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
|
|
if (data_len == 0)
|
|
if (data_len == 0)
|
|
return -EINVAL;
|
|
return -EINVAL;
|
|
|
|
|
|
- aead_req = kzalloc(reqsize + CCM_AAD_LEN, GFP_ATOMIC);
|
|
|
|
|
|
+ aead_req = kzalloc(reqsize + aad_len, GFP_ATOMIC);
|
|
if (!aead_req)
|
|
if (!aead_req)
|
|
return -ENOMEM;
|
|
return -ENOMEM;
|
|
|
|
|
|
__aad = (u8 *)aead_req + reqsize;
|
|
__aad = (u8 *)aead_req + reqsize;
|
|
- memcpy(__aad, aad, CCM_AAD_LEN);
|
|
|
|
|
|
+ memcpy(__aad, aad, aad_len);
|
|
|
|
|
|
sg_init_table(sg, 3);
|
|
sg_init_table(sg, 3);
|
|
- sg_set_buf(&sg[0], &__aad[2], be16_to_cpup((__be16 *)__aad));
|
|
|
|
|
|
+ sg_set_buf(&sg[0], __aad, aad_len);
|
|
sg_set_buf(&sg[1], data, data_len);
|
|
sg_set_buf(&sg[1], data, data_len);
|
|
sg_set_buf(&sg[2], mic, mic_len);
|
|
sg_set_buf(&sg[2], mic, mic_len);
|
|
|
|
|
|
@@ -84,14 +84,14 @@ int ieee80211_aes_ccm_decrypt(struct crypto_aead *tfm, u8 *b_0, u8 *aad,
|
|
return err;
|
|
return err;
|
|
}
|
|
}
|
|
|
|
|
|
-struct crypto_aead *ieee80211_aes_key_setup_encrypt(const u8 key[],
|
|
|
|
- size_t key_len,
|
|
|
|
- size_t mic_len)
|
|
|
|
|
|
+struct crypto_aead *
|
|
|
|
+aead_key_setup_encrypt(const char *alg, const u8 key[],
|
|
|
|
+ size_t key_len, size_t mic_len)
|
|
{
|
|
{
|
|
struct crypto_aead *tfm;
|
|
struct crypto_aead *tfm;
|
|
int err;
|
|
int err;
|
|
|
|
|
|
- tfm = crypto_alloc_aead("ccm(aes)", 0, CRYPTO_ALG_ASYNC);
|
|
|
|
|
|
+ tfm = crypto_alloc_aead(alg, 0, CRYPTO_ALG_ASYNC);
|
|
if (IS_ERR(tfm))
|
|
if (IS_ERR(tfm))
|
|
return tfm;
|
|
return tfm;
|
|
|
|
|
|
@@ -109,7 +109,7 @@ free_aead:
|
|
return ERR_PTR(err);
|
|
return ERR_PTR(err);
|
|
}
|
|
}
|
|
|
|
|
|
-void ieee80211_aes_key_free(struct crypto_aead *tfm)
|
|
|
|
|
|
+void aead_key_free(struct crypto_aead *tfm)
|
|
{
|
|
{
|
|
crypto_free_aead(tfm);
|
|
crypto_free_aead(tfm);
|
|
}
|
|
}
|