]> git.saurik.com Git - apple/xnu.git/blame - EXTERNAL_HEADERS/corecrypto/cchmac.h
xnu-7195.101.1.tar.gz
[apple/xnu.git] / EXTERNAL_HEADERS / corecrypto / cchmac.h
CommitLineData
f427ee49 1/* Copyright (c) (2010,2011,2012,2014,2015,2016,2017,2018,2019) Apple Inc. All rights reserved.
316670eb 2 *
f427ee49
A
3 * corecrypto is licensed under Apple Inc.’s Internal Use License Agreement (which
4 * is contained in the License.txt file distributed with corecrypto) and only to
5 * people who accept that license. IMPORTANT: Any license rights granted to you by
6 * Apple Inc. (if any) are limited to internal use within your organization only on
7 * devices and computers you own or control, for the sole purpose of verifying the
8 * security characteristics and correct functioning of the Apple Software. You may
9 * not, directly or indirectly, redistribute the Apple Software or any portions thereof.
316670eb
A
10 */
11
12#ifndef _CORECRYPTO_CCHMAC_H_
13#define _CORECRYPTO_CCHMAC_H_
14
15#include <corecrypto/cc.h>
16#include <corecrypto/ccdigest.h>
17
18/* An hmac_ctx_t is normally allocated as an array of these. */
19struct cchmac_ctx {
cb323159 20 uint8_t b[1];
39037602 21} CC_ALIGNED(8);
316670eb 22
5ba3f43e 23typedef struct cchmac_ctx* cchmac_ctx_t;
316670eb 24
cb323159 25#define cchmac_ctx_size(STATE_SIZE, BLOCK_SIZE) (cc_pad_align(ccdigest_ctx_size(STATE_SIZE, BLOCK_SIZE)) + (STATE_SIZE))
316670eb
A
26#define cchmac_di_size(_di_) (cchmac_ctx_size((_di_)->state_size, (_di_)->block_size))
27
28#define cchmac_ctx_n(STATE_SIZE, BLOCK_SIZE) ccn_nof_size(cchmac_ctx_size((STATE_SIZE), (BLOCK_SIZE)))
29
30#define cchmac_ctx_decl(STATE_SIZE, BLOCK_SIZE, _name_) cc_ctx_decl(struct cchmac_ctx, cchmac_ctx_size(STATE_SIZE, BLOCK_SIZE), _name_)
3e170ce0 31#define cchmac_ctx_clear(STATE_SIZE, BLOCK_SIZE, _name_) cc_clear(cchmac_ctx_size(STATE_SIZE, BLOCK_SIZE), _name_)
316670eb
A
32#define cchmac_di_decl(_di_, _name_) cchmac_ctx_decl((_di_)->state_size, (_di_)->block_size, _name_)
33#define cchmac_di_clear(_di_, _name_) cchmac_ctx_clear((_di_)->state_size, (_di_)->block_size, _name_)
34
35/* Return a ccdigest_ctx_t which can be accesed with the macros in ccdigest.h */
5ba3f43e 36#define cchmac_digest_ctx(_di_, HC) ((ccdigest_ctx_t)(HC))
316670eb
A
37
38/* Accesors for ostate fields, this is all cchmac_ctx_t adds to the ccdigest_ctx_t. */
cb323159 39#define cchmac_ostate(_di_, HC) ((struct ccdigest_state *)(((cchmac_ctx_t)(HC))->b + cc_pad_align(ccdigest_di_size(_di_))))
316670eb
A
40#define cchmac_ostate8(_di_, HC) (ccdigest_u8(cchmac_ostate(_di_, HC)))
41#define cchmac_ostate32(_di_, HC) (ccdigest_u32(cchmac_ostate(_di_, HC)))
42#define cchmac_ostate64(_di_, HC) (ccdigest_u64(cchmac_ostate(_di_, HC)))
43#define cchmac_ostateccn(_di_, HC) (ccdigest_ccn(cchmac_ostate(_di_, HC)))
44
45/* Convenience accessors for ccdigest_ctx_t fields. */
5ba3f43e 46#define cchmac_istate(_di_, HC) ccdigest_state(_di_, ((ccdigest_ctx_t)(HC)))
fe8ab488
A
47#define cchmac_istate8(_di_, HC) ccdigest_u8(cchmac_istate(_di_, HC))
48#define cchmac_istate32(_di_, HC) ccdigest_u32(cchmac_istate(_di_, HC))
49#define cchmac_istate64(_di_, HC) ccdigest_u64(cchmac_istate(_di_, HC))
50#define cchmac_istateccn(_di_, HC) ccdigest_ccn(cchmac_istate(_di_, HC))
5ba3f43e 51
5ba3f43e
A
52#define cchmac_data(_di_, HC) ccdigest_data(_di_, ((ccdigest_ctx_t)(HC)))
53#define cchmac_num(_di_, HC) ccdigest_num(_di_, ((ccdigest_ctx_t)(HC)))
54#define cchmac_nbits(_di_, HC) ccdigest_nbits(_di_, ((ccdigest_ctx_t)(HC)))
316670eb
A
55
56void cchmac_init(const struct ccdigest_info *di, cchmac_ctx_t ctx,
39037602 57 size_t key_len, const void *key);
316670eb 58void cchmac_update(const struct ccdigest_info *di, cchmac_ctx_t ctx,
39037602 59 size_t data_len, const void *data);
316670eb
A
60void cchmac_final(const struct ccdigest_info *di, cchmac_ctx_t ctx,
61 unsigned char *mac);
62
39037602
A
63void cchmac(const struct ccdigest_info *di, size_t key_len,
64 const void *key, size_t data_len, const void *data,
316670eb
A
65 unsigned char *mac);
66
316670eb 67#endif /* _CORECRYPTO_CCHMAC_H_ */