Coverage Report

Created: 2024-06-28 06:39

/src/nettle-with-mini-gmp/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
508
{
41
508
  aes128_set_encrypt_key (&ocb_key->encrypt, key);
42
508
  ocb_set_key (&ocb_key->ocb, &ocb_key->encrypt, (nettle_cipher_func *) aes128_encrypt);
43
508
}
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
364
{
49
364
  ocb_aes128_set_encrypt_key (ocb_key, key);
50
364
  aes128_invert_key (decrypt, &ocb_key->encrypt);
51
364
}
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
508
{
57
508
  ocb_set_nonce (ctx, &key->encrypt, (nettle_cipher_func *) aes128_encrypt,
58
508
     tag_length, nonce_length, nonce);
59
508
}
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
4.14k
{
65
4.14k
  ocb_update (ctx, &key->ocb, &key->encrypt, (nettle_cipher_func *) aes128_encrypt,
66
4.14k
        length, data);
67
4.14k
}
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
1.67k
{
73
1.67k
  ocb_encrypt (ctx, &key->ocb, &key->encrypt, (nettle_cipher_func *) aes128_encrypt,
74
1.67k
         length, dst, src);
75
1.67k
}
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
1.25k
{
82
1.25k
  ocb_decrypt (ctx, &key->ocb, &key->encrypt, (nettle_cipher_func *) aes128_encrypt,
83
1.25k
         decrypt, (nettle_cipher_func *) aes128_decrypt,
84
1.25k
         length, dst, src);
85
1.25k
}
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
508
{
91
508
  ocb_digest (ctx, &key->ocb, &key->encrypt, (nettle_cipher_func *) aes128_encrypt,
92
508
        length, digest);
93
508
}
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
}