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#include <stdio.h> 25#include "CCCryptorTestFuncs.h" 26#include "testbyteBuffer.h" 27#include "testmore.h" 28#include "capabilities.h" 29 30#if (CCSYMOFB == 0) 31entryPoint(CommonCryptoSymOFB,"CommonCrypto Symmetric OFB Testing") 32#else 33static int kTestTestCount = 5; 34 35int CommonCryptoSymOFB(int argc, char *const *argv) 36{ 37 char *keyStr; 38 char *iv; 39 char *plainText; 40 char *cipherText; 41 CCMode mode; 42 CCAlgorithm alg; 43 CCPadding padding; 44 int retval, accum = 0; 45 46 keyStr = "000102030405060708090a0b0c0d0e0f"; 47 iv = "0f0e0d0c0b0a09080706050403020100"; 48 mode = kCCModeOFB; 49 alg = kCCAlgorithmAES128; 50 padding = ccNoPadding; 51 52 plan_tests(kTestTestCount); 53 54 // 1 55 plainText = "0a"; 56 cipherText = "2a"; 57 retval = CCModeTestCase(keyStr, iv, mode, alg, padding, cipherText, plainText); 58 ok(retval == 0, "OFB Mode single byte"); 59 accum += retval; 60 61 // 15 62 plainText = "0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a"; 63 cipherText = "2aa3f398be4651e20e15f6d666a493a"; 64 retval = CCModeTestCase(keyStr, iv, mode, alg, padding, cipherText, plainText); 65 ok(retval == 0, "OFB Mode 15 byte"); 66 accum += retval; 67 68 // 16 69 plainText = "0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a0a"; 70 cipherText = "2aa3f398be4651e20e15f6d666a49360a"; 71 retval = CCModeTestCase(keyStr, iv, mode, alg, padding, cipherText, plainText); 72 ok(retval == 0, "OFB Mode single byte"); 73 accum += retval; 74 75 // from OFBVarTxt256e KAT test 1 76 keyStr = "0000000000000000000000000000000000000000000000000000000000000000"; 77 iv = "80000000000000000000000000000000"; 78 mode = kCCModeOFB; 79 alg = kCCAlgorithmAES128; 80 padding = ccNoPadding; 81 plainText = "00000000000000000000000000000000"; 82 cipherText = "ddc6bf790c15760d8d9aeb6f9a75fd4e"; 83 retval = CCModeTestCase(keyStr, iv, mode, alg, padding, cipherText, plainText); 84 ok(retval == 0, "OFB Mode OFBVarTxt256e KAT test 1"); 85 accum += retval; 86 87 // from OFBVarTxt256e KAT test 13 88 keyStr = "0000000000000000000000000000000000000000000000000000000000000000"; 89 iv = "fffc0000000000000000000000000000"; 90 mode = kCCModeOFB; 91 alg = kCCAlgorithmAES128; 92 padding = ccNoPadding; 93 plainText = "00000000000000000000000000000000"; 94 cipherText = "dc8f0e4915fd81ba70a331310882f6da"; 95 retval = CCModeTestCase(keyStr, iv, mode, alg, padding, cipherText, plainText); 96 ok(retval == 0, "OFB Mode OFBVarTxt256e KAT test 13"); 97 accum += retval; 98 99 return accum != 0; 100} 101#endif 102