1 /* 2 * Copyright (c) 2012 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. The rights granted to you under the License 10 * may not be used to create, or enable the creation or redistribution of, 11 * unlawful or unlicensed copies of an Apple operating system, or to 12 * circumvent, violate, or enable the circumvention or violation of, any 13 * terms of an Apple operating system software license agreement. 14 * 15 * Please obtain a copy of the License at 16 * http://www.opensource.apple.com/apsl/ and read it before using this file. 17 * 18 * The Original Code and all software distributed under the License are 19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23 * Please see the License for the specific language governing rights and 24 * limitations under the License. 25 * 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27 */ 28 29 #ifndef _CRYPTO_DES_H 30 #define _CRYPTO_DES_H 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 #include <corecrypto/ccmode.h> 37 #include <corecrypto/ccdes.h> 38 #include <corecrypto/ccn.h> 39 40 /* must be 32bit quantity */ 41 #define DES_LONG u_int32_t 42 43 typedef unsigned char des_cblock[8]; 44 45 /* Unholy hack: this is currently the size for the only implementation of DES in corecrypto */ 46 #define DES_ECB_CTX_MAX_SIZE (64*4) 47 #define DES3_ECB_CTX_MAX_SIZE (64*4*3) 48 49 50 typedef struct{ 51 ccecb_ctx_decl(DES_ECB_CTX_MAX_SIZE, enc); 52 ccecb_ctx_decl(DES_ECB_CTX_MAX_SIZE, dec); 53 } des_ecb_key_schedule; 54 55 typedef struct{ 56 ccecb_ctx_decl(DES3_ECB_CTX_MAX_SIZE, enc); 57 ccecb_ctx_decl(DES3_ECB_CTX_MAX_SIZE, dec); 58 } des3_ecb_key_schedule; 59 60 /* Only here for backward compatibility with smb kext */ 61 typedef des_ecb_key_schedule des_key_schedule[1]; 62 #define des_set_key des_ecb_key_sched 63 64 #define DES_ENCRYPT 1 65 #define DES_DECRYPT 0 66 67 68 /* Single DES ECB - 1 block */ 69 int des_ecb_key_sched(des_cblock *key, des_ecb_key_schedule *ks); 70 int des_ecb_encrypt(des_cblock * in, des_cblock *out, des_ecb_key_schedule *ks, int encrypt); 71 72 /* Triple DES ECB - 1 block */ 73 int des3_ecb_key_sched(des_cblock *key, des3_ecb_key_schedule *ks); 74 int des3_ecb_encrypt(des_cblock *block, des_cblock *, des3_ecb_key_schedule *ks, int encrypt); 75 76 int des_is_weak_key(des_cblock *key); 77 78 #ifdef __cplusplus 79 } 80 #endif 81 82 #endif 83