Coverage Report

Created: 2026-10-28 07:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl/providers/implementations/ciphers/cipher_aes_ocb.c
Line
Count
Source
1
/*
2
 * Copyright 2019-2026 The OpenSSL Project Authors. All Rights Reserved.
3
 *
4
 * Licensed under the Apache License 2.0 (the "License").  You may not use
5
 * this file except in compliance with the License.  You can obtain a copy
6
 * in the file LICENSE in the source distribution or at
7
 * https://www.openssl.org/source/license.html
8
 */
9
10
/*
11
 * AES low level APIs are deprecated for public use, but still ok for internal
12
 * use where we're using them to implement the higher level EVP interface, as is
13
 * the case here.
14
 */
15
#include "internal/deprecated.h"
16
17
#include <openssl/proverr.h>
18
#include "cipher_aes_ocb.h"
19
#include "prov/providercommon.h"
20
#include "prov/ciphercommon_aead.h"
21
#include "prov/implementations.h"
22
#include "providers/implementations/ciphers/cipher_aes_ocb.inc"
23
24
#define AES_OCB_FLAGS AEAD_FLAGS
25
26
0
#define OCB_DEFAULT_TAG_LEN 16
27
#define OCB_DEFAULT_IV_LEN 12
28
0
#define OCB_MIN_IV_LEN 1
29
0
#define OCB_MAX_IV_LEN 15
30
31
PROV_CIPHER_FUNC(int, ocb_cipher, (PROV_AES_OCB_CTX *ctx, const unsigned char *in, unsigned char *out, size_t nextblock));
32
/* forward declarations */
33
static OSSL_FUNC_cipher_encrypt_init_fn aes_ocb_einit;
34
static OSSL_FUNC_cipher_decrypt_init_fn aes_ocb_dinit;
35
static OSSL_FUNC_cipher_update_fn aes_ocb_block_update;
36
static OSSL_FUNC_cipher_final_fn aes_ocb_block_final;
37
static OSSL_FUNC_cipher_cipher_fn aes_ocb_cipher;
38
static OSSL_FUNC_cipher_freectx_fn aes_ocb_freectx;
39
static OSSL_FUNC_cipher_dupctx_fn aes_ocb_dupctx;
40
static OSSL_FUNC_cipher_get_ctx_params_fn aes_ocb_get_ctx_params;
41
static OSSL_FUNC_cipher_set_ctx_params_fn aes_ocb_set_ctx_params;
42
static OSSL_FUNC_cipher_gettable_ctx_params_fn cipher_ocb_gettable_ctx_params;
43
static OSSL_FUNC_cipher_settable_ctx_params_fn cipher_ocb_settable_ctx_params;
44
45
/*
46
 * The following methods could be moved into PROV_AES_OCB_HW if
47
 * multiple hardware implementations are ever needed.
48
 */
49
static ossl_inline int aes_generic_ocb_setiv(PROV_AES_OCB_CTX *ctx,
50
    const unsigned char *iv,
51
    size_t ivlen, size_t taglen)
52
0
{
53
0
    return (CRYPTO_ocb128_setiv(&ctx->ocb, iv, ivlen, taglen) == 1);
54
0
}
55
56
static ossl_inline int aes_generic_ocb_setaad(PROV_AES_OCB_CTX *ctx,
57
    const unsigned char *aad,
58
    size_t alen)
59
0
{
60
0
    return CRYPTO_ocb128_aad(&ctx->ocb, aad, alen) == 1;
61
0
}
62
63
static ossl_inline int aes_generic_ocb_gettag(PROV_AES_OCB_CTX *ctx,
64
    unsigned char *tag, size_t tlen)
65
0
{
66
0
    return CRYPTO_ocb128_tag(&ctx->ocb, tag, tlen) > 0;
67
0
}
68
69
static ossl_inline int aes_generic_ocb_final(PROV_AES_OCB_CTX *ctx)
70
0
{
71
0
    int ret = CRYPTO_ocb128_finish(&ctx->ocb, ctx->tag, ctx->taglen);
72
73
    /* ret: -1 = bad tag length, 0 = tag verified, otherwise = tag mismatch */
74
0
    if (ret == -1)
75
0
        ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_TAG_LENGTH);
