linux/drivers/crypto/hisilicon/hpre/hpre_crypto.c

// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2019 HiSilicon Limited. */
#include <crypto/akcipher.h>
#include <crypto/curve25519.h>
#include <crypto/dh.h>
#include <crypto/ecc_curve.h>
#include <crypto/ecdh.h>
#include <crypto/rng.h>
#include <crypto/internal/akcipher.h>
#include <crypto/internal/kpp.h>
#include <crypto/internal/rsa.h>
#include <crypto/kpp.h>
#include <crypto/scatterwalk.h>
#include <linux/dma-mapping.h>
#include <linux/fips.h>
#include <linux/module.h>
#include <linux/time.h>
#include "hpre.h"

struct hpre_ctx;

#define HPRE_CRYPTO_ALG_PRI
#define HPRE_ALIGN_SZ
#define HPRE_BITS_2_BYTES_SHIFT
#define HPRE_RSA_512BITS_KSZ
#define HPRE_RSA_1536BITS_KSZ
#define HPRE_CRT_PRMS
#define HPRE_CRT_Q
#define HPRE_CRT_P
#define HPRE_CRT_INV
#define HPRE_DH_G_FLAG
#define HPRE_TRY_SEND_TIMES
#define HPRE_INVLD_REQ_ID

#define HPRE_SQE_ALG_BITS
#define HPRE_SQE_DONE_SHIFT
#define HPRE_DH_MAX_P_SZ

#define HPRE_DFX_SEC_TO_US
#define HPRE_DFX_US_TO_NS

/* due to nist p521  */
#define HPRE_ECC_MAX_KSZ

/* size in bytes of the n prime */
#define HPRE_ECC_NIST_P192_N_SIZE
#define HPRE_ECC_NIST_P256_N_SIZE
#define HPRE_ECC_NIST_P384_N_SIZE

/* size in bytes */
#define HPRE_ECC_HW256_KSZ_B
#define HPRE_ECC_HW384_KSZ_B

/* capability register mask of driver */
#define HPRE_DRV_RSA_MASK_CAP
#define HPRE_DRV_DH_MASK_CAP
#define HPRE_DRV_ECDH_MASK_CAP
#define HPRE_DRV_X25519_MASK_CAP

static DEFINE_MUTEX(hpre_algs_lock);
static unsigned int hpre_available_devs;

hpre_cb;

struct hpre_rsa_ctx {};

struct hpre_dh_ctx {};

struct hpre_ecdh_ctx {};

struct hpre_curve25519_ctx {};

struct hpre_ctx {};

struct hpre_asym_request {};

static inline unsigned int hpre_align_sz(void)
{}

static inline unsigned int hpre_align_pd(void)
{}

static int hpre_alloc_req_id(struct hpre_ctx *ctx)
{}

static void hpre_free_req_id(struct hpre_ctx *ctx, int req_id)
{}

static int hpre_add_req_to_ctx(struct hpre_asym_request *hpre_req)
{}

static void hpre_rm_req_from_ctx(struct hpre_asym_request *hpre_req)
{}

static struct hisi_qp *hpre_get_qp_and_start(u8 type)
{}

static int hpre_get_data_dma_addr(struct hpre_asym_request *hpre_req,
				  struct scatterlist *data, unsigned int len,
				  int is_src, dma_addr_t *tmp)
{}

static int hpre_prepare_dma_buf(struct hpre_asym_request *hpre_req,
				struct scatterlist *data, unsigned int len,
				int is_src, dma_addr_t *tmp)
{}

static int hpre_hw_data_init(struct hpre_asym_request *hpre_req,
			     struct scatterlist *data, unsigned int len,
			     int is_src, int is_dh)
{}

static void hpre_hw_data_clr_all(struct hpre_ctx *ctx,
				 struct hpre_asym_request *req,
				 struct scatterlist *dst,
				 struct scatterlist *src)
{}

static int hpre_alg_res_post_hf(struct hpre_ctx *ctx, struct hpre_sqe *sqe,
				void **kreq)
{}

static int hpre_ctx_set(struct hpre_ctx *ctx, struct hisi_qp *qp, int qlen)
{}

static void hpre_ctx_clear(struct hpre_ctx *ctx, bool is_clear_all)
{}

