diff options
| -rw-r--r-- | CORE/VOSS/inc/vos_utils.h | 42 | ||||
| -rw-r--r-- | CORE/VOSS/src/vos_utils.c | 396 |
2 files changed, 1 insertions, 437 deletions
diff --git a/CORE/VOSS/inc/vos_utils.h b/CORE/VOSS/inc/vos_utils.h index f86e79684439..ad22b2d40bdb 100644 --- a/CORE/VOSS/inc/vos_utils.h +++ b/CORE/VOSS/inc/vos_utils.h @@ -132,48 +132,6 @@ VOS_STATUS vos_sha1_hmac_str(v_U32_t cryptHandle, /* Handle */ v_U32_t keyLen, /* length of authentication key */ v_U8_t digest[VOS_DIGEST_SHA1_SIZE]);/* caller digest to be filled in */ -/** - * vos_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 VOS_STATUS_SUCCSS if the operation succeeds - * - */ -VOS_STATUS vos_md5_hmac_str(v_U32_t cryptHandle, /* Handle */ - v_U8_t *text, /* pointer to data stream */ - v_U32_t textLen, /* length of data stream */ - v_U8_t *key, /* pointer to authentication key */ - v_U32_t keyLen, /* length of authentication key */ - v_U8_t digest[VOS_DIGEST_MD5_SIZE]);/* caller digest to be filled in */ - - - -VOS_STATUS vos_encrypt_AES(v_U32_t cryptHandle, /* Handle */ - v_U8_t *pText, /* pointer to data stream */ - v_U8_t *Encrypted, - v_U8_t *pKey); /* pointer to authentication key */ - - -VOS_STATUS vos_decrypt_AES(v_U32_t cryptHandle, /* Handle */ - v_U8_t *pText, /* pointer to data stream */ - v_U8_t *pDecrypted, - v_U8_t *pKey); /* pointer to authentication key */ - v_U32_t vos_chan_to_freq(v_U8_t chan); v_U8_t vos_freq_to_chan(v_U32_t freq); v_U8_t vos_chan_to_band(v_U32_t chan); diff --git a/CORE/VOSS/src/vos_utils.c b/CORE/VOSS/src/vos_utils.c index fbfb9b41b312..d6c4e7e92055 100644 --- a/CORE/VOSS/src/vos_utils.c +++ b/CORE/VOSS/src/vos_utils.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2011-2017 The Linux Foundation. All rights reserved. + * Copyright (c) 2011-2018 The Linux Foundation. All rights reserved. * * Previously licensed under the ISC license by Qualcomm Atheros, Inc. * @@ -971,400 +971,6 @@ struct ecb_aes_result { 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); -} - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,8,0)) -/*-------------------------------------------------------------------------- - - \brief vos_encrypt_AES() - Generate AES Encrypted byte stream - - The vos_encrypt_AES() function generates the encrypted byte stream for given text. - - Buffer should be allocated before calling vos_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 VOS_STATUS_SUCCESS - Successfully generated random memory. - - VOS_STATUS_E_FAULT - pbBuf is an invalid pointer. - - VOS_STATUS_E_FAILURE - default return value if it fails due to - unknown reasons - - ***VOS_STATUS_E_RESOURCES - System resources (other than memory) - are unavailable - \sa - - ( *** return value not considered yet ) - --------------------------------------------------------------------------*/ -VOS_STATUS vos_encrypt_AES(v_U32_t cryptHandle, /* Handle */ - v_U8_t *pPlainText, /* pointer to data stream */ - v_U8_t *pCiphertext, - v_U8_t *pKey) /* pointer to authentication key */ -{ - struct ecb_aes_result result; - struct crypto_skcipher *tfm; - struct skcipher_request *req; - int ret = 0; - char iv[IV_SIZE_AES_128]; - struct scatterlist sg_in; - struct scatterlist sg_out; - - init_completion(&result.completion); - -#if !defined(CONFIG_CNSS) && (defined(HIF_USB) || defined(HIF_SDIO) || defined(CONFIG_NON_QC_PLATFORM_PCI)) - tfm = crypto_alloc_skcipher( "cbc(aes)", 0, 0); -#else - tfm = wcnss_wlan_crypto_alloc_ablkcipher( "cbc(aes)", 0, 0); -#endif - if (IS_ERR(tfm)) { - VOS_TRACE(VOS_MODULE_ID_VOSS,VOS_TRACE_LEVEL_ERROR, "crypto_alloc_skcipher failed"); - ret = PTR_ERR(tfm); - goto err_tfm; - } - - req = skcipher_request_alloc(tfm, GFP_KERNEL); - if (!req) { - VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR, "Failed to allocate request for cbc(aes)"); - ret = -ENOMEM; - goto err_req; - } - - skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - ecb_aes_complete, &result); - - - crypto_skcipher_clear_flags(tfm, ~0); - - ret = crypto_skcipher_setkey(tfm, pKey, AES_KEYSIZE_128); - if (ret) { - VOS_TRACE(VOS_MODULE_ID_VOSS,VOS_TRACE_LEVEL_ERROR, "crypto_skcipher_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); - - skcipher_request_set_crypt(req, &sg_in, &sg_out, AES_BLOCK_SIZE, iv); - - ret = crypto_skcipher_encrypt(req); - if (ret == -EINPROGRESS || ret == -EBUSY) { - VOS_TRACE(VOS_MODULE_ID_VOSS,VOS_TRACE_LEVEL_ERROR, "crypto_skcipher_encrypt failed ret %d", ret); - wait_for_completion(&result.completion); - ret = result.err; - } - - -// ------------------------------------- -err_setkey: -#if !defined(CONFIG_CNSS) && (defined(HIF_USB) || defined(HIF_SDIO) || defined(CONFIG_NON_QC_PLATFORM_PCI)) - skcipher_request_free(req); -#else - wcnss_wlan_ablkcipher_request_free(req); -#endif -err_req: -#if !defined(CONFIG_CNSS) && (defined(HIF_USB) || defined(HIF_SDIO) || defined(CONFIG_NON_QC_PLATFORM_PCI)) - crypto_free_skcipher(tfm); -#else - wcnss_wlan_crypto_free_ablkcipher(tfm); -#endif -err_tfm: - //return ret; - if (ret != 0) { - VOS_TRACE(VOS_MODULE_ID_VOSS,VOS_TRACE_LEVEL_ERROR,"%s() call failed", __func__); - return VOS_STATUS_E_FAULT; - } - - return VOS_STATUS_SUCCESS; -} -#else //(LINUX_VERSION_CODE >= KERNEL_VERSION(4,8,0)) -VOS_STATUS vos_encrypt_AES(v_U32_t cryptHandle, /* Handle */ - v_U8_t *pPlainText, /* pointer to data stream */ - v_U8_t *pCiphertext, - v_U8_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); - -#if !defined(CONFIG_CNSS) && (defined(HIF_USB) || defined(HIF_SDIO) || defined(CONFIG_NON_QC_PLATFORM_PCI)) - tfm = crypto_alloc_ablkcipher( "cbc(aes)", 0, 0); -#else - tfm = wcnss_wlan_crypto_alloc_ablkcipher( "cbc(aes)", 0, 0); -#endif - if (IS_ERR(tfm)) { - VOS_TRACE(VOS_MODULE_ID_VOSS,VOS_TRACE_LEVEL_ERROR, "crypto_alloc_ablkcipher failed"); - ret = PTR_ERR(tfm); - goto err_tfm; - } - - req = ablkcipher_request_alloc(tfm, GFP_KERNEL); - if (!req) { - VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_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) { - VOS_TRACE(VOS_MODULE_ID_VOSS,VOS_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: -#if !defined(CONFIG_CNSS) && (defined(HIF_USB) || defined(HIF_SDIO) || defined(CONFIG_NON_QC_PLATFORM_PCI)) - ablkcipher_request_free(req); -#else - wcnss_wlan_ablkcipher_request_free(req); -#endif -err_req: -#if !defined(CONFIG_CNSS) && (defined(HIF_USB) || defined(HIF_SDIO) || defined(CONFIG_NON_QC_PLATFORM_PCI)) - crypto_free_ablkcipher(tfm); -#else - wcnss_wlan_crypto_free_ablkcipher(tfm); -#endif -err_tfm: - //return ret; - if (ret != 0) { - VOS_TRACE(VOS_MODULE_ID_VOSS,VOS_TRACE_LEVEL_ERROR,"%s() call failed", __func__); - return VOS_STATUS_E_FAULT; - } - - return VOS_STATUS_SUCCESS; -} -#endif //(LINUX_VERSION_CODE >= KERNEL_VERSION(4,8,0)) - -#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,8,0)) -/*-------------------------------------------------------------------------- - - \brief vos_decrypt_AES() - Decrypts an AES Encrypted byte stream - - The vos_decrypt_AES() function decrypts the encrypted byte stream. - - Buffer should be allocated before calling vos_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 VOS_STATUS_SUCCESS - Successfully generated random memory. - - VOS_STATUS_E_FAULT - pbBuf is an invalid pointer. - - VOS_STATUS_E_FAILURE - default return value if it fails due to - unknown reasons - - ***VOS_STATUS_E_RESOURCES - System resources (other than memory) - are unavailable - \sa - - ( *** return value not considered yet ) - --------------------------------------------------------------------------*/ -VOS_STATUS vos_decrypt_AES(v_U32_t cryptHandle, /* Handle */ - v_U8_t *pText, /* pointer to data stream */ - v_U8_t *pDecrypted, - v_U8_t *pKey) /* pointer to authentication key */ -{ -// VOS_STATUS uResult = VOS_STATUS_E_FAILURE; - struct ecb_aes_result result; - struct skcipher_request *req; - struct crypto_skcipher *tfm; - int ret = 0; - char iv[IV_SIZE_AES_128]; - struct scatterlist sg_in; - struct scatterlist sg_out; - - init_completion(&result.completion); - -#if !defined(CONFIG_CNSS) && (defined(HIF_USB) || defined(HIF_SDIO) || defined(CONFIG_NON_QC_PLATFORM_PCI)) - tfm = crypto_alloc_skcipher( "cbc(aes)", 0, 0); -#else - tfm = wcnss_wlan_crypto_alloc_ablkcipher( "cbc(aes)", 0, 0); -#endif - if (IS_ERR(tfm)) { - VOS_TRACE(VOS_MODULE_ID_VOSS,VOS_TRACE_LEVEL_ERROR, "crypto_alloc_skcipher failed"); - ret = PTR_ERR(tfm); - goto err_tfm; - } - - req = skcipher_request_alloc(tfm, GFP_KERNEL); - if (!req) { - VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR, "Failed to allocate request for cbc(aes)"); - ret = -ENOMEM; - goto err_req; - } - - skcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, - ecb_aes_complete, &result); - - - crypto_skcipher_clear_flags(tfm, ~0); - - ret = crypto_skcipher_setkey(tfm, pKey, AES_KEYSIZE_128); - if (ret) { - VOS_TRACE(VOS_MODULE_ID_VOSS,VOS_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); - - skcipher_request_set_crypt(req, &sg_in, &sg_out, AES_BLOCK_SIZE, iv); - - ret = crypto_skcipher_decrypt(req); - skcipher_request_zero(req); - if (ret) { - VOS_TRACE(VOS_MODULE_ID_VOSS,VOS_TRACE_LEVEL_ERROR,"AES: failed to decrypt received packet"); - } - - -// ------------------------------------- -err_setkey: -#if !defined(CONFIG_CNSS) && (defined(HIF_USB) || defined(HIF_SDIO) || defined(CONFIG_NON_QC_PLATFORM_PCI)) - skcipher_request_free(req); -#else - wcnss_wlan_ablkcipher_request_free(req); -#endif -err_req: -#if !defined(CONFIG_CNSS) && (defined(HIF_USB) || defined(HIF_SDIO) || defined(CONFIG_NON_QC_PLATFORM_PCI)) - crypto_free_skcipher(tfm); -#else - wcnss_wlan_crypto_free_ablkcipher(tfm); -#endif -err_tfm: - //return ret; - if (ret != 0) { - VOS_TRACE(VOS_MODULE_ID_VOSS,VOS_TRACE_LEVEL_ERROR,"%s() call failed", __func__); - return VOS_STATUS_E_FAULT; - } - - return VOS_STATUS_SUCCESS; -} -#else //LINUX_VERSION_CODE < KERNEL_VERSION(4,8,0) -VOS_STATUS vos_decrypt_AES(v_U32_t cryptHandle, /* Handle */ - v_U8_t *pText, /* pointer to data stream */ - v_U8_t *pDecrypted, - v_U8_t *pKey) /* pointer to authentication key */ -{ -// VOS_STATUS uResult = VOS_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); - -#if !defined(CONFIG_CNSS) && (defined(HIF_USB) || defined(HIF_SDIO) || defined(CONFIG_NON_QC_PLATFORM_PCI)) - tfm = crypto_alloc_ablkcipher( "cbc(aes)", 0, 0); -#else - tfm = wcnss_wlan_crypto_alloc_ablkcipher( "cbc(aes)", 0, 0); -#endif - if (IS_ERR(tfm)) { - VOS_TRACE(VOS_MODULE_ID_VOSS,VOS_TRACE_LEVEL_ERROR, "crypto_alloc_ablkcipher failed"); - ret = PTR_ERR(tfm); - goto err_tfm; - } - - req = ablkcipher_request_alloc(tfm, GFP_KERNEL); - if (!req) { - VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_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) { - VOS_TRACE(VOS_MODULE_ID_VOSS,VOS_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: -#if !defined(CONFIG_CNSS) && (defined(HIF_USB) || defined(HIF_SDIO) || defined(CONFIG_NON_QC_PLATFORM_PCI)) - ablkcipher_request_free(req); -#else - wcnss_wlan_ablkcipher_request_free(req); -#endif -err_req: -#if !defined(CONFIG_CNSS) && (defined(HIF_USB) || defined(HIF_SDIO) || defined(CONFIG_NON_QC_PLATFORM_PCI)) - crypto_free_ablkcipher(tfm); -#else - wcnss_wlan_crypto_free_ablkcipher(tfm); -#endif -err_tfm: - //return ret; - if (ret != 0) { - VOS_TRACE(VOS_MODULE_ID_VOSS,VOS_TRACE_LEVEL_ERROR,"%s() call failed", __func__); - return VOS_STATUS_E_FAULT; - } - - return VOS_STATUS_SUCCESS; -} -#endif //(LINUX_VERSION_CODE >= KERNEL_VERSION(4,8,0)) - v_U32_t vos_chan_to_freq(v_U8_t chan) { if (chan < VOS_24_GHZ_CHANNEL_14) // ch 0 - ch 13 |
