1/* 2 * Copyright (c) 2011 Apple Computer, Inc. All Rights Reserved. 3 * 4 * @APPLE_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. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24 25#ifndef _CC_CMACSPI_H_ 26#define _CC_CMACSPI_H_ 27 28#include <Availability.h> 29#include <stdint.h> 30#include <sys/types.h> 31 32#ifdef __cplusplus 33extern "C" { 34#endif 35 36#define CC_CMACAES_DIGEST_LENGTH 16 /* CMAC length in bytes - copy and paste error - */ 37 38#define CC_CMACAES_OUTPUT_LENGTH 16 /* CMAC length in bytes */ 39 40/*! 41@function CCAESCmac 42@abstract Stateless, one-shot AES CMAC function 43 44@param key Raw key bytes. 45@param data The data to process. 46@param dataLength The length of the data to process. 47@param macOut The MAC bytes (space provided by the caller). 48 49Output is written to caller-supplied buffer. 50*/ 51 52void 53CCAESCmac(const void *key, const uint8_t *data, size_t dataLength, void *macOut) 54__OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_6_0); 55 56 57typedef struct CCCmacContext * CCCmacContextPtr; 58 59 60/*! 61 @function CCAESCmacCreate 62 @abstract Create a CMac context. 63 64 @param key The bytes of the AES key. 65 @param keyLength The length (in bytes) of the AES key. 66 67 @discussion This returns an AES-CMac context to be used with 68 CCAESCmacUpdate(), CCAESCmacFinal() and CCAESCmacDestroy(). 69 */ 70 71CCCmacContextPtr 72CCAESCmacCreate(const void *key, size_t keyLength) 73__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0); 74 75/*! 76 @function CCAESCmacUpdate 77 @abstract Process some data. 78 79 @param ctx An HMAC context. 80 @param data Data to process. 81 @param dataLength Length of data to process, in bytes. 82 83 @discussion This can be called multiple times. 84 */ 85 86void CCAESCmacUpdate(CCCmacContextPtr ctx, const void *data, size_t dataLength) 87__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0); 88 89 90/*! 91 @function CCAESCmacFinal 92 @abstract Obtain the final Message Authentication Code. 93 94 @param ctx A CMAC context. 95 @param macOut Destination of MAC; allocated by caller. 96 97 @discussion The length of the MAC written to *macOut is 16 98*/ 99 100void CCAESCmacFinal(CCCmacContextPtr ctx, void *macOut) 101__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0); 102 103void 104CCAESCmacDestroy(CCCmacContextPtr ctx) 105__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0); 106 107size_t 108CCAESCmacOutputSizeFromContext(CCCmacContextPtr ctx) 109__OSX_AVAILABLE_STARTING(__MAC_10_10, __IPHONE_8_0); 110 111 112#ifdef __cplusplus 113} 114#endif 115 116#endif /* _CC_CMACSPI_H_ */ 117