^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * AMD Cryptographic Coprocessor (CCP) crypto API support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2013,2017 Advanced Micro Devices, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Author: Tom Lendacky <thomas.lendacky@amd.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #ifndef __CCP_CRYPTO_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define __CCP_CRYPTO_H__
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/ccp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <crypto/algapi.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <crypto/aes.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <crypto/internal/aead.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <crypto/aead.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <crypto/ctr.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <crypto/hash.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <crypto/sha.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <crypto/akcipher.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <crypto/skcipher.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <crypto/internal/rsa.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) /* We want the module name in front of our messages */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #undef pr_fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define CCP_LOG_LEVEL KERN_INFO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define CCP_CRA_PRIORITY 300
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct ccp_crypto_skcipher_alg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct list_head entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) u32 mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct skcipher_alg alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct ccp_crypto_aead {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) struct list_head entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) u32 mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) struct aead_alg alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct ccp_crypto_ahash_alg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct list_head entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) const __be32 *init;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) u32 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) u32 mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) /* Child algorithm used for HMAC, CMAC, etc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) char child_alg[CRYPTO_MAX_ALG_NAME];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) struct ahash_alg alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) struct ccp_crypto_akcipher_alg {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) struct list_head entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) struct akcipher_alg alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) static inline struct ccp_crypto_skcipher_alg *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) ccp_crypto_skcipher_alg(struct crypto_skcipher *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct skcipher_alg *alg = crypto_skcipher_alg(tfm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return container_of(alg, struct ccp_crypto_skcipher_alg, alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) static inline struct ccp_crypto_ahash_alg *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) ccp_crypto_ahash_alg(struct crypto_tfm *tfm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) struct crypto_alg *alg = tfm->__crt_alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) struct ahash_alg *ahash_alg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) ahash_alg = container_of(alg, struct ahash_alg, halg.base);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) return container_of(ahash_alg, struct ccp_crypto_ahash_alg, alg);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) /***** AES related defines *****/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) struct ccp_aes_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) /* Fallback cipher for XTS with unsupported unit sizes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) struct crypto_skcipher *tfm_skcipher;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) enum ccp_engine engine;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) enum ccp_aes_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) enum ccp_aes_mode mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) struct scatterlist key_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) unsigned int key_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) u8 key[AES_MAX_KEY_SIZE * 2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) u8 nonce[CTR_RFC3686_NONCE_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) /* CMAC key structures */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) struct scatterlist k1_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) struct scatterlist k2_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) unsigned int kn_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) u8 k1[AES_BLOCK_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) u8 k2[AES_BLOCK_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) struct ccp_aes_req_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) struct scatterlist iv_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) u8 iv[AES_BLOCK_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) struct scatterlist tag_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) u8 tag[AES_BLOCK_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /* Fields used for RFC3686 requests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) u8 *rfc3686_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) u8 rfc3686_iv[AES_BLOCK_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) struct ccp_cmd cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) struct skcipher_request fallback_req; // keep at the end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) struct ccp_aes_cmac_req_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) unsigned int null_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) unsigned int final;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) struct scatterlist *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) unsigned int nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) u64 hash_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) unsigned int hash_rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) struct sg_table data_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) struct scatterlist iv_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) u8 iv[AES_BLOCK_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) struct scatterlist buf_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) unsigned int buf_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) u8 buf[AES_BLOCK_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) struct scatterlist pad_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) unsigned int pad_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) u8 pad[AES_BLOCK_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) struct ccp_cmd cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) struct ccp_aes_cmac_exp_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) unsigned int null_msg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) u8 iv[AES_BLOCK_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) unsigned int buf_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) u8 buf[AES_BLOCK_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) /***** 3DES related defines *****/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct ccp_des3_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) enum ccp_engine engine;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) enum ccp_des3_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) enum ccp_des3_mode mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) struct scatterlist key_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) unsigned int key_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) u8 key[AES_MAX_KEY_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) struct ccp_des3_req_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) struct scatterlist iv_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) u8 iv[AES_BLOCK_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) struct ccp_cmd cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /* SHA-related defines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) * These values must be large enough to accommodate any variant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) #define MAX_SHA_CONTEXT_SIZE SHA512_DIGEST_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) #define MAX_SHA_BLOCK_SIZE SHA512_BLOCK_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) struct ccp_sha_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) struct scatterlist opad_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) unsigned int opad_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) unsigned int key_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) u8 key[MAX_SHA_BLOCK_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) u8 ipad[MAX_SHA_BLOCK_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) u8 opad[MAX_SHA_BLOCK_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct crypto_shash *hmac_tfm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) struct ccp_sha_req_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) enum ccp_sha_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) u64 msg_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) unsigned int first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) unsigned int final;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) struct scatterlist *src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) unsigned int nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) u64 hash_cnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) unsigned int hash_rem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) struct sg_table data_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct scatterlist ctx_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) u8 ctx[MAX_SHA_CONTEXT_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) struct scatterlist buf_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) unsigned int buf_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) u8 buf[MAX_SHA_BLOCK_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) /* CCP driver command */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) struct ccp_cmd cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct ccp_sha_exp_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) enum ccp_sha_type type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) u64 msg_bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) unsigned int first;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) u8 ctx[MAX_SHA_CONTEXT_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) unsigned int buf_count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) u8 buf[MAX_SHA_BLOCK_SIZE];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) /***** RSA related defines *****/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) struct ccp_rsa_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) unsigned int key_len; /* in bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct scatterlist e_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) u8 *e_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) unsigned int e_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) struct scatterlist n_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) u8 *n_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) unsigned int n_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) struct scatterlist d_sg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) u8 *d_buf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) unsigned int d_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) struct ccp_rsa_req_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct ccp_cmd cmd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) #define CCP_RSA_MAXMOD (4 * 1024 / 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) #define CCP5_RSA_MAXMOD (16 * 1024 / 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) /***** Common Context Structure *****/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) struct ccp_ctx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) int (*complete)(struct crypto_async_request *req, int ret);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) struct ccp_aes_ctx aes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) struct ccp_rsa_ctx rsa;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) struct ccp_sha_ctx sha;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) struct ccp_des3_ctx des3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) } u;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) int ccp_crypto_enqueue_request(struct crypto_async_request *req,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) struct ccp_cmd *cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) struct scatterlist *ccp_crypto_sg_table_add(struct sg_table *table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) struct scatterlist *sg_add);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) int ccp_register_aes_algs(struct list_head *head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) int ccp_register_aes_cmac_algs(struct list_head *head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) int ccp_register_aes_xts_algs(struct list_head *head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) int ccp_register_aes_aeads(struct list_head *head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) int ccp_register_sha_algs(struct list_head *head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) int ccp_register_des3_algs(struct list_head *head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) int ccp_register_rsa_algs(struct list_head *head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) #endif