1*eda14cbcSMatt Macy /* 2*eda14cbcSMatt Macy * CDDL HEADER START 3*eda14cbcSMatt Macy * 4*eda14cbcSMatt Macy * The contents of this file are subject to the terms of the 5*eda14cbcSMatt Macy * Common Development and Distribution License (the "License"). 6*eda14cbcSMatt Macy * You may not use this file except in compliance with the License. 7*eda14cbcSMatt Macy * 8*eda14cbcSMatt Macy * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*eda14cbcSMatt Macy * or http://www.opensolaris.org/os/licensing. 10*eda14cbcSMatt Macy * See the License for the specific language governing permissions 11*eda14cbcSMatt Macy * and limitations under the License. 12*eda14cbcSMatt Macy * 13*eda14cbcSMatt Macy * When distributing Covered Code, include this CDDL HEADER in each 14*eda14cbcSMatt Macy * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*eda14cbcSMatt Macy * If applicable, add the following below this CDDL HEADER, with the 16*eda14cbcSMatt Macy * fields enclosed by brackets "[]" replaced with your own identifying 17*eda14cbcSMatt Macy * information: Portions Copyright [yyyy] [name of copyright owner] 18*eda14cbcSMatt Macy * 19*eda14cbcSMatt Macy * CDDL HEADER END 20*eda14cbcSMatt Macy */ 21*eda14cbcSMatt Macy /* 22*eda14cbcSMatt Macy * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 23*eda14cbcSMatt Macy * Use is subject to license terms. 24*eda14cbcSMatt Macy */ 25*eda14cbcSMatt Macy 26*eda14cbcSMatt Macy #ifndef _COMMON_CRYPTO_MODES_H 27*eda14cbcSMatt Macy #define _COMMON_CRYPTO_MODES_H 28*eda14cbcSMatt Macy 29*eda14cbcSMatt Macy #ifdef __cplusplus 30*eda14cbcSMatt Macy extern "C" { 31*eda14cbcSMatt Macy #endif 32*eda14cbcSMatt Macy 33*eda14cbcSMatt Macy #include <sys/zfs_context.h> 34*eda14cbcSMatt Macy #include <sys/crypto/common.h> 35*eda14cbcSMatt Macy #include <sys/crypto/impl.h> 36*eda14cbcSMatt Macy 37*eda14cbcSMatt Macy /* 38*eda14cbcSMatt Macy * Does the build chain support all instructions needed for the GCM assembler 39*eda14cbcSMatt Macy * routines. AVX support should imply AES-NI and PCLMULQDQ, but make sure 40*eda14cbcSMatt Macy * anyhow. 41*eda14cbcSMatt Macy */ 42*eda14cbcSMatt Macy #if defined(__x86_64__) && defined(HAVE_AVX) && \ 43*eda14cbcSMatt Macy defined(HAVE_AES) && defined(HAVE_PCLMULQDQ) 44*eda14cbcSMatt Macy #define CAN_USE_GCM_ASM 45*eda14cbcSMatt Macy extern boolean_t gcm_avx_can_use_movbe; 46*eda14cbcSMatt Macy #endif 47*eda14cbcSMatt Macy 48*eda14cbcSMatt Macy #define ECB_MODE 0x00000002 49*eda14cbcSMatt Macy #define CBC_MODE 0x00000004 50*eda14cbcSMatt Macy #define CTR_MODE 0x00000008 51*eda14cbcSMatt Macy #define CCM_MODE 0x00000010 52*eda14cbcSMatt Macy #define GCM_MODE 0x00000020 53*eda14cbcSMatt Macy #define GMAC_MODE 0x00000040 54*eda14cbcSMatt Macy 55*eda14cbcSMatt Macy /* 56*eda14cbcSMatt Macy * cc_keysched: Pointer to key schedule. 57*eda14cbcSMatt Macy * 58*eda14cbcSMatt Macy * cc_keysched_len: Length of the key schedule. 59*eda14cbcSMatt Macy * 60*eda14cbcSMatt Macy * cc_remainder: This is for residual data, i.e. data that can't 61*eda14cbcSMatt Macy * be processed because there are too few bytes. 62*eda14cbcSMatt Macy * Must wait until more data arrives. 63*eda14cbcSMatt Macy * 64*eda14cbcSMatt Macy * cc_remainder_len: Number of bytes in cc_remainder. 65*eda14cbcSMatt Macy * 66*eda14cbcSMatt Macy * cc_iv: Scratch buffer that sometimes contains the IV. 67*eda14cbcSMatt Macy * 68*eda14cbcSMatt Macy * cc_lastp: Pointer to previous block of ciphertext. 69*eda14cbcSMatt Macy * 70*eda14cbcSMatt Macy * cc_copy_to: Pointer to where encrypted residual data needs 71*eda14cbcSMatt Macy * to be copied. 72*eda14cbcSMatt Macy * 73*eda14cbcSMatt Macy * cc_flags: PROVIDER_OWNS_KEY_SCHEDULE 74*eda14cbcSMatt Macy * When a context is freed, it is necessary 75*eda14cbcSMatt Macy * to know whether the key schedule was allocated 76*eda14cbcSMatt Macy * by the caller, or internally, e.g. an init routine. 77*eda14cbcSMatt Macy * If allocated by the latter, then it needs to be freed. 78*eda14cbcSMatt Macy * 79*eda14cbcSMatt Macy * ECB_MODE, CBC_MODE, CTR_MODE, or CCM_MODE 80*eda14cbcSMatt Macy */ 81*eda14cbcSMatt Macy struct common_ctx { 82*eda14cbcSMatt Macy void *cc_keysched; 83*eda14cbcSMatt Macy size_t cc_keysched_len; 84*eda14cbcSMatt Macy uint64_t cc_iv[2]; 85*eda14cbcSMatt Macy uint64_t cc_remainder[2]; 86*eda14cbcSMatt Macy size_t cc_remainder_len; 87*eda14cbcSMatt Macy uint8_t *cc_lastp; 88*eda14cbcSMatt Macy uint8_t *cc_copy_to; 89*eda14cbcSMatt Macy uint32_t cc_flags; 90*eda14cbcSMatt Macy }; 91*eda14cbcSMatt Macy 92*eda14cbcSMatt Macy typedef struct common_ctx common_ctx_t; 93*eda14cbcSMatt Macy 94*eda14cbcSMatt Macy typedef struct ecb_ctx { 95*eda14cbcSMatt Macy struct common_ctx ecb_common; 96*eda14cbcSMatt Macy uint64_t ecb_lastblock[2]; 97*eda14cbcSMatt Macy } ecb_ctx_t; 98*eda14cbcSMatt Macy 99*eda14cbcSMatt Macy #define ecb_keysched ecb_common.cc_keysched 100*eda14cbcSMatt Macy #define ecb_keysched_len ecb_common.cc_keysched_len 101*eda14cbcSMatt Macy #define ecb_iv ecb_common.cc_iv 102*eda14cbcSMatt Macy #define ecb_remainder ecb_common.cc_remainder 103*eda14cbcSMatt Macy #define ecb_remainder_len ecb_common.cc_remainder_len 104*eda14cbcSMatt Macy #define ecb_lastp ecb_common.cc_lastp 105*eda14cbcSMatt Macy #define ecb_copy_to ecb_common.cc_copy_to 106*eda14cbcSMatt Macy #define ecb_flags ecb_common.cc_flags 107*eda14cbcSMatt Macy 108*eda14cbcSMatt Macy typedef struct cbc_ctx { 109*eda14cbcSMatt Macy struct common_ctx cbc_common; 110*eda14cbcSMatt Macy uint64_t cbc_lastblock[2]; 111*eda14cbcSMatt Macy } cbc_ctx_t; 112*eda14cbcSMatt Macy 113*eda14cbcSMatt Macy #define cbc_keysched cbc_common.cc_keysched 114*eda14cbcSMatt Macy #define cbc_keysched_len cbc_common.cc_keysched_len 115*eda14cbcSMatt Macy #define cbc_iv cbc_common.cc_iv 116*eda14cbcSMatt Macy #define cbc_remainder cbc_common.cc_remainder 117*eda14cbcSMatt Macy #define cbc_remainder_len cbc_common.cc_remainder_len 118*eda14cbcSMatt Macy #define cbc_lastp cbc_common.cc_lastp 119*eda14cbcSMatt Macy #define cbc_copy_to cbc_common.cc_copy_to 120*eda14cbcSMatt Macy #define cbc_flags cbc_common.cc_flags 121*eda14cbcSMatt Macy 122*eda14cbcSMatt Macy /* 123*eda14cbcSMatt Macy * ctr_lower_mask Bit-mask for lower 8 bytes of counter block. 124*eda14cbcSMatt Macy * ctr_upper_mask Bit-mask for upper 8 bytes of counter block. 125*eda14cbcSMatt Macy */ 126*eda14cbcSMatt Macy typedef struct ctr_ctx { 127*eda14cbcSMatt Macy struct common_ctx ctr_common; 128*eda14cbcSMatt Macy uint64_t ctr_lower_mask; 129*eda14cbcSMatt Macy uint64_t ctr_upper_mask; 130*eda14cbcSMatt Macy uint32_t ctr_tmp[4]; 131*eda14cbcSMatt Macy } ctr_ctx_t; 132*eda14cbcSMatt Macy 133*eda14cbcSMatt Macy /* 134*eda14cbcSMatt Macy * ctr_cb Counter block. 135*eda14cbcSMatt Macy */ 136*eda14cbcSMatt Macy #define ctr_keysched ctr_common.cc_keysched 137*eda14cbcSMatt Macy #define ctr_keysched_len ctr_common.cc_keysched_len 138*eda14cbcSMatt Macy #define ctr_cb ctr_common.cc_iv 139*eda14cbcSMatt Macy #define ctr_remainder ctr_common.cc_remainder 140*eda14cbcSMatt Macy #define ctr_remainder_len ctr_common.cc_remainder_len 141*eda14cbcSMatt Macy #define ctr_lastp ctr_common.cc_lastp 142*eda14cbcSMatt Macy #define ctr_copy_to ctr_common.cc_copy_to 143*eda14cbcSMatt Macy #define ctr_flags ctr_common.cc_flags 144*eda14cbcSMatt Macy 145*eda14cbcSMatt Macy /* 146*eda14cbcSMatt Macy * 147*eda14cbcSMatt Macy * ccm_mac_len: Stores length of the MAC in CCM mode. 148*eda14cbcSMatt Macy * ccm_mac_buf: Stores the intermediate value for MAC in CCM encrypt. 149*eda14cbcSMatt Macy * In CCM decrypt, stores the input MAC value. 150*eda14cbcSMatt Macy * ccm_data_len: Length of the plaintext for CCM mode encrypt, or 151*eda14cbcSMatt Macy * length of the ciphertext for CCM mode decrypt. 152*eda14cbcSMatt Macy * ccm_processed_data_len: 153*eda14cbcSMatt Macy * Length of processed plaintext in CCM mode encrypt, 154*eda14cbcSMatt Macy * or length of processed ciphertext for CCM mode decrypt. 155*eda14cbcSMatt Macy * ccm_processed_mac_len: 156*eda14cbcSMatt Macy * Length of MAC data accumulated in CCM mode decrypt. 157*eda14cbcSMatt Macy * 158*eda14cbcSMatt Macy * ccm_pt_buf: Only used in CCM mode decrypt. It stores the 159*eda14cbcSMatt Macy * decrypted plaintext to be returned when 160*eda14cbcSMatt Macy * MAC verification succeeds in decrypt_final. 161*eda14cbcSMatt Macy * Memory for this should be allocated in the AES module. 162*eda14cbcSMatt Macy * 163*eda14cbcSMatt Macy */ 164*eda14cbcSMatt Macy typedef struct ccm_ctx { 165*eda14cbcSMatt Macy struct common_ctx ccm_common; 166*eda14cbcSMatt Macy uint32_t ccm_tmp[4]; 167*eda14cbcSMatt Macy size_t ccm_mac_len; 168*eda14cbcSMatt Macy uint64_t ccm_mac_buf[2]; 169*eda14cbcSMatt Macy size_t ccm_data_len; 170*eda14cbcSMatt Macy size_t ccm_processed_data_len; 171*eda14cbcSMatt Macy size_t ccm_processed_mac_len; 172*eda14cbcSMatt Macy uint8_t *ccm_pt_buf; 173*eda14cbcSMatt Macy uint64_t ccm_mac_input_buf[2]; 174*eda14cbcSMatt Macy uint64_t ccm_counter_mask; 175*eda14cbcSMatt Macy } ccm_ctx_t; 176*eda14cbcSMatt Macy 177*eda14cbcSMatt Macy #define ccm_keysched ccm_common.cc_keysched 178*eda14cbcSMatt Macy #define ccm_keysched_len ccm_common.cc_keysched_len 179*eda14cbcSMatt Macy #define ccm_cb ccm_common.cc_iv 180*eda14cbcSMatt Macy #define ccm_remainder ccm_common.cc_remainder 181*eda14cbcSMatt Macy #define ccm_remainder_len ccm_common.cc_remainder_len 182*eda14cbcSMatt Macy #define ccm_lastp ccm_common.cc_lastp 183*eda14cbcSMatt Macy #define ccm_copy_to ccm_common.cc_copy_to 184*eda14cbcSMatt Macy #define ccm_flags ccm_common.cc_flags 185*eda14cbcSMatt Macy 186*eda14cbcSMatt Macy /* 187*eda14cbcSMatt Macy * gcm_tag_len: Length of authentication tag. 188*eda14cbcSMatt Macy * 189*eda14cbcSMatt Macy * gcm_ghash: Stores output from the GHASH function. 190*eda14cbcSMatt Macy * 191*eda14cbcSMatt Macy * gcm_processed_data_len: 192*eda14cbcSMatt Macy * Length of processed plaintext (encrypt) or 193*eda14cbcSMatt Macy * length of processed ciphertext (decrypt). 194*eda14cbcSMatt Macy * 195*eda14cbcSMatt Macy * gcm_pt_buf: Stores the decrypted plaintext returned by 196*eda14cbcSMatt Macy * decrypt_final when the computed authentication 197*eda14cbcSMatt Macy * tag matches the user supplied tag. 198*eda14cbcSMatt Macy * 199*eda14cbcSMatt Macy * gcm_pt_buf_len: Length of the plaintext buffer. 200*eda14cbcSMatt Macy * 201*eda14cbcSMatt Macy * gcm_H: Subkey. 202*eda14cbcSMatt Macy * 203*eda14cbcSMatt Macy * gcm_Htable: Pre-computed and pre-shifted H, H^2, ... H^6 for the 204*eda14cbcSMatt Macy * Karatsuba Algorithm in host byte order. 205*eda14cbcSMatt Macy * 206*eda14cbcSMatt Macy * gcm_J0: Pre-counter block generated from the IV. 207*eda14cbcSMatt Macy * 208*eda14cbcSMatt Macy * gcm_len_a_len_c: 64-bit representations of the bit lengths of 209*eda14cbcSMatt Macy * AAD and ciphertext. 210*eda14cbcSMatt Macy * 211*eda14cbcSMatt Macy * gcm_kmflag: Current value of kmflag. Used for allocating 212*eda14cbcSMatt Macy * the plaintext buffer during decryption and a 213*eda14cbcSMatt Macy * gcm_avx_chunk_size'd buffer for avx enabled encryption. 214*eda14cbcSMatt Macy */ 215*eda14cbcSMatt Macy typedef struct gcm_ctx { 216*eda14cbcSMatt Macy struct common_ctx gcm_common; 217*eda14cbcSMatt Macy size_t gcm_tag_len; 218*eda14cbcSMatt Macy size_t gcm_processed_data_len; 219*eda14cbcSMatt Macy size_t gcm_pt_buf_len; 220*eda14cbcSMatt Macy uint32_t gcm_tmp[4]; 221*eda14cbcSMatt Macy /* 222*eda14cbcSMatt Macy * The relative positions of gcm_ghash, gcm_H and pre-computed 223*eda14cbcSMatt Macy * gcm_Htable are hard coded in aesni-gcm-x86_64.S and ghash-x86_64.S, 224*eda14cbcSMatt Macy * so please don't change (or adjust accordingly). 225*eda14cbcSMatt Macy */ 226*eda14cbcSMatt Macy uint64_t gcm_ghash[2]; 227*eda14cbcSMatt Macy uint64_t gcm_H[2]; 228*eda14cbcSMatt Macy #ifdef CAN_USE_GCM_ASM 229*eda14cbcSMatt Macy uint64_t gcm_Htable[12][2]; 230*eda14cbcSMatt Macy #endif 231*eda14cbcSMatt Macy uint64_t gcm_J0[2]; 232*eda14cbcSMatt Macy uint64_t gcm_len_a_len_c[2]; 233*eda14cbcSMatt Macy uint8_t *gcm_pt_buf; 234*eda14cbcSMatt Macy int gcm_kmflag; 235*eda14cbcSMatt Macy #ifdef CAN_USE_GCM_ASM 236*eda14cbcSMatt Macy boolean_t gcm_use_avx; 237*eda14cbcSMatt Macy #endif 238*eda14cbcSMatt Macy } gcm_ctx_t; 239*eda14cbcSMatt Macy 240*eda14cbcSMatt Macy #define gcm_keysched gcm_common.cc_keysched 241*eda14cbcSMatt Macy #define gcm_keysched_len gcm_common.cc_keysched_len 242*eda14cbcSMatt Macy #define gcm_cb gcm_common.cc_iv 243*eda14cbcSMatt Macy #define gcm_remainder gcm_common.cc_remainder 244*eda14cbcSMatt Macy #define gcm_remainder_len gcm_common.cc_remainder_len 245*eda14cbcSMatt Macy #define gcm_lastp gcm_common.cc_lastp 246*eda14cbcSMatt Macy #define gcm_copy_to gcm_common.cc_copy_to 247*eda14cbcSMatt Macy #define gcm_flags gcm_common.cc_flags 248*eda14cbcSMatt Macy 249*eda14cbcSMatt Macy #define AES_GMAC_IV_LEN 12 250*eda14cbcSMatt Macy #define AES_GMAC_TAG_BITS 128 251*eda14cbcSMatt Macy 252*eda14cbcSMatt Macy typedef struct aes_ctx { 253*eda14cbcSMatt Macy union { 254*eda14cbcSMatt Macy ecb_ctx_t acu_ecb; 255*eda14cbcSMatt Macy cbc_ctx_t acu_cbc; 256*eda14cbcSMatt Macy ctr_ctx_t acu_ctr; 257*eda14cbcSMatt Macy ccm_ctx_t acu_ccm; 258*eda14cbcSMatt Macy gcm_ctx_t acu_gcm; 259*eda14cbcSMatt Macy } acu; 260*eda14cbcSMatt Macy } aes_ctx_t; 261*eda14cbcSMatt Macy 262*eda14cbcSMatt Macy #define ac_flags acu.acu_ecb.ecb_common.cc_flags 263*eda14cbcSMatt Macy #define ac_remainder_len acu.acu_ecb.ecb_common.cc_remainder_len 264*eda14cbcSMatt Macy #define ac_keysched acu.acu_ecb.ecb_common.cc_keysched 265*eda14cbcSMatt Macy #define ac_keysched_len acu.acu_ecb.ecb_common.cc_keysched_len 266*eda14cbcSMatt Macy #define ac_iv acu.acu_ecb.ecb_common.cc_iv 267*eda14cbcSMatt Macy #define ac_lastp acu.acu_ecb.ecb_common.cc_lastp 268*eda14cbcSMatt Macy #define ac_pt_buf acu.acu_ccm.ccm_pt_buf 269*eda14cbcSMatt Macy #define ac_mac_len acu.acu_ccm.ccm_mac_len 270*eda14cbcSMatt Macy #define ac_data_len acu.acu_ccm.ccm_data_len 271*eda14cbcSMatt Macy #define ac_processed_mac_len acu.acu_ccm.ccm_processed_mac_len 272*eda14cbcSMatt Macy #define ac_processed_data_len acu.acu_ccm.ccm_processed_data_len 273*eda14cbcSMatt Macy #define ac_tag_len acu.acu_gcm.gcm_tag_len 274*eda14cbcSMatt Macy 275*eda14cbcSMatt Macy typedef struct blowfish_ctx { 276*eda14cbcSMatt Macy union { 277*eda14cbcSMatt Macy ecb_ctx_t bcu_ecb; 278*eda14cbcSMatt Macy cbc_ctx_t bcu_cbc; 279*eda14cbcSMatt Macy } bcu; 280*eda14cbcSMatt Macy } blowfish_ctx_t; 281*eda14cbcSMatt Macy 282*eda14cbcSMatt Macy #define bc_flags bcu.bcu_ecb.ecb_common.cc_flags 283*eda14cbcSMatt Macy #define bc_remainder_len bcu.bcu_ecb.ecb_common.cc_remainder_len 284*eda14cbcSMatt Macy #define bc_keysched bcu.bcu_ecb.ecb_common.cc_keysched 285*eda14cbcSMatt Macy #define bc_keysched_len bcu.bcu_ecb.ecb_common.cc_keysched_len 286*eda14cbcSMatt Macy #define bc_iv bcu.bcu_ecb.ecb_common.cc_iv 287*eda14cbcSMatt Macy #define bc_lastp bcu.bcu_ecb.ecb_common.cc_lastp 288*eda14cbcSMatt Macy 289*eda14cbcSMatt Macy typedef struct des_ctx { 290*eda14cbcSMatt Macy union { 291*eda14cbcSMatt Macy ecb_ctx_t dcu_ecb; 292*eda14cbcSMatt Macy cbc_ctx_t dcu_cbc; 293*eda14cbcSMatt Macy } dcu; 294*eda14cbcSMatt Macy } des_ctx_t; 295*eda14cbcSMatt Macy 296*eda14cbcSMatt Macy #define dc_flags dcu.dcu_ecb.ecb_common.cc_flags 297*eda14cbcSMatt Macy #define dc_remainder_len dcu.dcu_ecb.ecb_common.cc_remainder_len 298*eda14cbcSMatt Macy #define dc_keysched dcu.dcu_ecb.ecb_common.cc_keysched 299*eda14cbcSMatt Macy #define dc_keysched_len dcu.dcu_ecb.ecb_common.cc_keysched_len 300*eda14cbcSMatt Macy #define dc_iv dcu.dcu_ecb.ecb_common.cc_iv 301*eda14cbcSMatt Macy #define dc_lastp dcu.dcu_ecb.ecb_common.cc_lastp 302*eda14cbcSMatt Macy 303*eda14cbcSMatt Macy extern int ecb_cipher_contiguous_blocks(ecb_ctx_t *, char *, size_t, 304*eda14cbcSMatt Macy crypto_data_t *, size_t, int (*cipher)(const void *, const uint8_t *, 305*eda14cbcSMatt Macy uint8_t *)); 306*eda14cbcSMatt Macy 307*eda14cbcSMatt Macy extern int cbc_encrypt_contiguous_blocks(cbc_ctx_t *, char *, size_t, 308*eda14cbcSMatt Macy crypto_data_t *, size_t, 309*eda14cbcSMatt Macy int (*encrypt)(const void *, const uint8_t *, uint8_t *), 310*eda14cbcSMatt Macy void (*copy_block)(uint8_t *, uint8_t *), 311*eda14cbcSMatt Macy void (*xor_block)(uint8_t *, uint8_t *)); 312*eda14cbcSMatt Macy 313*eda14cbcSMatt Macy extern int cbc_decrypt_contiguous_blocks(cbc_ctx_t *, char *, size_t, 314*eda14cbcSMatt Macy crypto_data_t *, size_t, 315*eda14cbcSMatt Macy int (*decrypt)(const void *, const uint8_t *, uint8_t *), 316*eda14cbcSMatt Macy void (*copy_block)(uint8_t *, uint8_t *), 317*eda14cbcSMatt Macy void (*xor_block)(uint8_t *, uint8_t *)); 318*eda14cbcSMatt Macy 319*eda14cbcSMatt Macy extern int ctr_mode_contiguous_blocks(ctr_ctx_t *, char *, size_t, 320*eda14cbcSMatt Macy crypto_data_t *, size_t, 321*eda14cbcSMatt Macy int (*cipher)(const void *, const uint8_t *, uint8_t *), 322*eda14cbcSMatt Macy void (*xor_block)(uint8_t *, uint8_t *)); 323*eda14cbcSMatt Macy 324*eda14cbcSMatt Macy extern int ccm_mode_encrypt_contiguous_blocks(ccm_ctx_t *, char *, size_t, 325*eda14cbcSMatt Macy crypto_data_t *, size_t, 326*eda14cbcSMatt Macy int (*encrypt_block)(const void *, const uint8_t *, uint8_t *), 327*eda14cbcSMatt Macy void (*copy_block)(uint8_t *, uint8_t *), 328*eda14cbcSMatt Macy void (*xor_block)(uint8_t *, uint8_t *)); 329*eda14cbcSMatt Macy 330*eda14cbcSMatt Macy extern int ccm_mode_decrypt_contiguous_blocks(ccm_ctx_t *, char *, size_t, 331*eda14cbcSMatt Macy crypto_data_t *, size_t, 332*eda14cbcSMatt Macy int (*encrypt_block)(const void *, const uint8_t *, uint8_t *), 333*eda14cbcSMatt Macy void (*copy_block)(uint8_t *, uint8_t *), 334*eda14cbcSMatt Macy void (*xor_block)(uint8_t *, uint8_t *)); 335*eda14cbcSMatt Macy 336*eda14cbcSMatt Macy extern int gcm_mode_encrypt_contiguous_blocks(gcm_ctx_t *, char *, size_t, 337*eda14cbcSMatt Macy crypto_data_t *, size_t, 338*eda14cbcSMatt Macy int (*encrypt_block)(const void *, const uint8_t *, uint8_t *), 339*eda14cbcSMatt Macy void (*copy_block)(uint8_t *, uint8_t *), 340*eda14cbcSMatt Macy void (*xor_block)(uint8_t *, uint8_t *)); 341*eda14cbcSMatt Macy 342*eda14cbcSMatt Macy extern int gcm_mode_decrypt_contiguous_blocks(gcm_ctx_t *, char *, size_t, 343*eda14cbcSMatt Macy crypto_data_t *, size_t, 344*eda14cbcSMatt Macy int (*encrypt_block)(const void *, const uint8_t *, uint8_t *), 345*eda14cbcSMatt Macy void (*copy_block)(uint8_t *, uint8_t *), 346*eda14cbcSMatt Macy void (*xor_block)(uint8_t *, uint8_t *)); 347*eda14cbcSMatt Macy 348*eda14cbcSMatt Macy int ccm_encrypt_final(ccm_ctx_t *, crypto_data_t *, size_t, 349*eda14cbcSMatt Macy int (*encrypt_block)(const void *, const uint8_t *, uint8_t *), 350*eda14cbcSMatt Macy void (*xor_block)(uint8_t *, uint8_t *)); 351*eda14cbcSMatt Macy 352*eda14cbcSMatt Macy int gcm_encrypt_final(gcm_ctx_t *, crypto_data_t *, size_t, 353*eda14cbcSMatt Macy int (*encrypt_block)(const void *, const uint8_t *, uint8_t *), 354*eda14cbcSMatt Macy void (*copy_block)(uint8_t *, uint8_t *), 355*eda14cbcSMatt Macy void (*xor_block)(uint8_t *, uint8_t *)); 356*eda14cbcSMatt Macy 357*eda14cbcSMatt Macy extern int ccm_decrypt_final(ccm_ctx_t *, crypto_data_t *, size_t, 358*eda14cbcSMatt Macy int (*encrypt_block)(const void *, const uint8_t *, uint8_t *), 359*eda14cbcSMatt Macy void (*copy_block)(uint8_t *, uint8_t *), 360*eda14cbcSMatt Macy void (*xor_block)(uint8_t *, uint8_t *)); 361*eda14cbcSMatt Macy 362*eda14cbcSMatt Macy extern int gcm_decrypt_final(gcm_ctx_t *, crypto_data_t *, size_t, 363*eda14cbcSMatt Macy int (*encrypt_block)(const void *, const uint8_t *, uint8_t *), 364*eda14cbcSMatt Macy void (*xor_block)(uint8_t *, uint8_t *)); 365*eda14cbcSMatt Macy 366*eda14cbcSMatt Macy extern int ctr_mode_final(ctr_ctx_t *, crypto_data_t *, 367*eda14cbcSMatt Macy int (*encrypt_block)(const void *, const uint8_t *, uint8_t *)); 368*eda14cbcSMatt Macy 369*eda14cbcSMatt Macy extern int cbc_init_ctx(cbc_ctx_t *, char *, size_t, size_t, 370*eda14cbcSMatt Macy void (*copy_block)(uint8_t *, uint64_t *)); 371*eda14cbcSMatt Macy 372*eda14cbcSMatt Macy extern int ctr_init_ctx(ctr_ctx_t *, ulong_t, uint8_t *, 373*eda14cbcSMatt Macy void (*copy_block)(uint8_t *, uint8_t *)); 374*eda14cbcSMatt Macy 375*eda14cbcSMatt Macy extern int ccm_init_ctx(ccm_ctx_t *, char *, int, boolean_t, size_t, 376*eda14cbcSMatt Macy int (*encrypt_block)(const void *, const uint8_t *, uint8_t *), 377*eda14cbcSMatt Macy void (*xor_block)(uint8_t *, uint8_t *)); 378*eda14cbcSMatt Macy 379*eda14cbcSMatt Macy extern int gcm_init_ctx(gcm_ctx_t *, char *, size_t, 380*eda14cbcSMatt Macy int (*encrypt_block)(const void *, const uint8_t *, uint8_t *), 381*eda14cbcSMatt Macy void (*copy_block)(uint8_t *, uint8_t *), 382*eda14cbcSMatt Macy void (*xor_block)(uint8_t *, uint8_t *)); 383*eda14cbcSMatt Macy 384*eda14cbcSMatt Macy extern int gmac_init_ctx(gcm_ctx_t *, char *, size_t, 385*eda14cbcSMatt Macy int (*encrypt_block)(const void *, const uint8_t *, uint8_t *), 386*eda14cbcSMatt Macy void (*copy_block)(uint8_t *, uint8_t *), 387*eda14cbcSMatt Macy void (*xor_block)(uint8_t *, uint8_t *)); 388*eda14cbcSMatt Macy 389*eda14cbcSMatt Macy extern void calculate_ccm_mac(ccm_ctx_t *, uint8_t *, 390*eda14cbcSMatt Macy int (*encrypt_block)(const void *, const uint8_t *, uint8_t *)); 391*eda14cbcSMatt Macy 392*eda14cbcSMatt Macy extern void gcm_mul(uint64_t *, uint64_t *, uint64_t *); 393*eda14cbcSMatt Macy 394*eda14cbcSMatt Macy extern void crypto_init_ptrs(crypto_data_t *, void **, offset_t *); 395*eda14cbcSMatt Macy extern void crypto_get_ptrs(crypto_data_t *, void **, offset_t *, 396*eda14cbcSMatt Macy uint8_t **, size_t *, uint8_t **, size_t); 397*eda14cbcSMatt Macy 398*eda14cbcSMatt Macy extern void *ecb_alloc_ctx(int); 399*eda14cbcSMatt Macy extern void *cbc_alloc_ctx(int); 400*eda14cbcSMatt Macy extern void *ctr_alloc_ctx(int); 401*eda14cbcSMatt Macy extern void *ccm_alloc_ctx(int); 402*eda14cbcSMatt Macy extern void *gcm_alloc_ctx(int); 403*eda14cbcSMatt Macy extern void *gmac_alloc_ctx(int); 404*eda14cbcSMatt Macy extern void crypto_free_mode_ctx(void *); 405*eda14cbcSMatt Macy extern void gcm_set_kmflag(gcm_ctx_t *, int); 406*eda14cbcSMatt Macy 407*eda14cbcSMatt Macy #ifdef __cplusplus 408*eda14cbcSMatt Macy } 409*eda14cbcSMatt Macy #endif 410*eda14cbcSMatt Macy 411*eda14cbcSMatt Macy #endif /* _COMMON_CRYPTO_MODES_H */ 412