linux/drivers/crypto/caam/caamalg.c

// SPDX-License-Identifier: GPL-2.0+
/*
 * caam - Freescale FSL CAAM support for crypto API
 *
 * Copyright 2008-2011 Freescale Semiconductor, Inc.
 * Copyright 2016-2019, 2023 NXP
 *
 * Based on talitos crypto API driver.
 *
 * relationship of job descriptors to shared descriptors (SteveC Dec 10 2008):
 *
 * ---------------                     ---------------
 * | JobDesc #1  |-------------------->|  ShareDesc  |
 * | *(packet 1) |                     |   (PDB)     |
 * ---------------      |------------->|  (hashKey)  |
 *       .              |              | (cipherKey) |
 *       .              |    |-------->| (operation) |
 * ---------------      |    |         ---------------
 * | JobDesc #2  |------|    |
 * | *(packet 2) |           |
 * ---------------           |
 *       .                   |
 *       .                   |
 * ---------------           |
 * | JobDesc #3  |------------
 * | *(packet 3) |
 * ---------------
 *
 * The SharedDesc never changes for a connection unless rekeyed, but
 * each packet will likely be in a different place. So all we need
 * to know to process the packet is where the input is, where the
 * output goes, and what context we want to process with. Context is
 * in the SharedDesc, packet references in the JobDesc.
 *
 * So, a job desc looks like:
 *
 * ---------------------
 * | Header            |
 * | ShareDesc Pointer |
 * | SEQ_OUT_PTR       |
 * | (output buffer)   |
 * | (output length)   |
 * | SEQ_IN_PTR        |
 * | (input buffer)    |
 * | (input length)    |
 * ---------------------
 */

#include "compat.h"

#include "regs.h"
#include "intern.h"
#include "desc_constr.h"
#include "jr.h"
#include "error.h"
#include "sg_sw_sec4.h"
#include "key_gen.h"
#include "caamalg_desc.h"
#include <linux/unaligned.h>
#include <crypto/internal/aead.h>
#include <crypto/internal/engine.h>
#include <crypto/internal/skcipher.h>
#include <crypto/xts.h>
#include <linux/dma-mapping.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/string.h>

/*
 * crypto alg
 */
#define CAAM_CRA_PRIORITY
/* max key is sum of AES_MAX_KEY_SIZE, max split key size */
#define CAAM_MAX_KEY_SIZE

#define AEAD_DESC_JOB_IO_LEN
#define GCM_DESC_JOB_IO_LEN
#define AUTHENC_DESC_JOB_IO_LEN

#define CHACHAPOLY_DESC_JOB_IO_LEN

#define DESC_MAX_USED_BYTES
#define DESC_MAX_USED_LEN

struct caam_alg_entry {};

struct caam_aead_alg {};

struct caam_skcipher_alg {};

/*
 * per-session context
 */
struct caam_ctx {};

struct caam_skcipher_req_ctx {};

struct caam_aead_req_ctx {};

static int aead_null_set_sh_desc(struct crypto_aead *aead)
{}

static int aead_set_sh_desc(struct crypto_aead *aead)
{}

static int aead_setauthsize(struct crypto_aead *authenc,
				    unsigned int authsize)
{}

static int gcm_set_sh_desc(struct crypto_aead *aead)
{}

static int gcm_setauthsize(struct crypto_aead *authenc, unsigned int authsize)
{}

static int rfc4106_set_sh_desc(struct crypto_aead *aead)
{}

static int rfc4106_setauthsize(struct crypto_aead *authenc,
			       unsigned int authsize)
{}

static int rfc4543_set_sh_desc(struct crypto_aead *aead)
{}

static int rfc4543_setauthsize(struct crypto_aead *authenc,
			       unsigned int authsize)
{}

static int chachapoly_set_sh_desc(struct crypto_aead *aead)
{}

static int chachapoly_setauthsize(struct crypto_aead *aead,
				  unsigned int authsize)
{}

static int chachapoly_setkey(struct crypto_aead *aead, const u8 *key,
			     unsigned int keylen)
{}

static int aead_setkey(struct crypto_aead *aead,
			       const u8 *key, unsigned int keylen)
{}

static int des3_aead_setkey(struct crypto_aead *aead, const u8 *key,
			    unsigned int keylen)
{}

static int gcm_setkey(struct crypto_aead *aead,
		      const u8 *key, unsigned int keylen)
{}

static int rfc4106_setkey(struct crypto_aead *aead,
			  const u8 *key, unsigned int keylen)
{}

static int rfc4543_setkey(struct crypto_aead *aead,
			  const u8 *key, unsigned int keylen)
{}

static int skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
			   unsigned int keylen, const u32 ctx1_iv_off)
{}

static int aes_skcipher_setkey(struct crypto_skcipher *skcipher,
			       const u8 *key, unsigned int keylen)
{}

static int rfc3686_skcipher_setkey(struct crypto_skcipher *skcipher,
				   const u8 *key, unsigned int keylen)
{}

static int ctr_skcipher_setkey(struct crypto_skcipher *skcipher,
			       const u8 *key, unsigned int keylen)
{}

static int des_skcipher_setkey(struct crypto_skcipher *skcipher,
			       const u8 *key, unsigned int keylen)
{}

static int des3_skcipher_setkey(struct crypto_skcipher *skcipher,
				const u8 *key, unsigned int keylen)
{}

static int xts_skcipher_setkey(struct crypto_skcipher *skcipher, const u8 *key,
			       unsigned int keylen)
{}

