summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil DI FOLCO <neil.difolco@qorvo.com>2023-01-12 14:42:25 +0100
committerVictor Liu <victorliu@google.com>2023-01-18 21:40:53 +0000
commit034c483000c2f92cfeb2b3e7f3dc5e1bc66d387c (patch)
tree86516063be8674bf8bcc159e896b7a63158419c8
parent6f7a57c9037875af34177ba3b4744e26905ca720 (diff)
downloaduwb-034c483000c2f92cfeb2b3e7f3dc5e1bc66d387c.tar.gz
uwb: remove dw3000 specific code
Bug: 265987189 Change-Id: I323897b3d151b6acfcc4428e7775e7e052d602ee Signed-off-by: Neil DI FOLCO <neil.difolco@qorvo.com>
-rw-r--r--mcps_crypto.c321
-rw-r--r--mcps_crypto.h197
2 files changed, 0 insertions, 518 deletions
diff --git a/mcps_crypto.c b/mcps_crypto.c
deleted file mode 100644
index faef7a4..0000000
--- a/mcps_crypto.c
+++ /dev/null
@@ -1,321 +0,0 @@
-/*
- * This file is part of the UWB stack for linux.
- *
- * Copyright (c) 2022 Qorvo US, Inc.
- *
- * This software is provided under the GNU General Public License, version 2
- * (GPLv2), as well as under a Qorvo commercial license.
- *
- * You may choose to use this software under the terms of the GPLv2 License,
- * version 2 ("GPLv2"), as published by the Free Software Foundation.
- * You should have received a copy of the GPLv2 along with this program. If
- * not, see <http://www.gnu.org/licenses/>.
- *
- * This program is distributed under the GPLv2 in the hope that it will be
- * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GPLv2 for more
- * details.
- *
- * If you cannot meet the requirements of the GPLv2, you may not use this
- * software for any purpose without first obtaining a commercial license from
- * Qorvo. Please contact Qorvo to inquire about licensing terms.
- */
-
-#include <linux/crypto.h>
-#include <linux/scatterlist.h>
-#include <crypto/hash.h>
-#include <crypto/skcipher.h>
-#include <crypto/aead.h>
-#include <crypto/aes.h>
-
-#include "mcps_crypto.h"
-
-#if !(defined(CONFIG_CRYPTO_HASH2) && defined(CONFIG_CRYPTO_AEAD2))
-#error "required CONFIG_CRYPTO_HASH2 && CONFIG_CRYPTO_AEAD2"
-#endif
-
-#define FIRA_CRYPTO_AEAD_AUTHSIZE 8
-
-
-struct mcps_aes_ccm_star_128_ctx {
- struct crypto_aead *tfm;
-};
-
-struct mcps_aes_ecb_128_ctx {
- struct crypto_skcipher *tfm;
- bool decrypt;
-};
-
-
-int mcps_crypto_cmac_aes_128_digest(const uint8_t *key, const uint8_t *data,
- unsigned int data_len, uint8_t *out)
-{
- struct crypto_shash *tfm;
- int r;
-
- tfm = crypto_alloc_shash("cmac(aes)", 0, 0);
- if (IS_ERR(tfm)) {
- if (PTR_ERR(tfm) == -ENOENT)
- pr_err("The crypto transform cmac(aes) seems to be missing."
- " Please check your kernel configuration.\n");
- return PTR_ERR(tfm);
- }
-
- r = crypto_shash_setkey(tfm, key, AES_KEYSIZE_128);
- if (r != 0)
- goto out;
-
- do {
- /* tfm need to be allocated for kernel < 4.20, so don't remove
- * this do..while block
- */
- SHASH_DESC_ON_STACK(desc, tfm);
-
- desc->tfm = tfm;
-
- r = crypto_shash_init(desc);
- if (r != 0)
- goto out;
-
- r = crypto_shash_finup(desc, data, data_len, out);
- } while (0);
-
-out:
- crypto_free_shash(tfm);
-
- return r;
-}
-
-struct mcps_aes_ccm_star_128_ctx *mcps_crypto_aead_aes_ccm_star_128_create(void)
-{
- struct mcps_aes_ccm_star_128_ctx *ctx;
- int r;
-
- ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
- if (!ctx)
- goto error;
-
- ctx->tfm = crypto_alloc_aead("ccm(aes)", 0, 0);
- if (IS_ERR(ctx->tfm)) {
- if (PTR_ERR(ctx->tfm) == -ENOENT)
- pr_err("The crypto transform ccm(aes) seems to be missing."
- " Please check your kernel configuration.\n");
- goto error;
- }
-
- r = crypto_aead_setauthsize(ctx->tfm, FIRA_CRYPTO_AEAD_AUTHSIZE);
- if (r != 0)
- goto error;
-
- return ctx;
-
-error:
- mcps_crypto_aead_aes_ccm_star_128_destroy(ctx);
-
- return NULL;
-}
-
-int mcps_crypto_aead_aes_ccm_star_128_set(struct mcps_aes_ccm_star_128_ctx *ctx,
- const uint8_t *key)
-{
- if (!ctx || !key)
- return -EINVAL;
-
- return crypto_aead_setkey(ctx->tfm, key, AES_KEYSIZE_128);
-}
-
-void mcps_crypto_aead_aes_ccm_star_128_destroy(struct mcps_aes_ccm_star_128_ctx *ctx)
-{
- if (!ctx)
- return;
-
- crypto_free_aead(ctx->tfm);
- kfree(ctx);
-}
-
-int mcps_crypto_aead_aes_ccm_star_128_encrypt(
- struct mcps_aes_ccm_star_128_ctx *ctx, const uint8_t *nonce,
- const uint8_t *header, unsigned int header_len,
- uint8_t *data, unsigned int data_len,
- uint8_t *mac, unsigned int mac_len)
-{
- struct aead_request *req = NULL;
- struct scatterlist sg[3];
- u8 iv[AES_BLOCK_SIZE];
- DECLARE_CRYPTO_WAIT(wait);
- int r = -1;
-
- if (!ctx || !nonce || !header || header_len <= 0 || !data ||
- data_len <= 0 || !mac ||
- mac_len != FIRA_CRYPTO_AEAD_AUTHSIZE) {
- return -EINVAL;
- }
-
- req = aead_request_alloc(ctx->tfm, GFP_KERNEL);
- if (!req) {
- r = -ENOMEM;
- goto end;
- }
-
- sg_init_table(sg, ARRAY_SIZE(sg));
- sg_set_buf(&sg[0], header, header_len);
- sg_set_buf(&sg[1], data, data_len);
- sg_set_buf(&sg[2], mac, mac_len);
-
- iv[0] = sizeof(u16) - 1;
- memcpy(iv + 1, nonce, MCPS_CRYPTO_AES_CCM_STAR_NONCE_LEN);
-
- aead_request_set_callback(req,
- CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
- crypto_req_done, &wait);
- aead_request_set_ad(req, header_len);
- aead_request_set_crypt(req, sg, sg, data_len, iv);
-
- r = crypto_wait_req(crypto_aead_encrypt(req), &wait);
-
-end:
- aead_request_free(req);
-
- return r;
-}
-
-int mcps_crypto_aead_aes_ccm_star_128_decrypt(
- struct mcps_aes_ccm_star_128_ctx *ctx, const uint8_t *nonce,
- const uint8_t *header, unsigned int header_len,
- uint8_t *data, unsigned int data_len,
- uint8_t *mac, unsigned int mac_len)
-{
- struct aead_request *req = NULL;
- struct scatterlist sg[3];
- u8 iv[AES_BLOCK_SIZE];
- DECLARE_CRYPTO_WAIT(wait);
- int r = -1;
-
- if (!ctx || !nonce || !header || header_len <= 0 || !data ||
- data_len <= 0 || !mac ||
- mac_len != FIRA_CRYPTO_AEAD_AUTHSIZE) {
- return -EINVAL;
- }
-
- req = aead_request_alloc(ctx->tfm, GFP_KERNEL);
- if (!req) {
- r = -ENOMEM;
- goto end;
- }
-
- iv[0] = sizeof(u16) - 1;
- memcpy(iv + 1, nonce, MCPS_CRYPTO_AES_CCM_STAR_NONCE_LEN);
-
- sg_init_table(sg, ARRAY_SIZE(sg));
- sg_set_buf(&sg[0], header, header_len);
- sg_set_buf(&sg[1], data, data_len);
- sg_set_buf(&sg[2], mac, mac_len);
-
- aead_request_set_callback(req,
- CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
- crypto_req_done, &wait);
- aead_request_set_ad(req, header_len);
- aead_request_set_crypt(req, sg, sg, data_len + mac_len, iv);
-
- r = crypto_wait_req(crypto_aead_decrypt(req), &wait);
-
-end:
- aead_request_free(req);
-
- return r;
-}
-
-struct mcps_aes_ecb_128_ctx *mcps_crypto_aes_ecb_128_create(void)
-{
- struct mcps_aes_ecb_128_ctx *ctx;
-
- ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
- if (!ctx)
- goto error;
-
- ctx->tfm = crypto_alloc_skcipher("ecb(aes)", 0, 0);
- if (IS_ERR(ctx->tfm)) {
- if (PTR_ERR(ctx->tfm) == -ENOENT)
- pr_err("The crypto transform ecb(aes) seems to be missing."
- " Please check your kernel configuration.\n");
- goto error;
- }
-
- return ctx;
-
-error:
- mcps_crypto_aes_ecb_128_destroy(ctx);
-
- return NULL;
-}
-
-int mcps_crypto_aes_ecb_128_set_encrypt(struct mcps_aes_ecb_128_ctx *ctx,
- const uint8_t *key)
-{
- if (!ctx || !key)
- return -EINVAL;
-
- ctx->decrypt = false;
-
- return crypto_skcipher_setkey(ctx->tfm, key, AES_KEYSIZE_128);
-}
-
-int mcps_crypto_aes_ecb_128_set_decrypt(struct mcps_aes_ecb_128_ctx *ctx,
- const uint8_t *key)
-{
- if (!ctx || !key)
- return -EINVAL;
-
- ctx->decrypt = true;
-
- return crypto_skcipher_setkey(ctx->tfm, key, AES_KEYSIZE_128);
-}
-
-void mcps_crypto_aes_ecb_128_destroy(struct mcps_aes_ecb_128_ctx *ctx)
-{
- if (!ctx)
- return;
-
- crypto_free_skcipher(ctx->tfm);
- kfree(ctx);
-}
-
-int mcps_crypto_aes_ecb_128_encrypt(struct mcps_aes_ecb_128_ctx *ctx,
- const uint8_t *data, unsigned int data_len, uint8_t *out)
-{
- struct skcipher_request *req = NULL;
- struct scatterlist sgin, sgout;
- DECLARE_CRYPTO_WAIT(wait);
- int r = -1;
-
- if (!ctx || !data || data_len <= 0 || !out)
- return -EINVAL;
-
- /* round to full cipher block */
- data_len = ((data_len - 1) & -AES_KEYSIZE_128) + AES_KEYSIZE_128;
-
- req = skcipher_request_alloc(ctx->tfm, GFP_KERNEL);
- if (!req) {
- r = -ENOMEM;
- goto end;
- }
-
- sg_init_one(&sgin, data, data_len);
- sg_init_one(&sgout, out, data_len);
- skcipher_request_set_callback(req,
- CRYPTO_TFM_REQ_MAY_BACKLOG | CRYPTO_TFM_REQ_MAY_SLEEP,
- crypto_req_done, &wait);
- skcipher_request_set_crypt(req, &sgin, &sgout, data_len, NULL);
-
- if (ctx->decrypt)
- r = crypto_skcipher_decrypt(req);
- else
- r = crypto_skcipher_encrypt(req);
- r = crypto_wait_req(r, &wait);
-
-end:
- skcipher_request_free(req);
-
- return r;
-}
-
diff --git a/mcps_crypto.h b/mcps_crypto.h
deleted file mode 100644
index 5a1a5c5..0000000
--- a/mcps_crypto.h
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * This file is part of the UWB stack for linux.
- *
- * Copyright (c) 2020-2022 Qorvo US, Inc.
- *
- * This software is provided under the GNU General Public License, version 2
- * (GPLv2), as well as under a Qorvo commercial license.
- *
- * You may choose to use this software under the terms of the GPLv2 License,
- * version 2 ("GPLv2"), as published by the Free Software Foundation.
- * You should have received a copy of the GPLv2 along with this program. If
- * not, see <http://www.gnu.org/licenses/>.
- *
- * This program is distributed under the GPLv2 in the hope that it will be
- * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GPLv2 for more
- * details.
- *
- * If you cannot meet the requirements of the GPLv2, you may not use this
- * software for any purpose without first obtaining a commercial license from
- * Qorvo. Please contact Qorvo to inquire about licensing terms.
- */
-
-#ifndef MCPS_CRYPTO_H
-#define MCPS_CRYPTO_H
-
-#ifdef __KERNEL__
-#include <linux/types.h>
-#else
-#include <stdint.h>
-#endif
-
-#define MCPS_CRYPTO_AES_CCM_STAR_NONCE_LEN 13
-
-/**
- * struct mcps_aes_ccm_star_128_ctx - Context containing AES-128-CCM* related
- * information.
- *
- * This is an opaque structure left to the implementation.
- */
-struct mcps_aes_ccm_star_128_ctx;
-
-/**
- * struct mcps_aes_ecb_128_ctx - Context containing AES-128-ECB related
- * information.
- *
- * This is an opaque structure left to the implementation.
- */
-struct mcps_aes_ecb_128_ctx;
-
-
-/**
- * mcps_crypto_cmac_aes_128_digest() - Compute a cmac AES 128.
- * @key: AES key.
- * @data: Input data.
- * @data_len: Input data length in bytes.
- * @out: Output hash, with length AES_BLOCK_SIZE.
- *
- * NOTE: This API should be implemented by platform.
- *
- * Return: 0 or error.
- */
-int mcps_crypto_cmac_aes_128_digest(const uint8_t *key, const uint8_t *data,
- unsigned int data_len, uint8_t *out);
-
-/**
- * mcps_crypto_aead_aes_ccm_star_128_create() - Create a context using
- * Authenticated Encryption Associated Data with AES CCM* 128.
- *
- * NOTE: This API should be implemented by platform.
- *
- * Return: The pointer to the context that will be used to encrypt & decrypt.
- */
-struct mcps_aes_ccm_star_128_ctx *mcps_crypto_aead_aes_ccm_star_128_create(void);
-
-/**
- * mcps_crypto_aead_aes_ccm_star_128_set() - Set a context using
- * Authenticated Encryption Associated Data with AES CCM* 128.
- * @ctx: Context.
- * @key: AES key.
- *
- * NOTE: This API should be implemented by platform.
- *
- * Return: 0 or error.
- */
-int mcps_crypto_aead_aes_ccm_star_128_set(struct mcps_aes_ccm_star_128_ctx *ctx, const uint8_t *key);
-
-/**
- * mcps_crypto_aead_aes_ccm_star_128_destroy() - Destroy the Authenticated
- * Encryption Associated Data with AES CCM* 128 context.
- * @ctx: Context.
- *
- * NOTE: This API should be implemented by platform.
- */
-void mcps_crypto_aead_aes_ccm_star_128_destroy(struct mcps_aes_ccm_star_128_ctx *ctx);
-
-/**
- * mcps_crypto_aead_aes_ccm_star_128_encrypt() - Encrypt using Authenticated
- * Encryption Associated Data with AES CCM* 128.
- * @ctx: Context.
- * @nonce: Nonce, with length MCPS_CRYPTO_AES_CCM_STAR_NONCE_LEN.
- * @header: Header data.
- * @header_len: Header length in bytes.
- * @data: Data to encrypt, will be replaced with encrypted data.
- * @data_len: Data length in bytes.
- * @mac: AES CCM* MAC.
- * @mac_len: AES CCM* MAC size in bytes.
- *
- * NOTE: This API should be implemented by platform.
- *
- * Return: 0 or error.
- */
-int mcps_crypto_aead_aes_ccm_star_128_encrypt(
- struct mcps_aes_ccm_star_128_ctx *ctx, const uint8_t *nonce,
- const uint8_t *header, unsigned int header_len,
- uint8_t *data, unsigned int data_len,
- uint8_t *mac, unsigned int mac_len);
-
-/**
- * mcps_crypto_aead_aes_ccm_star_128_decrypt() - Decrypt using Authenticated
- * Encryption Associated Data with AES CCM* 128.
- * @ctx: Context.
- * @nonce: Nonce, with length MCPS_CRYPTO_AES_CCM_STAR_NONCE_LEN.
- * @header: Header data.
- * @header_len: Header length in bytes.
- * @data: Data to decrypt, will be replaced with decrypted data.
- * @data_len: Data length in bytes.
- * @mac: AES CCM* MAC.
- * @mac_len: AES CCM* MAC size in bytes.
- *
- * NOTE: This API should be implemented by platform. In case of mismatch
- * between the MAC and calculated MAC, this function should return -EBADMSG.
- *
- * Return: 0 or error.
- */
-int mcps_crypto_aead_aes_ccm_star_128_decrypt(
- struct mcps_aes_ccm_star_128_ctx *ctx, const uint8_t *nonce,
- const uint8_t *header, unsigned int header_len,
- uint8_t *data, unsigned int data_len,
- uint8_t *mac, unsigned int mac_len);
-
-/**
- * mcps_crypto_aes_ecb_128_create() - Create a context using AES ECB 128.
- *
- * NOTE: This API should be implemented by platform.
- *
- * Return: The pointer to the context that will be used to encrypt & decrypt.
- */
-struct mcps_aes_ecb_128_ctx *mcps_crypto_aes_ecb_128_create(void);
-
-/**
- * mcps_crypto_aes_ecb_128_set_encrypt() - Set a context using
- * Authenticated Encryption Associated Data with AES ECB* 128.
- * @ctx: Context.
- * @key: AES key.
- *
- * NOTE: This API should be implemented by platform.
- *
- * Return: 0 or error.
- */
-int mcps_crypto_aes_ecb_128_set_encrypt(struct mcps_aes_ecb_128_ctx *ctx, const uint8_t *key);
-
-/**
- * mcps_crypto_aes_ecb_128_set_decrypt() - Set a context using
- * Authenticated Encryption Associated Data with AES ECB* 128.
- * @ctx: Context.
- * @key: AES key.
- *
- * NOTE: This API should be implemented by platform.
- *
- * Return: 0 or error.
- */
-int mcps_crypto_aes_ecb_128_set_decrypt(struct mcps_aes_ecb_128_ctx *ctx, const uint8_t *key);
-
-/**
- * mcps_crypto_aes_ecb_128_destroy() - Destroy the AES ECB 128 context.
- * @ctx: Context.
- *
- * NOTE: This API should be implemented by platform.
- */
-void mcps_crypto_aes_ecb_128_destroy(struct mcps_aes_ecb_128_ctx *ctx);
-
-/**
- * mcps_crypto_aes_ecb_128_encrypt() - Encrypt using AES ECB 128.
- * @ctx: Context.
- * @data: Data to encrypt.
- * @data_len: Data length in bytes, should be a multiple of AES_BLOCK_SIZE.
- * @out: Ciphered data with same length as data.
- *
- * NOTE: This API should be implemented by platform.
- *
- * Return: 0 or error.
- */
-int mcps_crypto_aes_ecb_128_encrypt(struct mcps_aes_ecb_128_ctx *ctx,
- const uint8_t *data, unsigned int data_len, uint8_t *out);
-
-#endif /* MCPS_CRYPTO_H */