qcacld-3.0: 4.8 Kernel Migration - Remove ablkcipher

As of version 4.8 of the Linux kernel, the ablkcipher Api is removed.
Remove all obsolete crypto functions that reference this Api.

Change-Id: Ia82743d048834a67dfce23b91f660beb59b1e94d
CRs-Fixed: 1079951
(cherry picked from commit bf349575d765f53f207c7cb2ad6c66a198cf07de)
This commit is contained in:
Dustin Brown 2016-10-19 16:25:45 -07:00 • committed by qcabuildsw
commit cc1753d288
3 changed files with 1 additions and 649 deletions

View file

@ -34,28 +34,7 @@
*
*/
#include <qdf_types.h>
#include <qdf_status.h>
#include <qdf_mem.h>
#include <qdf_list.h>
#include <qdf_trace.h>
#include <qdf_event.h>
#include <qdf_lock.h>
#include <cds_reg_service.h>
#include <cds_mq.h>
#include <cds_packet.h>
#include <cds_sched.h>
#include <qdf_threads.h>
#include <qdf_mc_timer.h>
#include <cds_pack_align.h>
#include <crypto/aes.h>
#include <crypto/hash.h>
static inline struct crypto_ahash *cds_crypto_alloc_ahash(const char *alg_name,
u32 type, u32 mask)
{
return crypto_alloc_ahash(alg_name, type, mask);
}
#include <linux/crypto.h>
static inline struct crypto_cipher *
cds_crypto_alloc_cipher(const char *alg_name, u32 type, u32 mask)
@ -68,36 +47,4 @@ static inline void cds_crypto_free_cipher(struct crypto_cipher *tfm)
crypto_free_cipher(tfm);
}
static inline void cds_crypto_free_ahash(struct crypto_ahash *tfm)
{
crypto_free_ahash(tfm);
}
static inline int cds_crypto_ahash_setkey(struct crypto_ahash *tfm,
const u8 *key, unsigned int keylen)
{
return crypto_ahash_setkey(tfm, key, keylen);
}
static inline int cds_crypto_ahash_digest(struct ahash_request *req)
{
return crypto_ahash_digest(req);
}
static inline struct crypto_ablkcipher *
cds_crypto_alloc_ablkcipher(const char *alg_name, u32 type, u32 mask)
{
return crypto_alloc_ablkcipher(alg_name, type, mask);
}
static inline void cds_ablkcipher_request_free(struct ablkcipher_request *req)
{
ablkcipher_request_free(req);
}
static inline void cds_crypto_free_ablkcipher(struct crypto_ablkcipher *tfm)
{
crypto_free_ablkcipher(tfm);
}
#endif /* if !defined __CDS_CRYPTO_H */

View file

@ -118,72 +118,6 @@ QDF_STATUS cds_crypto_deinit(uint32_t hCryptProv);
QDF_STATUS cds_rand_get_bytes(uint32_t handle, uint8_t *pbBuf,
uint32_t numBytes);
/**
* cds_sha1_hmac_str
*
* FUNCTION:
* Generate the HMAC-SHA1 of a string given a key.
*
* LOGIC:
* Standard HMAC processing from RFC 2104. The code is provided in the
* appendix of the RFC.
*
* ASSUMPTIONS:
* The RFC is correct.
*
* @param text text to be hashed
* @param textLen length of text
* @param key key to use for HMAC
* @param keyLen length of key
* @param digest holds resultant SHA1 HMAC (20B)
*
* @return QDF_STATUS_SUCCSS if the operation succeeds
*
*/
QDF_STATUS cds_sha1_hmac_str(uint32_t cryptHandle, /* Handle */
uint8_t *text, /* pointer to data stream */
uint32_t textLen, /* length of data stream */
uint8_t *key, /* pointer to authentication key */
uint32_t keyLen, /* length of authentication key */
uint8_t digest[CDS_DIGEST_SHA1_SIZE]); /* caller digest to be filled in */
/**
* cds_md5_hmac_str
*
* FUNCTION:
* Generate the HMAC-MD5 of a string given a key.
*
* LOGIC:
* Standard HMAC processing from RFC 2104. The code is provided in the
* appendix of the RFC.
*
* ASSUMPTIONS:
* The RFC is correct.
*
* @param text text to be hashed
* @param textLen length of text
* @param key key to use for HMAC
* @param keyLen length of key
* @param digest holds resultant MD5 HMAC (16B)
*
* @return QDF_STATUS_SUCCSS if the operation succeeds
*
*/
QDF_STATUS cds_md5_hmac_str(uint32_t cryptHandle, /* Handle */
uint8_t *text, /* pointer to data stream */
uint32_t textLen, /* length of data stream */
uint8_t *key, /* pointer to authentication key */
uint32_t keyLen, /* length of authentication key */
uint8_t digest[CDS_DIGEST_MD5_SIZE]); /* caller digest to be filled in */
QDF_STATUS cds_encrypt_aes(uint32_t cryptHandle, /* Handle */
uint8_t *pText, /* pointer to data stream */
uint8_t *Encrypted, uint8_t *pKey); /* pointer to authentication key */
QDF_STATUS cds_decrypt_aes(uint32_t cryptHandle, /* Handle */
uint8_t *pText, /* pointer to data stream */
uint8_t *pDecrypted, uint8_t *pKey); /* pointer to authentication key */
uint32_t cds_chan_to_freq(uint8_t chan);
uint8_t cds_freq_to_chan(uint32_t freq);
enum cds_band_type cds_chan_to_band(uint32_t chan);

