]>
git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/corecrypto/ccmode_impl.h
ce1d1e1145728ea9fb18a569cdf8113166fd2eb7
5 * Created by James Murphy on 12/9/11.
6 * Copyright (c) 2011 Apple Inc. All rights reserved.
10 #ifndef _CORECRYPTO_CCMODE_IMPL_H_
11 #define _CORECRYPTO_CCMODE_IMPL_H_
13 #include <corecrypto/cc.h>
16 cc_aligned_struct(16) ccecb_ctx
;
19 /* Actual symmetric algorithm implementation should provide you one of these. */
21 size_t size
; /* first argument to ccecb_ctx_decl(). */
22 unsigned long block_size
;
23 void (*init
)(const struct ccmode_ecb
*ecb
, ccecb_ctx
*ctx
,
24 size_t key_len
, const void *key
);
25 void (*ecb
)(const ccecb_ctx
*ctx
, unsigned long nblocks
, const void *in
,
30 cc_aligned_struct(16) cccbc_ctx
;
31 cc_aligned_struct(16) cccbc_iv
;
34 size_t size
; /* first argument to cccbc_ctx_decl(). */
35 unsigned long block_size
;
36 void (*init
)(const struct ccmode_cbc
*cbc
, cccbc_ctx
*ctx
,
37 size_t key_len
, const void *key
);
38 /* cbc encrypt or decrypt nblocks from in to out, iv will be used and updated. */
39 void (*cbc
)(const cccbc_ctx
*ctx
, cccbc_iv
*iv
,
40 unsigned long nblocks
, const void *in
, void *out
);
45 cc_aligned_struct(16) cccfb_ctx
;
48 size_t size
; /* first argument to cccfb_ctx_decl(). */
49 unsigned long block_size
;
50 void (*init
)(const struct ccmode_cfb
*cfb
, cccfb_ctx
*ctx
,
51 size_t key_len
, const void *key
, const void *iv
);
52 void (*cfb
)(cccfb_ctx
*ctx
, size_t nbytes
, const void *in
, void *out
);
58 cc_aligned_struct(16) cccfb8_ctx
;
61 size_t size
; /* first argument to cccfb8_ctx_decl(). */
62 unsigned long block_size
;
63 void (*init
)(const struct ccmode_cfb8
*cfb8
, cccfb8_ctx
*ctx
,
64 size_t key_len
, const void *key
, const void *iv
);
65 void (*cfb8
)(cccfb8_ctx
*ctx
, size_t nbytes
, const void *in
, void *out
);
71 cc_aligned_struct(16) ccctr_ctx
;
74 size_t size
; /* first argument to ccctr_ctx_decl(). */
75 unsigned long block_size
;
76 void (*init
)(const struct ccmode_ctr
*ctr
, ccctr_ctx
*ctx
,
77 size_t key_len
, const void *key
, const void *iv
);
78 void (*ctr
)(ccctr_ctx
*ctx
, size_t nbytes
, const void *in
, void *out
);
84 cc_aligned_struct(16) ccofb_ctx
;
87 size_t size
; /* first argument to ccofb_ctx_decl(). */
88 unsigned long block_size
;
89 void (*init
)(const struct ccmode_ofb
*ofb
, ccofb_ctx
*ctx
,
90 size_t key_len
, const void *key
, const void *iv
);
91 void (*ofb
)(ccofb_ctx
*ctx
, size_t nbytes
, const void *in
, void *out
);
97 cc_aligned_struct(16) ccxts_ctx
;
98 cc_aligned_struct(16) ccxts_tweak
;
101 size_t size
; /* first argument to ccxts_ctx_decl(). */
102 size_t tweak_size
; /* first argument to ccxts_tweak_decl(). */
103 unsigned long block_size
;
105 /* Create a xts key from a xts mode object. The tweak_len here
106 determines how long the tweak is in bytes, for each subsequent call to
108 key must point to at least 'size' cc_units of free storage.
109 tweak_key must point to at least 'tweak_size' cc_units of free storage. */
110 void (*init
)(const struct ccmode_xts
*xts
, ccxts_ctx
*ctx
,
111 size_t key_len
, const void *key
, const void *tweak_key
);
113 /* Set the tweak (sector number), the block within the sector zero. */
114 void (*set_tweak
)(const ccxts_ctx
*ctx
, ccxts_tweak
*tweak
, const void *iv
);
116 /* Encrypt blocks for a sector, clients must call set_tweak before calling
117 this function. Return a pointer to the tweak buffer */
118 void *(*xts
)(const ccxts_ctx
*ctx
, ccxts_tweak
*tweak
,
119 unsigned long nblocks
, const void *in
, void *out
);
127 cc_aligned_struct(16) ccgcm_ctx
;
130 size_t size
; /* first argument to ccgcm_ctx_decl(). */
131 unsigned long block_size
;
132 void (*init
)(const struct ccmode_gcm
*gcm
, ccgcm_ctx
*ctx
,
133 size_t key_len
, const void *key
);
134 void (*set_iv
)(ccgcm_ctx
*ctx
, size_t iv_size
, const void *iv
);
135 void (*gmac
)(ccgcm_ctx
*ctx
, size_t nbytes
, const void *in
); // could just be gcm with NULL out
136 void (*gcm
)(ccgcm_ctx
*ctx
, size_t nbytes
, const void *in
, void *out
);
137 void (*finalize
)(ccgcm_ctx
*key
, size_t tag_size
, void *tag
);
138 void (*reset
)(ccgcm_ctx
*ctx
);
144 cc_aligned_struct(16) ccccm_ctx
;
145 cc_aligned_struct(16) ccccm_nonce
;
148 size_t size
; /* first argument to ccccm_ctx_decl(). */
149 size_t nonce_size
; /* first argument to ccccm_nonce_decl(). */
150 unsigned long block_size
;
151 void (*init
)(const struct ccmode_ccm
*ccm
, ccccm_ctx
*ctx
,
152 size_t key_len
, const void *key
);
153 void (*set_iv
)(ccccm_ctx
*ctx
, ccccm_nonce
*nonce_ctx
, size_t nonce_len
, const void *nonce
,
154 size_t mac_size
, size_t auth_len
, size_t data_len
);
155 void (*cbcmac
)(ccccm_ctx
*ctx
, ccccm_nonce
*nonce_ctx
, size_t nbytes
, const void *in
); // could just be ccm with NULL out
156 void (*ccm
)(ccccm_ctx
*ctx
, ccccm_nonce
*nonce_ctx
, size_t nbytes
, const void *in
, void *out
);
157 void (*finalize
)(ccccm_ctx
*key
, ccccm_nonce
*nonce_ctx
, void *mac
);
158 void (*reset
)(ccccm_ctx
*key
, ccccm_nonce
*nonce_ctx
);
165 cc_aligned_struct(16) ccomac_ctx
;
168 size_t size
; /* first argument to ccomac_ctx_decl(). */
169 unsigned long block_size
;
170 void (*init
)(const struct ccmode_omac
*omac
, ccomac_ctx
*ctx
,
171 size_t tweak_len
, size_t key_len
, const void *key
);
172 int (*omac
)(ccomac_ctx
*ctx
, unsigned long nblocks
,
173 const void *tweak
, const void *in
, void *out
);
177 #endif /* _CORECRYPTO_CCMODE_IMPL_H_ */