1 /*
2  * Copyright 2024 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9 
10 #include <openssl/proverr.h>
11 #include "prov/ciphercommon.h"
12 #include "crypto/aes_platform.h"
13 
14 int ossl_cipher_capable_aes_cbc_hmac_sha1_etm(void);
15 int ossl_cipher_capable_aes_cbc_hmac_sha256_etm(void);
16 int ossl_cipher_capable_aes_cbc_hmac_sha512_etm(void);
17 
18 typedef struct prov_cipher_hw_aes_hmac_sha_ctx_etm_st {
19     PROV_CIPHER_HW base; /* must be first */
20     void (*init_mac_key)(void *ctx, const unsigned char *inkey, size_t inlen);
21 } PROV_CIPHER_HW_AES_HMAC_SHA_ETM;
22 
23 const PROV_CIPHER_HW_AES_HMAC_SHA_ETM *ossl_prov_cipher_hw_aes_cbc_hmac_sha1_etm(void);
24 const PROV_CIPHER_HW_AES_HMAC_SHA_ETM *ossl_prov_cipher_hw_aes_cbc_hmac_sha256_etm(void);
25 const PROV_CIPHER_HW_AES_HMAC_SHA_ETM *ossl_prov_cipher_hw_aes_cbc_hmac_sha512_etm(void);
26 
27 #ifdef AES_CBC_HMAC_SHA_ETM_CAPABLE
28 # include <openssl/aes.h>
29 # include <openssl/sha.h>
30 
31 # define AES_CBC_MAX_HMAC_SIZE 64
32 
33 typedef struct prov_aes_hmac_sha_etm_ctx_st {
34     PROV_CIPHER_CTX base;
35     AES_KEY ks;
36     const PROV_CIPHER_HW_AES_HMAC_SHA_ETM *hw;
37     unsigned char tag[AES_CBC_MAX_HMAC_SIZE];
38     unsigned char exp_tag[AES_CBC_MAX_HMAC_SIZE];
39     size_t taglen;
40 } PROV_AES_HMAC_SHA_ETM_CTX;
41 
42 typedef struct prov_aes_hmac_sha1_etm_ctx_st {
43     PROV_AES_HMAC_SHA_ETM_CTX base_ctx;
44     SHA_CTX head, tail;
45 } PROV_AES_HMAC_SHA1_ETM_CTX;
46 
47 typedef struct prov_aes_hmac_sha256_etm_ctx_st {
48     PROV_AES_HMAC_SHA_ETM_CTX base_ctx;
49     SHA256_CTX head, tail;
50 } PROV_AES_HMAC_SHA256_ETM_CTX;
51 
52 typedef struct prov_aes_hmac_sha512_etm_ctx_st {
53     PROV_AES_HMAC_SHA_ETM_CTX base_ctx;
54     SHA512_CTX head, tail, md;
55 } PROV_AES_HMAC_SHA512_ETM_CTX;
56 
57 typedef struct {
58     struct {
59         uint8_t *key;
60         uint8_t key_rounds;
61         uint8_t *iv;
62     } cipher;
63     struct {
64         struct {
65             uint8_t *i_key_pad;
66             uint8_t *o_key_pad;
67         } hmac;
68     } digest;
69 } CIPH_DIGEST;
70 
71 #endif /* AES_CBC_HMAC_SHA_ETM_CAPABLE */
72