1 /* SPDX-License-Identifier: GPL-2.0 */
6 #include <crypto/ctr.h>
8 #define NX_NAME "nx-crypto"
9 #define NX_STRING "IBM Power7+ Nest Accelerator Crypto Driver"
10 #define NX_VERSION "1.0"
12 /* a scatterlist in the format PHYP is expecting */
17 } __attribute((packed
));
19 #define NX_PAGE_SIZE (4096)
20 #define NX_MAX_SG_ENTRIES (NX_PAGE_SIZE/(sizeof(struct nx_sg)))
28 /* msc_triplet and max_sync_cop are used only to assist in parsing the
29 * openFirmware property */
40 struct msc_triplet trip
[0];
48 #define NX_OF_FLAG_MAXSGLEN_SET (1)
49 #define NX_OF_FLAG_STATUS_SET (2)
50 #define NX_OF_FLAG_MAXSYNCCOP_SET (4)
51 #define NX_OF_FLAG_MASK_READY (NX_OF_FLAG_MAXSGLEN_SET | \
52 NX_OF_FLAG_STATUS_SET | \
53 NX_OF_FLAG_MAXSYNCCOP_SET)
57 enum nx_status status
;
58 struct alg_props ap
[NX_MAX_FC
][NX_MAX_MODE
][3];
65 atomic64_t sha256_bytes
;
67 atomic64_t sha512_bytes
;
73 atomic_t last_error_pid
;
76 struct nx_crypto_driver
{
77 struct nx_stats stats
;
79 struct vio_dev
*viodev
;
80 struct vio_driver viodriver
;
81 struct dentry
*dfs_root
;
84 #define NX_GCM4106_NONCE_LEN (4)
85 #define NX_GCM_CTR_OFFSET (12)
92 u8 nonce
[NX_GCM4106_NONCE_LEN
];
95 #define NX_CCM_AES_KEY_LEN (16)
96 #define NX_CCM4309_AES_KEY_LEN (19)
97 #define NX_CCM4309_NONCE_LEN (3)
106 u8 nonce
[NX_CCM4309_NONCE_LEN
];
109 struct nx_xcbc_priv
{
114 u8 nonce
[CTR_RFC3686_NONCE_SIZE
];
117 struct nx_crypto_ctx
{
118 spinlock_t lock
; /* synchronize access to the context */
119 void *kmem
; /* unaligned, kmalloc'd buffer */
120 size_t kmem_len
; /* length of kmem */
121 struct nx_csbcpb
*csbcpb
; /* aligned page given to phyp @ hcall time */
122 struct vio_pfo_op op
; /* operation struct with hcall parameters */
123 struct nx_csbcpb
*csbcpb_aead
; /* secondary csbcpb used by AEAD algs */
124 struct vio_pfo_op op_aead
;/* operation struct for csbcpb_aead */
126 struct nx_sg
*in_sg
; /* aligned pointer into kmem to an sg list */
127 struct nx_sg
*out_sg
; /* aligned pointer into kmem to an sg list */
129 struct alg_props
*ap
; /* pointer into props based on our key size */
130 struct alg_props props
[3];/* openFirmware properties for requests */
131 struct nx_stats
*stats
; /* pointer into an nx_crypto_driver for stats
135 struct nx_gcm_priv gcm
;
136 struct nx_ccm_priv ccm
;
137 struct nx_xcbc_priv xcbc
;
138 struct nx_ctr_priv ctr
;
145 int nx_crypto_ctx_aes_ccm_init(struct crypto_aead
*tfm
);
146 int nx_crypto_ctx_aes_gcm_init(struct crypto_aead
*tfm
);
147 int nx_crypto_ctx_aes_xcbc_init(struct crypto_tfm
*tfm
);
148 int nx_crypto_ctx_aes_ctr_init(struct crypto_skcipher
*tfm
);
149 int nx_crypto_ctx_aes_cbc_init(struct crypto_skcipher
*tfm
);
150 int nx_crypto_ctx_aes_ecb_init(struct crypto_skcipher
*tfm
);
151 int nx_crypto_ctx_sha_init(struct crypto_tfm
*tfm
);
152 void nx_crypto_ctx_exit(struct crypto_tfm
*tfm
);
153 void nx_crypto_ctx_skcipher_exit(struct crypto_skcipher
*tfm
);
154 void nx_crypto_ctx_aead_exit(struct crypto_aead
*tfm
);
155 void nx_ctx_init(struct nx_crypto_ctx
*nx_ctx
, unsigned int function
);
156 int nx_hcall_sync(struct nx_crypto_ctx
*ctx
, struct vio_pfo_op
*op
,
158 struct nx_sg
*nx_build_sg_list(struct nx_sg
*, u8
*, unsigned int *, u32
);
159 int nx_build_sg_lists(struct nx_crypto_ctx
*nx_ctx
, const u8
*iv
,
160 struct scatterlist
*dst
, struct scatterlist
*src
,
161 unsigned int *nbytes
, unsigned int offset
, u8
*oiv
);
162 struct nx_sg
*nx_walk_and_build(struct nx_sg
*, unsigned int,
163 struct scatterlist
*, unsigned int,
166 #ifdef CONFIG_DEBUG_FS
167 #define NX_DEBUGFS_INIT(drv) nx_debugfs_init(drv)
168 #define NX_DEBUGFS_FINI(drv) nx_debugfs_fini(drv)
170 void nx_debugfs_init(struct nx_crypto_driver
*);
171 void nx_debugfs_fini(struct nx_crypto_driver
*);
173 #define NX_DEBUGFS_INIT(drv) (0)
174 #define NX_DEBUGFS_FINI(drv) (0)
177 #define NX_PAGE_NUM(x) ((u64)(x) & 0xfffffffffffff000ULL)
179 extern struct skcipher_alg nx_cbc_aes_alg
;
180 extern struct skcipher_alg nx_ecb_aes_alg
;
181 extern struct aead_alg nx_gcm_aes_alg
;
182 extern struct aead_alg nx_gcm4106_aes_alg
;
183 extern struct skcipher_alg nx_ctr3686_aes_alg
;
184 extern struct aead_alg nx_ccm_aes_alg
;
185 extern struct aead_alg nx_ccm4309_aes_alg
;
186 extern struct shash_alg nx_shash_aes_xcbc_alg
;
187 extern struct shash_alg nx_shash_sha512_alg
;
188 extern struct shash_alg nx_shash_sha256_alg
;
190 extern struct nx_crypto_driver nx_driver
;
192 #define SCATTERWALK_TO_SG 1
193 #define SCATTERWALK_FROM_SG 0