modes.h revision 23c57df72989c916b3e98084eb88d48777999691
23c57df72989c916b3e98084eb88d48777999691mcpowers * CDDL HEADER START
23c57df72989c916b3e98084eb88d48777999691mcpowers * The contents of this file are subject to the terms of the
23c57df72989c916b3e98084eb88d48777999691mcpowers * Common Development and Distribution License (the "License").
23c57df72989c916b3e98084eb88d48777999691mcpowers * You may not use this file except in compliance with the License.
23c57df72989c916b3e98084eb88d48777999691mcpowers * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
23c57df72989c916b3e98084eb88d48777999691mcpowers * See the License for the specific language governing permissions
23c57df72989c916b3e98084eb88d48777999691mcpowers * and limitations under the License.
23c57df72989c916b3e98084eb88d48777999691mcpowers * When distributing Covered Code, include this CDDL HEADER in each
23c57df72989c916b3e98084eb88d48777999691mcpowers * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
23c57df72989c916b3e98084eb88d48777999691mcpowers * If applicable, add the following below this CDDL HEADER, with the
23c57df72989c916b3e98084eb88d48777999691mcpowers * fields enclosed by brackets "[]" replaced with your own identifying
23c57df72989c916b3e98084eb88d48777999691mcpowers * information: Portions Copyright [yyyy] [name of copyright owner]
23c57df72989c916b3e98084eb88d48777999691mcpowers * CDDL HEADER END
23c57df72989c916b3e98084eb88d48777999691mcpowers * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23c57df72989c916b3e98084eb88d48777999691mcpowers * Use is subject to license terms.
23c57df72989c916b3e98084eb88d48777999691mcpowers#pragma ident "%Z%%M% %I% %E% SMI"
23c57df72989c916b3e98084eb88d48777999691mcpowersextern "C" {
23c57df72989c916b3e98084eb88d48777999691mcpowers * cc_keysched: Pointer to key schedule.
23c57df72989c916b3e98084eb88d48777999691mcpowers * cc_keysched_len: Length of the key schedule.
23c57df72989c916b3e98084eb88d48777999691mcpowers * cc_remainder: This is for residual data, i.e. data that can't
23c57df72989c916b3e98084eb88d48777999691mcpowers * be processed because there are too few bytes.
23c57df72989c916b3e98084eb88d48777999691mcpowers * Must wait until more data arrives.
23c57df72989c916b3e98084eb88d48777999691mcpowers * cc_remainder_len: Number of bytes in cc_remainder.
23c57df72989c916b3e98084eb88d48777999691mcpowers * cc_iv: Scratch buffer that sometimes contains the IV.
23c57df72989c916b3e98084eb88d48777999691mcpowers * cc_lastblock: Scratch buffer.
23c57df72989c916b3e98084eb88d48777999691mcpowers * cc_lastp: Pointer to previous block of ciphertext.
23c57df72989c916b3e98084eb88d48777999691mcpowers * cc_copy_to: Pointer to where encrypted residual data needs
23c57df72989c916b3e98084eb88d48777999691mcpowers * to be copied.
23c57df72989c916b3e98084eb88d48777999691mcpowers * cc_flags: PROVIDER_OWNS_KEY_SCHEDULE
23c57df72989c916b3e98084eb88d48777999691mcpowers * When a context is freed, it is necessary
23c57df72989c916b3e98084eb88d48777999691mcpowers * to know whether the key schedule was allocated
23c57df72989c916b3e98084eb88d48777999691mcpowers * by the caller, or internally, e.g. an init routine.
23c57df72989c916b3e98084eb88d48777999691mcpowers * If allocated by the latter, then it needs to be freed.
23c57df72989c916b3e98084eb88d48777999691mcpowers * ECB_MODE, CBC_MODE, CTR_MODE, or CCM_MODE
23c57df72989c916b3e98084eb88d48777999691mcpowerstypedef struct ctr_ctx {
23c57df72989c916b3e98084eb88d48777999691mcpowers * ctr_cb Counter block.
23c57df72989c916b3e98084eb88d48777999691mcpowers * ctr_counter_mask Mask of counter bits in the last 8 bytes of the
23c57df72989c916b3e98084eb88d48777999691mcpowers * counter block.
23c57df72989c916b3e98084eb88d48777999691mcpowers#define ctr_remainder_len ctr_common.cc_remainder_len
23c57df72989c916b3e98084eb88d48777999691mcpowers * ccm_mac_len: Stores length of the MAC in CCM mode.
23c57df72989c916b3e98084eb88d48777999691mcpowers * ccm_mac_buf: Stores the intermediate value for MAC in CCM encrypt.
23c57df72989c916b3e98084eb88d48777999691mcpowers * In CCM decrypt, stores the input MAC value.
23c57df72989c916b3e98084eb88d48777999691mcpowers * ccm_data_len: Length of the plaintext for CCM mode encrypt, or
23c57df72989c916b3e98084eb88d48777999691mcpowers * length of the ciphertext for CCM mode decrypt.
23c57df72989c916b3e98084eb88d48777999691mcpowers * ccm_processed_data_len:
23c57df72989c916b3e98084eb88d48777999691mcpowers * Length of processed plaintext in CCM mode encrypt,
23c57df72989c916b3e98084eb88d48777999691mcpowers * or length of processed ciphertext for CCM mode decrypt.
23c57df72989c916b3e98084eb88d48777999691mcpowers * ccm_processed_mac_len:
23c57df72989c916b3e98084eb88d48777999691mcpowers * Length of MAC data accumulated in CCM mode decrypt.
23c57df72989c916b3e98084eb88d48777999691mcpowers * ccm_pt_buf: Only used in CCM mode decrypt. It stores the
23c57df72989c916b3e98084eb88d48777999691mcpowers * decrypted plaintext to be returned when
23c57df72989c916b3e98084eb88d48777999691mcpowers * MAC verification succeeds in decrypt_final.
23c57df72989c916b3e98084eb88d48777999691mcpowers * Memory for this should be allocated in the AES module.
23c57df72989c916b3e98084eb88d48777999691mcpowerstypedef struct ccm_ctx {
23c57df72989c916b3e98084eb88d48777999691mcpowers#define ccm_remainder_len ccm_common.cc_remainder_len
23c57df72989c916b3e98084eb88d48777999691mcpowerstypedef struct aes_ctx {
23c57df72989c916b3e98084eb88d48777999691mcpowers#define ac_remainder_len acu.acu_ecb.cc_remainder_len
23c57df72989c916b3e98084eb88d48777999691mcpowers#define ac_processed_mac_len acu.acu_ccm.ccm_processed_mac_len
23c57df72989c916b3e98084eb88d48777999691mcpowers#define ac_processed_data_len acu.acu_ccm.ccm_processed_data_len
23c57df72989c916b3e98084eb88d48777999691mcpowerstypedef struct blowfish_ctx {
23c57df72989c916b3e98084eb88d48777999691mcpowers#define bc_remainder_len bcu.bcu_ecb.cc_remainder_len
23c57df72989c916b3e98084eb88d48777999691mcpowerstypedef struct des_ctx {
23c57df72989c916b3e98084eb88d48777999691mcpowers#define dc_remainder_len dcu.dcu_ecb.cc_remainder_len
23c57df72989c916b3e98084eb88d48777999691mcpowersextern int ecb_cipher_contiguous_blocks(cbc_ctx_t *, char *, size_t,
23c57df72989c916b3e98084eb88d48777999691mcpowers crypto_data_t *, size_t, int (*cipher)(const void *, const uint8_t *,
23c57df72989c916b3e98084eb88d48777999691mcpowersextern int cbc_encrypt_contiguous_blocks(cbc_ctx_t *, char *, size_t,
23c57df72989c916b3e98084eb88d48777999691mcpowers int (*encrypt)(const void *, const uint8_t *, uint8_t *),
23c57df72989c916b3e98084eb88d48777999691mcpowersextern int cbc_decrypt_contiguous_blocks(cbc_ctx_t *, char *, size_t,
23c57df72989c916b3e98084eb88d48777999691mcpowers int (*decrypt)(const void *, const uint8_t *, uint8_t *),
23c57df72989c916b3e98084eb88d48777999691mcpowersextern int ctr_mode_contiguous_blocks(ctr_ctx_t *, char *, size_t,
23c57df72989c916b3e98084eb88d48777999691mcpowers int (*cipher)(const void *, const uint8_t *, uint8_t *),
23c57df72989c916b3e98084eb88d48777999691mcpowersextern int ccm_mode_encrypt_contiguous_blocks(ccm_ctx_t *, char *, size_t,
23c57df72989c916b3e98084eb88d48777999691mcpowers int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
23c57df72989c916b3e98084eb88d48777999691mcpowersextern int ccm_mode_decrypt_contiguous_blocks(ccm_ctx_t *, char *, size_t,
23c57df72989c916b3e98084eb88d48777999691mcpowers int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
23c57df72989c916b3e98084eb88d48777999691mcpowersint ccm_encrypt_final(ccm_ctx_t *, crypto_data_t *, size_t,
23c57df72989c916b3e98084eb88d48777999691mcpowers int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
23c57df72989c916b3e98084eb88d48777999691mcpowersextern int ccm_decrypt_final(ccm_ctx_t *, crypto_data_t *, size_t,
23c57df72989c916b3e98084eb88d48777999691mcpowers int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
23c57df72989c916b3e98084eb88d48777999691mcpowersextern int ctr_mode_final(ctr_ctx_t *, crypto_data_t *,
23c57df72989c916b3e98084eb88d48777999691mcpowers int (*encrypt_block)(const void *, const uint8_t *, uint8_t *));
23c57df72989c916b3e98084eb88d48777999691mcpowersextern int cbc_init_ctx(cbc_ctx_t *, char *, size_t, size_t,
23c57df72989c916b3e98084eb88d48777999691mcpowersextern int ctr_init_ctx(ctr_ctx_t *, ulong_t, uint8_t *,
23c57df72989c916b3e98084eb88d48777999691mcpowersextern int ccm_init_ctx(ccm_ctx_t *, char *, int, boolean_t, size_t,
23c57df72989c916b3e98084eb88d48777999691mcpowers int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
23c57df72989c916b3e98084eb88d48777999691mcpowersextern void calculate_ccm_mac(ccm_ctx_t *, uint8_t *,
23c57df72989c916b3e98084eb88d48777999691mcpowers int (*encrypt_block)(const void *, const uint8_t *, uint8_t *));
23c57df72989c916b3e98084eb88d48777999691mcpowersextern void crypto_init_ptrs(crypto_data_t *, void **, offset_t *);
23c57df72989c916b3e98084eb88d48777999691mcpowersextern void crypto_get_ptrs(crypto_data_t *, void **, offset_t *,
23c57df72989c916b3e98084eb88d48777999691mcpowersextern void *ecb_alloc_ctx(int);
23c57df72989c916b3e98084eb88d48777999691mcpowersextern void *cbc_alloc_ctx(int);
23c57df72989c916b3e98084eb88d48777999691mcpowersextern void *ctr_alloc_ctx(int);
23c57df72989c916b3e98084eb88d48777999691mcpowersextern void *ccm_alloc_ctx(int);
23c57df72989c916b3e98084eb88d48777999691mcpowersextern void crypto_free_mode_ctx(void *);
23c57df72989c916b3e98084eb88d48777999691mcpowers#endif /* _COMMON_CRYPTO_MODES_H */