]> git.saurik.com Git - apple/security.git/blob - SecurityTests/cspxutils/ccCtxSize/ccCtxSize.c
Security-57031.1.35.tar.gz
[apple/security.git] / SecurityTests / cspxutils / ccCtxSize / ccCtxSize.c
1 /*
2 * measure and report min context sizes for all CCCryptor ops and algorithms.
3 */
4
5 #include <string.h>
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <CommonCrypto/CommonCryptor.h>
9 #include <CoreServices/../Frameworks/CarbonCore.framework/Headers/MacErrors.h>
10
11 static void report(
12 const char *name,
13 CCOperation op,
14 CCAlgorithm alg,
15 size_t definedSize)
16 {
17 char key[4];
18 size_t cryptorLength = 0;
19 CCCryptorStatus crtn;
20 CCCryptorRef cryptorRef;
21 char buf[1];
22
23 crtn = CCCryptorCreateFromData(op, alg, 0, key, 4, NULL,
24 buf, 1, &cryptorRef, &cryptorLength);
25 switch(crtn) {
26 case kCCSuccess:
27 printf("***Unuexpected success on CCCryptorCreate()\n");
28 return;
29 case kCCBufferTooSmall:
30 break;
31 default:
32 printf("***Unexpected result on CCCryptorCreate: expect %d got %d\n",
33 (int)kCCBufferTooSmall, (int)crtn);
34 return;
35 }
36 printf("%s : %lu bytes\n", name, (unsigned long)cryptorLength);
37 if(definedSize < cryptorLength) {
38 printf("***Defined context size (%u) is less than reported!\n",
39 (unsigned)definedSize);
40 }
41 }
42
43 int main(int argc, char **argv)
44 {
45 report("kCCAlgorithmAES128 ", kCCEncrypt, kCCAlgorithmAES128, kCCContextSizeAES128);
46 report("kCCAlgorithmDES ", kCCEncrypt, kCCAlgorithmDES, kCCContextSizeDES);
47 report("kCCAlgorithm3DES ", kCCEncrypt, kCCAlgorithm3DES, kCCContextSize3DES);
48 report("kCCAlgorithmCAST ", kCCEncrypt, kCCAlgorithmCAST, kCCContextSizeCAST);
49 report("kCCAlgorithmRC4 ", kCCEncrypt, kCCAlgorithmRC4, kCCContextSizeRC4);
50 return 0;
51 }
52
53 /*
54
55 sizeof(CCCryptor) = 24 including the spiCtx[] array
56 sizeof(struct _CCCryptContext) = 60 including algCtx[]
57 sizeof(DES_key_schedule) = 128
58 sizeof(DES3_Schedule) = 384
59 sizeof(GAesKey) = 516
60 sizeof(_ccHmacContext) = 180
61
62 */