Commit 9363efb4 authored by Thara Gopinath's avatar Thara Gopinath Committed by Herbert Xu
Browse files

crypto: qce - Add support for AEAD algorithms



Introduce support to enable following algorithms in Qualcomm Crypto Engine.

- authenc(hmac(sha1),cbc(des))
- authenc(hmac(sha1),cbc(des3_ede))
- authenc(hmac(sha256),cbc(des))
- authenc(hmac(sha256),cbc(des3_ede))
- authenc(hmac(sha256),cbc(aes))
- ccm(aes)
- rfc4309(ccm(aes))

Signed-off-by: default avatarThara Gopinath <thara.gopinath@linaro.org>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 7ba9cd4e
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -627,6 +627,12 @@ config CRYPTO_DEV_QCE_SHA
	select CRYPTO_SHA1
	select CRYPTO_SHA256

config CRYPTO_DEV_QCE_AEAD
	bool
	depends on CRYPTO_DEV_QCE
	select CRYPTO_AUTHENC
	select CRYPTO_LIB_DES

choice
	prompt "Algorithms enabled for QCE acceleration"
	default CRYPTO_DEV_QCE_ENABLE_ALL
@@ -647,6 +653,7 @@ choice
		bool "All supported algorithms"
		select CRYPTO_DEV_QCE_SKCIPHER
		select CRYPTO_DEV_QCE_SHA
		select CRYPTO_DEV_QCE_AEAD
		help
		  Enable all supported algorithms:
			- AES (CBC, CTR, ECB, XTS)
@@ -672,6 +679,14 @@ choice
			- SHA1, HMAC-SHA1
			- SHA256, HMAC-SHA256

	config CRYPTO_DEV_QCE_ENABLE_AEAD
		bool "AEAD algorithms only"
		select CRYPTO_DEV_QCE_AEAD
		help
		  Enable AEAD algorithms only:
			- authenc()
			- ccm(aes)
			- rfc4309(ccm(aes))
endchoice

config CRYPTO_DEV_QCE_SW_MAX_LEN
+1 −0
Original line number Diff line number Diff line
@@ -6,3 +6,4 @@ qcrypto-objs := core.o \

qcrypto-$(CONFIG_CRYPTO_DEV_QCE_SHA) += sha.o
qcrypto-$(CONFIG_CRYPTO_DEV_QCE_SKCIPHER) += skcipher.o
qcrypto-$(CONFIG_CRYPTO_DEV_QCE_AEAD) += aead.o
+799 −0

File added.

Preview size limit exceeded, changes collapsed.

+53 −0
Original line number Diff line number Diff line
/* SPDX-License-Identifier: GPL-2.0-only */
/*
 * Copyright (c) 2021, Linaro Limited. All rights reserved.
 */

#ifndef _AEAD_H_
#define _AEAD_H_

#include "common.h"
#include "core.h"

#define QCE_MAX_KEY_SIZE		64
#define QCE_CCM4309_SALT_SIZE		3

struct qce_aead_ctx {
	u8 enc_key[QCE_MAX_KEY_SIZE];
	u8 auth_key[QCE_MAX_KEY_SIZE];
	u8 ccm4309_salt[QCE_CCM4309_SALT_SIZE];
	unsigned int enc_keylen;
	unsigned int auth_keylen;
	unsigned int authsize;
};

struct qce_aead_reqctx {
	unsigned long flags;
	u8 *iv;
	unsigned int ivsize;
	int src_nents;
	int dst_nents;
	struct scatterlist result_sg;
	struct scatterlist adata_sg;
	struct sg_table dst_tbl;
	struct sg_table src_tbl;
	struct scatterlist *dst_sg;
	struct scatterlist *src_sg;
	unsigned int cryptlen;
	unsigned int assoclen;
	unsigned char *adata;
	u8 ccm_nonce[QCE_MAX_NONCE];
	u8 ccmresult_buf[QCE_BAM_BURST_SIZE];
	u8 ccm_rfc4309_iv[QCE_MAX_IV_SIZE];
};

static inline struct qce_alg_template *to_aead_tmpl(struct crypto_aead *tfm)
{
	struct aead_alg *alg = crypto_aead_alg(tfm);

	return container_of(alg, struct qce_alg_template, alg.aead);
}

extern const struct qce_algo_ops aead_ops;

#endif /* _AEAD_H_ */
+2 −0
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@
#include <crypto/aes.h>
#include <crypto/hash.h>
#include <crypto/internal/skcipher.h>
#include <crypto/internal/aead.h>

/* xts du size */
#define QCE_SECTOR_SIZE			512
@@ -88,6 +89,7 @@ struct qce_alg_template {
	union {
		struct skcipher_alg skcipher;
		struct ahash_alg ahash;
		struct aead_alg aead;
	} alg;
	struct qce_device *qce;
	const u8 *hash_zero;
Loading