76
0
    else if (ret != 0)
77
0
        ERR_raise(ERR_LIB_PROV, PROV_R_BAD_DECRYPT);
78
0
    return ret == 0;
79
0
}
80
81
static ossl_inline void aes_generic_ocb_cleanup(PROV_AES_OCB_CTX *ctx)
82
0
{
83
0
    CRYPTO_ocb128_cleanup(&ctx->ocb);
84
0
}
85
86
static ossl_inline int aes_generic_ocb_cipher(PROV_AES_OCB_CTX *ctx,
87
    const unsigned char *in,
88
    unsigned char *out, size_t len)
89
0
{
90
0
    if (ctx->base.enc) {
91
0
        if (!CRYPTO_ocb128_encrypt(&ctx->ocb, in, out, len))
92
0
            return 0;
93
0
    } else {
94
0
        if (!CRYPTO_ocb128_decrypt(&ctx->ocb, in, out, len))
95
0
            return 0;
96
0
    }
97
0
    return 1;
98
0
}
99
100
static ossl_inline int aes_generic_ocb_copy_ctx(PROV_AES_OCB_CTX *dst,
101
    PROV_AES_OCB_CTX *src)
102
0
{
103
0
    return CRYPTO_ocb128_copy_ctx(&dst->ocb, &src->ocb,
104
0
        &dst->ksenc.ks, &dst->ksdec.ks);
105
0
}
106
107
/*-
108
 * Provider dispatch functions
109
 */
110
static int aes_ocb_init(void *vctx, const unsigned char *key, size_t keylen,
111
    const unsigned char *iv, size_t ivlen,
112
    const OSSL_PARAM params[], int enc)
113
0
{
114
0
    PROV_AES_OCB_CTX *ctx = (PROV_AES_OCB_CTX *)vctx;
115
116
0
    if (!ossl_prov_is_running())
117
0
        return 0;
118
119
0
    ctx->aad_buf_len = 0;
120
0
    ctx->data_buf_len = 0;
121
0
    ctx->base.enc = enc;
122
123
0
    if (iv != NULL) {
124
0
        if (ivlen != ctx->base.ivlen) {
125
            /* IV len must be 1 to 15 */
126
0
            if (ivlen < OCB_MIN_IV_LEN || ivlen > OCB_MAX_IV_LEN) {
127
0
                ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_IV_LENGTH);
128
0
                return 0;
129
0
            }
130
0
            ctx->base.ivlen = ivlen;
131
0
        }
132
0
        if (!ossl_cipher_generic_initiv(&ctx->base, iv, ivlen))
133
0
            return 0;
134
0
        ctx->iv_state = IV_STATE_BUFFERED;
135
0
    }
136
0
    if (key != NULL) {
137
0
        if (keylen != ctx->base.keylen) {
138
0
            ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
139
0
            return 0;
140
0
        }
141
0
        if (!ctx->base.hw->init(&ctx->base, key, keylen))
142
0
            return 0;
143
0
    }
144
0
    return aes_ocb_set_ctx_params(ctx, params);
145
0
}
146
147
static int aes_ocb_einit(void *vctx, const unsigned char *key, size_t keylen,
148
    const unsigned char *iv, size_t ivlen,
149
    const OSSL_PARAM params[])
150
0
{
151
0
    return aes_ocb_init(vctx, key, keylen, iv, ivlen, params, 1);
152
0
}
153
154
static int aes_ocb_dinit(void *vctx, const unsigned char *key, size_t keylen,
155
    const unsigned char *iv, size_t ivlen,
156
    const OSSL_PARAM params[])
157
0
{
158
0
    return aes_ocb_init(vctx, key, keylen, iv, ivlen, params, 0);
159
0
}
160
161
/*
162
 * Because of the way OCB works, both the AAD and data are buffered in the
163
 * same way. Only the last block can be a partial block.
164
 */
