]>
git.saurik.com Git - apple/security.git/blob - SecurityTests/cspxutils/aesVect/aesVect.c
2 * aesVect.c - generate NIST-compatible test vectors for various AES implementations.
4 * Written by Doug Mitchell.
10 #include "enDecrypt.h"
11 #include "rijndael-alg-ref.h"
14 static void usage(char **argv
)
16 printf("usage: %s r|t|c vectorStyle [options]\n", argv
[0]);
17 printf("r=reference t=testImple c=CSP\n");
18 printf("vectorStyle:\n");
19 printf(" k Variable key KAT\n");
20 printf(" p Variable plaintext KAT\n");
22 printf(" k=keySizeInBits (default = 128)\n");
23 printf(" i=max value of i (default = max per context)\n");
38 whichBit
= 7 - (i
% 8);
39 memset(val
, 0, valBytes
);
40 val
[whichByte
] = 1 << whichBit
;
43 static void printBigNum(
50 for(i
=0; i
<valBytes
; i
++) {
51 unsigned iNum
= val
[i
] & 0xff;
57 static void varKeyKAT(
58 encrDecrFcn encrDecr
, // encryptDecryptRef, encryptDecryptTest
59 unsigned keySizeInBits
,
63 unsigned char key
[MAX_AES_KEY_BYTES
];
64 unsigned char ptext
[MIN_AES_BLOCK_BYTES
];
65 unsigned char ctext
[MIN_AES_BLOCK_BYTES
];
66 unsigned keyBytes
= keySizeInBits
/ 8;
68 memset(ptext
, 0, MIN_AES_BLOCK_BYTES
);
73 printf("KEYSIZE=%d\n\n", keySizeInBits
);
74 printf("PT=00000000000000000000000000000000\n\n");
76 for(i
=1; i
<=maxI
; i
++) {
77 setBit(key
, keyBytes
, i
);
86 printBigNum("KEY", key
, keyBytes
);
87 printBigNum("CT", ctext
, MIN_AES_BLOCK_BYTES
);
92 static void varPtextKAT(
93 encrDecrFcn encrDecr
, // encryptDecryptRef, encryptDecryptTest
94 unsigned keySizeInBits
,
98 unsigned char key
[MAX_AES_KEY_BYTES
];
99 unsigned char ptext
[MIN_AES_BLOCK_BYTES
];
100 unsigned char ctext
[MIN_AES_BLOCK_BYTES
];
101 unsigned keyBytes
= keySizeInBits
/ 8;
103 memset(key
, 0, MAX_AES_KEY_BYTES
);
105 maxI
= MIN_AES_BLOCK_BITS
;
108 printf("KEYSIZE=%d\n\n", keySizeInBits
);
109 printBigNum("KEY", key
, keyBytes
);
112 for(i
=1; i
<=maxI
; i
++) {
113 setBit(ptext
, MIN_AES_BLOCK_BYTES
, i
);
122 printBigNum("PT", ptext
, MIN_AES_BLOCK_BYTES
);
123 printBigNum("CT", ctext
, MIN_AES_BLOCK_BYTES
);
128 int main(int argc
, char **argv
)
133 unsigned keySizeInBits
= MIN_AES_KEY_BITS
;
135 encrDecrFcn encrDecr
;
142 encrDecr
= encryptDecryptRef
;
145 encrDecr
= encryptDecryptTest
;
148 encrDecr
= encryptDecryptCsp
;
153 for(arg
=3; arg
<argc
; arg
++) {
157 keySizeInBits
= atoi(&argp
[2]);
160 maxI
= atoi(&argp
[2]);
169 varKeyKAT(encrDecr
, keySizeInBits
, maxI
);
172 varPtextKAT(encrDecr
, keySizeInBits
, maxI
);