10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 52439Sizick * Common Development and Distribution License (the "License"). 62439Sizick * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 2210444SVladimir.Kotal@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _DES_IMPL_H 270Sstevel@tonic-gate #define _DES_IMPL_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate /* 300Sstevel@tonic-gate * Common definitions used by DES 310Sstevel@tonic-gate */ 320Sstevel@tonic-gate 330Sstevel@tonic-gate #ifdef __cplusplus 340Sstevel@tonic-gate extern "C" { 350Sstevel@tonic-gate #endif 360Sstevel@tonic-gate 370Sstevel@tonic-gate #define DES_BLOCK_LEN 8 380Sstevel@tonic-gate 397188Smcpowers #define DES_COPY_BLOCK(src, dst) \ 407188Smcpowers (dst)[0] = (src)[0]; \ 417188Smcpowers (dst)[1] = (src)[1]; \ 427188Smcpowers (dst)[2] = (src)[2]; \ 437188Smcpowers (dst)[3] = (src)[3]; \ 447188Smcpowers (dst)[4] = (src)[4]; \ 457188Smcpowers (dst)[5] = (src)[5]; \ 467188Smcpowers (dst)[6] = (src)[6]; \ 477188Smcpowers (dst)[7] = (src)[7]; 487188Smcpowers 490Sstevel@tonic-gate #define DES_XOR_BLOCK(src, dst) \ 500Sstevel@tonic-gate (dst)[0] ^= (src)[0]; \ 510Sstevel@tonic-gate (dst)[1] ^= (src)[1]; \ 520Sstevel@tonic-gate (dst)[2] ^= (src)[2]; \ 530Sstevel@tonic-gate (dst)[3] ^= (src)[3]; \ 540Sstevel@tonic-gate (dst)[4] ^= (src)[4]; \ 550Sstevel@tonic-gate (dst)[5] ^= (src)[5]; \ 560Sstevel@tonic-gate (dst)[6] ^= (src)[6]; \ 570Sstevel@tonic-gate (dst)[7] ^= (src)[7] 580Sstevel@tonic-gate 590Sstevel@tonic-gate typedef enum des_strength { 600Sstevel@tonic-gate DES = 1, 610Sstevel@tonic-gate DES2, 620Sstevel@tonic-gate DES3 630Sstevel@tonic-gate } des_strength_t; 640Sstevel@tonic-gate 657188Smcpowers #define DES3_STRENGTH 0x08000000 667188Smcpowers 670Sstevel@tonic-gate #define DES_KEYSIZE 8 680Sstevel@tonic-gate #define DES_MINBITS 64 690Sstevel@tonic-gate #define DES_MAXBITS 64 700Sstevel@tonic-gate #define DES_MINBYTES (DES_MINBITS / 8) 710Sstevel@tonic-gate #define DES_MAXBYTES (DES_MAXBITS / 8) 720Sstevel@tonic-gate #define DES_IV_LEN 8 730Sstevel@tonic-gate 740Sstevel@tonic-gate #define DES2_KEYSIZE (2 * DES_KEYSIZE) 750Sstevel@tonic-gate #define DES2_MINBITS (2 * DES_MINBITS) 760Sstevel@tonic-gate #define DES2_MAXBITS (2 * DES_MAXBITS) 7710444SVladimir.Kotal@Sun.COM #define DES2_MINBYTES (DES2_MINBITS / 8) 7810444SVladimir.Kotal@Sun.COM #define DES2_MAXBYTES (DES2_MAXBITS / 8) 790Sstevel@tonic-gate 800Sstevel@tonic-gate #define DES3_KEYSIZE (3 * DES_KEYSIZE) 8110444SVladimir.Kotal@Sun.COM #define DES3_MINBITS (2 * DES_MINBITS) /* DES3 handles CKK_DES2 keys */ 820Sstevel@tonic-gate #define DES3_MAXBITS (3 * DES_MAXBITS) 830Sstevel@tonic-gate #define DES3_MINBYTES (DES3_MINBITS / 8) 840Sstevel@tonic-gate #define DES3_MAXBYTES (DES3_MAXBITS / 8) 850Sstevel@tonic-gate 867188Smcpowers extern int des_encrypt_contiguous_blocks(void *, char *, size_t, 877188Smcpowers crypto_data_t *); 887188Smcpowers extern int des_decrypt_contiguous_blocks(void *, char *, size_t, 897188Smcpowers crypto_data_t *); 900Sstevel@tonic-gate extern uint64_t des_crypt_impl(uint64_t *, uint64_t, int); 910Sstevel@tonic-gate extern void des_ks(uint64_t *, uint64_t); 927188Smcpowers extern int des_crunch_block(const void *, const uint8_t *, uint8_t *, 937188Smcpowers boolean_t); 947188Smcpowers extern int des3_crunch_block(const void *, const uint8_t *, uint8_t *, 957188Smcpowers boolean_t); 960Sstevel@tonic-gate extern void des_init_keysched(uint8_t *, des_strength_t, void *); 970Sstevel@tonic-gate extern void *des_alloc_keysched(size_t *, des_strength_t, int); 980Sstevel@tonic-gate extern boolean_t des_keycheck(uint8_t *, des_strength_t, uint8_t *); 992439Sizick extern void des_parity_fix(uint8_t *, des_strength_t, uint8_t *); 1007188Smcpowers extern void des_copy_block(uint8_t *, uint8_t *); 1017188Smcpowers extern void des_xor_block(uint8_t *, uint8_t *); 1027188Smcpowers extern int des_encrypt_block(const void *, const uint8_t *, uint8_t *); 1037188Smcpowers extern int des3_encrypt_block(const void *, const uint8_t *, uint8_t *); 1047188Smcpowers extern int des_decrypt_block(const void *, const uint8_t *, uint8_t *); 1057188Smcpowers extern int des3_decrypt_block(const void *, const uint8_t *, uint8_t *); 1060Sstevel@tonic-gate 107*10500SHai-May.Chao@Sun.COM /* 108*10500SHai-May.Chao@Sun.COM * The following definitions and declarations are only used by DES FIPS POST 109*10500SHai-May.Chao@Sun.COM */ 110*10500SHai-May.Chao@Sun.COM #ifdef _DES_FIPS_POST 111*10500SHai-May.Chao@Sun.COM 112*10500SHai-May.Chao@Sun.COM #include <modes/modes.h> 113*10500SHai-May.Chao@Sun.COM #include <fips/fips_post.h> 114*10500SHai-May.Chao@Sun.COM 115*10500SHai-May.Chao@Sun.COM /* DES FIPS Declarations */ 116*10500SHai-May.Chao@Sun.COM #define FIPS_DES_ENCRYPT_LENGTH 8 /* 64-bits */ 117*10500SHai-May.Chao@Sun.COM #define FIPS_DES_DECRYPT_LENGTH 8 /* 64-bits */ 118*10500SHai-May.Chao@Sun.COM #define FIPS_DES3_ENCRYPT_LENGTH 8 /* 64-bits */ 119*10500SHai-May.Chao@Sun.COM #define FIPS_DES3_DECRYPT_LENGTH 8 /* 64-bits */ 120*10500SHai-May.Chao@Sun.COM 121*10500SHai-May.Chao@Sun.COM #ifdef _KERNEL 122*10500SHai-May.Chao@Sun.COM typedef enum des_mech_type { 123*10500SHai-May.Chao@Sun.COM DES_ECB_MECH_INFO_TYPE, /* SUN_CKM_DES_ECB */ 124*10500SHai-May.Chao@Sun.COM DES_CBC_MECH_INFO_TYPE, /* SUN_CKM_DES_CBC */ 125*10500SHai-May.Chao@Sun.COM DES_CFB_MECH_INFO_TYPE, /* SUN_CKM_DES_CFB */ 126*10500SHai-May.Chao@Sun.COM DES3_ECB_MECH_INFO_TYPE, /* SUN_CKM_DES3_ECB */ 127*10500SHai-May.Chao@Sun.COM DES3_CBC_MECH_INFO_TYPE, /* SUN_CKM_DES3_CBC */ 128*10500SHai-May.Chao@Sun.COM DES3_CFB_MECH_INFO_TYPE /* SUN_CKM_DES3_CFB */ 129*10500SHai-May.Chao@Sun.COM } des_mech_type_t; 130*10500SHai-May.Chao@Sun.COM 131*10500SHai-May.Chao@Sun.COM 132*10500SHai-May.Chao@Sun.COM #undef CKM_DES_ECB 133*10500SHai-May.Chao@Sun.COM #undef CKM_DES3_ECB 134*10500SHai-May.Chao@Sun.COM #undef CKM_DES_CBC 135*10500SHai-May.Chao@Sun.COM #undef CKM_DES3_CBC 136*10500SHai-May.Chao@Sun.COM 137*10500SHai-May.Chao@Sun.COM #define CKM_DES_ECB DES_ECB_MECH_INFO_TYPE 138*10500SHai-May.Chao@Sun.COM #define CKM_DES3_ECB DES3_ECB_MECH_INFO_TYPE 139*10500SHai-May.Chao@Sun.COM #define CKM_DES_CBC DES_CBC_MECH_INFO_TYPE 140*10500SHai-May.Chao@Sun.COM #define CKM_DES3_CBC DES3_CBC_MECH_INFO_TYPE 141*10500SHai-May.Chao@Sun.COM #endif 142*10500SHai-May.Chao@Sun.COM 143*10500SHai-May.Chao@Sun.COM /* DES3 FIPS functions */ 144*10500SHai-May.Chao@Sun.COM extern int fips_des3_post(void); 145*10500SHai-May.Chao@Sun.COM 146*10500SHai-May.Chao@Sun.COM #ifndef _KERNEL 147*10500SHai-May.Chao@Sun.COM #ifdef _DES_IMPL 148*10500SHai-May.Chao@Sun.COM struct soft_des_ctx; 149*10500SHai-May.Chao@Sun.COM extern struct soft_des_ctx *des_build_context(uint8_t *, uint8_t *, 150*10500SHai-May.Chao@Sun.COM CK_KEY_TYPE, CK_MECHANISM_TYPE); 151*10500SHai-May.Chao@Sun.COM extern void fips_des_free_context(struct soft_des_ctx *); 152*10500SHai-May.Chao@Sun.COM extern CK_RV fips_des_encrypt(struct soft_des_ctx *, CK_BYTE_PTR, 153*10500SHai-May.Chao@Sun.COM CK_ULONG, CK_BYTE_PTR, CK_ULONG_PTR, CK_MECHANISM_TYPE); 154*10500SHai-May.Chao@Sun.COM extern CK_RV fips_des_decrypt(struct soft_des_ctx *, CK_BYTE_PTR, 155*10500SHai-May.Chao@Sun.COM CK_ULONG, CK_BYTE_PTR, CK_ULONG_PTR, CK_MECHANISM_TYPE); 156*10500SHai-May.Chao@Sun.COM #endif /* _DES_IMPL */ 157*10500SHai-May.Chao@Sun.COM #else 158*10500SHai-May.Chao@Sun.COM extern des_ctx_t *des_build_context(uint8_t *, uint8_t *, 159*10500SHai-May.Chao@Sun.COM des_mech_type_t); 160*10500SHai-May.Chao@Sun.COM extern void fips_des_free_context(des_ctx_t *); 161*10500SHai-May.Chao@Sun.COM extern int fips_des_encrypt(des_ctx_t *, uint8_t *, 162*10500SHai-May.Chao@Sun.COM ulong_t, uint8_t *, ulong_t *, des_mech_type_t); 163*10500SHai-May.Chao@Sun.COM extern int fips_des_decrypt(des_ctx_t *, uint8_t *, 164*10500SHai-May.Chao@Sun.COM ulong_t, uint8_t *, ulong_t *, des_mech_type_t); 165*10500SHai-May.Chao@Sun.COM #endif /* _KERNEL */ 166*10500SHai-May.Chao@Sun.COM #endif /* _DES_FIPS_POST */ 167*10500SHai-May.Chao@Sun.COM 1680Sstevel@tonic-gate #ifdef __cplusplus 1690Sstevel@tonic-gate } 1700Sstevel@tonic-gate #endif 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate #endif /* _DES_IMPL_H */ 173