165
static int aes_ocb_block_update_internal(PROV_AES_OCB_CTX *ctx,
166
    unsigned char *buf, size_t *bufsz,
167
    unsigned char *out, size_t *outl,
168
    size_t outsize, const unsigned char *in,
169
    size_t inl, OSSL_ocb_cipher_fn ciph)
170
0
{
171
0
    size_t nextblocks;
172
0
    size_t outlint = 0;
173
174
0
    if (*bufsz != 0)
175
0
        nextblocks = ossl_cipher_fillblock(buf, bufsz, AES_BLOCK_SIZE, &in, &inl);
176
0
    else
177
0
        nextblocks = inl & ~(AES_BLOCK_SIZE - 1);
178
179
0
    if (*bufsz == AES_BLOCK_SIZE) {
180
0
        if (outsize < AES_BLOCK_SIZE) {
181
0
            ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
182
0
            return 0;
183
0
        }
184
0
        if (!ciph(ctx, buf, out, AES_BLOCK_SIZE)) {
185
0
            ERR_raise(ERR_LIB_PROV, PROV_R_CIPHER_OPERATION_FAILED);
186
0
            return 0;
187
0
        }
188
0
        *bufsz = 0;
189
0
        outlint = AES_BLOCK_SIZE;
190
0
        if (out != NULL)
191
0
            out += AES_BLOCK_SIZE;
192
0
    }
193
0
    if (nextblocks > 0) {
194
0
        outlint += nextblocks;
195
0
        if (outsize < outlint) {
196
0
            ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
197
0
            return 0;
198
0
        }
199
0
        if (!ciph(ctx, in, out, nextblocks)) {
200
0
            ERR_raise(ERR_LIB_PROV, PROV_R_CIPHER_OPERATION_FAILED);
201
0
            return 0;
202
0
        }
203
0
        in += nextblocks;
204
0
        inl -= nextblocks;
205
0
    }
206
0
    if (inl != 0
207
0
        && !ossl_cipher_trailingdata(buf, bufsz, AES_BLOCK_SIZE, &in, &inl)) {
208
        /* PROVerr already called */
209
0
        return 0;
210
0
    }
211
212
0
    *outl = outlint;
213
0
    return inl == 0;
214
0
}
215
216
/* A wrapper function that has the same signature as cipher */
217
static int cipher_updateaad(PROV_AES_OCB_CTX *ctx, const unsigned char *in,
218
    unsigned char *out, size_t len)
219
0
{
220
0
    return aes_generic_ocb_setaad(ctx, in, len);
221
0
}
222
223
static int update_iv(PROV_AES_OCB_CTX *ctx)
224
0
{
225
0
    if (ctx->iv_state == IV_STATE_FINISHED
226
0
        || ctx->iv_state == IV_STATE_UNINITIALISED)
227
0
        return 0;
228
0
    if (ctx->iv_state == IV_STATE_BUFFERED) {
229
0
        if (!aes_generic_ocb_setiv(ctx, ctx->base.iv, ctx->base.ivlen,
230
0
                ctx->taglen))
231
0
            return 0;
232
0
        ctx->iv_state = IV_STATE_COPIED;
233
0
    }
234
0
    return 1;
235
0
}
236
237
static int aes_ocb_block_update(void *vctx, unsigned char *out, size_t *outl,
238
    size_t outsize, const unsigned char *in,
239
    size_t inl)
240
0
{
241
0
    PROV_AES_OCB_CTX *ctx = (PROV_AES_OCB_CTX *)vctx;
242
0
    unsigned char *buf;
243
0
    size_t *buflen;
244
0
    OSSL_ocb_cipher_fn fn;
245
246
0
    if (!ctx->key_set || !update_iv(ctx))
247
0
        return 0;
248
249
0
    if (inl == 0) {
250
0
        *outl = 0;
251
0
        return 1;
252
0
    }
253
254
0
    if (in == NULL) {
255
0
        ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_NULL_PARAMETER);
256
0
        return 0;
257
0
    }
258
259
    /* Are we dealing with AAD or normal data here? */