/*
 * aead_edesc - s/w-extended aead descriptor
 * @src_nents: number of segments in input s/w scatterlist
 * @dst_nents: number of segments in output s/w scatterlist
 * @mapped_src_nents: number of segments in input h/w link table
 * @mapped_dst_nents: number of segments in output h/w link table
 * @sec4_sg_bytes: length of dma mapped sec4_sg space
 * @bklog: stored to determine if the request needs backlog
 * @sec4_sg_dma: bus physical mapped address of h/w link table
 * @sec4_sg: pointer to h/w link table
 * @hw_desc: the h/w job descriptor followed by any referenced link tables
 */
struct aead_edesc {};

/*
 * skcipher_edesc - s/w-extended skcipher descriptor
 * @src_nents: number of segments in input s/w scatterlist
 * @dst_nents: number of segments in output s/w scatterlist
 * @mapped_src_nents: number of segments in input h/w link table
 * @mapped_dst_nents: number of segments in output h/w link table
 * @iv_dma: dma address of iv for checking continuity and link table
 * @sec4_sg_bytes: length of dma mapped sec4_sg space
 * @bklog: stored to determine if the request needs backlog
 * @sec4_sg_dma: bus physical mapped address of h/w link table
 * @sec4_sg: pointer to h/w link table
 * @hw_desc: the h/w job descriptor followed by any referenced link tables
 *	     and IV
 */
struct skcipher_edesc {};

static void caam_unmap(struct device *dev, struct scatterlist *src,
		       struct scatterlist *dst, int src_nents,
		       int dst_nents,
		       dma_addr_t iv_dma, int ivsize, dma_addr_t sec4_sg_dma,
		       int sec4_sg_bytes)
{}

static void aead_unmap(struct device *dev,
		       struct aead_edesc *edesc,
		       struct aead_request *req)
{}

static void skcipher_unmap(struct device *dev, struct skcipher_edesc *edesc,
			   struct skcipher_request *req)
{}

static void aead_crypt_done(struct device *jrdev, u32 *desc, u32 err,
			    void *context)
{}

static inline u8 *skcipher_edesc_iv(struct skcipher_edesc *edesc)
{}

static void skcipher_crypt_done(struct device *jrdev, u32 *desc, u32 err,
				void *context)
{}

/*
 * Fill in aead job descriptor
 */
static void init_aead_job(struct aead_request *req,
			  struct aead_edesc *edesc,
			  bool all_contig, bool encrypt)
{}

static void init_gcm_job(struct aead_request *req,
			 struct aead_edesc *edesc,
			 bool all_contig, bool encrypt)
{}

static void init_chachapoly_job(struct aead_request *req,
				struct aead_edesc *edesc, bool all_contig,
				bool encrypt)
{}

static void init_authenc_job(struct aead_request *req,
			     struct aead_edesc *edesc,
			     bool all_contig, bool encrypt)
{}

/*
 * Fill in skcipher job descriptor
 */
static void init_skcipher_job(struct skcipher_request *req,
			      struct skcipher_edesc *edesc,
			      const bool encrypt)
{}

/*
 * allocate and map the aead extended descriptor
 */
static struct aead_edesc *aead_edesc_alloc(struct aead_request *req,
					   int desc_bytes, bool *all_contig_ptr,
					   bool encrypt)
{}

static int aead_enqueue_req(struct device *jrdev, struct aead_request *req)
{}

static inline int chachapoly_crypt(struct aead_request *req, bool encrypt)
{}

static int chachapoly_encrypt(struct aead_request *req)
{}

static int chachapoly_decrypt(struct aead_request *req)
{}

static inline int aead_crypt(struct aead_request *req, bool encrypt)
{}

static int aead_encrypt(struct aead_request *req)
{}

static int aead_decrypt(struct aead_request *req)
{}

static int aead_do_one_req(struct crypto_engine *engine, void *areq)
{}

static inline int gcm_crypt(struct aead_request *req, bool encrypt)
{}

static int gcm_encrypt(struct aead_request *req)
{}

static int gcm_decrypt(struct aead_request *req)
{}

static int ipsec_gcm_encrypt(struct aead_request *req)
{}

static int ipsec_gcm_decrypt(struct aead_request *req)
{}

/*
 * allocate and map the skcipher extended descriptor for skcipher
 */
static struct skcipher_edesc *skcipher_edesc_alloc(struct skcipher_request *req,
						   int desc_bytes)
{}

static int skcipher_do_one_req(struct crypto_engine *engine, void *areq)
{}

static inline bool xts_skcipher_ivsize(struct skcipher_request *req)
{}

static inline int skcipher_crypt(struct skcipher_request *req, bool encrypt)
{}

static int skcipher_encrypt(struct skcipher_request *req)
{}

static int skcipher_decrypt(struct skcipher_request *req)
{}

static struct caam_skcipher_alg driver_algs[] =;

static struct caam_aead_alg driver_aeads[] =;

static int caam_init_common(struct caam_ctx *ctx, struct caam_alg_entry *caam,
			    bool uses_dkp)
{}

static int caam_cra_init(struct crypto_skcipher *tfm)
{}

static int caam_aead_init(struct crypto_aead *tfm)
{}

static void caam_exit_common(struct caam_ctx *ctx)
{}

static void caam_cra_exit(struct crypto_skcipher *tfm)
{}

static void caam_aead_exit(struct crypto_aead *tfm)
{}

void caam_algapi_exit(void)
{}

static void caam_skcipher_alg_init(struct caam_skcipher_alg *t_alg)
{}

static void caam_aead_alg_init(struct caam_aead_alg *t_alg)
{}

int caam_algapi_init(struct device *ctrldev)
{}