]>
git.saurik.com Git - apple/security.git/blob - SecurityTests/cspxutils/aesVect/std_defs.h
4 /* 1. Standard types for AES cryptography source code */
6 typedef unsigned char u1byte
; /* an 8 bit unsigned character type */
7 typedef unsigned short u2byte
; /* a 16 bit unsigned integer type */
8 typedef unsigned long u4byte
; /* a 32 bit unsigned integer type */
10 typedef signed char s1byte
; /* an 8 bit signed character type */
11 typedef signed short s2byte
; /* a 16 bit signed integer type */
12 typedef signed long s4byte
; /* a 32 bit signed integer type */
14 /* 2. Standard interface for AES cryptographic routines */
16 /* These are all based on 32 bit unsigned values and will therefore */
17 /* require endian conversions for big-endian architectures */
24 char **cipher_name(void);
25 u4byte
*set_key(const u4byte in_key
[], const u4byte key_len
);
26 void rEncrypt(const u4byte in_blk
[4], u4byte out_blk
[4]);
27 void rDecrypt(const u4byte in_blk
[4], u4byte out_blk
[4]);
33 /* 3. Basic macros for speeding up generic operations */
35 /* Circular rotate of 32 bit values */
40 # pragma intrinsic(_lrotr,_lrotl)
41 # define rotr(x,n) _lrotr(x,n)
42 # define rotl(x,n) _lrotl(x,n)
46 #define rotr(x,n) (((x) >> ((int)(n))) | ((x) << (32 - (int)(n))))
47 #define rotl(x,n) (((x) << ((int)(n))) | ((x) >> (32 - (int)(n))))
51 /* Invert byte order in a 32 bit variable */
53 #define bswap(x) ((rotl(x, 8) & 0x00ff00ff) | (rotr(x, 8) & 0xff00ff00))
55 /* Extract byte from a 32 bit quantity (little endian notation) */
57 #define byte(x,n) ((u1byte)((x) >> (8 * n)))
59 /* For inverting byte order in input/output 32 bit words if needed */
70 #define io_swap(x) bswap(x)
72 #define io_swap(x) (x)
75 /* For inverting the byte order of input/output blocks if needed */
79 #define get_block(x) \
80 ((u4byte*)(x))[0] = io_swap(in_blk[3]); \
81 ((u4byte*)(x))[1] = io_swap(in_blk[2]); \
82 ((u4byte*)(x))[2] = io_swap(in_blk[1]); \
83 ((u4byte*)(x))[3] = io_swap(in_blk[0])
85 #define put_block(x) \
86 out_blk[3] = io_swap(((u4byte*)(x))[0]); \
87 out_blk[2] = io_swap(((u4byte*)(x))[1]); \
88 out_blk[1] = io_swap(((u4byte*)(x))[2]); \
89 out_blk[0] = io_swap(((u4byte*)(x))[3])
91 #define get_key(x,len) \
92 ((u4byte*)(x))[4] = ((u4byte*)(x))[5] = \
93 ((u4byte*)(x))[6] = ((u4byte*)(x))[7] = 0; \
94 switch((((len) + 63) / 64)) { \
96 ((u4byte*)(x))[0] = io_swap(in_key[3]); \
97 ((u4byte*)(x))[1] = io_swap(in_key[2]); \
98 ((u4byte*)(x))[2] = io_swap(in_key[1]); \
99 ((u4byte*)(x))[3] = io_swap(in_key[0]); \
102 ((u4byte*)(x))[0] = io_swap(in_key[5]); \
103 ((u4byte*)(x))[1] = io_swap(in_key[4]); \
104 ((u4byte*)(x))[2] = io_swap(in_key[3]); \
105 ((u4byte*)(x))[3] = io_swap(in_key[2]); \
106 ((u4byte*)(x))[4] = io_swap(in_key[1]); \
107 ((u4byte*)(x))[5] = io_swap(in_key[0]); \
110 ((u4byte*)(x))[0] = io_swap(in_key[7]); \
111 ((u4byte*)(x))[1] = io_swap(in_key[6]); \
112 ((u4byte*)(x))[2] = io_swap(in_key[5]); \
113 ((u4byte*)(x))[3] = io_swap(in_key[4]); \
114 ((u4byte*)(x))[4] = io_swap(in_key[3]); \
115 ((u4byte*)(x))[5] = io_swap(in_key[2]); \
116 ((u4byte*)(x))[6] = io_swap(in_key[1]); \
117 ((u4byte*)(x))[7] = io_swap(in_key[0]); \
122 #define get_block(x) \
123 ((u4byte*)(x))[0] = io_swap(in_blk[0]); \
124 ((u4byte*)(x))[1] = io_swap(in_blk[1]); \
125 ((u4byte*)(x))[2] = io_swap(in_blk[2]); \
126 ((u4byte*)(x))[3] = io_swap(in_blk[3])
128 #define put_block(x) \
129 out_blk[0] = io_swap(((u4byte*)(x))[0]); \
130 out_blk[1] = io_swap(((u4byte*)(x))[1]); \
131 out_blk[2] = io_swap(((u4byte*)(x))[2]); \
132 out_blk[3] = io_swap(((u4byte*)(x))[3])
134 #define get_key(x,len) \
135 ((u4byte*)(x))[4] = ((u4byte*)(x))[5] = \
136 ((u4byte*)(x))[6] = ((u4byte*)(x))[7] = 0; \
137 switch((((len) + 63) / 64)) { \
139 ((u4byte*)(x))[6] = io_swap(in_key[6]); \
140 ((u4byte*)(x))[7] = io_swap(in_key[7]); \
142 ((u4byte*)(x))[4] = io_swap(in_key[4]); \
143 ((u4byte*)(x))[5] = io_swap(in_key[5]); \
145 ((u4byte*)(x))[0] = io_swap(in_key[0]); \
146 ((u4byte*)(x))[1] = io_swap(in_key[1]); \
147 ((u4byte*)(x))[2] = io_swap(in_key[2]); \
148 ((u4byte*)(x))[3] = io_swap(in_key[3]); \