static bool hpre_is_bd_timeout(struct hpre_asym_request *req,
			       u64 overtime_thrhld)
{}

static void hpre_dh_cb(struct hpre_ctx *ctx, void *resp)
{}

static void hpre_rsa_cb(struct hpre_ctx *ctx, void *resp)
{}

static void hpre_alg_cb(struct hisi_qp *qp, void *resp)
{}

static void hpre_stop_qp_and_put(struct hisi_qp *qp)
{}

static int hpre_ctx_init(struct hpre_ctx *ctx, u8 type)
{}

static int hpre_msg_request_set(struct hpre_ctx *ctx, void *req, bool is_rsa)
{}

static int hpre_send(struct hpre_ctx *ctx, struct hpre_sqe *msg)
{}

static int hpre_dh_compute_value(struct kpp_request *req)
{}

static int hpre_is_dh_params_length_valid(unsigned int key_sz)
{}

static int hpre_dh_set_params(struct hpre_ctx *ctx, struct dh *params)
{}

static void hpre_dh_clear_ctx(struct hpre_ctx *ctx, bool is_clear_all)
{}

static int hpre_dh_set_secret(struct crypto_kpp *tfm, const void *buf,
			      unsigned int len)
{}

static unsigned int hpre_dh_max_size(struct crypto_kpp *tfm)
{}

static int hpre_dh_init_tfm(struct crypto_kpp *tfm)
{}

static void hpre_dh_exit_tfm(struct crypto_kpp *tfm)
{}

static void hpre_rsa_drop_leading_zeros(const char **ptr, size_t *len)
{}

static bool hpre_rsa_key_size_is_support(unsigned int len)
{}

static int hpre_rsa_enc(struct akcipher_request *req)
{}

static int hpre_rsa_dec(struct akcipher_request *req)
{}

static int hpre_rsa_set_n(struct hpre_ctx *ctx, const char *value,
			  size_t vlen, bool private)
{}

static int hpre_rsa_set_e(struct hpre_ctx *ctx, const char *value,
			  size_t vlen)
{}

static int hpre_rsa_set_d(struct hpre_ctx *ctx, const char *value,
			  size_t vlen)
{}

static int hpre_crt_para_get(char *para, size_t para_sz,
			     const char *raw, size_t raw_sz)
{}

static int hpre_rsa_setkey_crt(struct hpre_ctx *ctx, struct rsa_key *rsa_key)
{}

/* If it is clear all, all the resources of the QP will be cleaned. */
static void hpre_rsa_clear_ctx(struct hpre_ctx *ctx, bool is_clear_all)
{}

/*
 * we should judge if it is CRT or not,
 * CRT: return true,  N-CRT: return false .
 */
static bool hpre_is_crt_key(struct rsa_key *key)
{}

static int hpre_rsa_setkey(struct hpre_ctx *ctx, const void *key,
			   unsigned int keylen, bool private)
{}

static int hpre_rsa_setpubkey(struct crypto_akcipher *tfm, const void *key,
			      unsigned int keylen)
{}

static int hpre_rsa_setprivkey(struct crypto_akcipher *tfm, const void *key,
			       unsigned int keylen)
{}

static unsigned int hpre_rsa_max_size(struct crypto_akcipher *tfm)
{}

static int hpre_rsa_init_tfm(struct crypto_akcipher *tfm)
{}

static void hpre_rsa_exit_tfm(struct crypto_akcipher *tfm)
{}

static void hpre_key_to_big_end(u8 *data, int len)
{}

static void hpre_ecc_clear_ctx(struct hpre_ctx *ctx, bool is_clear_all,
			       bool is_ecdh)
{}

/*
 * The bits of 192/224/256/384/521 are supported by HPRE,
 * and convert the bits like:
 * bits<=256, bits=256; 256<bits<=384, bits=384; 384<bits<=576, bits=576;
 * If the parameter bit width is insufficient, then we fill in the
 * high-order zeros by soft, so TASK_LENGTH1 is 0x3/0x5/0x8;
 */
static unsigned int hpre_ecdh_supported_curve(unsigned short id)
{}

static void fill_curve_param(void *addr, u64 *param, unsigned int cur_sz, u8 ndigits)
{}

static int hpre_ecdh_fill_curve(struct hpre_ctx *ctx, struct ecdh *params,
				unsigned int cur_sz)
{}

