1*2c2f96dcSApple OSS Distributions /* Copyright (c) (2015-2019,2021,2022) Apple Inc. All rights reserved.
2*2c2f96dcSApple OSS Distributions *
3*2c2f96dcSApple OSS Distributions * corecrypto is licensed under Apple Inc.’s Internal Use License Agreement (which
4*2c2f96dcSApple OSS Distributions * is contained in the License.txt file distributed with corecrypto) and only to
5*2c2f96dcSApple OSS Distributions * people who accept that license. IMPORTANT: Any license rights granted to you by
6*2c2f96dcSApple OSS Distributions * Apple Inc. (if any) are limited to internal use within your organization only on
7*2c2f96dcSApple OSS Distributions * devices and computers you own or control, for the sole purpose of verifying the
8*2c2f96dcSApple OSS Distributions * security characteristics and correct functioning of the Apple Software. You may
9*2c2f96dcSApple OSS Distributions * not, directly or indirectly, redistribute the Apple Software or any portions thereof.
10*2c2f96dcSApple OSS Distributions *
11*2c2f96dcSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
12*2c2f96dcSApple OSS Distributions *
13*2c2f96dcSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code
14*2c2f96dcSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License
15*2c2f96dcSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in
16*2c2f96dcSApple OSS Distributions * compliance with the License. The rights granted to you under the License
17*2c2f96dcSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of,
18*2c2f96dcSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to
19*2c2f96dcSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any
20*2c2f96dcSApple OSS Distributions * terms of an Apple operating system software license agreement.
21*2c2f96dcSApple OSS Distributions *
22*2c2f96dcSApple OSS Distributions * Please obtain a copy of the License at
23*2c2f96dcSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file.
24*2c2f96dcSApple OSS Distributions *
25*2c2f96dcSApple OSS Distributions * The Original Code and all software distributed under the License are
26*2c2f96dcSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
27*2c2f96dcSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
28*2c2f96dcSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
29*2c2f96dcSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
30*2c2f96dcSApple OSS Distributions * Please see the License for the specific language governing rights and
31*2c2f96dcSApple OSS Distributions * limitations under the License.
32*2c2f96dcSApple OSS Distributions *
33*2c2f96dcSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
34*2c2f96dcSApple OSS Distributions */
35*2c2f96dcSApple OSS Distributions
36*2c2f96dcSApple OSS Distributions #include "cc_internal.h"
37*2c2f96dcSApple OSS Distributions #include "cc_macros.h"
38*2c2f96dcSApple OSS Distributions #include "fipspost_trace.h"
39*2c2f96dcSApple OSS Distributions #include "ccmode_gcm_internal.h"
40*2c2f96dcSApple OSS Distributions #include <corecrypto/ccmode.h>
41*2c2f96dcSApple OSS Distributions
42*2c2f96dcSApple OSS Distributions size_t
ccgcm_context_size(const struct ccmode_gcm * mode)43*2c2f96dcSApple OSS Distributions ccgcm_context_size(const struct ccmode_gcm *mode)
44*2c2f96dcSApple OSS Distributions {
45*2c2f96dcSApple OSS Distributions CC_ENSURE_DIT_ENABLED
46*2c2f96dcSApple OSS Distributions
47*2c2f96dcSApple OSS Distributions return mode->size;
48*2c2f96dcSApple OSS Distributions }
49*2c2f96dcSApple OSS Distributions
50*2c2f96dcSApple OSS Distributions size_t
ccgcm_block_size(const struct ccmode_gcm * mode)51*2c2f96dcSApple OSS Distributions ccgcm_block_size(const struct ccmode_gcm *mode)
52*2c2f96dcSApple OSS Distributions {
53*2c2f96dcSApple OSS Distributions CC_ENSURE_DIT_ENABLED
54*2c2f96dcSApple OSS Distributions
55*2c2f96dcSApple OSS Distributions return mode->block_size;
56*2c2f96dcSApple OSS Distributions }
57*2c2f96dcSApple OSS Distributions
58*2c2f96dcSApple OSS Distributions int
ccgcm_init(const struct ccmode_gcm * mode,ccgcm_ctx * ctx,size_t key_nbytes,const void * cc_sized_by (key_nbytes)key)59*2c2f96dcSApple OSS Distributions ccgcm_init(const struct ccmode_gcm *mode,
60*2c2f96dcSApple OSS Distributions ccgcm_ctx *ctx,
61*2c2f96dcSApple OSS Distributions size_t key_nbytes,
62*2c2f96dcSApple OSS Distributions const void *cc_sized_by(key_nbytes)key)
63*2c2f96dcSApple OSS Distributions {
64*2c2f96dcSApple OSS Distributions CC_ENSURE_DIT_ENABLED
65*2c2f96dcSApple OSS Distributions
66*2c2f96dcSApple OSS Distributions return mode->init(mode, ctx, key_nbytes, key);
67*2c2f96dcSApple OSS Distributions }
68*2c2f96dcSApple OSS Distributions
69*2c2f96dcSApple OSS Distributions int
ccgcm_init_with_iv(const struct ccmode_gcm * mode,ccgcm_ctx * ctx,size_t key_nbytes,const void * key,const void * iv)70*2c2f96dcSApple OSS Distributions ccgcm_init_with_iv(const struct ccmode_gcm *mode, ccgcm_ctx *ctx,
71*2c2f96dcSApple OSS Distributions size_t key_nbytes, const void *key,
72*2c2f96dcSApple OSS Distributions const void *iv)
73*2c2f96dcSApple OSS Distributions {
74*2c2f96dcSApple OSS Distributions CC_ENSURE_DIT_ENABLED
75*2c2f96dcSApple OSS Distributions
76*2c2f96dcSApple OSS Distributions int rc;
77*2c2f96dcSApple OSS Distributions
78*2c2f96dcSApple OSS Distributions rc = ccgcm_init(mode, ctx, key_nbytes, key);
79*2c2f96dcSApple OSS Distributions if (rc == 0) {
80*2c2f96dcSApple OSS Distributions rc = ccgcm_set_iv(mode, ctx, CCGCM_IV_NBYTES, iv);
81*2c2f96dcSApple OSS Distributions }
82*2c2f96dcSApple OSS Distributions if (rc == 0) {
83*2c2f96dcSApple OSS Distributions _CCMODE_GCM_KEY(ctx)->flags |= CCGCM_FLAGS_INIT_WITH_IV;
84*2c2f96dcSApple OSS Distributions }
85*2c2f96dcSApple OSS Distributions return rc;
86*2c2f96dcSApple OSS Distributions }
87*2c2f96dcSApple OSS Distributions
88*2c2f96dcSApple OSS Distributions int
ccgcm_set_iv(const struct ccmode_gcm * mode,ccgcm_ctx * ctx,size_t iv_nbytes,const void * cc_sized_by (iv_nbytes)iv)89*2c2f96dcSApple OSS Distributions ccgcm_set_iv(const struct ccmode_gcm *mode,
90*2c2f96dcSApple OSS Distributions ccgcm_ctx *ctx,
91*2c2f96dcSApple OSS Distributions size_t iv_nbytes,
92*2c2f96dcSApple OSS Distributions const void *cc_sized_by(iv_nbytes)iv)
93*2c2f96dcSApple OSS Distributions {
94*2c2f96dcSApple OSS Distributions CC_ENSURE_DIT_ENABLED
95*2c2f96dcSApple OSS Distributions
96*2c2f96dcSApple OSS Distributions return mode->set_iv(ctx, iv_nbytes, iv);
97*2c2f96dcSApple OSS Distributions }
98*2c2f96dcSApple OSS Distributions
99*2c2f96dcSApple OSS Distributions int
ccgcm_inc_iv(CC_UNUSED const struct ccmode_gcm * mode,ccgcm_ctx * ctx,void * iv)100*2c2f96dcSApple OSS Distributions ccgcm_inc_iv(CC_UNUSED const struct ccmode_gcm *mode, ccgcm_ctx *ctx, void *iv)
101*2c2f96dcSApple OSS Distributions {
102*2c2f96dcSApple OSS Distributions CC_ENSURE_DIT_ENABLED
103*2c2f96dcSApple OSS Distributions
104*2c2f96dcSApple OSS Distributions uint8_t *Y0 = CCMODE_GCM_KEY_Y_0(ctx);
105*2c2f96dcSApple OSS Distributions
106*2c2f96dcSApple OSS Distributions cc_require(_CCMODE_GCM_KEY(ctx)->state == CCMODE_GCM_STATE_IV, errOut);
107*2c2f96dcSApple OSS Distributions cc_require(_CCMODE_GCM_KEY(ctx)->flags & CCGCM_FLAGS_INIT_WITH_IV, errOut);
108*2c2f96dcSApple OSS Distributions
109*2c2f96dcSApple OSS Distributions inc_uint(Y0 + 4, 8);
110*2c2f96dcSApple OSS Distributions cc_memcpy(iv, Y0, CCGCM_IV_NBYTES);
111*2c2f96dcSApple OSS Distributions cc_memcpy(CCMODE_GCM_KEY_Y(ctx), Y0, CCGCM_BLOCK_NBYTES);
112*2c2f96dcSApple OSS Distributions ccmode_gcm_update_pad(ctx);
113*2c2f96dcSApple OSS Distributions
114*2c2f96dcSApple OSS Distributions _CCMODE_GCM_KEY(ctx)->state = CCMODE_GCM_STATE_AAD;
115*2c2f96dcSApple OSS Distributions
116*2c2f96dcSApple OSS Distributions return 0;
117*2c2f96dcSApple OSS Distributions
118*2c2f96dcSApple OSS Distributions errOut:
119*2c2f96dcSApple OSS Distributions return CCMODE_INVALID_CALL_SEQUENCE;
120*2c2f96dcSApple OSS Distributions }
121*2c2f96dcSApple OSS Distributions
122*2c2f96dcSApple OSS Distributions int
ccgcm_aad(const struct ccmode_gcm * mode,ccgcm_ctx * ctx,size_t nbytes,const void * cc_sized_by (nbytes)additional_data)123*2c2f96dcSApple OSS Distributions ccgcm_aad(const struct ccmode_gcm *mode,
124*2c2f96dcSApple OSS Distributions ccgcm_ctx *ctx,
125*2c2f96dcSApple OSS Distributions size_t nbytes,
126*2c2f96dcSApple OSS Distributions const void *cc_sized_by(nbytes)additional_data)
127*2c2f96dcSApple OSS Distributions {
128*2c2f96dcSApple OSS Distributions CC_ENSURE_DIT_ENABLED
129*2c2f96dcSApple OSS Distributions
130*2c2f96dcSApple OSS Distributions return mode->gmac(ctx, nbytes, additional_data);
131*2c2f96dcSApple OSS Distributions }
132*2c2f96dcSApple OSS Distributions
133*2c2f96dcSApple OSS Distributions int
ccgcm_gmac(const struct ccmode_gcm * mode,ccgcm_ctx * ctx,size_t nbytes,const void * cc_sized_by (nbytes)in)134*2c2f96dcSApple OSS Distributions ccgcm_gmac(const struct ccmode_gcm *mode,
135*2c2f96dcSApple OSS Distributions ccgcm_ctx *ctx,
136*2c2f96dcSApple OSS Distributions size_t nbytes,
137*2c2f96dcSApple OSS Distributions const void *cc_sized_by(nbytes)in)
138*2c2f96dcSApple OSS Distributions {
139*2c2f96dcSApple OSS Distributions CC_ENSURE_DIT_ENABLED
140*2c2f96dcSApple OSS Distributions
141*2c2f96dcSApple OSS Distributions return mode->gmac(ctx, nbytes, in);
142*2c2f96dcSApple OSS Distributions }
143*2c2f96dcSApple OSS Distributions
144*2c2f96dcSApple OSS Distributions int
ccgcm_update(const struct ccmode_gcm * mode,ccgcm_ctx * ctx,size_t nbytes,const void * cc_sized_by (nbytes)in,void * cc_sized_by (nbytes)out)145*2c2f96dcSApple OSS Distributions ccgcm_update(const struct ccmode_gcm *mode,
146*2c2f96dcSApple OSS Distributions ccgcm_ctx *ctx,
147*2c2f96dcSApple OSS Distributions size_t nbytes,
148*2c2f96dcSApple OSS Distributions const void *cc_sized_by(nbytes)in,
149*2c2f96dcSApple OSS Distributions void *cc_sized_by(nbytes)out)
150*2c2f96dcSApple OSS Distributions {
151*2c2f96dcSApple OSS Distributions CC_ENSURE_DIT_ENABLED
152*2c2f96dcSApple OSS Distributions
153*2c2f96dcSApple OSS Distributions return mode->gcm(ctx, nbytes, in, out);
154*2c2f96dcSApple OSS Distributions }
155*2c2f96dcSApple OSS Distributions
156*2c2f96dcSApple OSS Distributions int
ccgcm_finalize(const struct ccmode_gcm * mode,ccgcm_ctx * ctx,size_t tag_nbytes,void * cc_sized_by (tag_nbytes)tag)157*2c2f96dcSApple OSS Distributions ccgcm_finalize(const struct ccmode_gcm *mode,
158*2c2f96dcSApple OSS Distributions ccgcm_ctx *ctx,
159*2c2f96dcSApple OSS Distributions size_t tag_nbytes,
160*2c2f96dcSApple OSS Distributions void *cc_sized_by(tag_nbytes)tag)
161*2c2f96dcSApple OSS Distributions {
162*2c2f96dcSApple OSS Distributions CC_ENSURE_DIT_ENABLED
163*2c2f96dcSApple OSS Distributions
164*2c2f96dcSApple OSS Distributions return mode->finalize(ctx, tag_nbytes, tag);
165*2c2f96dcSApple OSS Distributions }
166*2c2f96dcSApple OSS Distributions
167*2c2f96dcSApple OSS Distributions int
ccgcm_reset(const struct ccmode_gcm * mode,ccgcm_ctx * ctx)168*2c2f96dcSApple OSS Distributions ccgcm_reset(const struct ccmode_gcm *mode, ccgcm_ctx *ctx)
169*2c2f96dcSApple OSS Distributions {
170*2c2f96dcSApple OSS Distributions CC_ENSURE_DIT_ENABLED
171*2c2f96dcSApple OSS Distributions
172*2c2f96dcSApple OSS Distributions return mode->reset(ctx);
173*2c2f96dcSApple OSS Distributions }
174*2c2f96dcSApple OSS Distributions
175*2c2f96dcSApple OSS Distributions int
ccgcm_one_shot(const struct ccmode_gcm * mode,size_t key_nbytes,const void * key,size_t iv_nbytes,const void * iv,size_t adata_nbytes,const void * adata,size_t nbytes,const void * in,void * out,size_t tag_nbytes,void * tag)176*2c2f96dcSApple OSS Distributions ccgcm_one_shot(const struct ccmode_gcm *mode,
177*2c2f96dcSApple OSS Distributions size_t key_nbytes, const void *key,
178*2c2f96dcSApple OSS Distributions size_t iv_nbytes, const void *iv,
179*2c2f96dcSApple OSS Distributions size_t adata_nbytes, const void *adata,
180*2c2f96dcSApple OSS Distributions size_t nbytes, const void *in, void *out,
181*2c2f96dcSApple OSS Distributions size_t tag_nbytes, void *tag)
182*2c2f96dcSApple OSS Distributions {
183*2c2f96dcSApple OSS Distributions CC_ENSURE_DIT_ENABLED
184*2c2f96dcSApple OSS Distributions
185*2c2f96dcSApple OSS Distributions FIPSPOST_TRACE_EVENT;
186*2c2f96dcSApple OSS Distributions
187*2c2f96dcSApple OSS Distributions int rc = 0;
188*2c2f96dcSApple OSS Distributions
189*2c2f96dcSApple OSS Distributions ccgcm_ctx_decl(mode->size, ctx);
190*2c2f96dcSApple OSS Distributions rc = ccgcm_init(mode, ctx, key_nbytes, key); cc_require(rc == 0, errOut);
191*2c2f96dcSApple OSS Distributions rc = ccgcm_set_iv(mode, ctx, iv_nbytes, iv); cc_require(rc == 0, errOut);
192*2c2f96dcSApple OSS Distributions rc = ccgcm_aad(mode, ctx, adata_nbytes, adata); cc_require(rc == 0, errOut);
193*2c2f96dcSApple OSS Distributions rc = ccgcm_update(mode, ctx, nbytes, in, out); cc_require(rc == 0, errOut);
194*2c2f96dcSApple OSS Distributions rc = ccgcm_finalize(mode, ctx, tag_nbytes, tag); cc_require(rc == 0, errOut);
195*2c2f96dcSApple OSS Distributions
196*2c2f96dcSApple OSS Distributions errOut:
197*2c2f96dcSApple OSS Distributions ccgcm_ctx_clear(mode->size, ctx);
198*2c2f96dcSApple OSS Distributions return rc;
199*2c2f96dcSApple OSS Distributions }
200*2c2f96dcSApple OSS Distributions
201*2c2f96dcSApple OSS Distributions
202*2c2f96dcSApple OSS Distributions //ccgcm_one_shot_legacy() is created because in the previous implementation of aes-gcm
203*2c2f96dcSApple OSS Distributions //set_iv() could be skipped.
204*2c2f96dcSApple OSS Distributions //In the new version of aes-gcm set_iv() cannot be skipped and IV length cannot
205*2c2f96dcSApple OSS Distributions //be zero, as specified in FIPS.
206*2c2f96dcSApple OSS Distributions //do not call ccgcm_one_shot_legacy() in any new application
207*2c2f96dcSApple OSS Distributions int
ccgcm_set_iv_legacy(const struct ccmode_gcm * mode,ccgcm_ctx * key,size_t iv_nbytes,const void * iv)208*2c2f96dcSApple OSS Distributions ccgcm_set_iv_legacy(const struct ccmode_gcm *mode, ccgcm_ctx *key, size_t iv_nbytes, const void *iv)
209*2c2f96dcSApple OSS Distributions {
210*2c2f96dcSApple OSS Distributions CC_ENSURE_DIT_ENABLED
211*2c2f96dcSApple OSS Distributions
212*2c2f96dcSApple OSS Distributions int rc = -1;
213*2c2f96dcSApple OSS Distributions
214*2c2f96dcSApple OSS Distributions if (iv_nbytes == 0 || iv == NULL) {
215*2c2f96dcSApple OSS Distributions /* must be in IV state */
216*2c2f96dcSApple OSS Distributions cc_require(_CCMODE_GCM_KEY(key)->state == CCMODE_GCM_STATE_IV, errOut); /* CRYPT_INVALID_ARG */
217*2c2f96dcSApple OSS Distributions
218*2c2f96dcSApple OSS Distributions // this is the net effect of setting IV to the empty string
219*2c2f96dcSApple OSS Distributions cc_clear(CCGCM_BLOCK_NBYTES, CCMODE_GCM_KEY_Y(key));
220*2c2f96dcSApple OSS Distributions ccmode_gcm_update_pad(key);
221*2c2f96dcSApple OSS Distributions cc_clear(CCGCM_BLOCK_NBYTES, CCMODE_GCM_KEY_Y_0(key));
222*2c2f96dcSApple OSS Distributions
223*2c2f96dcSApple OSS Distributions _CCMODE_GCM_KEY(key)->state = CCMODE_GCM_STATE_AAD;
224*2c2f96dcSApple OSS Distributions rc = 0;
225*2c2f96dcSApple OSS Distributions } else {
226*2c2f96dcSApple OSS Distributions rc = ccgcm_set_iv(mode, key, iv_nbytes, iv);
227*2c2f96dcSApple OSS Distributions }
228*2c2f96dcSApple OSS Distributions
229*2c2f96dcSApple OSS Distributions errOut:
230*2c2f96dcSApple OSS Distributions return rc;
231*2c2f96dcSApple OSS Distributions }
232*2c2f96dcSApple OSS Distributions
233*2c2f96dcSApple OSS Distributions int
ccgcm_one_shot_legacy(const struct ccmode_gcm * mode,size_t key_nbytes,const void * key,size_t iv_nbytes,const void * iv,size_t adata_nbytes,const void * adata,size_t nbytes,const void * in,void * out,size_t tag_nbytes,void * tag)234*2c2f96dcSApple OSS Distributions ccgcm_one_shot_legacy(const struct ccmode_gcm *mode,
235*2c2f96dcSApple OSS Distributions size_t key_nbytes, const void *key,
236*2c2f96dcSApple OSS Distributions size_t iv_nbytes, const void *iv,
237*2c2f96dcSApple OSS Distributions size_t adata_nbytes, const void *adata,
238*2c2f96dcSApple OSS Distributions size_t nbytes, const void *in, void *out,
239*2c2f96dcSApple OSS Distributions size_t tag_nbytes, void *tag)
240*2c2f96dcSApple OSS Distributions {
241*2c2f96dcSApple OSS Distributions CC_ENSURE_DIT_ENABLED
242*2c2f96dcSApple OSS Distributions
243*2c2f96dcSApple OSS Distributions int rc = 0;
244*2c2f96dcSApple OSS Distributions
245*2c2f96dcSApple OSS Distributions ccgcm_ctx_decl(mode->size, ctx);
246*2c2f96dcSApple OSS Distributions rc = ccgcm_init(mode, ctx, key_nbytes, key); cc_require(rc == 0, errOut);
247*2c2f96dcSApple OSS Distributions rc = ccgcm_set_iv_legacy(mode, ctx, iv_nbytes, iv); cc_require(rc == 0, errOut);
248*2c2f96dcSApple OSS Distributions rc = ccgcm_aad(mode, ctx, adata_nbytes, adata); cc_require(rc == 0, errOut);
249*2c2f96dcSApple OSS Distributions rc = ccgcm_update(mode, ctx, nbytes, in, out); cc_require(rc == 0, errOut);
250*2c2f96dcSApple OSS Distributions rc = ccgcm_finalize(mode, ctx, tag_nbytes, tag); cc_require(rc == 0, errOut);
251*2c2f96dcSApple OSS Distributions
252*2c2f96dcSApple OSS Distributions errOut:
253*2c2f96dcSApple OSS Distributions ccgcm_ctx_clear(mode->size, ctx);
254*2c2f96dcSApple OSS Distributions return rc;
255*2c2f96dcSApple OSS Distributions }
256*2c2f96dcSApple OSS Distributions
257*2c2f96dcSApple OSS Distributions void
inc_uint(uint8_t * buf,size_t nbytes)258*2c2f96dcSApple OSS Distributions inc_uint(uint8_t *buf, size_t nbytes)
259*2c2f96dcSApple OSS Distributions {
260*2c2f96dcSApple OSS Distributions for (size_t i = 1; i <= nbytes; i += 1) {
261*2c2f96dcSApple OSS Distributions size_t j = nbytes - i;
262*2c2f96dcSApple OSS Distributions buf[j] = (uint8_t)(buf[j] + 1);
263*2c2f96dcSApple OSS Distributions if (buf[j] > 0) {
264*2c2f96dcSApple OSS Distributions return;
265*2c2f96dcSApple OSS Distributions }
266*2c2f96dcSApple OSS Distributions }
267*2c2f96dcSApple OSS Distributions }
268*2c2f96dcSApple OSS Distributions
269*2c2f96dcSApple OSS Distributions void
ccmode_gcm_update_pad(ccgcm_ctx * key)270*2c2f96dcSApple OSS Distributions ccmode_gcm_update_pad(ccgcm_ctx *key)
271*2c2f96dcSApple OSS Distributions {
272*2c2f96dcSApple OSS Distributions inc_uint(CCMODE_GCM_KEY_Y(key) + 12, 4);
273*2c2f96dcSApple OSS Distributions CCMODE_GCM_KEY_ECB(key)->ecb(CCMODE_GCM_KEY_ECB_KEY(key), 1,
274*2c2f96dcSApple OSS Distributions CCMODE_GCM_KEY_Y(key),
275*2c2f96dcSApple OSS Distributions CCMODE_GCM_KEY_PAD(key));
276*2c2f96dcSApple OSS Distributions }
277*2c2f96dcSApple OSS Distributions
278*2c2f96dcSApple OSS Distributions void
ccmode_gcm_aad_finalize(ccgcm_ctx * key)279*2c2f96dcSApple OSS Distributions ccmode_gcm_aad_finalize(ccgcm_ctx *key)
280*2c2f96dcSApple OSS Distributions {
281*2c2f96dcSApple OSS Distributions if (_CCMODE_GCM_KEY(key)->state == CCMODE_GCM_STATE_AAD) {
282*2c2f96dcSApple OSS Distributions if (_CCMODE_GCM_KEY(key)->aad_nbytes % CCGCM_BLOCK_NBYTES > 0) {
283*2c2f96dcSApple OSS Distributions ccmode_gcm_mult_h(key, CCMODE_GCM_KEY_X(key));
284*2c2f96dcSApple OSS Distributions }
285*2c2f96dcSApple OSS Distributions _CCMODE_GCM_KEY(key)->state = CCMODE_GCM_STATE_TEXT;
286*2c2f96dcSApple OSS Distributions }
287*2c2f96dcSApple OSS Distributions }
288