1/* 2 * Copyright (c) 2010 Apple 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 * CCSymOffset.c 26 * CommonCrypto 27 */ 28 29#include <stdio.h> 30#include <CommonCrypto/CommonCryptor.h> 31#include <CommonCrypto/CommonCryptorSPI.h> 32#include "testbyteBuffer.h" 33#include "testmore.h" 34#include "capabilities.h" 35 36#if (CCSYMOFFSET == 0) 37entryPoint(CommonCryptoSymOffset,"CommonCrypto Symmetric Unaligned Testing") 38#else 39 40 41 42#define ILIKEEMDISBIG 4096 43#define ALITTLEONTHESIDE 5 44 45 46static int kTestTestCount = ALITTLEONTHESIDE * 3; 47 48 49int CommonCryptoSymOffset(int argc, char *const *argv) { 50 int accum = 0; 51 uint8_t iLikeBigBuffs[ILIKEEMDISBIG]; 52 uint8_t andICannotLie[ILIKEEMDISBIG]; 53 uint8_t iLikeEmRoundandBig[ILIKEEMDISBIG]; 54 int i; 55 size_t moved; 56 CCCryptorStatus retval; 57 byteBuffer key = hexStringToBytes("010203040506070809000a0b0c0d0e0f"); 58 59 plan_tests(kTestTestCount); 60 61 62 for(i=0; i<ALITTLEONTHESIDE; i++) { 63 retval = CCCrypt(kCCEncrypt, kCCAlgorithmAES128, 0, key->bytes, key->len, NULL, iLikeBigBuffs+i, ILIKEEMDISBIG-16, andICannotLie+i, ILIKEEMDISBIG, &moved); 64 ok(retval == 0, "Encrypt worked"); 65 retval = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, 0, key->bytes, key->len, NULL, andICannotLie+i, moved, iLikeEmRoundandBig+i, ILIKEEMDISBIG, &moved); 66 ok(retval == 0, "Decrypt worked"); 67 if(moved != (ILIKEEMDISBIG-16)) 68 retval = 99; 69 else if(memcmp(iLikeBigBuffs+i, iLikeEmRoundandBig+i, moved)) 70 retval = 999; 71 ok(retval == 0, "Encrypt/Decrypt Cycle"); 72 accum += retval; 73 } 74 75 return accum != 0; 76} 77#endif 78 79