• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

cryspen / hacl-packages / 5808703668

pending completion
5808703668

Pull #418

github

web-flow
Merge 4abdd0203 into 1575f26e8
Pull Request #418: Add support for Hacl_AES_128_GCM_NI and Hacl_AES_128_GCM_M32

7433 of 7433 new or added lines in 12 files covered. (100.0%)

31975 of 62256 relevant lines covered (51.36%)

1238863.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

68.63
/src/Hacl_AES_256_GCM_CT64.c
1
/* MIT License
2
 *
3
 * Copyright (c) 2016-2022 INRIA, CMU and Microsoft Corporation
4
 * Copyright (c) 2022-2023 HACL* Contributors
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in all
14
 * copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
 * SOFTWARE.
23
 */
24

25

26
#include "Hacl_AES_256_GCM_CT64.h"
27

28
uint32_t Hacl_AES_256_GCM_CT64_aes_gcm_ctx_len = (uint32_t)148U;
29

30
void Hacl_AES_256_GCM_CT64_aes256_gcm_init(uint64_t *ctx, uint8_t *key)
31
{
2,976✔
32
  uint8_t gcm_key[16U] = { 0U };
2,976✔
33
  uint8_t nonce0[12U] = { 0U };
2,976✔
34
  uint64_t *aes_ctx = ctx;
2,976✔
35
  uint64_t *gcm_ctx = ctx + (uint32_t)128U;
2,976✔
36
  Hacl_AES_256_CTR32_BitSlice_aes256_init(aes_ctx, key, nonce0);
2,976✔
37
  Hacl_AES_256_CTR32_BitSlice_aes256_key_block(gcm_key, aes_ctx, (uint32_t)0U);
2,976✔
38
  Hacl_Gf128_CT64_gcm_init(gcm_ctx, gcm_key);
2,976✔
39
}
2,976✔
40

