Coverage Report

Created: 2024-06-28 06:39

/src/nettle-with-mini-gmp/ccm-aes128.c
Line
Count
Source (jump to first uncovered line)
1
/* ccm-aes128.c
2
3
   Counter with CBC-MAC mode using AES128 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
void
45
ccm_aes128_set_key(struct ccm_aes128_ctx *ctx, const uint8_t *key)
46
91
{
47
91
  aes128_set_encrypt_key(&ctx->cipher, key);
48
91
}
49
50
void
51
ccm_aes128_set_nonce(struct ccm_aes128_ctx *ctx,
52
         size_t length, const uint8_t *nonce,
53
         size_t authlen, size_t msglen, size_t taglen)
54
91
{
55
91
  ccm_set_nonce(&ctx->ccm, &ctx->cipher, (nettle_cipher_func *) aes128_encrypt,
56
91
    length, nonce, authlen, msglen, taglen);
57
91
}
58
59
void
60
ccm_aes128_update(struct ccm_aes128_ctx *ctx,
61
      size_t length, const uint8_t *data)
62
57
{
63
57
  ccm_update(&ctx->ccm, &ctx->cipher, (nettle_cipher_func *) aes128_encrypt,
64
57
       length, data);
65
57
}
66
67
void
68
ccm_aes128_encrypt(struct ccm_aes128_ctx *ctx,
69
       size_t length, uint8_t *dst, const uint8_t *src)
70
78
{
71
78
  ccm_encrypt(&ctx->ccm, &ctx->cipher, (nettle_cipher_func *) aes128_encrypt,
72
78
        length, dst, src);
73
78
}
74
75
void
76
ccm_aes128_decrypt(struct ccm_aes128_ctx *ctx,
77
       size_t length, uint8_t *dst, const uint8_t *src)
78
52
{
79
52
  ccm_decrypt(&ctx->ccm, &ctx->cipher, (nettle_cipher_func *) aes128_encrypt,
80
52
        length, dst, src);
81
52
}
82
83
void
84
ccm_aes128_digest(struct ccm_aes128_ctx *ctx,
85
      size_t length, uint8_t *digest)
86
91
{
87
91
  ccm_digest(&ctx->ccm, &ctx->cipher, (nettle_cipher_func *) aes128_encrypt,
88
91
       length, digest);
89
91
}
90
91
void
92
ccm_aes128_encrypt_message(struct ccm_aes128_ctx *ctx,
93
         size_t nlength, const uint8_t *nonce,
94
         size_t alength, const uint8_t *adata,
95
         size_t tlength,
96
         size_t clength, uint8_t *dst, const uint8_t *src)
97
0
{
98
0
  ccm_encrypt_message(&ctx->cipher, (nettle_cipher_func *) aes128_encrypt,
99
0
          nlength, nonce, alength, adata,
100
0
          tlength, clength, dst, src);
101
0
}
102
103
int
104
ccm_aes128_decrypt_message(struct ccm_aes128_ctx *ctx,
105
         size_t nlength, const uint8_t *nonce,
106
         size_t alength, const uint8_t *adata,
107
         size_t tlength,
108
         size_t mlength, uint8_t *dst, const uint8_t *src)
109
0
{
110
0
  return ccm_decrypt_message(&ctx->cipher,
111
0
           (nettle_cipher_func *) aes128_encrypt,
112
0
           nlength, nonce, alength, adata,
113
0
           tlength, mlength, dst, src);
114
0
}