#include #include #include "testbyteBuffer.h" #include "testmore.h" #include "capabilities.h" #if (CCSYMOUTPUTLEN == 0) entryPoint(CommonCryptoOutputLength,"CommonCrypto Output Length Testing") #else static int kTestTestCount = 21912; #define MAXSTART 64 #define MAXOUT 4096 static int testOutputLength(CCOperation op, CCMode mode, CCAlgorithm alg, size_t keyLength, CCPadding padding, size_t bufferPos, size_t inputLength, bool final, size_t expectedLen) { CCCryptorRef cryptorRef; size_t retval; CCCryptorStatus status; uint8_t iv[16]; uint8_t key[16]; uint8_t dataIn[MAXSTART], dataOut[MAXOUT]; size_t moved = 0; status = CCCryptorCreateWithMode(op, mode, alg, padding, iv, key, keyLength, NULL, 0, 1, kCCModeOptionCTR_BE, &cryptorRef); ok(status == kCCSuccess, "Created Cryptor"); status = CCCryptorUpdate(cryptorRef, dataIn, bufferPos, dataOut, MAXOUT, &moved); ok(status == kCCSuccess, "Setup Initial Internal Length"); retval = CCCryptorGetOutputLength(cryptorRef, inputLength, final); ok(retval == expectedLen, "Got Length Value Expected"); if(retval != expectedLen) { printf("bufferPos = %lu + inputLength = %lu Got %lu expected %lu\n", bufferPos, inputLength, retval, expectedLen); } status = CCCryptorRelease(cryptorRef); ok(status == kCCSuccess, "Released Cryptor"); return -1; } static inline size_t round_down_by_blocksize(size_t len, size_t blocksize) { return len / blocksize * blocksize; } static inline size_t pkcs7decryptUpdateResultLength_by_blocksize(size_t len, size_t blocksize) { if(len <= blocksize) return 0; if(!(len % blocksize)) return len - blocksize; return round_down_by_blocksize(len, blocksize); } int CommonCryptoOutputLength (int argc, char *const *argv) { int verbose = 0; plan_tests(kTestTestCount); /* ENCRYPTING ****************************************************************************************************************************************/ if(verbose) diag("ENCRYPTING AES-CTR (Streaming Mode) Update"); for(size_t i=0; i<3*kCCBlockSizeAES128; i++) { for(size_t bufferPos=0; bufferPos