View file

@ -38,9 +38,6 @@
cds_crypto_init() - Initializes Crypto module
cds_crypto_deinit() - De-initializes Crypto module
cds_rand_get_bytes() - Generates random byte
cds_sha1_hmac_str() - Generate the HMAC-SHA1 of a string given a key
cds_encrypt_aes() - Generate AES Encrypted byte stream
cds_decrypt_aes() - Decrypts an AES Encrypted byte stream
DEPENDENCIES:
============================================================================*/
@ -568,532 +565,6 @@ err_tfm:
}
#endif /* WLAN_FEATURE_11W */
/**
* cds_sha1_hmac_str
*
* FUNCTION:
* Generate the HMAC-SHA1 of a string given a key.
*
* LOGIC:
* Standard HMAC processing from RFC 2104. The code is provided in the
* appendix of the RFC.
*
* ASSUMPTIONS:
* The RFC is correct.
*
* @param text text to be hashed
* @param textLen length of text
* @param key key to use for HMAC
* @param keyLen length of key
* @param digest holds resultant SHA1 HMAC (20B)
*
* @return QDF_STATUS_SUCCSS if the operation succeeds
*
*/
struct hmac_sha1_result {
struct completion completion;
int err;
};
static void hmac_sha1_complete(struct crypto_async_request *req, int err)
{
struct hmac_sha1_result *r = req->data;
if (err == -EINPROGRESS)
return;
r->err = err;
complete(&r->completion);
}
static int
hmac_sha1(uint8_t *key, uint8_t ksize, char *plaintext, uint8_t psize,
uint8_t *output, uint8_t outlen)
{
int ret = 0;
struct crypto_ahash *tfm;
struct scatterlist sg;
struct ahash_request *req;
struct hmac_sha1_result tresult;
void *hash_buff = NULL;
unsigned char hash_result[64];
int i;
memset(output, 0, outlen);
init_completion(&tresult.completion);
tfm = cds_crypto_alloc_ahash("hmac(sha1)", CRYPTO_ALG_TYPE_AHASH,
CRYPTO_ALG_TYPE_AHASH_MASK);
if (IS_ERR(tfm)) {
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
"crypto_alloc_ahash failed");
ret = PTR_ERR(tfm);
goto err_tfm;
}
req = ahash_request_alloc(tfm, GFP_KERNEL);
if (!req) {
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
"failed to allocate request for hmac(sha1)");
ret = -ENOMEM;
goto err_req;
}
ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
hmac_sha1_complete, &tresult);
hash_buff = kzalloc(psize, GFP_KERNEL);
if (!hash_buff) {
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
"failed to kzalloc hash_buff");
ret = -ENOMEM;
goto err_hash_buf;
}
memset(hash_result, 0, 64);
memcpy(hash_buff, plaintext, psize);
sg_init_one(&sg, hash_buff, psize);
if (ksize) {
crypto_ahash_clear_flags(tfm, ~0);
ret = cds_crypto_ahash_setkey(tfm, key, ksize);
if (ret) {
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
"crypto_ahash_setkey failed");
goto err_setkey;
}
}
ahash_request_set_crypt(req, &sg, hash_result, psize);
ret = cds_crypto_ahash_digest(req);
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR, "ret 0x%x", ret);
switch (ret) {
case 0:
for (i = 0; i < outlen; i++)
output[i] = hash_result[i];
break;
case -EINPROGRESS:
case -EBUSY:
ret = wait_for_completion_interruptible(&tresult.completion);
if (!ret && !tresult.err) {
for (i = 0; i < outlen; i++)
output[i] = hash_result[i];
INIT_COMPLETION(tresult.completion);
break;
} else {
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
"wait_for_completion_interruptible failed");
if (!ret)
ret = tresult.err;
goto out;
}
default:
goto out;
}
out:
err_setkey:
kfree(hash_buff);
err_hash_buf:
ahash_request_free(req);
err_req:
cds_crypto_free_ahash(tfm);
err_tfm:
return ret;
}
QDF_STATUS cds_sha1_hmac_str(uint32_t cryptHandle, /* Handle */
uint8_t *pText, /* pointer to data stream */
uint32_t textLen, /* length of data stream */
uint8_t *pKey, /* pointer to authentication key */
uint32_t keyLen, /* length of authentication key */
uint8_t digest[CDS_DIGEST_SHA1_SIZE])
{ /* caller digest to be filled in */
int ret = 0;
ret = hmac_sha1(pKey, /* uint8_t *key, */
(uint8_t) keyLen, /* uint8_t ksize, */
(char *)pText, /* char *plaintext, */
(uint8_t) textLen, /* uint8_t psize, */
digest, /* uint8_t *output, */
CDS_DIGEST_SHA1_SIZE /* uint8_t outlen */
);
if (ret != 0) {
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
"hmac_sha1() call failed");
return QDF_STATUS_E_FAULT;
}
return QDF_STATUS_SUCCESS;
}
/**
* cds_md5_hmac_str
*
* FUNCTION:
* Generate the HMAC-MD5 of a string given a key.
*
* LOGIC:
* Standard HMAC processing from RFC 2104. The code is provided in the
* appendix of the RFC.
*
* ASSUMPTIONS:
* The RFC is correct.
*
* @param text text to be hashed
* @param textLen length of text
* @param key key to use for HMAC
* @param keyLen length of key
* @param digest holds resultant MD5 HMAC (20B)
*
* @return QDF_STATUS_SUCCSS if the operation succeeds
*
*/
struct hmac_md5_result {
struct completion completion;
int err;
};
static void hmac_md5_complete(struct crypto_async_request *req, int err)
{
struct hmac_md5_result *r = req->data;
if (err == -EINPROGRESS)
return;
r->err = err;
complete(&r->completion);
}
static int
hmac_md5(uint8_t *key, uint8_t ksize, char *plaintext, uint8_t psize,
uint8_t *output, uint8_t outlen)
{
int ret = 0;
struct crypto_ahash *tfm;
struct scatterlist sg;
struct ahash_request *req;
struct hmac_md5_result tresult = {.err = 0 };
void *hash_buff = NULL;
unsigned char hash_result[64];
int i;
memset(output, 0, outlen);
init_completion(&tresult.completion);
tfm = cds_crypto_alloc_ahash("hmac(md5)", CRYPTO_ALG_TYPE_AHASH,
CRYPTO_ALG_TYPE_AHASH_MASK);
if (IS_ERR(tfm)) {
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
"crypto_alloc_ahash failed");
ret = PTR_ERR(tfm);
goto err_tfm;
}
req = ahash_request_alloc(tfm, GFP_KERNEL);
if (!req) {
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
"failed to allocate request for hmac(md5)");
ret = -ENOMEM;
goto err_req;
}
ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
hmac_md5_complete, &tresult);
hash_buff = kzalloc(psize, GFP_KERNEL);
if (!hash_buff) {
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
"failed to kzalloc hash_buff");
ret = -ENOMEM;
goto err_hash_buf;
}
memset(hash_result, 0, 64);
memcpy(hash_buff, plaintext, psize);
sg_init_one(&sg, hash_buff, psize);
if (ksize) {
crypto_ahash_clear_flags(tfm, ~0);
ret = cds_crypto_ahash_setkey(tfm, key, ksize);
if (ret) {
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
"crypto_ahash_setkey failed");
goto err_setkey;
}
}
ahash_request_set_crypt(req, &sg, hash_result, psize);
ret = cds_crypto_ahash_digest(req);
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR, "ret 0x%x", ret);
switch (ret) {
case 0:
for (i = 0; i < outlen; i++)
output[i] = hash_result[i];
break;
case -EINPROGRESS:
case -EBUSY:
ret = wait_for_completion_interruptible(&tresult.completion);
if (!ret && !tresult.err) {
INIT_COMPLETION(tresult.completion);
break;
} else {
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
"wait_for_completion_interruptible failed");
if (!ret)
ret = tresult.err;
goto out;
}
default:
goto out;
}
out:
err_setkey:
kfree(hash_buff);
err_hash_buf:
ahash_request_free(req);
err_req:
cds_crypto_free_ahash(tfm);
err_tfm:
return ret;
}
QDF_STATUS cds_md5_hmac_str(uint32_t cryptHandle, /* Handle */
uint8_t *pText, /* pointer to data stream */
uint32_t textLen, /* length of data stream */
uint8_t *pKey, /* pointer to authentication key */
uint32_t keyLen, /* length of authentication key */
uint8_t digest[CDS_DIGEST_MD5_SIZE])
{ /* caller digest to be filled in */
int ret = 0;
ret = hmac_md5(pKey, /* uint8_t *key, */
(uint8_t) keyLen, /* uint8_t ksize, */
(char *)pText, /* char *plaintext, */
(uint8_t) textLen, /* uint8_t psize, */
digest, /* uint8_t *output, */
CDS_DIGEST_MD5_SIZE /* uint8_t outlen */
);
if (ret != 0) {
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
"hmac_md5() call failed");
return QDF_STATUS_E_FAULT;
}
return QDF_STATUS_SUCCESS;
}
struct ecb_aes_result {
struct completion completion;
int err;
};
static void ecb_aes_complete(struct crypto_async_request *req, int err)
{
struct ecb_aes_result *r = req->data;
if (err == -EINPROGRESS)
return;
r->err = err;
complete(&r->completion);
}
/*--------------------------------------------------------------------------
\brief cds_encrypt_aes() - Generate AES Encrypted byte stream
The cds_encrypt_aes() function generates the encrypted byte stream for given text.
Buffer should be allocated before calling cds_rand_get_bytes().
Attempting to initialize an already initialized lock results in
a failure.
\param lock - pointer to the opaque lock object to initialize
\return QDF_STATUS_SUCCESS - Successfully generated random memory.
QDF_STATUS_E_FAULT - pbBuf is an invalid pointer.
QDF_STATUS_E_FAILURE - default return value if it fails due to
unknown reasons
***QDF_STATUS_E_RESOURCES - System resources (other than memory)
are unavailable
\sa
( *** return value not considered yet )
--------------------------------------------------------------------------*/
QDF_STATUS cds_encrypt_aes(uint32_t cryptHandle, /* Handle */
uint8_t *pPlainText, /* pointer to data stream */
uint8_t *pCiphertext, uint8_t *pKey)
{ /* pointer to authentication key */
struct ecb_aes_result result;
struct ablkcipher_request *req;
struct crypto_ablkcipher *tfm;
int ret = 0;
char iv[IV_SIZE_AES_128];
struct scatterlist sg_in;
struct scatterlist sg_out;
init_completion(&result.completion);
tfm = cds_crypto_alloc_ablkcipher("cbc(aes)", 0, 0);
if (IS_ERR(tfm)) {
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
"crypto_alloc_ablkcipher failed");
ret = PTR_ERR(tfm);
goto err_tfm;
}
req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
if (!req) {
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
"Failed to allocate request for cbc(aes)");
ret = -ENOMEM;
goto err_req;
}
ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
ecb_aes_complete, &result);
crypto_ablkcipher_clear_flags(tfm, ~0);
ret = crypto_ablkcipher_setkey(tfm, pKey, AES_KEYSIZE_128);
if (ret) {
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
"crypto_cipher_setkey failed");
goto err_setkey;
}
memset(iv, 0, IV_SIZE_AES_128);
sg_init_one(&sg_in, pPlainText, AES_BLOCK_SIZE);
sg_init_one(&sg_out, pCiphertext, AES_BLOCK_SIZE);
ablkcipher_request_set_crypt(req, &sg_in, &sg_out, AES_BLOCK_SIZE, iv);
crypto_ablkcipher_encrypt(req);
/* ------------------------------------- */
err_setkey:
cds_ablkcipher_request_free(req);
err_req:
cds_crypto_free_ablkcipher(tfm);
err_tfm:
/* return ret; */
if (ret != 0) {
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
"%s() call failed", __func__);
return QDF_STATUS_E_FAULT;
}
return QDF_STATUS_SUCCESS;
}
/*--------------------------------------------------------------------------
\brief cds_decrypt_aes() - Decrypts an AES Encrypted byte stream
The cds_decrypt_aes() function decrypts the encrypted byte stream.
Buffer should be allocated before calling cds_rand_get_bytes().
Attempting to initialize an already initialized lock results in
a failure.
\param lock - pointer to the opaque lock object to initialize
\return QDF_STATUS_SUCCESS - Successfully generated random memory.
QDF_STATUS_E_FAULT - pbBuf is an invalid pointer.
QDF_STATUS_E_FAILURE - default return value if it fails due to
unknown reasons
***QDF_STATUS_E_RESOURCES - System resources (other than memory)
are unavailable
\sa
( *** return value not considered yet )
--------------------------------------------------------------------------*/
QDF_STATUS cds_decrypt_aes(uint32_t cryptHandle, /* Handle */
uint8_t *pText, /* pointer to data stream */
uint8_t *pDecrypted, uint8_t *pKey)
{ /* pointer to authentication key */
/* QDF_STATUS uResult = QDF_STATUS_E_FAILURE; */
struct ecb_aes_result result;
struct ablkcipher_request *req;
struct crypto_ablkcipher *tfm;
int ret = 0;
char iv[IV_SIZE_AES_128];
struct scatterlist sg_in;
struct scatterlist sg_out;
init_completion(&result.completion);
tfm = cds_crypto_alloc_ablkcipher("cbc(aes)", 0, 0);
if (IS_ERR(tfm)) {
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
"crypto_alloc_ablkcipher failed");
ret = PTR_ERR(tfm);
goto err_tfm;
}
req = ablkcipher_request_alloc(tfm, GFP_KERNEL);
if (!req) {
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
"Failed to allocate request for cbc(aes)");
ret = -ENOMEM;
goto err_req;
}
ablkcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG,
ecb_aes_complete, &result);
crypto_ablkcipher_clear_flags(tfm, ~0);
ret = crypto_ablkcipher_setkey(tfm, pKey, AES_KEYSIZE_128);
if (ret) {
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
"crypto_cipher_setkey failed");
goto err_setkey;
}
memset(iv, 0, IV_SIZE_AES_128);
sg_init_one(&sg_in, pText, AES_BLOCK_SIZE);
sg_init_one(&sg_out, pDecrypted, AES_BLOCK_SIZE);
ablkcipher_request_set_crypt(req, &sg_in, &sg_out, AES_BLOCK_SIZE, iv);
crypto_ablkcipher_decrypt(req);
/* ------------------------------------- */
err_setkey:
cds_ablkcipher_request_free(req);
err_req:
cds_crypto_free_ablkcipher(tfm);
err_tfm:
/* return ret; */
if (ret != 0) {
QDF_TRACE(QDF_MODULE_ID_QDF, QDF_TRACE_LEVEL_ERROR,
"%s() call failed", __func__);
return QDF_STATUS_E_FAULT;
}
return QDF_STATUS_SUCCESS;
}
uint32_t cds_chan_to_freq(uint8_t chan)
{