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 /* 22*10444SVladimir.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) 77*10444SVladimir.Kotal@Sun.COM #define DES2_MINBYTES (DES2_MINBITS / 8) 78*10444SVladimir.Kotal@Sun.COM #define DES2_MAXBYTES (DES2_MAXBITS / 8) 790Sstevel@tonic-gate 800Sstevel@tonic-gate #define DES3_KEYSIZE (3 * DES_KEYSIZE) 81*10444SVladimir.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 1070Sstevel@tonic-gate #ifdef __cplusplus 1080Sstevel@tonic-gate } 1090Sstevel@tonic-gate #endif 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate #endif /* _DES_IMPL_H */ 112