260
0
    if (out == NULL) {
261
0
        buf = ctx->aad_buf;
262
0
        buflen = &ctx->aad_buf_len;
263
0
        fn = cipher_updateaad;
264
0
    } else {
265
0
        buf = ctx->data_buf;
266
0
        buflen = &ctx->data_buf_len;
267
0
        fn = aes_generic_ocb_cipher;
268
0
    }
269
0
    return aes_ocb_block_update_internal(ctx, buf, buflen, out, outl, outsize,
270
0
        in, inl, fn);
271
0
}
272
273
static int aes_ocb_block_final(void *vctx, unsigned char *out, size_t *outl,
274
    size_t outsize)
275
0
{
276
0
    PROV_AES_OCB_CTX *ctx = (PROV_AES_OCB_CTX *)vctx;
277
278
0
    if (!ossl_prov_is_running())
279
0
        return 0;
280
281
    /* If no block_update has run then the iv still needs to be set */
282
0
    if (!ctx->key_set || !update_iv(ctx))
283
0
        return 0;
284
285
    /*
286
     * Empty the buffer of any partial block that we might have been provided,
287
     * both for data and AAD
288
     */
289
0
    *outl = 0;
290
0
    if (ctx->data_buf_len > 0) {
291
0
        if (!aes_generic_ocb_cipher(ctx, ctx->data_buf, out, ctx->data_buf_len))
292
0
            return 0;
293
0
        *outl = ctx->data_buf_len;
294
0
        ctx->data_buf_len = 0;
295
0
    }
296
0
    if (ctx->aad_buf_len > 0) {
297
0
        if (!aes_generic_ocb_setaad(ctx, ctx->aad_buf, ctx->aad_buf_len))
298
0
            return 0;
299
0
        ctx->aad_buf_len = 0;
300
0
    }
301
0
    if (ctx->base.enc) {
302
        /* If encrypting then just get the tag */
303
0
        if (!aes_generic_ocb_gettag(ctx, ctx->tag, ctx->taglen))
304
0
            return 0;
305
0
    } else {
306
        /* If decrypting then verify */
307
0
        if (ctx->taglen == 0)
308
0
            return 0;
309
0
        if (!aes_generic_ocb_final(ctx))
310
0
            return 0;
311
0
    }
312
    /* Don't reuse the IV */
313
0
    ctx->iv_state = IV_STATE_FINISHED;
314
0
    return 1;
315
0
}
316
317
static void *aes_ocb_newctx(void *provctx, size_t kbits, size_t blkbits,
318
    size_t ivbits, unsigned int mode, uint64_t flags)
319
0
{
320
0
    PROV_AES_OCB_CTX *ctx;
321
322
0
    CIPHER_PROV_CHECK(provctx, AES_128_OCB);
323
0
    ctx = OPENSSL_zalloc(sizeof(*ctx));
324
0
    if (ctx != NULL) {
325
0
        ossl_cipher_generic_initkey(ctx, kbits, blkbits, ivbits, mode, flags,
326
0
            ossl_prov_cipher_hw_aes_ocb(kbits), NULL);
327
0
        ctx->taglen = OCB_DEFAULT_TAG_LEN;
328
0
    }
329
0
    return ctx;
330
0
}
331
332
static void aes_ocb_freectx(void *vctx)
333
0
{
334
0
    PROV_AES_OCB_CTX *ctx = (PROV_AES_OCB_CTX *)vctx;
335
336
0
    if (ctx != NULL) {
337
0
        aes_generic_ocb_cleanup(ctx);
338
0
        ossl_cipher_generic_reset_ctx((PROV_CIPHER_CTX *)vctx);
339
0
        OPENSSL_clear_free(ctx, sizeof(*ctx));
340
0
    }
341
0
}
342
343
static void *aes_ocb_dupctx(void *vctx)
344
0
{
345
0
    PROV_AES_OCB_CTX *in = (PROV_AES_OCB_CTX *)vctx;
346
0
    PROV_AES_OCB_CTX *ret;
347
348
0
    if (!ossl_prov_is_running())
349
0
        return NULL;
350
351
0
    ret = OPENSSL_malloc(sizeof(*ret));
352
0
    if (ret == NULL)
353
0
        return NULL;
354
0
    *ret = *in;
355
0
    if (!aes_generic_ocb_copy_ctx(ret, in)) {
356
0
        OPENSSL_free(ret);
357
0
        ret = NULL;
358
0
    }
359
0
    return ret;
360
0
}
361
362
static const OSSL_PARAM *cipher_ocb_settable_ctx_params(ossl_unused void *cctx,
363
    ossl_unused void *p_ctx)
