/src/nettle-with-libgmp/ccm-aes256.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /* ccm-aes256.c  | 
2  |  |  | 
3  |  |    Counter with CBC-MAC mode using AES256 as the underlying cipher.  | 
4  |  |  | 
5  |  |    Copyright (C) 2014 Exegin Technologies Limited  | 
6  |  |    Copyright (C) 2014 Owen Kirby  | 
7  |  |  | 
8  |  |    This file is part of GNU Nettle.  | 
9  |  |  | 
10  |  |    GNU Nettle is free software: you can redistribute it and/or  | 
11  |  |    modify it under the terms of either:  | 
12  |  |  | 
13  |  |      * the GNU Lesser General Public License as published by the Free  | 
14  |  |        Software Foundation; either version 3 of the License, or (at your  | 
15  |  |        option) any later version.  | 
16  |  |  | 
17  |  |    or  | 
18  |  |  | 
19  |  |      * the GNU General Public License as published by the Free  | 
20  |  |        Software Foundation; either version 2 of the License, or (at your  | 
21  |  |        option) any later version.  | 
22  |  |  | 
23  |  |    or both in parallel, as here.  | 
24  |  |  | 
25  |  |    GNU Nettle is distributed in the hope that it will be useful,  | 
26  |  |    but WITHOUT ANY WARRANTY; without even the implied warranty of  | 
27  |  |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  | 
28  |  |    General Public License for more details.  | 
29  |  |  | 
30  |  |    You should have received copies of the GNU General Public License and  | 
31  |  |    the GNU Lesser General Public License along with this program.  If  | 
32  |  |    not, see http://www.gnu.org/licenses/.  | 
33  |  | */  | 
34  |  |  | 
35  |  | #if HAVE_CONFIG_H  | 
36  |  | # include "config.h"  | 
37  |  | #endif  | 
38  |  |  | 
39  |  | #include <assert.h>  | 
40  |  |  | 
41  |  | #include "aes.h"  | 
42  |  | #include "ccm.h"  | 
43  |  |  | 
44  |  |  | 
45  |  | void  | 
46  |  | ccm_aes256_set_key(struct ccm_aes256_ctx *ctx, const uint8_t *key)  | 
47  | 227  | { | 
48  | 227  |   aes256_set_encrypt_key(&ctx->cipher, key);  | 
49  | 227  | }  | 
50  |  |  | 
51  |  | void  | 
52  |  | ccm_aes256_set_nonce(struct ccm_aes256_ctx *ctx,  | 
53  |  |          size_t length, const uint8_t *nonce,  | 
54  |  |          size_t authlen, size_t msglen, size_t taglen)  | 
55  | 227  | { | 
56  | 227  |   ccm_set_nonce(&ctx->ccm, &ctx->cipher, (nettle_cipher_func *) aes256_encrypt,  | 
57  | 227  |     length, nonce, authlen, msglen, taglen);  | 
58  | 227  | }  | 
59  |  |  | 
60  |  | void  | 
61  |  | ccm_aes256_update(struct ccm_aes256_ctx *ctx,  | 
62  |  |       size_t length, const uint8_t *data)  | 
63  | 125  | { | 
64  | 125  |   ccm_update(&ctx->ccm, &ctx->cipher, (nettle_cipher_func *) aes256_encrypt,  | 
65  | 125  |        length, data);  | 
66  | 125  | }  | 
67  |  |  | 
68  |  | void  | 
69  |  | ccm_aes256_encrypt(struct ccm_aes256_ctx *ctx,  | 
70  |  |        size_t length, uint8_t *dst, const uint8_t *src)  | 
71  | 827  | { | 
72  | 827  |   ccm_encrypt(&ctx->ccm, &ctx->cipher, (nettle_cipher_func *) aes256_encrypt,  | 
73  | 827  |         length, dst, src);  | 
74  | 827  | }  | 
75  |  |  | 
76  |  | void  | 
77  |  | ccm_aes256_decrypt(struct ccm_aes256_ctx *ctx,  | 
78  |  |        size_t length, uint8_t *dst, const uint8_t *src)  | 
79  | 176  | { | 
80  | 176  |   ccm_decrypt(&ctx->ccm, &ctx->cipher, (nettle_cipher_func *) aes256_encrypt,  | 
81  | 176  |         length, dst, src);  | 
82  | 176  | }  | 
83  |  |  | 
84  |  | void  | 
85  |  | ccm_aes256_digest(struct ccm_aes256_ctx *ctx,  | 
86  |  |       size_t length, uint8_t *digest)  | 
87  | 227  | { | 
88  | 227  |   ccm_digest(&ctx->ccm, &ctx->cipher, (nettle_cipher_func *) aes256_encrypt,  | 
89  | 227  |        length, digest);  | 
90  | 227  | }  | 
91  |  |  | 
92  |  | void  | 
93  |  | ccm_aes256_encrypt_message(struct ccm_aes256_ctx *ctx,  | 
94  |  |          size_t nlength, const uint8_t *nonce,  | 
95  |  |          size_t alength, const uint8_t *adata,  | 
96  |  |          size_t tlength,  | 
97  |  |          size_t clength, uint8_t *dst, const uint8_t *src)  | 
98  | 0  | { | 
99  | 0  |   ccm_encrypt_message(&ctx->cipher, (nettle_cipher_func *) aes256_encrypt,  | 
100  | 0  |           nlength, nonce, alength, adata,  | 
101  | 0  |           tlength, clength, dst, src);  | 
102  | 0  | }  | 
103  |  |  | 
104  |  | int  | 
105  |  | ccm_aes256_decrypt_message(struct ccm_aes256_ctx *ctx,  | 
106  |  |          size_t nlength, const uint8_t *nonce,  | 
107  |  |          size_t alength, const uint8_t *adata,  | 
108  |  |          size_t tlength,  | 
109  |  |          size_t mlength, uint8_t *dst, const uint8_t *src)  | 
110  | 0  | { | 
111  | 0  |   return ccm_decrypt_message(&ctx->cipher, (nettle_cipher_func *) aes256_encrypt,  | 
112  | 0  |            nlength, nonce, alength, adata,  | 
113  | 0  |            tlength, mlength, dst, src);  | 
114  | 0  | }  |