dlopen-test: Use libnettle.dylib on MacOS.
[gd/nettle] / siv-cmac-aes128.c
1 /* siv-cmac-aes128.c
2
3    AES-SIV, RFC5297
4
5    Copyright (C) 2017 Nikos Mavrogiannopoulos
6
7    This file is part of GNU Nettle.
8
9    GNU Nettle is free software: you can redistribute it and/or
10    modify it under the terms of either:
11
12      * the GNU Lesser General Public License as published by the Free
13        Software Foundation; either version 3 of the License, or (at your
14        option) any later version.
15
16    or
17
18      * the GNU General Public License as published by the Free
19        Software Foundation; either version 2 of the License, or (at your
20        option) any later version.
21
22    or both in parallel, as here.
23
24    GNU Nettle is distributed in the hope that it will be useful,
25    but WITHOUT ANY WARRANTY; without even the implied warranty of
26    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
27    General Public License for more details.
28
29    You should have received copies of the GNU General Public License and
30    the GNU Lesser General Public License along with this program.  If
31    not, see http://www.gnu.org/licenses/.
32 */
33
34 #if HAVE_CONFIG_H
35 # include "config.h"
36 #endif
37
38 #include <assert.h>
39 #include <string.h>
40
41 #include "aes.h"
42 #include "siv-cmac.h"
43 #include "cmac.h"
44 #include "ctr.h"
45 #include "memxor.h"
46 #include "memops.h"
47
48 void
49 siv_cmac_aes128_set_key(struct siv_cmac_aes128_ctx *ctx, const uint8_t *key)
50 {
51   siv_cmac_set_key(&ctx->cmac_key, &ctx->cmac_cipher, &ctx->ctr_cipher, &nettle_aes128, key);
52 }
53
54 void
55 siv_cmac_aes128_encrypt_message(const struct siv_cmac_aes128_ctx *ctx,
56                                 size_t nlength, const uint8_t *nonce,
57                                 size_t alength, const uint8_t *adata,
58                                 size_t clength, uint8_t *dst, const uint8_t *src)
59 {
60   siv_cmac_encrypt_message(&ctx->cmac_key, &ctx->cmac_cipher,
61                            &nettle_aes128, &ctx->ctr_cipher,
62                            nlength, nonce, alength, adata,
63                            clength, dst, src);
64 }
65
66 int
67 siv_cmac_aes128_decrypt_message(const struct siv_cmac_aes128_ctx *ctx,
68                                 size_t nlength, const uint8_t *nonce,
69                                 size_t alength, const uint8_t *adata,
70                                 size_t mlength, uint8_t *dst, const uint8_t *src)
71 {
72   return siv_cmac_decrypt_message(&ctx->cmac_key, &ctx->cmac_cipher,
73                                   &nettle_aes128, &ctx->ctr_cipher,
74                                   nlength, nonce, alength, adata,
75                                   mlength, dst, src);
76 }