lib/crypto: optimize aes_cmac_128
[gd/samba-autobuild/.git] / lib / crypto / aes_ccm_128.h
1 /*
2    AES-CCM-128 (rfc 3610)
3
4    Copyright (C) Stefan Metzmacher 2012
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifndef LIB_CRYPTO_AES_CCM_128_H
21 #define LIB_CRYPTO_AES_CCM_128_H
22
23 #define AES_CCM_128_M 16
24 #define AES_CCM_128_L 4
25 #define AES_CCM_128_NONCE_SIZE (15 - AES_CCM_128_L)
26
27 struct aes_ccm_128_context {
28         AES_KEY aes_key;
29         uint8_t nonce[AES_CCM_128_NONCE_SIZE];
30
31         size_t a_remain;
32         size_t m_remain;
33
34         uint8_t X_i[AES_BLOCK_SIZE];
35         uint8_t B_i[AES_BLOCK_SIZE];
36         size_t B_i_ofs;
37
38         uint8_t S_i[AES_BLOCK_SIZE];
39         size_t S_i_ofs;
40         size_t S_i_ctr;
41 };
42
43 void aes_ccm_128_init(struct aes_ccm_128_context *ctx,
44                       const uint8_t K[AES_BLOCK_SIZE],
45                       const uint8_t N[AES_CCM_128_NONCE_SIZE],
46                       size_t a_total, size_t m_total);
47 void aes_ccm_128_update(struct aes_ccm_128_context *ctx,
48                         const uint8_t *v, size_t v_len);
49 void aes_ccm_128_crypt(struct aes_ccm_128_context *ctx,
50                          uint8_t *m, size_t m_len);
51 void aes_ccm_128_digest(struct aes_ccm_128_context *ctx,
52                         uint8_t digest[AES_BLOCK_SIZE]);
53
54 #endif /* LIB_CRYPTO_AES_CCM_128_H */