123c57dfmcpowers/*
223c57dfmcpowers * CDDL HEADER START
323c57dfmcpowers *
423c57dfmcpowers * The contents of this file are subject to the terms of the
523c57dfmcpowers * Common Development and Distribution License (the "License").
623c57dfmcpowers * You may not use this file except in compliance with the License.
723c57dfmcpowers *
823c57dfmcpowers * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
923c57dfmcpowers * or http://www.opensolaris.org/os/licensing.
1023c57dfmcpowers * See the License for the specific language governing permissions
1123c57dfmcpowers * and limitations under the License.
1223c57dfmcpowers *
1323c57dfmcpowers * When distributing Covered Code, include this CDDL HEADER in each
1423c57dfmcpowers * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1523c57dfmcpowers * If applicable, add the following below this CDDL HEADER, with the
1623c57dfmcpowers * fields enclosed by brackets "[]" replaced with your own identifying
1723c57dfmcpowers * information: Portions Copyright [yyyy] [name of copyright owner]
1823c57dfmcpowers *
1923c57dfmcpowers * CDDL HEADER END
2023c57dfmcpowers */
2123c57dfmcpowers/*
22e8c016eMark Powers * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
2323c57dfmcpowers * Use is subject to license terms.
24cd964fcMatt Barden *
25cd964fcMatt Barden * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
268d91e49Jason King * Copyright 2019 Joyent, Inc.
2723c57dfmcpowers */
2823c57dfmcpowers
2923c57dfmcpowers#ifndef	_COMMON_CRYPTO_MODES_H
3023c57dfmcpowers#define	_COMMON_CRYPTO_MODES_H
3123c57dfmcpowers
3223c57dfmcpowers#ifdef	__cplusplus
3323c57dfmcpowersextern "C" {
3423c57dfmcpowers#endif
3523c57dfmcpowers
3623c57dfmcpowers#include <sys/strsun.h>
3723c57dfmcpowers#include <sys/systm.h>
3823c57dfmcpowers#include <sys/sysmacros.h>
3923c57dfmcpowers#include <sys/types.h>
4023c57dfmcpowers#include <sys/errno.h>
4123c57dfmcpowers#include <sys/rwlock.h>
4223c57dfmcpowers#include <sys/kmem.h>
4323c57dfmcpowers#include <sys/crypto/common.h>
4423c57dfmcpowers#include <sys/crypto/impl.h>
4523c57dfmcpowers
4623c57dfmcpowers#define	ECB_MODE			0x00000002
4723c57dfmcpowers#define	CBC_MODE			0x00000004
4823c57dfmcpowers#define	CTR_MODE			0x00000008
4923c57dfmcpowers#define	CCM_MODE			0x00000010
504d703b5Mark Powers#define	GCM_MODE			0x00000020
51983a103Mark Powers#define	GMAC_MODE			0x00000040
52cd964fcMatt Barden#define	CMAC_MODE			0x00000080
5323c57dfmcpowers
548d91e49Jason King/* Private flag for pkcs11_softtoken */
558d91e49Jason King#define	P11_DECRYPTED			0x80000000
568d91e49Jason King
5723c57dfmcpowers/*
5823c57dfmcpowers * cc_keysched:		Pointer to key schedule.
5923c57dfmcpowers *
6023c57dfmcpowers * cc_keysched_len:	Length of the key schedule.
6123c57dfmcpowers *
6223c57dfmcpowers * cc_remainder:	This is for residual data, i.e. data that can't
6323c57dfmcpowers *			be processed because there are too few bytes.
6423c57dfmcpowers *			Must wait until more data arrives.
6523c57dfmcpowers *
6623c57dfmcpowers * cc_remainder_len:	Number of bytes in cc_remainder.
6723c57dfmcpowers *
6823c57dfmcpowers * cc_iv:		Scratch buffer that sometimes contains the IV.
6923c57dfmcpowers *
7023c57dfmcpowers * cc_lastp:		Pointer to previous block of ciphertext.
7123c57dfmcpowers *
7223c57dfmcpowers * cc_copy_to:		Pointer to where encrypted residual data needs
7323c57dfmcpowers *			to be copied.
7423c57dfmcpowers *
7523c57dfmcpowers * cc_flags:		PROVIDER_OWNS_KEY_SCHEDULE
7623c57dfmcpowers *			When a context is freed, it is necessary
7723c57dfmcpowers *			to know whether the key schedule was allocated
7823c57dfmcpowers *			by the caller, or internally, e.g. an init routine.
7923c57dfmcpowers *			If allocated by the latter, then it needs to be freed.
8023c57dfmcpowers *
8123c57dfmcpowers *			ECB_MODE, CBC_MODE, CTR_MODE, or CCM_MODE
8223c57dfmcpowers */
8323c57dfmcpowersstruct common_ctx {
8423c57dfmcpowers	void *cc_keysched;
8523c57dfmcpowers	size_t cc_keysched_len;
8623c57dfmcpowers	uint64_t cc_iv[2];
8723c57dfmcpowers	uint64_t cc_remainder[2];
8823c57dfmcpowers	size_t cc_remainder_len;
8923c57dfmcpowers	uint8_t *cc_lastp;
9023c57dfmcpowers	uint8_t *cc_copy_to;
9123c57dfmcpowers	uint32_t cc_flags;
9223c57dfmcpowers};
9323c57dfmcpowers
9423c57dfmcpowerstypedef struct common_ctx common_ctx_t;
9523c57dfmcpowers
9616239bcMark Powerstypedef struct ecb_ctx {
9716239bcMark Powers	struct common_ctx ecb_common;
9816239bcMark Powers	uint64_t ecb_lastblock[2];
9916239bcMark Powers} ecb_ctx_t;
10016239bcMark Powers
10116239bcMark Powers#define	ecb_keysched		ecb_common.cc_keysched
10216239bcMark Powers#define	ecb_keysched_len	ecb_common.cc_keysched_len
10316239bcMark Powers#define	ecb_iv			ecb_common.cc_iv
10416239bcMark Powers#define	ecb_remainder		ecb_common.cc_remainder
10516239bcMark Powers#define	ecb_remainder_len	ecb_common.cc_remainder_len
10616239bcMark Powers#define	ecb_lastp		ecb_common.cc_lastp
10716239bcMark Powers#define	ecb_copy_to		ecb_common.cc_copy_to
10816239bcMark Powers#define	ecb_flags		ecb_common.cc_flags
10916239bcMark Powers
110cd964fcMatt Barden/*
111cd964fcMatt Barden * max_remain			max bytes in cbc_remainder
112cd964fcMatt Barden */
11316239bcMark Powerstypedef struct cbc_ctx {
11416239bcMark Powers	struct common_ctx cbc_common;
11516239bcMark Powers	uint64_t cbc_lastblock[2];
116cd964fcMatt Barden	size_t max_remain;
11716239bcMark Powers} cbc_ctx_t;
11816239bcMark Powers
11916239bcMark Powers#define	cbc_keysched		cbc_common.cc_keysched
12016239bcMark Powers#define	cbc_keysched_len	cbc_common.cc_keysched_len
12116239bcMark Powers#define	cbc_iv			cbc_common.cc_iv
12216239bcMark Powers#define	cbc_remainder		cbc_common.cc_remainder
12316239bcMark Powers#define	cbc_remainder_len	cbc_common.cc_remainder_len
12416239bcMark Powers#define	cbc_lastp		cbc_common.cc_lastp
12516239bcMark Powers#define	cbc_copy_to		cbc_common.cc_copy_to
12616239bcMark Powers#define	cbc_flags		cbc_common.cc_flags
12716239bcMark Powers
12816239bcMark Powers/*
12916239bcMark Powers * ctr_lower_mask		Bit-mask for lower 8 bytes of counter block.
13016239bcMark Powers * ctr_upper_mask		Bit-mask for upper 8 bytes of counter block.
13116239bcMark Powers */
13223c57dfmcpowerstypedef struct ctr_ctx {
13323c57dfmcpowers	struct common_ctx ctr_common;
13416239bcMark Powers	uint64_t ctr_lower_mask;
13516239bcMark Powers	uint64_t ctr_upper_mask;
1362f9f8a9Jason King	size_t ctr_offset;
1372f9f8a9Jason King	uint32_t ctr_keystream[4];
13823c57dfmcpowers} ctr_ctx_t;
13923c57dfmcpowers
14023c57dfmcpowers/*
14116239bcMark Powers * ctr_cb			Counter block.
14223c57dfmcpowers */
14323c57dfmcpowers#define	ctr_keysched		ctr_common.cc_keysched
14423c57dfmcpowers#define	ctr_keysched_len	ctr_common.cc_keysched_len
14523c57dfmcpowers#define	ctr_cb			ctr_common.cc_iv
14623c57dfmcpowers#define	ctr_remainder		ctr_common.cc_remainder
14723c57dfmcpowers#define	ctr_remainder_len	ctr_common.cc_remainder_len
14823c57dfmcpowers#define	ctr_lastp		ctr_common.cc_lastp
14923c57dfmcpowers#define	ctr_copy_to		ctr_common.cc_copy_to
15023c57dfmcpowers#define	ctr_flags		ctr_common.cc_flags
15123c57dfmcpowers
15223c57dfmcpowers/*
15323c57dfmcpowers *
15423c57dfmcpowers * ccm_mac_len:		Stores length of the MAC in CCM mode.
15523c57dfmcpowers * ccm_mac_buf:		Stores the intermediate value for MAC in CCM encrypt.
15623c57dfmcpowers *			In CCM decrypt, stores the input MAC value.
15723c57dfmcpowers * ccm_data_len:	Length of the plaintext for CCM mode encrypt, or
15823c57dfmcpowers *			length of the ciphertext for CCM mode decrypt.
15923c57dfmcpowers * ccm_processed_data_len:
16023c57dfmcpowers *			Length of processed plaintext in CCM mode encrypt,
16123c57dfmcpowers *			or length of processed ciphertext for CCM mode decrypt.
16223c57dfmcpowers * ccm_processed_mac_len:
16323c57dfmcpowers *			Length of MAC data accumulated in CCM mode decrypt.
16423c57dfmcpowers *
16523c57dfmcpowers * ccm_pt_buf:		Only used in CCM mode decrypt.  It stores the
16623c57dfmcpowers *			decrypted plaintext to be returned when
16723c57dfmcpowers *			MAC verification succeeds in decrypt_final.
16823c57dfmcpowers *			Memory for this should be allocated in the AES module.
16923c57dfmcpowers *
17023c57dfmcpowers */
17123c57dfmcpowerstypedef struct ccm_ctx {
17223c57dfmcpowers	struct common_ctx ccm_common;
17323c57dfmcpowers	uint32_t ccm_tmp[4];
17423c57dfmcpowers	size_t ccm_mac_len;
17523c57dfmcpowers	uint64_t ccm_mac_buf[2];
17623c57dfmcpowers	size_t ccm_data_len;
17723c57dfmcpowers	size_t ccm_processed_data_len;
17823c57dfmcpowers	size_t ccm_processed_mac_len;
17923c57dfmcpowers	uint8_t *ccm_pt_buf;
18023c57dfmcpowers	uint64_t ccm_mac_input_buf[2];
18116239bcMark Powers	uint64_t ccm_counter_mask;
18223c57dfmcpowers} ccm_ctx_t;
18323c57dfmcpowers
18423c57dfmcpowers#define	ccm_keysched		ccm_common.cc_keysched
18523c57dfmcpowers#define	ccm_keysched_len	ccm_common.cc_keysched_len
18623c57dfmcpowers#define	ccm_cb			ccm_common.cc_iv
18723c57dfmcpowers#define	ccm_remainder		ccm_common.cc_remainder
18823c57dfmcpowers#define	ccm_remainder_len	ccm_common.cc_remainder_len
18923c57dfmcpowers#define	ccm_lastp		ccm_common.cc_lastp
19023c57dfmcpowers#define	ccm_copy_to		ccm_common.cc_copy_to
19123c57dfmcpowers#define	ccm_flags		ccm_common.cc_flags
19223c57dfmcpowers
1934d703b5Mark Powers/*
1944d703b5Mark Powers * gcm_tag_len:		Length of authentication tag.
1954d703b5Mark Powers *
1964d703b5Mark Powers * gcm_ghash:		Stores output from the GHASH function.
1974d703b5Mark Powers *
1984d703b5Mark Powers * gcm_processed_data_len:
1994d703b5Mark Powers *			Length of processed plaintext (encrypt) or
2004d703b5Mark Powers *			length of processed ciphertext (decrypt).
2014d703b5Mark Powers *
2024d703b5Mark Powers * gcm_pt_buf:		Stores the decrypted plaintext returned by
2034d703b5Mark Powers *			decrypt_final when the computed authentication
2044d703b5Mark Powers *			tag matches the	user supplied tag.
2054d703b5Mark Powers *
2064d703b5Mark Powers * gcm_pt_buf_len:	Length of the plaintext buffer.
2074d703b5Mark Powers *
2084d703b5Mark Powers * gcm_H:		Subkey.
2094d703b5Mark Powers *
2104d703b5Mark Powers * gcm_J0:		Pre-counter block generated from the IV.
2114d703b5Mark Powers *
2124d703b5Mark Powers * gcm_len_a_len_c:	64-bit representations of the bit lengths of
2134d703b5Mark Powers *			AAD and ciphertext.
2144d703b5Mark Powers *
2154d703b5Mark Powers * gcm_kmflag:		Current value of kmflag. Used only for allocating
2164d703b5Mark Powers *			the plaintext buffer during decryption.
2174d703b5Mark Powers */
2184d703b5Mark Powerstypedef struct gcm_ctx {
2194d703b5Mark Powers	struct common_ctx gcm_common;
2204d703b5Mark Powers	size_t gcm_tag_len;
2214d703b5Mark Powers	size_t gcm_processed_data_len;
2224d703b5Mark Powers	size_t gcm_pt_buf_len;
2234d703b5Mark Powers	uint32_t gcm_tmp[4];
2244d703b5Mark Powers	uint64_t gcm_ghash[2];
2254d703b5Mark Powers	uint64_t gcm_H[2];
2264d703b5Mark Powers	uint64_t gcm_J0[2];
2274d703b5Mark Powers	uint64_t gcm_len_a_len_c[2];
2284d703b5Mark Powers	uint8_t *gcm_pt_buf;
2294d703b5Mark Powers	int gcm_kmflag;
2304d703b5Mark Powers} gcm_ctx_t;
2314d703b5Mark Powers
2324d703b5Mark Powers#define	gcm_keysched		gcm_common.cc_keysched
2334d703b5Mark Powers#define	gcm_keysched_len	gcm_common.cc_keysched_len
2344d703b5Mark Powers#define	gcm_cb			gcm_common.cc_iv
2354d703b5Mark Powers#define	gcm_remainder		gcm_common.cc_remainder
2364d703b5Mark Powers#define	gcm_remainder_len	gcm_common.cc_remainder_len
2374d703b5Mark Powers#define	gcm_lastp		gcm_common.cc_lastp
2384d703b5Mark Powers#define	gcm_copy_to		gcm_common.cc_copy_to
2394d703b5Mark Powers#define	gcm_flags		gcm_common.cc_flags
2404d703b5Mark Powers
241983a103Mark Powers#define	AES_GMAC_IV_LEN		12
242983a103Mark Powers#define	AES_GMAC_TAG_BITS	128
243983a103Mark Powers
24423c57dfmcpowerstypedef struct aes_ctx {
24523c57dfmcpowers	union {
24623c57dfmcpowers		ecb_ctx_t acu_ecb;
24723c57dfmcpowers		cbc_ctx_t acu_cbc;
24823c57dfmcpowers		ctr_ctx_t acu_ctr;
24923c57dfmcpowers		ccm_ctx_t acu_ccm;
2504d703b5Mark Powers		gcm_ctx_t acu_gcm;
25123c57dfmcpowers	} acu;
25223c57dfmcpowers} aes_ctx_t;
25323c57dfmcpowers
25416239bcMark Powers#define	ac_flags		acu.acu_ecb.ecb_common.cc_flags
25516239bcMark Powers#define	ac_remainder_len	acu.acu_ecb.ecb_common.cc_remainder_len
256fb26128Jason King#define	ac_remainder		acu.acu_ecb.ecb_common.cc_remainder
25716239bcMark Powers#define	ac_keysched		acu.acu_ecb.ecb_common.cc_keysched
25816239bcMark Powers#define	ac_keysched_len		acu.acu_ecb.ecb_common.cc_keysched_len
25916239bcMark Powers#define	ac_iv			acu.acu_ecb.ecb_common.cc_iv
26016239bcMark Powers#define	ac_lastp		acu.acu_ecb.ecb_common.cc_lastp
26123c57dfmcpowers#define	ac_pt_buf		acu.acu_ccm.ccm_pt_buf
26223c57dfmcpowers#define	ac_mac_len		acu.acu_ccm.ccm_mac_len
26323c57dfmcpowers#define	ac_data_len		acu.acu_ccm.ccm_data_len
26423c57dfmcpowers#define	ac_processed_mac_len	acu.acu_ccm.ccm_processed_mac_len
26523c57dfmcpowers#define	ac_processed_data_len	acu.acu_ccm.ccm_processed_data_len
2661dcbfafMark Powers#define	ac_tag_len		acu.acu_gcm.gcm_tag_len
26723c57dfmcpowers
26823c57dfmcpowerstypedef struct blowfish_ctx {
26923c57dfmcpowers	union {
27023c57dfmcpowers		ecb_ctx_t bcu_ecb;
27123c57dfmcpowers		cbc_ctx_t bcu_cbc;
27223c57dfmcpowers	} bcu;
27323c57dfmcpowers} blowfish_ctx_t;
27423c57dfmcpowers
27516239bcMark Powers#define	bc_flags		bcu.bcu_ecb.ecb_common.cc_flags
27616239bcMark Powers#define	bc_remainder_len	bcu.bcu_ecb.ecb_common.cc_remainder_len
27716239bcMark Powers#define	bc_keysched		bcu.bcu_ecb.ecb_common.cc_keysched
27816239bcMark Powers#define	bc_keysched_len		bcu.bcu_ecb.ecb_common.cc_keysched_len
27916239bcMark Powers#define	bc_iv			bcu.bcu_ecb.ecb_common.cc_iv
28016239bcMark Powers#define	bc_lastp		bcu.bcu_ecb.ecb_common.cc_lastp
28123c57dfmcpowers
28223c57dfmcpowerstypedef struct des_ctx {
28323c57dfmcpowers	union {
28423c57dfmcpowers		ecb_ctx_t dcu_ecb;
28523c57dfmcpowers		cbc_ctx_t dcu_cbc;
28623c57dfmcpowers	} dcu;
28723c57dfmcpowers} des_ctx_t;
28823c57dfmcpowers
28916239bcMark Powers#define	dc_flags		dcu.dcu_ecb.ecb_common.cc_flags
29016239bcMark Powers#define	dc_remainder_len	dcu.dcu_ecb.ecb_common.cc_remainder_len
29116239bcMark Powers#define	dc_keysched		dcu.dcu_ecb.ecb_common.cc_keysched
29216239bcMark Powers#define	dc_keysched_len		dcu.dcu_ecb.ecb_common.cc_keysched_len
29316239bcMark Powers#define	dc_iv			dcu.dcu_ecb.ecb_common.cc_iv
29416239bcMark Powers#define	dc_lastp		dcu.dcu_ecb.ecb_common.cc_lastp
29523c57dfmcpowers
29616239bcMark Powersextern int ecb_cipher_contiguous_blocks(ecb_ctx_t *, char *, size_t,
29723c57dfmcpowers    crypto_data_t *, size_t, int (*cipher)(const void *, const uint8_t *,
29823c57dfmcpowers    uint8_t *));
29923c57dfmcpowers
30023c57dfmcpowersextern int cbc_encrypt_contiguous_blocks(cbc_ctx_t *, char *, size_t,
30123c57dfmcpowers    crypto_data_t *, size_t,
30223c57dfmcpowers    int (*encrypt)(const void *, const uint8_t *, uint8_t *),
30323c57dfmcpowers    void (*copy_block)(uint8_t *, uint8_t *),
30423c57dfmcpowers    void (*xor_block)(uint8_t *, uint8_t *));
30523c57dfmcpowers
30623c57dfmcpowersextern int cbc_decrypt_contiguous_blocks(cbc_ctx_t *, char *, size_t,
30723c57dfmcpowers    crypto_data_t *, size_t,
30823c57dfmcpowers    int (*decrypt)(const void *, const uint8_t *, uint8_t *),
30923c57dfmcpowers    void (*copy_block)(uint8_t *, uint8_t *),
31023c57dfmcpowers    void (*xor_block)(uint8_t *, uint8_t *));
31123c57dfmcpowers
31223c57dfmcpowersextern int ctr_mode_contiguous_blocks(ctr_ctx_t *, char *, size_t,
31323c57dfmcpowers    crypto_data_t *, size_t,
3142f9f8a9Jason King    int (*cipher)(const void *, const uint8_t *, uint8_t *));
31523c57dfmcpowers
31623c57dfmcpowersextern int ccm_mode_encrypt_contiguous_blocks(ccm_ctx_t *, char *, size_t,
31723c57dfmcpowers    crypto_data_t *, size_t,
31823c57dfmcpowers    int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
31923c57dfmcpowers    void (*copy_block)(uint8_t *, uint8_t *),
32023c57dfmcpowers    void (*xor_block)(uint8_t *, uint8_t *));
32123c57dfmcpowers
32223c57dfmcpowersextern int ccm_mode_decrypt_contiguous_blocks(ccm_ctx_t *, char *, size_t,
32323c57dfmcpowers    crypto_data_t *, size_t,
32423c57dfmcpowers    int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
32523c57dfmcpowers    void (*copy_block)(uint8_t *, uint8_t *),
32623c57dfmcpowers    void (*xor_block)(uint8_t *, uint8_t *));
32723c57dfmcpowers
3284d703b5Mark Powersextern int gcm_mode_encrypt_contiguous_blocks(gcm_ctx_t *, char *, size_t,
3294d703b5Mark Powers    crypto_data_t *, size_t,
3304d703b5Mark Powers    int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
3314d703b5Mark Powers    void (*copy_block)(uint8_t *, uint8_t *),
3324d703b5Mark Powers    void (*xor_block)(uint8_t *, uint8_t *));
3334d703b5Mark Powers
3344d703b5Mark Powersextern int gcm_mode_decrypt_contiguous_blocks(gcm_ctx_t *, char *, size_t,
3354d703b5Mark Powers    crypto_data_t *, size_t,
3364d703b5Mark Powers    int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
3374d703b5Mark Powers    void (*copy_block)(uint8_t *, uint8_t *),
3384d703b5Mark Powers    void (*xor_block)(uint8_t *, uint8_t *));
3394d703b5Mark Powers
34023c57dfmcpowersint ccm_encrypt_final(ccm_ctx_t *, crypto_data_t *, size_t,
34123c57dfmcpowers    int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
34223c57dfmcpowers    void (*xor_block)(uint8_t *, uint8_t *));
34323c57dfmcpowers
3444d703b5Mark Powersint gcm_encrypt_final(gcm_ctx_t *, crypto_data_t *, size_t,
3454d703b5Mark Powers    int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
3464d703b5Mark Powers    void (*copy_block)(uint8_t *, uint8_t *),
3474d703b5Mark Powers    void (*xor_block)(uint8_t *, uint8_t *));
3484d703b5Mark Powers
34923c57dfmcpowersextern int ccm_decrypt_final(ccm_ctx_t *, crypto_data_t *, size_t,
35023c57dfmcpowers    int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
35123c57dfmcpowers    void (*copy_block)(uint8_t *, uint8_t *),
35223c57dfmcpowers    void (*xor_block)(uint8_t *, uint8_t *));
35323c57dfmcpowers
3544d703b5Mark Powersextern int gcm_decrypt_final(gcm_ctx_t *, crypto_data_t *, size_t,
3554d703b5Mark Powers    int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
3564d703b5Mark Powers    void (*xor_block)(uint8_t *, uint8_t *));
3574d703b5Mark Powers
358cd964fcMatt Bardenextern int cmac_mode_final(cbc_ctx_t *, crypto_data_t *,
359cd964fcMatt Barden    int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
360cd964fcMatt Barden    void (*xor_block)(uint8_t *, uint8_t *));
361cd964fcMatt Barden
36223c57dfmcpowersextern int cbc_init_ctx(cbc_ctx_t *, char *, size_t, size_t,
36323c57dfmcpowers    void (*copy_block)(uint8_t *, uint64_t *));
36423c57dfmcpowers
365cd964fcMatt Bardenextern int cmac_init_ctx(cbc_ctx_t *, size_t);
366cd964fcMatt Barden
36723c57dfmcpowersextern int ctr_init_ctx(ctr_ctx_t *, ulong_t, uint8_t *,
3682f9f8a9Jason King    int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
36923c57dfmcpowers    void (*copy_block)(uint8_t *, uint8_t *));
37023c57dfmcpowers
37123c57dfmcpowersextern int ccm_init_ctx(ccm_ctx_t *, char *, int, boolean_t, size_t,
37223c57dfmcpowers    int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
37323c57dfmcpowers    void (*xor_block)(uint8_t *, uint8_t *));
37423c57dfmcpowers
3754d703b5Mark Powersextern int gcm_init_ctx(gcm_ctx_t *, char *, size_t,
3764d703b5Mark Powers    int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
3774d703b5Mark Powers    void (*copy_block)(uint8_t *, uint8_t *),
3784d703b5Mark Powers    void (*xor_block)(uint8_t *, uint8_t *));
3794d703b5Mark Powers
380983a103Mark Powersextern int gmac_init_ctx(gcm_ctx_t *, char *, size_t,
381983a103Mark Powers    int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
382983a103Mark Powers    void (*copy_block)(uint8_t *, uint8_t *),
383983a103Mark Powers    void (*xor_block)(uint8_t *, uint8_t *));
384983a103Mark Powers
38523c57dfmcpowersextern void calculate_ccm_mac(ccm_ctx_t *, uint8_t *,
38623c57dfmcpowers    int (*encrypt_block)(const void *, const uint8_t *, uint8_t *));
38723c57dfmcpowers
388e8c016eMark Powersextern void gcm_mul(uint64_t *, uint64_t *, uint64_t *);
389e8c016eMark Powers
39023c57dfmcpowersextern void crypto_init_ptrs(crypto_data_t *, void **, offset_t *);
39123c57dfmcpowersextern void crypto_get_ptrs(crypto_data_t *, void **, offset_t *,
39223c57dfmcpowers    uint8_t **, size_t *, uint8_t **, size_t);
39323c57dfmcpowers
39423c57dfmcpowersextern void *ecb_alloc_ctx(int);
39523c57dfmcpowersextern void *cbc_alloc_ctx(int);
396cd964fcMatt Bardenextern void *cmac_alloc_ctx(int);
39723c57dfmcpowersextern void *ctr_alloc_ctx(int);
39823c57dfmcpowersextern void *ccm_alloc_ctx(int);
3994d703b5Mark Powersextern void *gcm_alloc_ctx(int);
400983a103Mark Powersextern void *gmac_alloc_ctx(int);
40123c57dfmcpowersextern void crypto_free_mode_ctx(void *);
4024d703b5Mark Powersextern void gcm_set_kmflag(gcm_ctx_t *, int);
403cd964fcMatt Bardenextern int crypto_put_output_data(uchar_t *, crypto_data_t *, int);
40423c57dfmcpowers
40523c57dfmcpowers#ifdef	__cplusplus
40623c57dfmcpowers}
40723c57dfmcpowers#endif
40823c57dfmcpowers
40923c57dfmcpowers#endif	/* _COMMON_CRYPTO_MODES_H */
410