364
0
{
365
0
    return aes_ocb_set_ctx_params_list;
366
0
}
367
368
static int aes_ocb_set_ctx_params(void *vctx, const OSSL_PARAM params[])
369
0
{
370
0
    PROV_AES_OCB_CTX *ctx = (PROV_AES_OCB_CTX *)vctx;
371
0
    struct aes_ocb_set_ctx_params_st p;
372
0
    size_t sz;
373
374
0
    if (ctx == NULL || !aes_ocb_set_ctx_params_decoder(params, &p))
375
0
        return 0;
376
377
0
    if (p.tag != NULL) {
378
0
        if (p.tag->data_type != OSSL_PARAM_OCTET_STRING) {
379
0
            ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
380
0
            return 0;
381
0
        }
382
0
        if (p.tag->data == NULL) {
383
            /* Tag len must be 0 to 16 */
384
0
            if (p.tag->data_size > OCB_MAX_TAG_LEN) {
385
0
                ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_TAG_LENGTH);
386
0
                return 0;
387
0
            }
388
0
            ctx->taglen = p.tag->data_size;
389
0
        } else {
390
0
            if (ctx->base.enc) {
391
0
                ERR_raise(ERR_LIB_PROV, PROV_R_TAG_NOT_NEEDED);
392
0
                return 0;
393
0
            }
394
0
            if (p.tag->data_size != ctx->taglen) {
395
0
                ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_TAG_LENGTH);
396
0
                return 0;
397
0
            }
398
0
            memcpy(ctx->tag, p.tag->data, p.tag->data_size);
399
0
        }
400
0
    }
401
402
0
    if (p.ivlen != NULL) {
403
0
        if (!OSSL_PARAM_get_size_t(p.ivlen, &sz)) {
404
0
            ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
405
0
            return 0;
406
0
        }
407
        /* IV len must be 1 to 15 */
408
0
        if (sz < OCB_MIN_IV_LEN || sz > OCB_MAX_IV_LEN)
409
0
            return 0;
410
0
        if (ctx->base.ivlen != sz) {
411
0
            ctx->base.ivlen = sz;
412
0
            ctx->iv_state = IV_STATE_UNINITIALISED;
413
0
        }
414
0
    }
415
416
0
    if (p.keylen != NULL) {
417
0
        size_t keylen;
418
419
0
        if (!OSSL_PARAM_get_size_t(p.keylen, &keylen)) {
420
0
            ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
421
0
            return 0;
422
0
        }
423
0
        if (ctx->base.keylen != keylen) {
424
0
            ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
425
0
            return 0;
426
0
        }
427
0
    }
428
0
    return 1;
429
0
}
430
431
static const OSSL_PARAM *cipher_ocb_gettable_ctx_params(ossl_unused void *cctx,
432
    ossl_unused void *p_ctx)
433
3
{
434
3
    return aes_ocb_get_ctx_params_list;
435
3
}
436
437
static int aes_ocb_get_ctx_params(void *vctx, OSSL_PARAM params[])
438
0
{
439
0
    PROV_AES_OCB_CTX *ctx = (PROV_AES_OCB_CTX *)vctx;
440
0
    struct aes_ocb_get_ctx_params_st p;
441
442
0
    if (ctx == NULL || !aes_ocb_get_ctx_params_decoder(params, &p))
443
0
        return 0;
444
445
0
    if (p.ivlen != NULL && !OSSL_PARAM_set_size_t(p.ivlen, ctx->base.ivlen)) {
446
0
        ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
447
0
        return 0;
448
0
    }
449
450
0
    if (p.keylen != NULL && !OSSL_PARAM_set_size_t(p.keylen, ctx->base.keylen)) {
451
0
        ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
452
0
        return 0;
453
0
    }
454
455
0
    if (p.taglen != NULL) {
456
0
        if (!OSSL_PARAM_set_size_t(p.taglen, ctx->taglen)) {
457
0
            ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
458
0
            return 0;
459
0
        }
460
0
    }
461
462
0
    if (p.iv != NULL) {
463
0
        if (ctx->base.ivlen > p.iv->data_size) {
464
0
            ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_IV_LENGTH);
465
0
            return 0;
466
0
        }
467
0
        if (!OSSL_PARAM_set_octet_string_or_ptr(p.iv, ctx->base.oiv,
468
0
                ctx->base.ivlen)) {
469
0
            ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
470
0
            return 0;
471
0
        }
472
0
    }