41
void
42
Hacl_AES_256_GCM_CT64_aes256_gcm_encrypt(
43
  uint64_t *ctx,
44
  uint32_t len,
45
  uint8_t *out,
46
  uint8_t *text,
47
  uint32_t aad_len,
48
  uint8_t *aad,
49
  uint32_t iv_len,
50
  uint8_t *iv
51
)
52
{
2,976✔
53
  uint8_t tmp[16U] = { 0U };
2,976✔
54
  uint8_t *cip = out;
2,976✔
55
  uint64_t *aes_ctx = ctx;
2,976✔
56
  uint64_t *gcm_ctx = ctx + (uint32_t)128U;
2,976✔
57
  uint64_t *tag_mix = ctx + (uint32_t)146U;
2,976✔
58
  uint32_t ctr;
2,976✔
59
  uint8_t tag_mix10[16U] = { 0U };
2,976✔
60
  uint8_t gcm_key[16U] = { 0U };
2,976✔
61
  uint8_t tag_iv[16U] = { 0U };
2,976✔
62
  uint8_t size_iv[16U] = { 0U };
2,976✔
63
  uint8_t tag_mix1[16U] = { 0U };
2,976✔
64
  if (iv_len == (uint32_t)12U)
2,976✔
65
  {
2,976✔
66
    uint64_t *aes_ctx1 = ctx;
2,976✔
67
    Hacl_AES_256_CTR32_BitSlice_aes256_set_nonce(aes_ctx1, iv);
2,976✔
68
    Hacl_AES_256_CTR32_BitSlice_aes256_key_block(tag_mix10, aes_ctx1, (uint32_t)1U);
2,976✔
69
    uint64_t u = load64_le(tag_mix10);
2,976✔
70
    ctx[146U] = u;
2,976✔
71
    uint64_t u0 = load64_le(tag_mix10 + (uint32_t)8U);
2,976✔
72
    ctx[147U] = u0;
2,976✔
73
    ctr = (uint32_t)2U;
2,976✔
74
  }
2,976✔
75
  else
×
76
  {
×
77
    uint64_t *aes_ctx1 = ctx;
×
78
    uint64_t *gcm_ctx1 = ctx + (uint32_t)128U;
×
79
    store64_be(gcm_key + (uint32_t)8U, gcm_ctx1[8U]);
×
80
    store64_be(gcm_key, gcm_ctx1[9U]);
×
81
    Hacl_Gf128_CT64_ghash(tag_iv, iv_len, iv, gcm_key);
×
82
    store64_be(size_iv + (uint32_t)8U, (uint64_t)(iv_len * (uint32_t)8U));
×
83
    KRML_MAYBE_FOR16(i,
×
84
      (uint32_t)0U,
×
85
      (uint32_t)16U,
×
86
      (uint32_t)1U,
×
87
      size_iv[i] = tag_iv[i] ^ size_iv[i];);
×
88
    Hacl_Gf128_CT64_ghash(tag_iv, (uint32_t)16U, size_iv, gcm_key);
×
89
    Hacl_AES_256_CTR32_BitSlice_aes256_set_nonce(aes_ctx1, tag_iv);
×
90
    uint32_t u0 = load32_be(tag_iv + (uint32_t)12U);
×
91
    uint32_t ctr0 = u0;
×
92
    Hacl_AES_256_CTR32_BitSlice_aes256_key_block(tag_mix1, aes_ctx1, ctr0);
×
93
    uint64_t u = load64_le(tag_mix1);
×
94
    ctx[146U] = u;
×
95
    uint64_t u1 = load64_le(tag_mix1 + (uint32_t)8U);
×
96
    ctx[147U] = u1;
×
97
    ctr = ctr0 + (uint32_t)1U;
×
98
  }
×
99
  Hacl_AES_256_CTR32_BitSlice_aes256_ctr(len, cip, text, aes_ctx, ctr);
2,976✔
100
  gcm_ctx[0U] = (uint64_t)0U;
2,976✔
101
  gcm_ctx[1U] = (uint64_t)0U;
2,976✔
102
  Hacl_Gf128_CT64_gcm_update_blocks_padded(gcm_ctx, aad_len, aad);
2,976✔
103
  Hacl_Gf128_CT64_gcm_update_blocks_padded(gcm_ctx, len, cip);
2,976✔
104
  store64_be(tmp, (uint64_t)(aad_len * (uint32_t)8U));
2,976✔
105
  store64_be(tmp + (uint32_t)8U, (uint64_t)(len * (uint32_t)8U));
2,976✔
106
  Hacl_Gf128_CT64_gcm_update_blocks(gcm_ctx, (uint32_t)16U, tmp);
2,976✔
107
  Hacl_Gf128_CT64_gcm_emit(tmp, gcm_ctx);
2,976✔
108
  uint64_t u0 = load64_le(tmp);
2,976✔
109
  uint64_t tmp0 = u0;
2,976✔
110
  uint64_t u = load64_le(tmp + (uint32_t)8U);
2,976✔
111
  uint64_t tmp1 = u;
2,976✔
112
  uint64_t tmp01 = tmp0 ^ tag_mix[0U];
2,976✔
113
  uint64_t tmp11 = tmp1 ^ tag_mix[1U];
2,976✔
114
  store64_le(out + len, tmp01);
2,976✔
115
  store64_le(out + len + (uint32_t)8U, tmp11);
2,976✔
116
}
2,976✔
117

