]> git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/corecrypto/ccmode_factory.h
a9498d1f7a03fce1ba0e11a5d61a7dc57822fc75
[apple/xnu.git] / EXTERNAL_HEADERS / corecrypto / ccmode_factory.h
1 /*
2 * ccmode_factory.h
3 * corecrypto
4 *
5 * Created on 01/21/2011
6 *
7 * Copyright (c) 2011,2012,2013,2014,2015 Apple Inc. All rights reserved.
8 *
9 */
10
11 #ifndef _CORECRYPTO_CCMODE_FACTORY_H_
12 #define _CORECRYPTO_CCMODE_FACTORY_H_
13
14 #include <corecrypto/ccn.h> /* TODO: Remove dependency on this header. */
15 #include <corecrypto/ccmode_impl.h>
16
17 /* Function and macros defined in this file are only to be used
18 within corecrypto files.
19 */
20
21 /* For CBC, direction of underlying ecb is the same as the cbc direction */
22 #define CCMODE_CBC_FACTORY(_cipher_, _dir_) \
23 static struct ccmode_cbc cbc_##_cipher_##_##_dir_; \
24 \
25 const struct ccmode_cbc *cc##_cipher_##_cbc_##_dir_##_mode(void) \
26 { \
27 const struct ccmode_ecb *ecb=cc##_cipher_##_ecb_##_dir_##_mode(); \
28 ccmode_factory_cbc_##_dir_(&cbc_##_cipher_##_##_dir_, ecb); \
29 return &cbc_##_cipher_##_##_dir_; \
30 }
31
32 /* For CTR, only one direction, underlying ecb is always encrypt */
33 #define CCMODE_CTR_FACTORY(_cipher_) \
34 static struct ccmode_ctr ctr_##_cipher_; \
35 \
36 const struct ccmode_ctr *cc##_cipher_##_ctr_crypt_mode(void) \
37 { \
38 const struct ccmode_ecb *ecb=cc##_cipher_##_ecb_encrypt_mode(); \
39 ccmode_factory_ctr_crypt(&ctr_##_cipher_, ecb); \
40 return &ctr_##_cipher_; \
41 }
42
43 /* OFB, same as CTR */
44 #define CCMODE_OFB_FACTORY(_cipher_) \
45 static struct ccmode_ofb ofb_##_cipher_; \
46 \
47 const struct ccmode_ofb *cc##_cipher_##_ofb_crypt_mode(void) \
48 { \
49 const struct ccmode_ecb *ecb=cc##_cipher_##_ecb_encrypt_mode(); \
50 ccmode_factory_ofb_crypt(&ofb_##_cipher_, ecb); \
51 return &ofb_##_cipher_; \
52 }
53
54
55 /* For CFB, the underlying ecb operation is encrypt for both directions */
56 #define CCMODE_CFB_FACTORY(_cipher_, _mode_, _dir_) \
57 static struct ccmode_##_mode_ _mode_##_##_cipher_##_##_dir_; \
58 \
59 const struct ccmode_##_mode_ *cc##_cipher_##_##_mode_##_##_dir_##_mode(void) \
60 { \
61 const struct ccmode_ecb *ecb=cc##_cipher_##_ecb_encrypt_mode(); \
62 ccmode_factory_##_mode_##_##_dir_(&_mode_##_##_cipher_##_##_dir_, ecb); \
63 return &_mode_##_##_cipher_##_##_dir_; \
64 }
65
66 /* For GCM, same as CFB */
67 #define CCMODE_GCM_FACTORY(_cipher_, _dir_) CCMODE_CFB_FACTORY(_cipher_, gcm, _dir_)
68
69 /* For CCM, same as CFB */
70 #define CCMODE_CCM_FACTORY(_cipher_, _dir_) CCMODE_CFB_FACTORY(_cipher_, ccm, _dir_)
71
72
73 /* Fot XTS, you always need an ecb encrypt */
74 #define CCMODE_XTS_FACTORY(_cipher_ , _dir_) \
75 static struct ccmode_xts xts##_cipher_##_##_dir_; \
76 \
77 const struct ccmode_xts *cc##_cipher_##_xts_##_dir_##_mode(void) \
78 { \
79 const struct ccmode_ecb *ecb=cc##_cipher_##_ecb_##_dir_##_mode(); \
80 const struct ccmode_ecb *ecb_enc=cc##_cipher_##_ecb_encrypt_mode(); \
81 \
82 ccmode_factory_xts_##_dir_(&xts##_cipher_##_##_dir_, ecb, ecb_enc); \
83 return &xts##_cipher_##_##_dir_; \
84 }
85
86 /* Use these function to runtime initialize a ccmode_cbc decrypt object (for
87 example if it's part of a larger structure). Normally you would pass a
88 ecb decrypt mode implementation of some underlying algorithm as the ecb
89 parameter. */
90 void ccmode_factory_cbc_decrypt(struct ccmode_cbc *cbc,
91 const struct ccmode_ecb *ecb);
92
93 /* Use these function to runtime initialize a ccmode_cbc encrypt object (for
94 example if it's part of a larger structure). Normally you would pass a
95 ecb encrypt mode implementation of some underlying algorithm as the ecb
96 parameter. */
97 void ccmode_factory_cbc_encrypt(struct ccmode_cbc *cbc,
98 const struct ccmode_ecb *ecb);
99
100
101 /* Use these function to runtime initialize a ccmode_cfb decrypt object (for
102 example if it's part of a larger structure). Normally you would pass a
103 ecb encrypt mode implementation of some underlying algorithm as the ecb
104 parameter. */
105 void ccmode_factory_cfb_decrypt(struct ccmode_cfb *cfb,
106 const struct ccmode_ecb *ecb);
107
108 /* Use these function to runtime initialize a ccmode_cfb encrypt object (for
109 example if it's part of a larger structure). Normally you would pass a
110 ecb encrypt mode implementation of some underlying algorithm as the ecb
111 parameter. */
112 void ccmode_factory_cfb_encrypt(struct ccmode_cfb *cfb,
113 const struct ccmode_ecb *ecb);
114
115 /* Use these function to runtime initialize a ccmode_cfb8 decrypt object (for
116 example if it's part of a larger structure). Normally you would pass a
117 ecb decrypt mode implementation of some underlying algorithm as the ecb
118 parameter. */
119 void ccmode_factory_cfb8_decrypt(struct ccmode_cfb8 *cfb8,
120 const struct ccmode_ecb *ecb);
121
122 /* Use these function to runtime initialize a ccmode_cfb8 encrypt object (for
123 example if it's part of a larger structure). Normally you would pass a
124 ecb encrypt mode implementation of some underlying algorithm as the ecb
125 parameter. */
126 void ccmode_factory_cfb8_encrypt(struct ccmode_cfb8 *cfb8,
127 const struct ccmode_ecb *ecb);
128
129 /* Use these function to runtime initialize a ccmode_ctr decrypt object (for
130 example if it's part of a larger structure). Normally you would pass a
131 ecb encrypt mode implementation of some underlying algorithm as the ecb
132 parameter. */
133 void ccmode_factory_ctr_crypt(struct ccmode_ctr *ctr,
134 const struct ccmode_ecb *ecb);
135
136 /* Use these function to runtime initialize a ccmode_gcm decrypt object (for
137 example if it's part of a larger structure). For GCM you always pass a
138 ecb encrypt mode implementation of some underlying algorithm as the ecb
139 parameter. */
140 void ccmode_factory_gcm_decrypt(struct ccmode_gcm *gcm,
141 const struct ccmode_ecb *ecb_encrypt);
142
143 /* Use these function to runtime initialize a ccmode_gcm encrypt object (for
144 example if it's part of a larger structure). For GCM you always pass a
145 ecb encrypt mode implementation of some underlying algorithm as the ecb
146 parameter. */
147 void ccmode_factory_gcm_encrypt(struct ccmode_gcm *gcm,
148 const struct ccmode_ecb *ecb_encrypt);
149
150 /* Use these function to runtime initialize a ccmode_ccm decrypt object (for
151 example if it's part of a larger structure). For CCM you always pass a
152 ecb encrypt mode implementation of some underlying algorithm as the ecb
153 parameter. */
154
155 void ccmode_factory_ccm_decrypt(struct ccmode_ccm *ccm,
156 const struct ccmode_ecb *ecb_encrypt);
157
158 /* Use these function to runtime initialize a ccmode_ccm encrypt object (for
159 example if it's part of a larger structure). For CCM you always pass a
160 ecb encrypt mode implementation of some underlying algorithm as the ecb
161 parameter. */
162 void ccmode_factory_ccm_encrypt(struct ccmode_ccm *ccm,
163 const struct ccmode_ecb *ecb_encrypt);
164
165 /* Use these function to runtime initialize a ccmode_ofb encrypt object (for
166 example if it's part of a larger structure). Normally you would pass a
167 ecb encrypt mode implementation of some underlying algorithm as the ecb
168 parameter. */
169 void ccmode_factory_ofb_crypt(struct ccmode_ofb *ofb,
170 const struct ccmode_ecb *ecb);
171
172 /* Use these function to runtime initialize a ccmode_omac decrypt object (for
173 example if it's part of a larger structure). Normally you would pass a
174 ecb decrypt mode implementation of some underlying algorithm as the ecb
175 parameter. */
176 void ccmode_factory_omac_decrypt(struct ccmode_omac *omac,
177 const struct ccmode_ecb *ecb);
178
179 /* Use these function to runtime initialize a ccmode_omac encrypt object (for
180 example if it's part of a larger structure). Normally you would pass a
181 ecb encrypt mode implementation of some underlying algorithm as the ecb
182 parameter. */
183 void ccmode_factory_omac_encrypt(struct ccmode_omac *omac,
184 const struct ccmode_ecb *ecb);
185
186 /* Use these function to runtime initialize a ccmode_xts decrypt object (for
187 example if it's part of a larger structure). Normally you would pass a
188 ecb decrypt mode implementation of some underlying algorithm as the ecb
189 parameter. */
190 void ccmode_factory_xts_decrypt(struct ccmode_xts *xts,
191 const struct ccmode_ecb *ecb,
192 const struct ccmode_ecb *ecb_encrypt);
193
194 /* Use these function to runtime initialize a ccmode_xts encrypt object (for
195 example if it's part of a larger structure). Normally you would pass a
196 ecb encrypt mode implementation of some underlying algorithm as the ecb
197 parameter. */
198 void ccmode_factory_xts_encrypt(struct ccmode_xts *xts,
199 const struct ccmode_ecb *ecb,
200 const struct ccmode_ecb *ecb_encrypt);
201
202 #endif /* _CORECRYPTO_CCMODE_FACTORY_H_ */