]>
git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/corecrypto/ccmode_factory.h
a9498d1f7a03fce1ba0e11a5d61a7dc57822fc75
5 * Created on 01/21/2011
7 * Copyright (c) 2011,2012,2013,2014,2015 Apple Inc. All rights reserved.
11 #ifndef _CORECRYPTO_CCMODE_FACTORY_H_
12 #define _CORECRYPTO_CCMODE_FACTORY_H_
14 #include <corecrypto/ccn.h> /* TODO: Remove dependency on this header. */
15 #include <corecrypto/ccmode_impl.h>
17 /* Function and macros defined in this file are only to be used
18 within corecrypto files.
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_; \
25 const struct ccmode_cbc *cc##_cipher_##_cbc_##_dir_##_mode(void) \
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_; \
32 /* For CTR, only one direction, underlying ecb is always encrypt */
33 #define CCMODE_CTR_FACTORY(_cipher_) \
34 static struct ccmode_ctr ctr_##_cipher_; \
36 const struct ccmode_ctr *cc##_cipher_##_ctr_crypt_mode(void) \
38 const struct ccmode_ecb *ecb=cc##_cipher_##_ecb_encrypt_mode(); \
39 ccmode_factory_ctr_crypt(&ctr_##_cipher_, ecb); \
40 return &ctr_##_cipher_; \
43 /* OFB, same as CTR */
44 #define CCMODE_OFB_FACTORY(_cipher_) \
45 static struct ccmode_ofb ofb_##_cipher_; \
47 const struct ccmode_ofb *cc##_cipher_##_ofb_crypt_mode(void) \
49 const struct ccmode_ecb *ecb=cc##_cipher_##_ecb_encrypt_mode(); \
50 ccmode_factory_ofb_crypt(&ofb_##_cipher_, ecb); \
51 return &ofb_##_cipher_; \
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_; \
59 const struct ccmode_##_mode_ *cc##_cipher_##_##_mode_##_##_dir_##_mode(void) \
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_; \
66 /* For GCM, same as CFB */
67 #define CCMODE_GCM_FACTORY(_cipher_, _dir_) CCMODE_CFB_FACTORY(_cipher_, gcm, _dir_)
69 /* For CCM, same as CFB */
70 #define CCMODE_CCM_FACTORY(_cipher_, _dir_) CCMODE_CFB_FACTORY(_cipher_, ccm, _dir_)
73 /* Fot XTS, you always need an ecb encrypt */
74 #define CCMODE_XTS_FACTORY(_cipher_ , _dir_) \
75 static struct ccmode_xts xts##_cipher_##_##_dir_; \
77 const struct ccmode_xts *cc##_cipher_##_xts_##_dir_##_mode(void) \
79 const struct ccmode_ecb *ecb=cc##_cipher_##_ecb_##_dir_##_mode(); \
80 const struct ccmode_ecb *ecb_enc=cc##_cipher_##_ecb_encrypt_mode(); \
82 ccmode_factory_xts_##_dir_(&xts##_cipher_##_##_dir_, ecb, ecb_enc); \
83 return &xts##_cipher_##_##_dir_; \
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
90 void ccmode_factory_cbc_decrypt(struct ccmode_cbc
*cbc
,
91 const struct ccmode_ecb
*ecb
);
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
97 void ccmode_factory_cbc_encrypt(struct ccmode_cbc
*cbc
,
98 const struct ccmode_ecb
*ecb
);
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
105 void ccmode_factory_cfb_decrypt(struct ccmode_cfb
*cfb
,
106 const struct ccmode_ecb
*ecb
);
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
112 void ccmode_factory_cfb_encrypt(struct ccmode_cfb
*cfb
,
113 const struct ccmode_ecb
*ecb
);
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
119 void ccmode_factory_cfb8_decrypt(struct ccmode_cfb8
*cfb8
,
120 const struct ccmode_ecb
*ecb
);
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
126 void ccmode_factory_cfb8_encrypt(struct ccmode_cfb8
*cfb8
,
127 const struct ccmode_ecb
*ecb
);
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
133 void ccmode_factory_ctr_crypt(struct ccmode_ctr
*ctr
,
134 const struct ccmode_ecb
*ecb
);
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
140 void ccmode_factory_gcm_decrypt(struct ccmode_gcm
*gcm
,
141 const struct ccmode_ecb
*ecb_encrypt
);
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
147 void ccmode_factory_gcm_encrypt(struct ccmode_gcm
*gcm
,
148 const struct ccmode_ecb
*ecb_encrypt
);
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
155 void ccmode_factory_ccm_decrypt(struct ccmode_ccm
*ccm
,
156 const struct ccmode_ecb
*ecb_encrypt
);
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
162 void ccmode_factory_ccm_encrypt(struct ccmode_ccm
*ccm
,
163 const struct ccmode_ecb
*ecb_encrypt
);
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
169 void ccmode_factory_ofb_crypt(struct ccmode_ofb
*ofb
,
170 const struct ccmode_ecb
*ecb
);
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
176 void ccmode_factory_omac_decrypt(struct ccmode_omac
*omac
,
177 const struct ccmode_ecb
*ecb
);
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
183 void ccmode_factory_omac_encrypt(struct ccmode_omac
*omac
,
184 const struct ccmode_ecb
*ecb
);
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
190 void ccmode_factory_xts_decrypt(struct ccmode_xts
*xts
,
191 const struct ccmode_ecb
*ecb
,
192 const struct ccmode_ecb
*ecb_encrypt
);
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
198 void ccmode_factory_xts_encrypt(struct ccmode_xts
*xts
,
199 const struct ccmode_ecb
*ecb
,
200 const struct ccmode_ecb
*ecb_encrypt
);
202 #endif /* _CORECRYPTO_CCMODE_FACTORY_H_ */