473
474
0
    if (p.upd_iv != NULL) {
475
0
        if (ctx->base.ivlen > p.upd_iv->data_size) {
476
0
            ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_IV_LENGTH);
477
0
            return 0;
478
0
        }
479
0
        if (!OSSL_PARAM_set_octet_string_or_ptr(p.upd_iv, ctx->base.iv,
480
0
                ctx->base.ivlen)) {
481
0
            ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
482
0
            return 0;
483
0
        }
484
0
    }
485
486
0
    if (p.tag != NULL) {
487
0
        if (p.tag->data_type != OSSL_PARAM_OCTET_STRING) {
488
0
            ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
489
0
            return 0;
490
0
        }
491
0
        if (!ctx->base.enc) {
492
0
            ERR_raise(ERR_LIB_PROV, PROV_R_TAG_NOT_SET);
493
0
            return 0;
494
0
        }
495
0
        if (p.tag->data_size != ctx->taglen) {
496
0
            ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_TAG_LENGTH);
497
0
            return 0;
498
0
        }
499
0
        memcpy(p.tag->data, ctx->tag, ctx->taglen);
500
0
    }
501
0
    return 1;
502
0
}
503
504
static int aes_ocb_cipher(void *vctx, unsigned char *out, size_t *outl,
505
    size_t outsize, const unsigned char *in, size_t inl)
506
0
{
507
0
    PROV_AES_OCB_CTX *ctx = (PROV_AES_OCB_CTX *)vctx;
508
509
0
    if (!ossl_prov_is_running())
510
0
        return 0;
511
512
    /*
513
     * EVP_Cipher() MUST CHECK THE TAG
514
     * in == NULL indicates finalize, so hand it to the finalize path
515
     * (which checks the tag on decrypt / produces it on encrypt)
516
     */
517
0
    if (in == NULL)
518
0
        return aes_ocb_block_final(vctx, out, outl, outsize);
519
520
0
    if (outsize < inl) {
521
0
        ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
522
0
        return 0;
523
0
    }
524
525
    /*
526
     * Mirror the streaming handler: refuse if the key has not been set,
527
     * and push the buffered IV into the OCB context before any data is
528
     * processed.  Without this, CRYPTO_ocb128_encrypt/decrypt runs with
529
     * Offset_0 = 0 regardless of the caller's IV -- catastrophic
530
     * (key, nonce) reuse, and a subsequent EVP_*Final_ex() emits a tag
531
     * that is a function of (key, iv) only.
532
     */
533
0
    if (!ctx->key_set || !update_iv(ctx)) {
534
0
        ERR_raise(ERR_LIB_PROV, PROV_R_CIPHER_OPERATION_FAILED);
535
0
        return 0;
536
0
    }
537
538
0
    if (!aes_generic_ocb_cipher(ctx, in, out, inl)) {
539
0
        ERR_raise(ERR_LIB_PROV, PROV_R_CIPHER_OPERATION_FAILED);
540
0
        return 0;
541
0
    }
542
543
0
    *outl = inl;
544
0
    return 1;
545
0
}
546
547
#define IMPLEMENT_cipher(mode, UCMODE, flags, kbits, blkbits, ivbits)           \
548
    static OSSL_FUNC_cipher_get_params_fn aes_##kbits##_##mode##_get_params;    \