118
bool
119
Hacl_AES_256_GCM_CT64_aes256_gcm_decrypt(
120
  uint64_t *ctx,
121
  uint32_t len,
122
  uint8_t *out,
123
  uint8_t *cipher,
124
  uint32_t aad_len,
125
  uint8_t *aad,
126
  uint32_t iv_len,
127
  uint8_t *iv
128
)
129
{
2,976✔
130
  uint8_t scratch[18U] = { 0U };
2,976✔
131
  uint8_t *text = scratch;
2,976✔
132
  uint8_t *result = scratch + (uint32_t)17U;
2,976✔
133
  uint8_t *ciphertext = cipher;
2,976✔
134
  uint8_t *tag = cipher + len;
2,976✔
135
  uint32_t ctr;
2,976✔
136
  uint8_t tag_mix0[16U] = { 0U };
2,976✔
137
  uint8_t gcm_key[16U] = { 0U };
2,976✔
138
  uint8_t tag_iv[16U] = { 0U };
2,976✔
139
  uint8_t size_iv[16U] = { 0U };
2,976✔
140
  uint8_t tag_mix1[16U] = { 0U };
2,976✔
141
  if (iv_len == (uint32_t)12U)
2,976✔
142
  {
2,976✔
143
    uint64_t *aes_ctx = ctx;
2,976✔
144
    Hacl_AES_256_CTR32_BitSlice_aes256_set_nonce(aes_ctx, iv);
2,976✔
145
    Hacl_AES_256_CTR32_BitSlice_aes256_key_block(tag_mix0, aes_ctx, (uint32_t)1U);
2,976✔
146
    uint64_t u = load64_le(tag_mix0);
2,976✔
147
    ctx[146U] = u;
2,976✔
148
    uint64_t u0 = load64_le(tag_mix0 + (uint32_t)8U);
2,976✔
149
    ctx[147U] = u0;
2,976✔
150
    ctr = (uint32_t)2U;
2,976✔
151
  }
2,976✔
152
  else
×
153
  {
×
154
    uint64_t *aes_ctx = ctx;
×
155
    uint64_t *gcm_ctx = ctx + (uint32_t)128U;
×
156
    store64_be(gcm_key + (uint32_t)8U, gcm_ctx[8U]);
×
157
    store64_be(gcm_key, gcm_ctx[9U]);
×
158
    Hacl_Gf128_CT64_ghash(tag_iv, iv_len, iv, gcm_key);
×
159
    store64_be(size_iv + (uint32_t)8U, (uint64_t)(iv_len * (uint32_t)8U));
×
160
    KRML_MAYBE_FOR16(i,
×
161
      (uint32_t)0U,
×
162
      (uint32_t)16U,
×
163
      (uint32_t)1U,
×
164
      size_iv[i] = tag_iv[i] ^ size_iv[i];);
×
165
    Hacl_Gf128_CT64_ghash(tag_iv, (uint32_t)16U, size_iv, gcm_key);
×
166
    Hacl_AES_256_CTR32_BitSlice_aes256_set_nonce(aes_ctx, tag_iv);
×
167
    uint32_t u0 = load32_be(tag_iv + (uint32_t)12U);
×
168
    uint32_t ctr0 = u0;
×
169
    Hacl_AES_256_CTR32_BitSlice_aes256_key_block(tag_mix1, aes_ctx, ctr0);
×
170
    uint64_t u = load64_le(tag_mix1);
×
171
    ctx[146U] = u;
×
172
    uint64_t u1 = load64_le(tag_mix1 + (uint32_t)8U);
×
173
    ctx[147U] = u1;
×
174
    ctr = ctr0 + (uint32_t)1U;
×
175
  }
×
176
  uint64_t *aes_ctx = ctx;
2,976✔
177
  uint64_t *gcm_ctx = ctx + (uint32_t)128U;
2,976✔
178
  uint64_t *tag_mix = ctx + (uint32_t)146U;
2,976✔
179
  gcm_ctx[0U] = (uint64_t)0U;
2,976✔
180
  gcm_ctx[1U] = (uint64_t)0U;
2,976✔
181
  Hacl_Gf128_CT64_gcm_update_blocks_padded(gcm_ctx, aad_len, aad);
2,976✔
182
  Hacl_Gf128_CT64_gcm_update_blocks_padded(gcm_ctx, len, ciphertext);
2,976✔
183
  store64_be(text, (uint64_t)(aad_len * (uint32_t)8U));
2,976✔
184
  store64_be(text + (uint32_t)8U, (uint64_t)(len * (uint32_t)8U));
2,976✔
185
  Hacl_Gf128_CT64_gcm_update_blocks(gcm_ctx, (uint32_t)16U, text);
2,976✔
186
  Hacl_Gf128_CT64_gcm_emit(text, gcm_ctx);
2,976✔
187
  uint64_t u0 = load64_le(text);
2,976✔
188
  uint64_t text0 = u0;
2,976✔
189
  uint64_t u = load64_le(text + (uint32_t)8U);
2,976✔
190
  uint64_t text1 = u;
2,976✔
191
  uint64_t text01 = text0 ^ tag_mix[0U];
2,976✔
192
  uint64_t text11 = text1 ^ tag_mix[1U];
2,976✔
193
  store64_le(text, text01);
2,976✔
194
  store64_le(text + (uint32_t)8U, text11);
2,976✔
195
  KRML_MAYBE_FOR16(i,
2,976✔
196
    (uint32_t)0U,
2,976✔
197
    (uint32_t)16U,
2,976✔
198
    (uint32_t)1U,
2,976✔
199
    result[0U] = result[0U] | (text[i] ^ tag[i]););
2,976✔
200
  uint8_t res8 = result[0U];
2,976✔
201
  if (res8 == (uint8_t)0U)
2,976✔
202
  {
1,302✔
203
    Hacl_AES_256_CTR32_BitSlice_aes256_ctr(len, out, ciphertext, aes_ctx, ctr);
1,302✔
204
    return true;
1,302✔
205
  }
1,302✔
206
  return false;
1,674✔
207
}
1,674✔
208

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc