]>
git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/corecrypto/cccmac.h
5 * Created on 11/07/2013
7 * Copyright (c) 2013,2014,2015 Apple Inc. All rights reserved.
11 #ifndef _CORECRYPTO_cccmac_H_
12 #define _CORECRYPTO_cccmac_H_
14 #include <corecrypto/cc.h>
15 #include <corecrypto/ccmode.h>
16 #include <corecrypto/ccaes.h>
18 #define CMAC_BLOCKSIZE 16
21 uint8_t k1
[CMAC_BLOCKSIZE
];
22 uint8_t k2
[CMAC_BLOCKSIZE
];
23 uint8_t block
[CMAC_BLOCKSIZE
];
24 size_t block_nbytes
; // Number of byte occupied in block
25 size_t cumulated_nbytes
; // Total size processed
26 const struct ccmode_cbc
*cbc
;
28 } CC_ALIGNED(8);// cccmac_ctx_hdr;
30 typedef struct cccmac_ctx
* cccmac_ctx_t
;
32 #define cccmac_hdr_size sizeof(struct cccmac_ctx)
35 #define cccmac_iv_size(_mode_) ((_mode_)->block_size)
36 #define cccmac_cbc_size(_mode_) ((_mode_)->size)
38 #define cccmac_ctx_size(_mode_) (cccmac_hdr_size + cccmac_iv_size(_mode_) + cccmac_cbc_size(_mode_))
39 #define cccmac_ctx_n(_mode_) ccn_nof_size(cccmac_ctx_size(_mode_))
41 #define cccmac_mode_decl(_mode_, _name_) cc_ctx_decl(struct cccmac_ctx, cccmac_ctx_size(_mode_), _name_)
42 #define cccmac_mode_clear(_mode_, _name_) cc_clear(cccmac_ctx_size(_mode_), _name_)
44 /* Return a cccbc_ctx * which can be accesed with the macros in ccmode.h */
45 #define cccmac_mode_ctx_start(_mode_, HC) (HC->ctx)
46 #define CCCMAC_HDR(HC) (HC)
48 #define cccmac_mode_sym_ctx(_mode_, HC) (cccbc_ctx *)(cccmac_mode_ctx_start(_mode_, HC))
49 #define cccmac_mode_iv(_mode_, HC) (cccbc_iv *)(cccmac_mode_ctx_start(_mode_, HC)+cccmac_cbc_size(_mode_))
50 #define cccmac_k1(HC) (CCCMAC_HDR(HC)->k1)
51 #define cccmac_k2(HC) (CCCMAC_HDR(HC)->k2)
52 #define cccmac_block(HC) (CCCMAC_HDR(HC)->block)
53 #define cccmac_cbc(HC) (CCCMAC_HDR(HC)->cbc)
54 #define cccmac_block_nbytes(HC) (CCCMAC_HDR(HC)->block_nbytes)
55 #define cccmac_cumulated_nbytes(HC) (CCCMAC_HDR(HC)->cumulated_nbytes)
58 /* CMAC as defined in NIST SP800-38B - 2005 */
60 /* =============================================================================
64 ==============================================================================*/
67 @function cccmac_one_shot_generate
68 @abstract CMAC generation in one call
70 @param cbc CBC and block cipher specification
71 @param key_nbytes Length of the key in bytes
72 @param key Pointer to the key of length key_nbytes
73 @param data_nbytes Length of the data in bytes
74 @param data Pointer to the data in bytes
75 @param mac_nbytes Length in byte of the mac, > 0
76 @param mac Output of length cbc->block_size
78 @result 0 iff successful.
80 @discussion Only supports CMAC_BLOCKSIZE block ciphers
82 int cccmac_one_shot_generate(const struct ccmode_cbc
*cbc
,
83 size_t key_nbytes
, const void *key
,
84 size_t data_nbytes
, const void *data
,
85 size_t mac_nbytes
, void *mac
);
88 @function cccmac_one_shot_verify
89 @abstract CMAC verification in one call
91 @param cbc CBC and block cipher specification
92 @param key_nbytes Length of the key in bytes
93 @param key Pointer to the key of length key_nbytes
94 @param data_nbytes Length of the data in bytes
95 @param data Pointer to the data in bytes
96 @param expected_mac_nbytes Length in byte of the mac, > 0
97 @param expected_mac Mac value expected
99 @result 0 iff successful.
101 @discussion Only supports CMAC_BLOCKSIZE block ciphers
103 int cccmac_one_shot_verify(const struct ccmode_cbc
*cbc
,
104 size_t key_nbytes
, const void *key
,
105 size_t data_nbytes
, const void *data
,
106 size_t expected_mac_nbytes
, const void *expected_mac
);
108 /* =============================================================================
112 Init - Update - Final
114 ==============================================================================*/
117 @function cccmac_init
118 @abstract Init CMAC context with CBC mode and key
120 @param cbc CBC and block cipher specification
121 @param ctx Context use to store internal state
122 @param key_nbytes Length of the key in bytes
125 @result 0 iff successful.
127 @discussion Only supports CMAC_BLOCKSIZE block ciphers
130 int cccmac_init(const struct ccmode_cbc
*cbc
,
132 size_t key_nbytes
, const void *key
);
135 @function cccmac_update
136 @abstract Process data
138 @param ctx Context use to store internal state
139 @param data_nbytes Length in byte of the data
140 @param data Data to process
142 @result 0 iff successful.
144 @discussion Only supports CMAC_BLOCKSIZE block ciphers
147 int cccmac_update(cccmac_ctx_t ctx
,
148 size_t data_nbytes
, const void *data
);
151 @function cccmac_final_generate
152 @abstract Final step for generation
154 @param ctx Context use to store internal state
155 @param mac_nbytes Length in byte of the mac, > 0
156 @param mac Output of length mac_nbytes
158 @result 0 iff successful.
160 @discussion Only supports CMAC_BLOCKSIZE block ciphers
162 int cccmac_final_generate(cccmac_ctx_t ctx
,
163 size_t mac_nbytes
, void *mac
);
166 @function cccmac_final_verify
167 @abstract Final step and verification
169 @param ctx Context use to store internal state
170 @param expected_mac_nbytes Length in byte of the mac, > 0
171 @param expected_mac Mac value expected
173 @result 0 iff successful.
175 @discussion Only supports CMAC_BLOCKSIZE block ciphers
177 int cccmac_final_verify(cccmac_ctx_t ctx
,
178 size_t expected_mac_nbytes
, const void *expected_mac
);
180 #endif /* _CORECRYPTO_cccmac_H_ */