| 1 | /* |
| 2 | * cchmac.h |
| 3 | * corecrypto |
| 4 | * |
| 5 | * Created on 12/07/2010 |
| 6 | * |
| 7 | * Copyright (c) 2010,2011,2012,2014,2015 Apple Inc. All rights reserved. |
| 8 | * |
| 9 | */ |
| 10 | |
| 11 | #ifndef _CORECRYPTO_CCHMAC_H_ |
| 12 | #define _CORECRYPTO_CCHMAC_H_ |
| 13 | |
| 14 | #include <corecrypto/cc.h> |
| 15 | #include <corecrypto/ccdigest.h> |
| 16 | |
| 17 | /* An hmac_ctx_t is normally allocated as an array of these. */ |
| 18 | struct cchmac_ctx { |
| 19 | uint8_t b[8]; |
| 20 | } CC_ALIGNED(8); |
| 21 | |
| 22 | typedef struct cchmac_ctx* cchmac_ctx_t; |
| 23 | |
| 24 | #define cchmac_ctx_size(STATE_SIZE, BLOCK_SIZE) (ccdigest_ctx_size(STATE_SIZE, BLOCK_SIZE) + (STATE_SIZE)) |
| 25 | #define cchmac_di_size(_di_) (cchmac_ctx_size((_di_)->state_size, (_di_)->block_size)) |
| 26 | |
| 27 | #define cchmac_ctx_n(STATE_SIZE, BLOCK_SIZE) ccn_nof_size(cchmac_ctx_size((STATE_SIZE), (BLOCK_SIZE))) |
| 28 | |
| 29 | #define cchmac_ctx_decl(STATE_SIZE, BLOCK_SIZE, _name_) cc_ctx_decl(struct cchmac_ctx, cchmac_ctx_size(STATE_SIZE, BLOCK_SIZE), _name_) |
| 30 | #define cchmac_ctx_clear(STATE_SIZE, BLOCK_SIZE, _name_) cc_clear(cchmac_ctx_size(STATE_SIZE, BLOCK_SIZE), _name_) |
| 31 | #define cchmac_di_decl(_di_, _name_) cchmac_ctx_decl((_di_)->state_size, (_di_)->block_size, _name_) |
| 32 | #define cchmac_di_clear(_di_, _name_) cchmac_ctx_clear((_di_)->state_size, (_di_)->block_size, _name_) |
| 33 | |
| 34 | /* Return a ccdigest_ctx_t which can be accesed with the macros in ccdigest.h */ |
| 35 | #define cchmac_digest_ctx(_di_, HC) ((ccdigest_ctx_t)(HC)) |
| 36 | |
| 37 | /* Accesors for ostate fields, this is all cchmac_ctx_t adds to the ccdigest_ctx_t. */ |
| 38 | #define cchmac_ostate(_di_, HC) ((struct ccdigest_state *)(((cchmac_ctx_t)(HC))->b + ccdigest_di_size(_di_))) |
| 39 | #define cchmac_ostate8(_di_, HC) (ccdigest_u8(cchmac_ostate(_di_, HC))) |
| 40 | #define cchmac_ostate32(_di_, HC) (ccdigest_u32(cchmac_ostate(_di_, HC))) |
| 41 | #define cchmac_ostate64(_di_, HC) (ccdigest_u64(cchmac_ostate(_di_, HC))) |
| 42 | #define cchmac_ostateccn(_di_, HC) (ccdigest_ccn(cchmac_ostate(_di_, HC))) |
| 43 | |
| 44 | /* Convenience accessors for ccdigest_ctx_t fields. */ |
| 45 | #define cchmac_istate(_di_, HC) ccdigest_state(_di_, ((ccdigest_ctx_t)(HC))) |
| 46 | #define cchmac_istate8(_di_, HC) ccdigest_u8(cchmac_istate(_di_, HC)) |
| 47 | #define cchmac_istate32(_di_, HC) ccdigest_u32(cchmac_istate(_di_, HC)) |
| 48 | #define cchmac_istate64(_di_, HC) ccdigest_u64(cchmac_istate(_di_, HC)) |
| 49 | #define cchmac_istateccn(_di_, HC) ccdigest_ccn(cchmac_istate(_di_, HC)) |
| 50 | |
| 51 | #define cchmac_data(_di_, HC) ccdigest_data(_di_, ((ccdigest_ctx_t)(HC))) |
| 52 | #define cchmac_num(_di_, HC) ccdigest_num(_di_, ((ccdigest_ctx_t)(HC))) |
| 53 | #define cchmac_nbits(_di_, HC) ccdigest_nbits(_di_, ((ccdigest_ctx_t)(HC))) |
| 54 | |
| 55 | void cchmac_init(const struct ccdigest_info *di, cchmac_ctx_t ctx, |
| 56 | size_t key_len, const void *key); |
| 57 | void cchmac_update(const struct ccdigest_info *di, cchmac_ctx_t ctx, |
| 58 | size_t data_len, const void *data); |
| 59 | void cchmac_final(const struct ccdigest_info *di, cchmac_ctx_t ctx, |
| 60 | unsigned char *mac); |
| 61 | |
| 62 | void cchmac(const struct ccdigest_info *di, size_t key_len, |
| 63 | const void *key, size_t data_len, const void *data, |
| 64 | unsigned char *mac); |
| 65 | |
| 66 | #endif /* _CORECRYPTO_CCHMAC_H_ */ |
| 67 | |