]>
git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/corecrypto/ccmode_impl.h
5 * Created on 12/07/2010
7 * Copyright (c) 2012,2015 Apple Inc. All rights reserved.
11 #ifndef _CORECRYPTO_CCMODE_IMPL_H_
12 #define _CORECRYPTO_CCMODE_IMPL_H_
14 #include <corecrypto/cc.h>
17 cc_aligned_struct(16) ccecb_ctx
;
20 /* Actual symmetric algorithm implementation should provide you one of these. */
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
,
31 cc_aligned_struct(16) cccbc_ctx
;
32 cc_aligned_struct(16) cccbc_iv
;
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
);
46 cc_aligned_struct(16) cccfb_ctx
;
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
);
59 cc_aligned_struct(16) cccfb8_ctx
;
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
);
72 cc_aligned_struct(16) ccctr_ctx
;
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
);
85 cc_aligned_struct(16) ccofb_ctx
;
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
);
98 cc_aligned_struct(16) ccxts_ctx
;
99 cc_aligned_struct(16) ccxts_tweak
;
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
;
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
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
);
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
);
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
);
128 cc_aligned_struct(16) ccgcm_ctx
;
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
);
145 cc_aligned_struct(16) ccccm_ctx
;
146 cc_aligned_struct(16) ccccm_nonce
;
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
);
166 cc_aligned_struct(16) ccomac_ctx
;
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
);
178 #endif /* _CORECRYPTO_CCMODE_IMPL_H_ */