]> git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/corecrypto/ccmode_impl.h
xnu-3248.60.10.tar.gz
[apple/xnu.git] / EXTERNAL_HEADERS / corecrypto / ccmode_impl.h
1 /*
2 * ccmode_impl.h
3 * corecrypto
4 *
5 * Created on 12/07/2010
6 *
7 * Copyright (c) 2012,2015 Apple Inc. All rights reserved.
8 *
9 */
10
11 #ifndef _CORECRYPTO_CCMODE_IMPL_H_
12 #define _CORECRYPTO_CCMODE_IMPL_H_
13
14 #include <corecrypto/cc.h>
15
16 /* ECB mode. */
17 cc_aligned_struct(16) ccecb_ctx;
18
19
20 /* Actual symmetric algorithm implementation should provide you one of these. */
21 struct ccmode_ecb {
22 size_t size; /* first argument to ccecb_ctx_decl(). */
23 unsigned long block_size;
24 void (*init)(const struct ccmode_ecb *ecb, ccecb_ctx *ctx,
25 size_t key_len, const void *key);
26 void (*ecb)(const ccecb_ctx *ctx, unsigned long nblocks, const void *in,
27 void *out);
28 };
29
30 /* CBC mode. */
31 cc_aligned_struct(16) cccbc_ctx;
32 cc_aligned_struct(16) cccbc_iv;
33
34 struct ccmode_cbc {
35 size_t size; /* first argument to cccbc_ctx_decl(). */
36 unsigned long block_size;
37 void (*init)(const struct ccmode_cbc *cbc, cccbc_ctx *ctx,
38 size_t key_len, const void *key);
39 /* cbc encrypt or decrypt nblocks from in to out, iv will be used and updated. */
40 void (*cbc)(const cccbc_ctx *ctx, cccbc_iv *iv,
41 unsigned long nblocks, const void *in, void *out);
42 const void *custom;
43 };
44
45 /* CFB mode. */
46 cc_aligned_struct(16) cccfb_ctx;
47
48 struct ccmode_cfb {
49 size_t size; /* first argument to cccfb_ctx_decl(). */
50 unsigned long block_size;
51 void (*init)(const struct ccmode_cfb *cfb, cccfb_ctx *ctx,
52 size_t key_len, const void *key, const void *iv);
53 void (*cfb)(cccfb_ctx *ctx, size_t nbytes, const void *in, void *out);
54 const void *custom;
55 };
56
57 /* CFB8 mode. */
58
59 cc_aligned_struct(16) cccfb8_ctx;
60
61 struct ccmode_cfb8 {
62 size_t size; /* first argument to cccfb8_ctx_decl(). */
63 unsigned long block_size;
64 void (*init)(const struct ccmode_cfb8 *cfb8, cccfb8_ctx *ctx,
65 size_t key_len, const void *key, const void *iv);
66 void (*cfb8)(cccfb8_ctx *ctx, size_t nbytes, const void *in, void *out);
67 const void *custom;
68 };
69
70 /* CTR mode. */
71
72 cc_aligned_struct(16) ccctr_ctx;
73
74 struct ccmode_ctr {
75 size_t size; /* first argument to ccctr_ctx_decl(). */
76 unsigned long block_size;
77 void (*init)(const struct ccmode_ctr *ctr, ccctr_ctx *ctx,
78 size_t key_len, const void *key, const void *iv);
79 void (*ctr)(ccctr_ctx *ctx, size_t nbytes, const void *in, void *out);
80 const void *custom;
81 };
82
83 /* OFB mode. */
84
85 cc_aligned_struct(16) ccofb_ctx;
86
87 struct ccmode_ofb {
88 size_t size; /* first argument to ccofb_ctx_decl(). */
89 unsigned long block_size;
90 void (*init)(const struct ccmode_ofb *ofb, ccofb_ctx *ctx,
91 size_t key_len, const void *key, const void *iv);
92 void (*ofb)(ccofb_ctx *ctx, size_t nbytes, const void *in, void *out);
93 const void *custom;
94 };
95
96 /* XTS mode. */
97
98 cc_aligned_struct(16) ccxts_ctx;
99 cc_aligned_struct(16) ccxts_tweak;
100
101 struct ccmode_xts {
102 size_t size; /* first argument to ccxts_ctx_decl(). */
103 size_t tweak_size; /* first argument to ccxts_tweak_decl(). */
104 unsigned long block_size;
105
106 /* Create a xts key from a xts mode object. The tweak_len here
107 determines how long the tweak is in bytes, for each subsequent call to
108 ccmode_xts->xts().
109 key must point to at least 'size' cc_units of free storage.
110 tweak_key must point to at least 'tweak_size' cc_units of free storage. */
111 void (*init)(const struct ccmode_xts *xts, ccxts_ctx *ctx,
112 size_t key_len, const void *key, const void *tweak_key);
113
114 /* Set the tweak (sector number), the block within the sector zero. */
115 void (*set_tweak)(const ccxts_ctx *ctx, ccxts_tweak *tweak, const void *iv);
116
117 /* Encrypt blocks for a sector, clients must call set_tweak before calling
118 this function. Return a pointer to the tweak buffer */
119 void *(*xts)(const ccxts_ctx *ctx, ccxts_tweak *tweak,
120 unsigned long nblocks, const void *in, void *out);
121
122 const void *custom;
123 const void *custom1;
124 };
125
126 /* GCM mode. */
127
128 cc_aligned_struct(16) ccgcm_ctx;
129
130 struct ccmode_gcm {
131 size_t size; /* first argument to ccgcm_ctx_decl(). */
132 unsigned long block_size;
133 void (*init)(const struct ccmode_gcm *gcm, ccgcm_ctx *ctx,
134 size_t key_len, const void *key);
135 void (*set_iv)(ccgcm_ctx *ctx, size_t iv_size, const void *iv);
136 void (*gmac)(ccgcm_ctx *ctx, size_t nbytes, const void *in); // could just be gcm with NULL out
137 void (*gcm)(ccgcm_ctx *ctx, size_t nbytes, const void *in, void *out);
138 void (*finalize)(ccgcm_ctx *key, size_t tag_size, void *tag);
139 void (*reset)(ccgcm_ctx *ctx);
140 const void *custom;
141 };
142
143 /* GCM mode. */
144
145 cc_aligned_struct(16) ccccm_ctx;
146 cc_aligned_struct(16) ccccm_nonce;
147
148 struct ccmode_ccm {
149 size_t size; /* first argument to ccccm_ctx_decl(). */
150 size_t nonce_size; /* first argument to ccccm_nonce_decl(). */
151 unsigned long block_size;
152 void (*init)(const struct ccmode_ccm *ccm, ccccm_ctx *ctx,
153 size_t key_len, const void *key);
154 void (*set_iv)(ccccm_ctx *ctx, ccccm_nonce *nonce_ctx, size_t nonce_len, const void *nonce,
155 size_t mac_size, size_t auth_len, size_t data_len);
156 void (*cbcmac)(ccccm_ctx *ctx, ccccm_nonce *nonce_ctx, size_t nbytes, const void *in); // could just be ccm with NULL out
157 void (*ccm)(ccccm_ctx *ctx, ccccm_nonce *nonce_ctx, size_t nbytes, const void *in, void *out);
158 void (*finalize)(ccccm_ctx *key, ccccm_nonce *nonce_ctx, void *mac);
159 void (*reset)(ccccm_ctx *key, ccccm_nonce *nonce_ctx);
160 const void *custom;
161 };
162
163
164 /* OMAC mode. */
165
166 cc_aligned_struct(16) ccomac_ctx;
167
168 struct ccmode_omac {
169 size_t size; /* first argument to ccomac_ctx_decl(). */
170 unsigned long block_size;
171 void (*init)(const struct ccmode_omac *omac, ccomac_ctx *ctx,
172 size_t tweak_len, size_t key_len, const void *key);
173 int (*omac)(ccomac_ctx *ctx, unsigned long nblocks,
174 const void *tweak, const void *in, void *out);
175 const void *custom;
176 };
177
178 #endif /* _CORECRYPTO_CCMODE_IMPL_H_ */