static unsigned int hpre_ecdh_get_curvesz(unsigned short id)
{}

static int hpre_ecdh_set_param(struct hpre_ctx *ctx, struct ecdh *params)
{}

static bool hpre_key_is_zero(char *key, unsigned short key_sz)
{}

static int ecdh_gen_privkey(struct hpre_ctx *ctx, struct ecdh *params)
{}

static int hpre_ecdh_set_secret(struct crypto_kpp *tfm, const void *buf,
				unsigned int len)
{}

static void hpre_ecdh_hw_data_clr_all(struct hpre_ctx *ctx,
				      struct hpre_asym_request *req,
				      struct scatterlist *dst,
				      struct scatterlist *src)
{}

static void hpre_ecdh_cb(struct hpre_ctx *ctx, void *resp)
{}

static int hpre_ecdh_msg_request_set(struct hpre_ctx *ctx,
				     struct kpp_request *req)
{}

static int hpre_ecdh_src_data_init(struct hpre_asym_request *hpre_req,
				   struct scatterlist *data, unsigned int len)
{}

static int hpre_ecdh_dst_data_init(struct hpre_asym_request *hpre_req,
				   struct scatterlist *data, unsigned int len)
{}

static int hpre_ecdh_compute_value(struct kpp_request *req)
{}

static unsigned int hpre_ecdh_max_size(struct crypto_kpp *tfm)
{}

static int hpre_ecdh_nist_p192_init_tfm(struct crypto_kpp *tfm)
{}

static int hpre_ecdh_nist_p256_init_tfm(struct crypto_kpp *tfm)
{}

static int hpre_ecdh_nist_p384_init_tfm(struct crypto_kpp *tfm)
{}

static void hpre_ecdh_exit_tfm(struct crypto_kpp *tfm)
{}

static void hpre_curve25519_fill_curve(struct hpre_ctx *ctx, const void *buf,
				       unsigned int len)
{}

static int hpre_curve25519_set_param(struct hpre_ctx *ctx, const void *buf,
				     unsigned int len)
{}

static int hpre_curve25519_set_secret(struct crypto_kpp *tfm, const void *buf,
				      unsigned int len)
{}

static void hpre_curve25519_hw_data_clr_all(struct hpre_ctx *ctx,
					    struct hpre_asym_request *req,
					    struct scatterlist *dst,
					    struct scatterlist *src)
{}

static void hpre_curve25519_cb(struct hpre_ctx *ctx, void *resp)
{}

static int hpre_curve25519_msg_request_set(struct hpre_ctx *ctx,
					   struct kpp_request *req)
{}

static void hpre_curve25519_src_modulo_p(u8 *ptr)
{}

static int hpre_curve25519_src_init(struct hpre_asym_request *hpre_req,
				    struct scatterlist *data, unsigned int len)
{}

static int hpre_curve25519_dst_init(struct hpre_asym_request *hpre_req,
				    struct scatterlist *data, unsigned int len)
{}

static int hpre_curve25519_compute_value(struct kpp_request *req)
{}

static unsigned int hpre_curve25519_max_size(struct crypto_kpp *tfm)
{}

static int hpre_curve25519_init_tfm(struct crypto_kpp *tfm)
{}

static void hpre_curve25519_exit_tfm(struct crypto_kpp *tfm)
{}

static struct akcipher_alg rsa =;

static struct kpp_alg dh =;

static struct kpp_alg ecdh_curves[] =;

static struct kpp_alg curve25519_alg =;

static int hpre_register_rsa(struct hisi_qm *qm)
{}

static void hpre_unregister_rsa(struct hisi_qm *qm)
{}

static int hpre_register_dh(struct hisi_qm *qm)
{}

static void hpre_unregister_dh(struct hisi_qm *qm)
{}

static int hpre_register_ecdh(struct hisi_qm *qm)
{}

static void hpre_unregister_ecdh(struct hisi_qm *qm)
{}

static int hpre_register_x25519(struct hisi_qm *qm)
{}

static void hpre_unregister_x25519(struct hisi_qm *qm)
{}

int hpre_algs_register(struct hisi_qm *qm)
{}

void hpre_algs_unregister(struct hisi_qm *qm)
{}