]>
git.saurik.com Git - apple/xnu.git/blob - EXTERNAL_HEADERS/corecrypto/cchmac.h
81c1ab835a5cff83249e9ba872c2d5ef2830db9f
5 * Created on 12/07/2010
7 * Copyright (c) 2010,2011,2012,2014,2015 Apple Inc. All rights reserved.
11 #ifndef _CORECRYPTO_CCHMAC_H_
12 #define _CORECRYPTO_CCHMAC_H_
14 #include <corecrypto/cc.h>
15 #include <corecrypto/ccdigest.h>
17 /* An hmac_ctx_t is normally allocated as an array of these. */
22 #if CORECRYPTO_USE_TRANSPARENT_UNION
24 struct cchmac_ctx
*hdr
;
25 ccdigest_ctx_t digest
;
26 } cchmac_ctx_t
__attribute__((transparent_union
));
28 typedef struct cchmac_ctx
* cchmac_ctx_t
;
31 #define cchmac_ctx_size(STATE_SIZE, BLOCK_SIZE) (ccdigest_ctx_size(STATE_SIZE, BLOCK_SIZE) + (STATE_SIZE))
32 #define cchmac_di_size(_di_) (cchmac_ctx_size((_di_)->state_size, (_di_)->block_size))
34 #define cchmac_ctx_n(STATE_SIZE, BLOCK_SIZE) ccn_nof_size(cchmac_ctx_size((STATE_SIZE), (BLOCK_SIZE)))
36 #define cchmac_ctx_decl(STATE_SIZE, BLOCK_SIZE, _name_) cc_ctx_decl(struct cchmac_ctx, cchmac_ctx_size(STATE_SIZE, BLOCK_SIZE), _name_)
37 #define cchmac_ctx_clear(STATE_SIZE, BLOCK_SIZE, _name_) cc_clear(cchmac_ctx_size(STATE_SIZE, BLOCK_SIZE), _name_)
38 #define cchmac_di_decl(_di_, _name_) cchmac_ctx_decl((_di_)->state_size, (_di_)->block_size, _name_)
39 #define cchmac_di_clear(_di_, _name_) cchmac_ctx_clear((_di_)->state_size, (_di_)->block_size, _name_)
41 /* Return a ccdigest_ctx_t which can be accesed with the macros in ccdigest.h */
42 #if CORECRYPTO_USE_TRANSPARENT_UNION
43 #define cchmac_digest_ctx(_di_, HC) (((cchmac_ctx_t)(HC)).digest)
45 #define cchmac_digest_ctx(_di_, HC) ((ccdigest_ctx_t)(HC))
48 /* Accesors for ostate fields, this is all cchmac_ctx_t adds to the ccdigest_ctx_t. */
49 #if CORECRYPTO_USE_TRANSPARENT_UNION
50 #define cchmac_ostate(_di_, HC) ((struct ccdigest_state *)(((cchmac_ctx_t)(HC)).hdr->b + ccdigest_di_size(_di_)))
52 #define cchmac_ostate(_di_, HC) ((struct ccdigest_state *)(((cchmac_ctx_t)(HC))->b + ccdigest_di_size(_di_)))
54 #define cchmac_ostate8(_di_, HC) (ccdigest_u8(cchmac_ostate(_di_, HC)))
55 #define cchmac_ostate32(_di_, HC) (ccdigest_u32(cchmac_ostate(_di_, HC)))
56 #define cchmac_ostate64(_di_, HC) (ccdigest_u64(cchmac_ostate(_di_, HC)))
57 #define cchmac_ostateccn(_di_, HC) (ccdigest_ccn(cchmac_ostate(_di_, HC)))
59 /* Convenience accessors for ccdigest_ctx_t fields. */
60 #if CORECRYPTO_USE_TRANSPARENT_UNION
61 #define cchmac_istate(_di_, HC) ccdigest_state(_di_, ((cchmac_ctx_t)(HC)).digest)
63 #define cchmac_istate(_di_, HC) ccdigest_state(_di_, ((ccdigest_ctx_t)(HC)))
65 #define cchmac_istate8(_di_, HC) ccdigest_u8(cchmac_istate(_di_, HC))
66 #define cchmac_istate32(_di_, HC) ccdigest_u32(cchmac_istate(_di_, HC))
67 #define cchmac_istate64(_di_, HC) ccdigest_u64(cchmac_istate(_di_, HC))
68 #define cchmac_istateccn(_di_, HC) ccdigest_ccn(cchmac_istate(_di_, HC))
70 #if CORECRYPTO_USE_TRANSPARENT_UNION
71 #define cchmac_data(_di_, HC) ccdigest_data(_di_, ((cchmac_ctx_t)(HC)).digest)
72 #define cchmac_num(_di_, HC) ccdigest_num(_di_, ((cchmac_ctx_t)(HC)).digest)
73 #define cchmac_nbits(_di_, HC) ccdigest_nbits(_di_, ((cchmac_ctx_t)(HC)).digest)
75 #define cchmac_data(_di_, HC) ccdigest_data(_di_, ((ccdigest_ctx_t)(HC)))
76 #define cchmac_num(_di_, HC) ccdigest_num(_di_, ((ccdigest_ctx_t)(HC)))
77 #define cchmac_nbits(_di_, HC) ccdigest_nbits(_di_, ((ccdigest_ctx_t)(HC)))
80 void cchmac_init(const struct ccdigest_info
*di
, cchmac_ctx_t ctx
,
81 size_t key_len
, const void *key
);
82 void cchmac_update(const struct ccdigest_info
*di
, cchmac_ctx_t ctx
,
83 size_t data_len
, const void *data
);
84 void cchmac_final(const struct ccdigest_info
*di
, cchmac_ctx_t ctx
,
87 void cchmac(const struct ccdigest_info
*di
, size_t key_len
,
88 const void *key
, size_t data_len
, const void *data
,
93 struct cchmac_test_input
{
94 const struct ccdigest_info
*di
;
100 const void *expected_mac
;
103 int cchmac_test(const struct cchmac_test_input
*input
);
104 int cchmac_test_chunks(const struct cchmac_test_input
*input
, size_t chunk_size
);
107 #endif /* _CORECRYPTO_CCHMAC_H_ */