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
e8c016ef6bb7e825057460cea4d904e2b90eb424Mark Powers * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23c57df72989c916b3e98084eb88d48777999691mcpowers * Use is subject to license terms.
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_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
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers#define ecb_keysched_len ecb_common.cc_keysched_len
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers#define ecb_remainder_len ecb_common.cc_remainder_len
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers#define cbc_keysched_len cbc_common.cc_keysched_len
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers#define cbc_remainder_len cbc_common.cc_remainder_len
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers * ctr_lower_mask Bit-mask for lower 8 bytes of counter block.
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers * ctr_upper_mask Bit-mask for upper 8 bytes of counter block.
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers * ctr_cb 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.
23c57df72989c916b3e98084eb88d48777999691mcpowers#define ccm_remainder_len ccm_common.cc_remainder_len
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powers * gcm_tag_len: Length of authentication tag.
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powers * gcm_ghash: Stores output from the GHASH function.
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powers * gcm_processed_data_len:
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powers * Length of processed plaintext (encrypt) or
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powers * length of processed ciphertext (decrypt).
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powers * gcm_pt_buf: Stores the decrypted plaintext returned by
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powers * decrypt_final when the computed authentication
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powers * tag matches the user supplied tag.
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powers * gcm_pt_buf_len: Length of the plaintext buffer.
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powers * gcm_H: Subkey.
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powers * gcm_J0: Pre-counter block generated from the IV.
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powers * gcm_len_a_len_c: 64-bit representations of the bit lengths of
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powers * AAD and ciphertext.
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powers * gcm_kmflag: Current value of kmflag. Used only for allocating
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powers * the plaintext buffer during decryption.
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powers#define gcm_keysched_len gcm_common.cc_keysched_len
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powers#define gcm_remainder_len gcm_common.cc_remainder_len
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers#define ac_remainder_len acu.acu_ecb.ecb_common.cc_remainder_len
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers#define ac_keysched acu.acu_ecb.ecb_common.cc_keysched
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers#define ac_keysched_len acu.acu_ecb.ecb_common.cc_keysched_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
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers#define bc_remainder_len bcu.bcu_ecb.ecb_common.cc_remainder_len
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers#define bc_keysched bcu.bcu_ecb.ecb_common.cc_keysched
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers#define bc_keysched_len bcu.bcu_ecb.ecb_common.cc_keysched_len
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers#define dc_remainder_len dcu.dcu_ecb.ecb_common.cc_remainder_len
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers#define dc_keysched dcu.dcu_ecb.ecb_common.cc_keysched
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powers#define dc_keysched_len dcu.dcu_ecb.ecb_common.cc_keysched_len
16239bc82c111618343e0a5b1a70e0fc702d00e0Mark Powersextern int ecb_cipher_contiguous_blocks(ecb_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 *),
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powersextern int gcm_mode_encrypt_contiguous_blocks(gcm_ctx_t *, char *, size_t,
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powers int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powersextern int gcm_mode_decrypt_contiguous_blocks(gcm_ctx_t *, char *, size_t,
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powers 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 *),
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powersint gcm_encrypt_final(gcm_ctx_t *, crypto_data_t *, size_t,
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powers 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 *),
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powersextern int gcm_decrypt_final(gcm_ctx_t *, crypto_data_t *, size_t,
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powers 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 *),
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powersextern int gcm_init_ctx(gcm_ctx_t *, char *, size_t,
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powers int (*encrypt_block)(const void *, const uint8_t *, uint8_t *),
983a10335731bc55a0b7a37f195575fa109e30d4Mark Powersextern int gmac_init_ctx(gcm_ctx_t *, char *, size_t,
983a10335731bc55a0b7a37f195575fa109e30d4Mark Powers 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 *));
e8c016ef6bb7e825057460cea4d904e2b90eb424Mark Powersextern void gcm_mul(uint64_t *, uint64_t *, uint64_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);
4d703b5c9cb1bc29ace6c53cb50b2fe766e6370fMark Powersextern void *gcm_alloc_ctx(int);
983a10335731bc55a0b7a37f195575fa109e30d4Mark Powersextern void *gmac_alloc_ctx(int);
23c57df72989c916b3e98084eb88d48777999691mcpowersextern void crypto_free_mode_ctx(void *);
23c57df72989c916b3e98084eb88d48777999691mcpowers#endif /* _COMMON_CRYPTO_MODES_H */