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_AESXTS_H 30 #define _CRYPTO_AESXTS_H 31 32 #if defined(__cplusplus) 33 extern "C" 34 { 35 #endif 36 37 #include <corecrypto/ccmode.h> 38 #include <corecrypto/ccaes.h> 39 #include <corecrypto/ccn.h> 40 41 //Unholy HACK: this works because we know the size of the context for every 42 //possible corecrypto implementation is less than this. 43 #define AES_XTS_CTX_MAX_SIZE (ccn_sizeof_size(3*sizeof(void *)) + 2*ccn_sizeof_size(128*4) + ccn_sizeof_size(16)) 44 45 typedef struct { 46 ccxts_ctx_decl(AES_XTS_CTX_MAX_SIZE, enc); 47 ccxts_ctx_decl(AES_XTS_CTX_MAX_SIZE, dec); 48 } symmetric_xts; 49 50 51 /* 52 * These are the interfaces required for XTS-AES support 53 */ 54 55 uint32_t 56 xts_start(uint32_t cipher, // ignored - we're doing this for xts-aes only 57 const uint8_t *IV, // ignored 58 const uint8_t *key1, int keylen, 59 const uint8_t *key2, int tweaklen, // both keys are the same size for xts 60 uint32_t num_rounds, // ignored 61 uint32_t options, // ignored 62 symmetric_xts *xts); 63 64 int xts_encrypt(const uint8_t *pt, unsigned long ptlen, 65 uint8_t *ct, 66 const uint8_t *tweak, // this can be considered the sector IV for this use 67 symmetric_xts *xts); 68 69 int xts_decrypt(const uint8_t *ct, unsigned long ptlen, 70 uint8_t *pt, 71 const uint8_t *tweak, // this can be considered the sector IV for this use 72 symmetric_xts *xts); 73 74 void xts_done(symmetric_xts *xts); 75 76 #if defined(__cplusplus) 77 } 78 #endif 79 80 #endif 81