xref: /illumos-gate/usr/src/common/crypto/modes/modes.h (revision fb2612809ed5f2cb9109db768e63d61f6659f71b)
123c57df7Smcpowers /*
223c57df7Smcpowers  * CDDL HEADER START
323c57df7Smcpowers  *
423c57df7Smcpowers  * The contents of this file are subject to the terms of the
523c57df7Smcpowers  * Common Development and Distribution License (the "License").
623c57df7Smcpowers  * You may not use this file except in compliance with the License.
723c57df7Smcpowers  *
823c57df7Smcpowers  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
923c57df7Smcpowers  * or http://www.opensolaris.org/os/licensing.
1023c57df7Smcpowers  * See the License for the specific language governing permissions
1123c57df7Smcpowers  * and limitations under the License.
1223c57df7Smcpowers  *
1323c57df7Smcpowers  * When distributing Covered Code, include this CDDL HEADER in each
1423c57df7Smcpowers  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1523c57df7Smcpowers  * If applicable, add the following below this CDDL HEADER, with the
1623c57df7Smcpowers  * fields enclosed by brackets "[]" replaced with your own identifying
1723c57df7Smcpowers  * information: Portions Copyright [yyyy] [name of copyright owner]
1823c57df7Smcpowers  *
1923c57df7Smcpowers  * CDDL HEADER END
2023c57df7Smcpowers  */
2123c57df7Smcpowers /*
22e8c016efSMark Powers  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
2323c57df7Smcpowers  * Use is subject to license terms.
24cd964fceSMatt Barden  *
25cd964fceSMatt Barden  * Copyright 2014 Nexenta Systems, Inc.  All rights reserved.
26*fb261280SJason King  * Copyright (c) 2018, Joyent, Inc.
2723c57df7Smcpowers  */
2823c57df7Smcpowers 
2923c57df7Smcpowers #ifndef	_COMMON_CRYPTO_MODES_H
3023c57df7Smcpowers #define	_COMMON_CRYPTO_MODES_H
3123c57df7Smcpowers 
3223c57df7Smcpowers #ifdef	__cplusplus
3323c57df7Smcpowers extern "C" {
3423c57df7Smcpowers #endif
3523c57df7Smcpowers 
3623c57df7Smcpowers #include <sys/strsun.h>
3723c57df7Smcpowers #include <sys/systm.h>
3823c57df7Smcpowers #include <sys/sysmacros.h>
3923c57df7Smcpowers #include <sys/types.h>
4023c57df7Smcpowers #include <sys/errno.h>
4123c57df7Smcpowers #include <sys/rwlock.h>
4223c57df7Smcpowers #include <sys/kmem.h>
4323c57df7Smcpowers #include <sys/crypto/common.h>
4423c57df7Smcpowers #include <sys/crypto/impl.h>
4523c57df7Smcpowers 
4623c57df7Smcpowers #define	ECB_MODE			0x00000002
4723c57df7Smcpowers #define	CBC_MODE			0x00000004
4823c57df7Smcpowers #define	CTR_MODE			0x00000008
4923c57df7Smcpowers #define	CCM_MODE			0x00000010
504d703b5cSMark Powers #define	GCM_MODE			0x00000020
51983a1033SMark Powers #define	GMAC_MODE			0x00000040
52cd964fceSMatt Barden #define	CMAC_MODE			0x00000080
5323c57df7Smcpowers 
5423c57df7Smcpowers /*
5523c57df7Smcpowers  * cc_keysched:		Pointer to key schedule.
5623c57df7Smcpowers  *
5723c57df7Smcpowers  * cc_keysched_len:	Length of the key schedule.
5823c57df7Smcpowers  *
5923c57df7Smcpowers  * cc_remainder:	This is for residual data, i.e. data that can't
6023c57df7Smcpowers  *			be processed because there are too few bytes.
6123c57df7Smcpowers  *			Must wait until more data arrives.
6223c57df7Smcpowers  *
6323c57df7Smcpowers  * cc_remainder_len:	Number of bytes in cc_remainder.
6423c57df7Smcpowers  *
6523c57df7Smcpowers  * cc_iv:		Scratch buffer that sometimes contains the IV.
6623c57df7Smcpowers  *
6723c57df7Smcpowers  * cc_lastp:		Pointer to previous block of ciphertext.
6823c57df7Smcpowers  *
6923c57df7Smcpowers  * cc_copy_to:		Pointer to where encrypted residual data needs
7023c57df7Smcpowers  *			to be copied.
7123c57df7Smcpowers  *
7223c57df7Smcpowers  * cc_flags:		PROVIDER_OWNS_KEY_SCHEDULE
7323c57df7Smcpowers  *			When a context is freed, it is necessary
7423c57df7Smcpowers  *			to know whether the key schedule was allocated
7523c57df7Smcpowers  *			by the caller, or internally, e.g. an init routine.
7623c57df7Smcpowers  *			If allocated by the latter, then it needs to be freed.
7723c57df7Smcpowers  *
7823c57df7Smcpowers  *			ECB_MODE, CBC_MODE, CTR_MODE, or CCM_MODE
7923c57df7Smcpowers  */
8023c57df7Smcpowers struct common_ctx {
8123c57df7Smcpowers 	void *cc_keysched;
8223c57df7Smcpowers 	size_t cc_keysched_len;
8323c57df7Smcpowers 	uint64_t cc_iv[2];
8423c57df7Smcpowers 	uint64_t cc_remainder[2];
8523c57df7Smcpowers 	size_t cc_remainder_len;
8623c57df7Smcpowers 	uint8_t *cc_lastp;
8723c57df7Smcpowers 	uint8_t *cc_copy_to;
8823c57df7Smcpowers 	uint32_t cc_flags;
8923c57df7Smcpowers };
9023c57df7Smcpowers 
9123c57df7Smcpowers typedef struct common_ctx common_ctx_t;
9223c57df7Smcpowers 
9316239bc8SMark Powers typedef struct ecb_ctx {
9416239bc8SMark Powers 	struct common_ctx ecb_common;
9516239bc8SMark Powers 	uint64_t ecb_lastblock[2];
9616239bc8SMark Powers } ecb_ctx_t;
9716239bc8SMark Powers 
9816239bc8SMark Powers #define	ecb_keysched		ecb_common.cc_keysched
9916239bc8SMark Powers #define	ecb_keysched_len	ecb_common.cc_keysched_len
10016239bc8SMark Powers #define	ecb_iv			ecb_common.cc_iv
10116239bc8SMark Powers #define	ecb_remainder		ecb_common.cc_remainder
10216239bc8SMark Powers #define	ecb_remainder_len	ecb_common.cc_remainder_len
10316239bc8SMark Powers #define	ecb_lastp		ecb_common.cc_lastp
10416239bc8SMark Powers #define	ecb_copy_to		ecb_common.cc_copy_to
10516239bc8SMark Powers #define	ecb_flags		ecb_common.cc_flags
10616239bc8SMark Powers 
107cd964fceSMatt Barden /*
108cd964fceSMatt Barden  * max_remain			max bytes in cbc_remainder
109cd964fceSMatt Barden  */
11016239bc8SMark Powers typedef struct cbc_ctx {
11116239bc8SMark Powers 	struct common_ctx cbc_common;
11216239bc8SMark Powers 	uint64_t cbc_lastblock[2];
113cd964fceSMatt Barden 	size_t max_remain;
11416239bc8SMark Powers } cbc_ctx_t;
11516239bc8SMark Powers 
11616239bc8SMark Powers #define	cbc_keysched		cbc_common.cc_keysched
11716239bc8SMark Powers #define	cbc_keysched_len	cbc_common.cc_keysched_len
11816239bc8SMark Powers #define	cbc_iv			cbc_common.cc_iv
11916239bc8SMark Powers #define	cbc_remainder		cbc_common.cc_remainder
12016239bc8SMark Powers #define	cbc_remainder_len	cbc_common.cc_remainder_len
12116239bc8SMark Powers #define	cbc_lastp		cbc_common.cc_lastp
12216239bc8SMark Powers #define	cbc_copy_to		cbc_common.cc_copy_to
12316239bc8SMark Powers #define	cbc_flags		cbc_common.cc_flags
12416239bc8SMark Powers 
12516239bc8SMark Powers /*
12616239bc8SMark Powers  * ctr_lower_mask		Bit-mask for lower 8 bytes of counter block.
12716239bc8SMark Powers  * ctr_upper_mask		Bit-mask for upper 8 bytes of counter block.
12816239bc8SMark Powers  */
12923c57df7Smcpowers typedef struct ctr_ctx {
13023c57df7Smcpowers 	struct common_ctx ctr_common;
13116239bc8SMark Powers 	uint64_t ctr_lower_mask;
13216239bc8SMark Powers 	uint64_t ctr_upper_mask;
13323c57df7Smcpowers 	uint32_t ctr_tmp[4];
13423c57df7Smcpowers } ctr_ctx_t;
13523c57df7Smcpowers 
13623c57df7Smcpowers /*
13716239bc8SMark Powers  * ctr_cb			Counter block.
13823c57df7Smcpowers  */
13923c57df7Smcpowers #define	ctr_keysched		ctr_common.cc_keysched
14023c57df7Smcpowers #define	ctr_keysched_len	ctr_common.cc_keysched_len
14123c57df7Smcpowers #define	ctr_cb			ctr_common.cc_iv
14223c57df7Smcpowers #define	ctr_remainder		ctr_common.cc_remainder
14323c57df7Smcpowers #define	ctr_remainder_len	ctr_common.cc_remainder_len
14423c57df7Smcpowers #define	ctr_lastp		ctr_common.cc_lastp
14523c57df7Smcpowers #define	ctr_copy_to		ctr_common.cc_copy_to
14623c57df7Smcpowers #define	ctr_flags		ctr_common.cc_flags
14723c57df7Smcpowers 
14823c57df7Smcpowers /*
14923c57df7Smcpowers  *
15023c57df7Smcpowers  * ccm_mac_len:		Stores length of the MAC in CCM mode.
15123c57df7Smcpowers  * ccm_mac_buf:		Stores the intermediate value for MAC in CCM encrypt.
15223c57df7Smcpowers  *			In CCM decrypt, stores the input MAC value.
15323c57df7Smcpowers  * ccm_data_len:	Length of the plaintext for CCM mode encrypt, or
15423c57df7Smcpowers  *			length of the ciphertext for CCM mode decrypt.
15523c57df7Smcpowers  * ccm_processed_data_len:
15623c57df7Smcpowers  *			Length of processed plaintext in CCM mode encrypt,
15723c57df7Smcpowers  *			or length of processed ciphertext for CCM mode decrypt.
15823c57df7Smcpowers  * ccm_processed_mac_len:
15923c57df7Smcpowers  *			Length of MAC data accumulated in CCM mode decrypt.
16023c57df7Smcpowers  *
16123c57df7Smcpowers  * ccm_pt_buf:		Only used in CCM mode decrypt.  It stores the
16223c57df7Smcpowers  *			decrypted plaintext to be returned when
16323c57df7Smcpowers  *			MAC verification succeeds in decrypt_final.
16423c57df7Smcpowers  *			Memory for this should be allocated in the AES module.
16523c57df7Smcpowers  *
16623c57df7Smcpowers  */
16723c57df7Smcpowers typedef struct ccm_ctx {
16823c57df7Smcpowers 	struct common_ctx ccm_common;
16923c57df7Smcpowers 	uint32_t ccm_tmp[4];
17023c57df7Smcpowers 	size_t ccm_mac_len;
17123c57df7Smcpowers 	uint64_t ccm_mac_buf[2];
17223c57df7Smcpowers 	size_t ccm_data_len;
17323c57df7Smcpowers 	size_t ccm_processed_data_len;
17423c57df7Smcpowers 	size_t ccm_processed_mac_len;
17523c57df7Smcpowers 	uint8_t *ccm_pt_buf;
17623c57df7Smcpowers 	uint64_t ccm_mac_input_buf[2];
17716239bc8SMark Powers 	uint64_t ccm_counter_mask;
17823c57df7Smcpowers } ccm_ctx_t;
17923c57df7Smcpowers 
18023c57df7Smcpowers #define	ccm_keysched		ccm_common.cc_keysched
18123c57df7Smcpowers #define	ccm_keysched_len	ccm_common.cc_keysched_len
18223c57df7Smcpowers #define	ccm_cb			ccm_common.cc_iv
18323c57df7Smcpowers #define	ccm_remainder		ccm_common.cc_remainder
18423c57df7Smcpowers #define	ccm_remainder_len	ccm_common.cc_remainder_len
18523c57df7Smcpowers #define	ccm_lastp		ccm_common.cc_lastp
18623c57df7Smcpowers #define	ccm_copy_to		ccm_common.cc_copy_to
18723c57df7Smcpowers #define	ccm_flags		ccm_common.cc_flags
18823c57df7Smcpowers 
1894d703b5cSMark Powers /*
1904d703b5cSMark Powers  * gcm_tag_len:		Length of authentication tag.
1914d703b5cSMark Powers  *
1924d703b5cSMark Powers  * gcm_ghash:		Stores output from the GHASH function.
1934d703b5cSMark Powers  *
1944d703b5cSMark Powers  * gcm_processed_data_len:
1954d703b5cSMark Powers  *			Length of processed plaintext (encrypt) or
1964d703b5cSMark Powers  *			length of processed ciphertext (decrypt).
1974d703b5cSMark Powers  *
1984d703b5cSMark Powers  * gcm_pt_buf:		Stores the decrypted plaintext returned by
1994d703b5cSMark Powers  *			decrypt_final when the computed authentication
2004d703b5cSMark Powers  *			tag matches the	user supplied tag.
2014d703b5cSMark Powers  *
2024d703b5cSMark Powers  * gcm_pt_buf_len:	Length of the plaintext buffer.
2034d703b5cSMark Powers  *
2044d703b5cSMark Powers  * gcm_H:		Subkey.
2054d703b5cSMark Powers  *
2064d703b5cSMark Powers  * gcm_J0:		Pre-counter block generated from the IV.
2074d703b5cSMark Powers  *
2084d703b5cSMark Powers  * gcm_len_a_len_c:	64-bit representations of the bit lengths of
2094d703b5cSMark Powers  *			AAD and ciphertext.
2104d703b5cSMark Powers  *
2114d703b5cSMark Powers  * gcm_kmflag:		Current value of kmflag. Used only for allocating
2124d703b5cSMark Powers  *			the plaintext buffer during decryption.
2134d703b5cSMark Powers  */
2144d703b5cSMark Powers typedef struct gcm_ctx {
2154d703b5cSMark Powers 	struct common_ctx gcm_common;
2164d703b5cSMark Powers 	size_t gcm_tag_len;
2174d703b5cSMark Powers 	size_t gcm_processed_data_len;
2184d703b5cSMark Powers 	size_t gcm_pt_buf_len;
2194d703b5cSMark Powers 	uint32_t gcm_tmp[4];
2204d703b5cSMark Powers 	uint64_t gcm_ghash[2];
2214d703b5cSMark Powers 	uint64_t gcm_H[2];
2224d703b5cSMark Powers 	uint64_t gcm_J0[2];
2234d703b5cSMark Powers 	uint64_t gcm_len_a_len_c[2];
2244d703b5cSMark Powers 	uint8_t *gcm_pt_buf;
2254d703b5cSMark Powers 	int gcm_kmflag;
2264d703b5cSMark Powers } gcm_ctx_t;
2274d703b5cSMark Powers 
2284d703b5cSMark Powers #define	gcm_keysched		gcm_common.cc_keysched
2294d703b5cSMark Powers #define	gcm_keysched_len	gcm_common.cc_keysched_len
2304d703b5cSMark Powers #define	gcm_cb			gcm_common.cc_iv
2314d703b5cSMark Powers #define	gcm_remainder		gcm_common.cc_remainder
2324d703b5cSMark Powers #define	gcm_remainder_len	gcm_common.cc_remainder_len
2334d703b5cSMark Powers #define	gcm_lastp		gcm_common.cc_lastp
2344d703b5cSMark Powers #define	gcm_copy_to		gcm_common.cc_copy_to
2354d703b5cSMark Powers #define	gcm_flags		gcm_common.cc_flags
2364d703b5cSMark Powers 
237983a1033SMark Powers #define	AES_GMAC_IV_LEN		12
238983a1033SMark Powers #define	AES_GMAC_TAG_BITS	128
239983a1033SMark Powers 
24023c57df7Smcpowers typedef struct aes_ctx {
24123c57df7Smcpowers 	union {
24223c57df7Smcpowers 		ecb_ctx_t acu_ecb;
24323c57df7Smcpowers 		cbc_ctx_t acu_cbc;
24423c57df7Smcpowers 		ctr_ctx_t acu_ctr;
24523c57df7Smcpowers 		ccm_ctx_t acu_ccm;
2464d703b5cSMark Powers 		gcm_ctx_t acu_gcm;
24723c57df7Smcpowers 	} acu;
24823c57df7Smcpowers } aes_ctx_t;
24923c57df7Smcpowers 
25016239bc8SMark Powers #define	ac_flags		acu.acu_ecb.ecb_common.cc_flags
25116239bc8SMark Powers #define	ac_remainder_len	acu.acu_ecb.ecb_common.cc_remainder_len
252*fb261280SJason King #define	ac_remainder		acu.acu_ecb.ecb_common.cc_remainder
25316239bc8SMark Powers #define	ac_keysched		acu.acu_ecb.ecb_common.cc_keysched
25416239bc8SMark Powers #define	ac_keysched_len		acu.acu_ecb.ecb_common.cc_keysched_len
25516239bc8SMark Powers #define	ac_iv			acu.acu_ecb.ecb_common.cc_iv
25616239bc8SMark Powers #define	ac_lastp		acu.acu_ecb.ecb_common.cc_lastp
25723c57df7Smcpowers #define	ac_pt_buf		acu.acu_ccm.ccm_pt_buf
25823c57df7Smcpowers #define	ac_mac_len		acu.acu_ccm.ccm_mac_len
25923c57df7Smcpowers #define	ac_data_len		acu.acu_ccm.ccm_data_len
26023c57df7Smcpowers #define	ac_processed_mac_len	acu.acu_ccm.ccm_processed_mac_len
26123c57df7Smcpowers #define	ac_processed_data_len	acu.acu_ccm.ccm_processed_data_len
2621dcbfafdSMark Powers #define	ac_tag_len		acu.acu_gcm.gcm_tag_len
26323c57df7Smcpowers 
26423c57df7Smcpowers typedef struct blowfish_ctx {
26523c57df7Smcpowers 	union {
26623c57df7Smcpowers 		ecb_ctx_t bcu_ecb;
26723c57df7Smcpowers 		cbc_ctx_t bcu_cbc;
26823c57df7Smcpowers 	} bcu;
26923c57df7Smcpowers } blowfish_ctx_t;
27023c57df7Smcpowers 
27116239bc8SMark Powers #define	bc_flags		bcu.bcu_ecb.ecb_common.cc_flags
27216239bc8SMark Powers #define	bc_remainder_len	bcu.bcu_ecb.ecb_common.cc_remainder_len
27316239bc8SMark Powers #define	bc_keysched		bcu.bcu_ecb.ecb_common.cc_keysched
27416239bc8SMark Powers #define	bc_keysched_len		bcu.bcu_ecb.ecb_common.cc_keysched_len
27516239bc8SMark Powers #define	bc_iv			bcu.bcu_ecb.ecb_common.cc_iv
27616239bc8SMark Powers #define	bc_lastp		bcu.bcu_ecb.ecb_common.cc_lastp
27723c57df7Smcpowers 
27823c57df7Smcpowers typedef struct des_ctx {
27923c57df7Smcpowers 	union {
28023c57df7Smcpowers 		ecb_ctx_t dcu_ecb;
28123c57df7Smcpowers 		cbc_ctx_t dcu_cbc;
28223c57df7Smcpowers 	} dcu;
28323c57df7Smcpowers } des_ctx_t;
28423c57df7Smcpowers 
28516239bc8SMark Powers #define	dc_flags		dcu.dcu_ecb.ecb_common.cc_flags
28616239bc8SMark Powers #define	dc_remainder_len	dcu.dcu_ecb.ecb_common.cc_remainder_len
28716239bc8SMark Powers #define	dc_keysched		dcu.dcu_ecb.ecb_common.cc_keysched
28816239bc8SMark Powers #define	dc_keysched_len		dcu.dcu_ecb.ecb_common.cc_keysched_len
28916239bc8SMark Powers #define	dc_iv			dcu.dcu_ecb.ecb_common.cc_iv
29016239bc8SMark Powers #define	dc_lastp		dcu.dcu_ecb.ecb_common.cc_lastp
29123c57df7Smcpowers 
29216239bc8SMark Powers extern int ecb_cipher_contiguous_blocks(ecb_ctx_t *, char *, size_t,
29323c57df7Smcpowers     crypto_data_t *, size_t, int (*cipher)(const void *, const uint8_t *,
29423c57df7Smcpowers     uint8_t *));
29523c57df7Smcpowers 
29623c57df7Smcpowers extern int cbc_encrypt_contiguous_blocks(cbc_ctx_t *, char *, size_t,
29723c57df7Smcpowers     crypto_data_t *, size_t,
29823c57df7Smcpowers     int (*encrypt)(const void *, const uint8_t *, uint8_t *),
29923c57df7Smcpowers     void (*copy_block)(uint8_t *, uint8_t *),
30023c57df7Smcpowers     void (*xor_block)(uint8_t *, uint8_t *));
30123c57df7Smcpowers 
30223c57df7Smcpowers extern int cbc_decrypt_contiguous_blocks(cbc_ctx_t *, char *, size_t,
30323c57df7Smcpowers     crypto_data_t *, size_t,
30423c57df7Smcpowers     int (*decrypt)(const void *, const uint8_t *, uint8_t *),
30523c57df7Smcpowers     void (*copy_block)(uint8_t *, uint8_t *),
30623c57df7Smcpowers     void (*xor_block)(uint8_t *, uint8_t *));
30723c57df7Smcpowers 
30823c57df7Smcpowers extern int ctr_mode_contiguous_blocks(ctr_ctx_t *, char *, size_t,
30923c57df7Smcpowers     crypto_data_t *, size_t,
31023c57df7Smcpowers     int (*cipher)(const void *, const uint8_t *, uint8_t *),
31123c57df7Smcpowers     void (*xor_block)(uint8_t *, uint8_t *));
31223c57df7Smcpowers 
31323c57df7Smcpowers extern int ccm_mode_encrypt_contiguous_blocks(ccm_ctx_t *, char *, size_t,
31423c57df7Smcpowers     crypto_data_t *, size_t,
31523c57df7Smcpowers     int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
31623c57df7Smcpowers     void (*copy_block)(uint8_t *, uint8_t *),
31723c57df7Smcpowers     void (*xor_block)(uint8_t *, uint8_t *));
31823c57df7Smcpowers 
31923c57df7Smcpowers extern int ccm_mode_decrypt_contiguous_blocks(ccm_ctx_t *, char *, size_t,
32023c57df7Smcpowers     crypto_data_t *, size_t,
32123c57df7Smcpowers     int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
32223c57df7Smcpowers     void (*copy_block)(uint8_t *, uint8_t *),
32323c57df7Smcpowers     void (*xor_block)(uint8_t *, uint8_t *));
32423c57df7Smcpowers 
3254d703b5cSMark Powers extern int gcm_mode_encrypt_contiguous_blocks(gcm_ctx_t *, char *, size_t,
3264d703b5cSMark Powers     crypto_data_t *, size_t,
3274d703b5cSMark Powers     int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
3284d703b5cSMark Powers     void (*copy_block)(uint8_t *, uint8_t *),
3294d703b5cSMark Powers     void (*xor_block)(uint8_t *, uint8_t *));
3304d703b5cSMark Powers 
3314d703b5cSMark Powers extern int gcm_mode_decrypt_contiguous_blocks(gcm_ctx_t *, char *, size_t,
3324d703b5cSMark Powers     crypto_data_t *, size_t,
3334d703b5cSMark Powers     int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
3344d703b5cSMark Powers     void (*copy_block)(uint8_t *, uint8_t *),
3354d703b5cSMark Powers     void (*xor_block)(uint8_t *, uint8_t *));
3364d703b5cSMark Powers 
33723c57df7Smcpowers int ccm_encrypt_final(ccm_ctx_t *, crypto_data_t *, size_t,
33823c57df7Smcpowers     int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
33923c57df7Smcpowers     void (*xor_block)(uint8_t *, uint8_t *));
34023c57df7Smcpowers 
3414d703b5cSMark Powers int gcm_encrypt_final(gcm_ctx_t *, crypto_data_t *, size_t,
3424d703b5cSMark Powers     int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
3434d703b5cSMark Powers     void (*copy_block)(uint8_t *, uint8_t *),
3444d703b5cSMark Powers     void (*xor_block)(uint8_t *, uint8_t *));
3454d703b5cSMark Powers 
34623c57df7Smcpowers extern int ccm_decrypt_final(ccm_ctx_t *, crypto_data_t *, size_t,
34723c57df7Smcpowers     int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
34823c57df7Smcpowers     void (*copy_block)(uint8_t *, uint8_t *),
34923c57df7Smcpowers     void (*xor_block)(uint8_t *, uint8_t *));
35023c57df7Smcpowers 
3514d703b5cSMark Powers extern int gcm_decrypt_final(gcm_ctx_t *, crypto_data_t *, size_t,
3524d703b5cSMark Powers     int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
3534d703b5cSMark Powers     void (*xor_block)(uint8_t *, uint8_t *));
3544d703b5cSMark Powers 
355cd964fceSMatt Barden extern int cmac_mode_final(cbc_ctx_t *, crypto_data_t *,
356cd964fceSMatt Barden     int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
357cd964fceSMatt Barden     void (*xor_block)(uint8_t *, uint8_t *));
358cd964fceSMatt Barden 
35923c57df7Smcpowers extern int ctr_mode_final(ctr_ctx_t *, crypto_data_t *,
36023c57df7Smcpowers     int (*encrypt_block)(const void *, const uint8_t *, uint8_t *));
36123c57df7Smcpowers 
36223c57df7Smcpowers extern int cbc_init_ctx(cbc_ctx_t *, char *, size_t, size_t,
36323c57df7Smcpowers     void (*copy_block)(uint8_t *, uint64_t *));
36423c57df7Smcpowers 
365cd964fceSMatt Barden extern int cmac_init_ctx(cbc_ctx_t *, size_t);
366cd964fceSMatt Barden 
36723c57df7Smcpowers extern int ctr_init_ctx(ctr_ctx_t *, ulong_t, uint8_t *,
36823c57df7Smcpowers     void (*copy_block)(uint8_t *, uint8_t *));
36923c57df7Smcpowers 
37023c57df7Smcpowers extern int ccm_init_ctx(ccm_ctx_t *, char *, int, boolean_t, size_t,
37123c57df7Smcpowers     int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
37223c57df7Smcpowers     void (*xor_block)(uint8_t *, uint8_t *));
37323c57df7Smcpowers 
3744d703b5cSMark Powers extern int gcm_init_ctx(gcm_ctx_t *, char *, size_t,
3754d703b5cSMark Powers     int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
3764d703b5cSMark Powers     void (*copy_block)(uint8_t *, uint8_t *),
3774d703b5cSMark Powers     void (*xor_block)(uint8_t *, uint8_t *));
3784d703b5cSMark Powers 
379983a1033SMark Powers extern int gmac_init_ctx(gcm_ctx_t *, char *, size_t,
380983a1033SMark Powers     int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
381983a1033SMark Powers     void (*copy_block)(uint8_t *, uint8_t *),
382983a1033SMark Powers     void (*xor_block)(uint8_t *, uint8_t *));
383983a1033SMark Powers 
38423c57df7Smcpowers extern void calculate_ccm_mac(ccm_ctx_t *, uint8_t *,
38523c57df7Smcpowers     int (*encrypt_block)(const void *, const uint8_t *, uint8_t *));
38623c57df7Smcpowers 
387e8c016efSMark Powers extern void gcm_mul(uint64_t *, uint64_t *, uint64_t *);
388e8c016efSMark Powers 
38923c57df7Smcpowers extern void crypto_init_ptrs(crypto_data_t *, void **, offset_t *);
39023c57df7Smcpowers extern void crypto_get_ptrs(crypto_data_t *, void **, offset_t *,
39123c57df7Smcpowers     uint8_t **, size_t *, uint8_t **, size_t);
39223c57df7Smcpowers 
39323c57df7Smcpowers extern void *ecb_alloc_ctx(int);
39423c57df7Smcpowers extern void *cbc_alloc_ctx(int);
395cd964fceSMatt Barden extern void *cmac_alloc_ctx(int);
39623c57df7Smcpowers extern void *ctr_alloc_ctx(int);
39723c57df7Smcpowers extern void *ccm_alloc_ctx(int);
3984d703b5cSMark Powers extern void *gcm_alloc_ctx(int);
399983a1033SMark Powers extern void *gmac_alloc_ctx(int);
40023c57df7Smcpowers extern void crypto_free_mode_ctx(void *);
4014d703b5cSMark Powers extern void gcm_set_kmflag(gcm_ctx_t *, int);
402cd964fceSMatt Barden extern int crypto_put_output_data(uchar_t *, crypto_data_t *, int);
40323c57df7Smcpowers 
40423c57df7Smcpowers #ifdef	__cplusplus
40523c57df7Smcpowers }
40623c57df7Smcpowers #endif
40723c57df7Smcpowers 
40823c57df7Smcpowers #endif	/* _COMMON_CRYPTO_MODES_H */
409