549
    static int aes_##kbits##_##mode##_get_params(OSSL_PARAM params[])           \
550
3
    {                                                                           \
551
3
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE, \
552
3
            flags, kbits, blkbits, ivbits);                                     \
553
3
    }                                                                           \
cipher_aes_ocb.c:aes_256_ocb_get_params
Line
Count
Source
550
1
    {                                                                           \
551
1
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE, \
552
1
            flags, kbits, blkbits, ivbits);                                     \
553
1
    }                                                                           \
cipher_aes_ocb.c:aes_192_ocb_get_params
Line
Count
Source
550
1
    {                                                                           \
551
1
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE, \
552
1
            flags, kbits, blkbits, ivbits);                                     \
553
1
    }                                                                           \
cipher_aes_ocb.c:aes_128_ocb_get_params
Line
Count
Source
550
1
    {                                                                           \
551
1
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE, \
552
1
            flags, kbits, blkbits, ivbits);                                     \
553
1
    }                                                                           \
554
    static OSSL_FUNC_cipher_newctx_fn aes_##kbits##_##mode##_newctx;            \
555
    static void *aes_##kbits##_##mode##_newctx(void *provctx)                   \
556
0
    {                                                                           \
557
0
        return aes_##mode##_newctx(provctx, kbits, blkbits, ivbits,             \
558
0
            EVP_CIPH_##UCMODE##_MODE, flags);                                   \
559
0
    }                                                                           \
Unexecuted instantiation: cipher_aes_ocb.c:aes_256_ocb_newctx
Unexecuted instantiation: cipher_aes_ocb.c:aes_192_ocb_newctx
Unexecuted instantiation: cipher_aes_ocb.c:aes_128_ocb_newctx
560
    const OSSL_DISPATCH ossl_##aes##kbits##mode##_functions[] = {               \
561
        { OSSL_FUNC_CIPHER_NEWCTX,                                              \
562
            (void (*)(void))aes_##kbits##_##mode##_newctx },                    \
563
        { OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void))aes_##mode##_einit },  \
564
        { OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void))aes_##mode##_dinit },  \
565
        { OSSL_FUNC_CIPHER_UPDATE, (void (*)(void))aes_##mode##_block_update }, \
566
        { OSSL_FUNC_CIPHER_FINAL, (void (*)(void))aes_##mode##_block_final },   \
567
        { OSSL_FUNC_CIPHER_CIPHER, (void (*)(void))aes_ocb_cipher },            \
568
        { OSSL_FUNC_CIPHER_FREECTX, (void (*)(void))aes_##mode##_freectx },     \
569
        { OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void))aes_##mode##_dupctx },       \
570
        { OSSL_FUNC_CIPHER_GET_PARAMS,                                          \
571
            (void (*)(void))aes_##kbits##_##mode##_get_params },                \
572
        { OSSL_FUNC_CIPHER_GET_CTX_PARAMS,                                      \
573
            (void (*)(void))aes_##mode##_get_ctx_params },                      \
574
        { OSSL_FUNC_CIPHER_SET_CTX_PARAMS,                                      \
575
            (void (*)(void))aes_##mode##_set_ctx_params },                      \
576
        { OSSL_FUNC_CIPHER_GETTABLE_PARAMS,                                     \
577
            (void (*)(void))ossl_cipher_generic_gettable_params },              \
578
        { OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS,                                 \
579
            (void (*)(void))cipher_ocb_gettable_ctx_params },                   \
580
        { OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS,                                 \
581
            (void (*)(void))cipher_ocb_settable_ctx_params },                   \
582
        OSSL_DISPATCH_END                                                       \
583
    }
584
585
IMPLEMENT_cipher(ocb, OCB, AES_OCB_FLAGS, 256, 128, OCB_DEFAULT_IV_LEN * 8);
586
IMPLEMENT_cipher(ocb, OCB, AES_OCB_FLAGS, 192, 128, OCB_DEFAULT_IV_LEN * 8);
587
IMPLEMENT_cipher(ocb, OCB, AES_OCB_FLAGS, 128, 128, OCB_DEFAULT_IV_LEN * 8);