/src/nettle-with-libgmp/ocb-aes128.c
Line  | Count  | Source (jump to first uncovered line)  | 
1  |  | /* ocb-aes128.c  | 
2  |  |  | 
3  |  |    Copyright (C) 2022 Niels Möller  | 
4  |  |  | 
5  |  |    This file is part of GNU Nettle.  | 
6  |  |  | 
7  |  |    GNU Nettle is free software: you can redistribute it and/or  | 
8  |  |    modify it under the terms of either:  | 
9  |  |  | 
10  |  |      * the GNU Lesser General Public License as published by the Free  | 
11  |  |        Software Foundation; either version 3 of the License, or (at your  | 
12  |  |        option) any later version.  | 
13  |  |  | 
14  |  |    or  | 
15  |  |  | 
16  |  |      * the GNU General Public License as published by the Free  | 
17  |  |        Software Foundation; either version 2 of the License, or (at your  | 
18  |  |        option) any later version.  | 
19  |  |  | 
20  |  |    or both in parallel, as here.  | 
21  |  |  | 
22  |  |    GNU Nettle is distributed in the hope that it will be useful,  | 
23  |  |    but WITHOUT ANY WARRANTY; without even the implied warranty of  | 
24  |  |    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU  | 
25  |  |    General Public License for more details.  | 
26  |  |  | 
27  |  |    You should have received copies of the GNU General Public License and  | 
28  |  |    the GNU Lesser General Public License along with this program.  If  | 
29  |  |    not, see http://www.gnu.org/licenses/.  | 
30  |  | */  | 
31  |  |  | 
32  |  | #if HAVE_CONFIG_H  | 
33  |  | # include "config.h"  | 
34  |  | #endif  | 
35  |  |  | 
36  |  | #include "ocb.h"  | 
37  |  |  | 
38  |  | void  | 
39  |  | ocb_aes128_set_encrypt_key (struct ocb_aes128_encrypt_key *ocb_key, const uint8_t *key)  | 
40  | 975  | { | 
41  | 975  |   aes128_set_encrypt_key (&ocb_key->encrypt, key);  | 
42  | 975  |   ocb_set_key (&ocb_key->ocb, &ocb_key->encrypt, (nettle_cipher_func *) aes128_encrypt);  | 
43  | 975  | }  | 
44  |  |  | 
45  |  | void  | 
46  |  | ocb_aes128_set_decrypt_key (struct ocb_aes128_encrypt_key *ocb_key, struct aes128_ctx *decrypt,  | 
47  |  |           const uint8_t *key)  | 
48  | 707  | { | 
49  | 707  |   ocb_aes128_set_encrypt_key (ocb_key, key);  | 
50  | 707  |   aes128_invert_key (decrypt, &ocb_key->encrypt);  | 
51  | 707  | }  | 
52  |  |  | 
53  |  | void  | 
54  |  | ocb_aes128_set_nonce (struct ocb_ctx *ctx, const struct ocb_aes128_encrypt_key *key,  | 
55  |  |           size_t tag_length, size_t nonce_length, const uint8_t *nonce)  | 
56  | 975  | { | 
57  | 975  |   ocb_set_nonce (ctx, &key->encrypt, (nettle_cipher_func *) aes128_encrypt,  | 
58  | 975  |      tag_length, nonce_length, nonce);  | 
59  | 975  | }  | 
60  |  |  | 
61  |  | void  | 
62  |  | ocb_aes128_update (struct ocb_ctx *ctx, const struct ocb_aes128_encrypt_key *key,  | 
63  |  |        size_t length, const uint8_t *data)  | 
64  | 9.24k  | { | 
65  | 9.24k  |   ocb_update (ctx, &key->ocb, &key->encrypt, (nettle_cipher_func *) aes128_encrypt,  | 
66  | 9.24k  |         length, data);  | 
67  | 9.24k  | }  | 
68  |  |  | 
69  |  | void  | 
70  |  | ocb_aes128_encrypt(struct ocb_ctx *ctx, const struct ocb_aes128_encrypt_key *key,  | 
71  |  |        size_t length, uint8_t *dst, const uint8_t *src)  | 
72  | 4.79k  | { | 
73  | 4.79k  |   ocb_encrypt (ctx, &key->ocb, &key->encrypt, (nettle_cipher_func *) aes128_encrypt,  | 
74  | 4.79k  |          length, dst, src);  | 
75  | 4.79k  | }  | 
76  |  |  | 
77  |  | void  | 
78  |  | ocb_aes128_decrypt(struct ocb_ctx *ctx, const struct ocb_aes128_encrypt_key *key,  | 
79  |  |        const struct aes128_ctx *decrypt,  | 
80  |  |        size_t length, uint8_t *dst, const uint8_t *src)  | 
81  | 2.84k  | { | 
82  | 2.84k  |   ocb_decrypt (ctx, &key->ocb, &key->encrypt, (nettle_cipher_func *) aes128_encrypt,  | 
83  | 2.84k  |          decrypt, (nettle_cipher_func *) aes128_decrypt,  | 
84  | 2.84k  |          length, dst, src);  | 
85  | 2.84k  | }  | 
86  |  |  | 
87  |  | void  | 
88  |  | ocb_aes128_digest(struct ocb_ctx *ctx, const struct ocb_aes128_encrypt_key *key,  | 
89  |  |       size_t length, uint8_t *digest)  | 
90  | 975  | { | 
91  | 975  |   ocb_digest (ctx, &key->ocb, &key->encrypt, (nettle_cipher_func *) aes128_encrypt,  | 
92  | 975  |         length, digest);  | 
93  | 975  | }  | 
94  |  |  | 
95  |  | void  | 
96  |  | ocb_aes128_encrypt_message (const struct ocb_aes128_encrypt_key *key,  | 
97  |  |           size_t nlength, const uint8_t *nonce,  | 
98  |  |           size_t alength, const uint8_t *adata,  | 
99  |  |           size_t tlength,  | 
100  |  |           size_t clength, uint8_t *dst, const uint8_t *src)  | 
101  | 0  | { | 
102  | 0  |   ocb_encrypt_message (&key->ocb, &key->encrypt, (nettle_cipher_func *) aes128_encrypt,  | 
103  | 0  |            nlength, nonce, alength, adata, tlength, clength, dst, src);  | 
104  | 0  | }  | 
105  |  |  | 
106  |  | int  | 
107  |  | ocb_aes128_decrypt_message (const struct ocb_aes128_encrypt_key *key,  | 
108  |  |           const struct aes128_ctx *decrypt,  | 
109  |  |           size_t nlength, const uint8_t *nonce,  | 
110  |  |           size_t alength, const uint8_t *adata,  | 
111  |  |           size_t tlength,  | 
112  |  |           size_t mlength, uint8_t *dst, const uint8_t *src)  | 
113  | 0  | { | 
114  | 0  |   return ocb_decrypt_message (&key->ocb, &key->encrypt, (nettle_cipher_func *) aes128_encrypt,  | 
115  | 0  |             &decrypt, (nettle_cipher_func *) aes128_decrypt,  | 
116  | 0  |             nlength, nonce, alength, adata,  | 
117  | 0  |             tlength, mlength, dst, src);  | 
118  | 0  | }  |