Coverage Report

Created: 2026-09-12 06:55

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/openssl41/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
21
#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
21
{
83
21
    CRYPTO_ocb128_cleanup(&ctx->ocb);
84
21
}
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
36
{
114
36
    PROV_AES_OCB_CTX *ctx = (PROV_AES_OCB_CTX *)vctx;
115
116
36
    if (!ossl_prov_is_running())
117
0
        return 0;
118
119
36
    ctx->aad_buf_len = 0;
120
36
    ctx->data_buf_len = 0;
121
36
    ctx->base.enc = enc;
122
123
36
    if (iv != NULL) {
124
3
        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
3
        if (!ossl_cipher_generic_initiv(&ctx->base, iv, ivlen))
133
0
            return 0;
134
3
        ctx->iv_state = IV_STATE_BUFFERED;
135
3
    }
136
36
    if (key != NULL) {
137
18
        if (keylen != ctx->base.keylen) {
138
0
            ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
139
0
            return 0;
140
0
        }
141
18
        if (!ctx->base.hw->init(&ctx->base, key, keylen))
142
0
            return 0;
143
18
    }
144
36
    return aes_ocb_set_ctx_params(ctx, params);
145
36
}
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
36
{
151
36
    return aes_ocb_init(vctx, key, keylen, iv, ivlen, params, 1);
152
36
}
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
15
{
225
15
    if (ctx->iv_state == IV_STATE_FINISHED
226
15
        || ctx->iv_state == IV_STATE_UNINITIALISED)
227
15
        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
15
{
241
15
    PROV_AES_OCB_CTX *ctx = (PROV_AES_OCB_CTX *)vctx;
242
15
    unsigned char *buf;
243
15
    size_t *buflen;
244
15
    OSSL_ocb_cipher_fn fn;
245
246
15
    if (!ctx->key_set || !update_iv(ctx))
247
15
        return 0;
248
249
0
    if (inl == 0) {
250
0
        *outl = 0;
251
0
        return 1;
252
0
    }
253
254
    /* Are we dealing with AAD or normal data here? */
255
0
    if (out == NULL) {
256
0
        buf = ctx->aad_buf;
257
0
        buflen = &ctx->aad_buf_len;
258
0
        fn = cipher_updateaad;
259
0
    } else {
260
0
        buf = ctx->data_buf;
261
0
        buflen = &ctx->data_buf_len;
262
0
        fn = aes_generic_ocb_cipher;
263
0
    }
264
0
    return aes_ocb_block_update_internal(ctx, buf, buflen, out, outl, outsize,
265
0
        in, inl, fn);
266
0
}
267
268
static int aes_ocb_block_final(void *vctx, unsigned char *out, size_t *outl,
269
    size_t outsize)
270
0
{
271
0
    PROV_AES_OCB_CTX *ctx = (PROV_AES_OCB_CTX *)vctx;
272
273
0
    if (!ossl_prov_is_running())
274
0
        return 0;
275
276
    /* If no block_update has run then the iv still needs to be set */
277
0
    if (!ctx->key_set || !update_iv(ctx))
278
0
        return 0;
279
280
    /*
281
     * Empty the buffer of any partial block that we might have been provided,
282
     * both for data and AAD
283
     */
284
0
    *outl = 0;
285
0
    if (ctx->data_buf_len > 0) {
286
0
        if (!aes_generic_ocb_cipher(ctx, ctx->data_buf, out, ctx->data_buf_len))
287
0
            return 0;
288
0
        *outl = ctx->data_buf_len;
289
0
        ctx->data_buf_len = 0;
290
0
    }
291
0
    if (ctx->aad_buf_len > 0) {
292
0
        if (!aes_generic_ocb_setaad(ctx, ctx->aad_buf, ctx->aad_buf_len))
293
0
            return 0;
294
0
        ctx->aad_buf_len = 0;
295
0
    }
296
0
    if (ctx->base.enc) {
297
        /* If encrypting then just get the tag */
298
0
        if (!aes_generic_ocb_gettag(ctx, ctx->tag, ctx->taglen))
299
0
            return 0;
300
0
    } else {
301
        /* If decrypting then verify */
302
0
        if (ctx->taglen == 0)
303
0
            return 0;
304
0
        if (!aes_generic_ocb_final(ctx))
305
0
            return 0;
306
0
    }
307
    /* Don't reuse the IV */
308
0
    ctx->iv_state = IV_STATE_FINISHED;
309
0
    return 1;
310
0
}
311
312
static void *aes_ocb_newctx(void *provctx, size_t kbits, size_t blkbits,
313
    size_t ivbits, unsigned int mode, uint64_t flags)
314
21
{
315
21
    PROV_AES_OCB_CTX *ctx;
316
317
21
    CIPHER_PROV_CHECK(provctx, AES_128_OCB);
318
21
    ctx = OPENSSL_zalloc(sizeof(*ctx));
319
21
    if (ctx != NULL) {
320
21
        ossl_cipher_generic_initkey(ctx, kbits, blkbits, ivbits, mode, flags,
321
21
            ossl_prov_cipher_hw_aes_ocb(kbits), NULL);
322
21
        ctx->taglen = OCB_DEFAULT_TAG_LEN;
323
21
    }
324
21
    return ctx;
325
21
}
326
327
static void aes_ocb_freectx(void *vctx)
328
21
{
329
21
    PROV_AES_OCB_CTX *ctx = (PROV_AES_OCB_CTX *)vctx;
330
331
21
    if (ctx != NULL) {
332
21
        aes_generic_ocb_cleanup(ctx);
333
21
        ossl_cipher_generic_reset_ctx((PROV_CIPHER_CTX *)vctx);
334
21
        OPENSSL_clear_free(ctx, sizeof(*ctx));
335
21
    }
336
21
}
337
338
static void *aes_ocb_dupctx(void *vctx)
339
0
{
340
0
    PROV_AES_OCB_CTX *in = (PROV_AES_OCB_CTX *)vctx;
341
0
    PROV_AES_OCB_CTX *ret;
342
343
0
    if (!ossl_prov_is_running())
344
0
        return NULL;
345
346
0
    ret = OPENSSL_malloc(sizeof(*ret));
347
0
    if (ret == NULL)
348
0
        return NULL;
349
0
    *ret = *in;
350
0
    if (!aes_generic_ocb_copy_ctx(ret, in)) {
351
0
        OPENSSL_free(ret);
352
0
        ret = NULL;
353
0
    }
354
0
    return ret;
355
0
}
356
357
static const OSSL_PARAM *cipher_ocb_settable_ctx_params(ossl_unused void *cctx,
358
    ossl_unused void *p_ctx)
359
11
{
360
11
    return aes_ocb_set_ctx_params_list;
361
11
}
362
363
static int aes_ocb_set_ctx_params(void *vctx, const OSSL_PARAM params[])
364
32
{
365
32
    PROV_AES_OCB_CTX *ctx = (PROV_AES_OCB_CTX *)vctx;
366
32
    struct aes_ocb_set_ctx_params_st p;
367
32
    size_t sz;
368
369
32
    if (ctx == NULL || !aes_ocb_set_ctx_params_decoder(params, &p))
370
0
        return 0;
371
372
32
    if (p.tag != NULL) {
373
3
        if (p.tag->data_type != OSSL_PARAM_OCTET_STRING) {
374
0
            ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
375
0
            return 0;
376
0
        }
377
3
        if (p.tag->data == NULL) {
378
            /* Tag len must be 0 to 16 */
379
0
            if (p.tag->data_size > OCB_MAX_TAG_LEN) {
380
0
                ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_TAG_LENGTH);
381
0
                return 0;
382
0
            }
383
0
            ctx->taglen = p.tag->data_size;
384
3
        } else {
385
3
            if (ctx->base.enc) {
386
3
                ERR_raise(ERR_LIB_PROV, PROV_R_TAG_NOT_NEEDED);
387
3
                return 0;
388
3
            }
389
0
            if (p.tag->data_size != ctx->taglen) {
390
0
                ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_TAG_LENGTH);
391
0
                return 0;
392
0
            }
393
0
            memcpy(ctx->tag, p.tag->data, p.tag->data_size);
394
0
        }
395
3
    }
396
397
29
    if (p.ivlen != NULL) {
398
0
        if (!OSSL_PARAM_get_size_t(p.ivlen, &sz)) {
399
0
            ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
400
0
            return 0;
401
0
        }
402
        /* IV len must be 1 to 15 */
403
0
        if (sz < OCB_MIN_IV_LEN || sz > OCB_MAX_IV_LEN)
404
0
            return 0;
405
0
        if (ctx->base.ivlen != sz) {
406
0
            ctx->base.ivlen = sz;
407
0
            ctx->iv_state = IV_STATE_UNINITIALISED;
408
0
        }
409
0
    }
410
411
29
    if (p.keylen != NULL) {
412
1
        size_t keylen;
413
414
1
        if (!OSSL_PARAM_get_size_t(p.keylen, &keylen)) {
415
0
            ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
416
0
            return 0;
417
0
        }
418
1
        if (ctx->base.keylen != keylen) {
419
1
            ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_KEY_LENGTH);
420
1
            return 0;
421
1
        }
422
1
    }
423
28
    return 1;
424
29
}
425
426
static const OSSL_PARAM *cipher_ocb_gettable_ctx_params(ossl_unused void *cctx,
427
    ossl_unused void *p_ctx)
428
210
{
429
210
    return aes_ocb_get_ctx_params_list;
430
210
}
431
432
static int aes_ocb_get_ctx_params(void *vctx, OSSL_PARAM params[])
433
15
{
434
15
    PROV_AES_OCB_CTX *ctx = (PROV_AES_OCB_CTX *)vctx;
435
15
    struct aes_ocb_get_ctx_params_st p;
436
437
15
    if (ctx == NULL || !aes_ocb_get_ctx_params_decoder(params, &p))
438
0
        return 0;
439
440
15
    if (p.ivlen != NULL && !OSSL_PARAM_set_size_t(p.ivlen, ctx->base.ivlen)) {
441
0
        ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
442
0
        return 0;
443
0
    }
444
445
15
    if (p.keylen != NULL && !OSSL_PARAM_set_size_t(p.keylen, ctx->base.keylen)) {
446
0
        ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
447
0
        return 0;
448
0
    }
449
450
15
    if (p.taglen != NULL) {
451
0
        if (!OSSL_PARAM_set_size_t(p.taglen, ctx->taglen)) {
452
0
            ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
453
0
            return 0;
454
0
        }
455
0
    }
456
457
15
    if (p.iv != NULL) {
458
0
        if (ctx->base.ivlen > p.iv->data_size) {
459
0
            ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_IV_LENGTH);
460
0
            return 0;
461
0
        }
462
0
        if (!OSSL_PARAM_set_octet_string_or_ptr(p.iv, ctx->base.oiv,
463
0
                ctx->base.ivlen)) {
464
0
            ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
465
0
            return 0;
466
0
        }
467
0
    }
468
469
15
    if (p.upd_iv != NULL) {
470
0
        if (ctx->base.ivlen > p.upd_iv->data_size) {
471
0
            ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_IV_LENGTH);
472
0
            return 0;
473
0
        }
474
0
        if (!OSSL_PARAM_set_octet_string_or_ptr(p.upd_iv, ctx->base.iv,
475
0
                ctx->base.ivlen)) {
476
0
            ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_SET_PARAMETER);
477
0
            return 0;
478
0
        }
479
0
    }
480
481
15
    if (p.tag != NULL) {
482
0
        if (p.tag->data_type != OSSL_PARAM_OCTET_STRING) {
483
0
            ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
484
0
            return 0;
485
0
        }
486
0
        if (!ctx->base.enc) {
487
0
            ERR_raise(ERR_LIB_PROV, PROV_R_TAG_NOT_SET);
488
0
            return 0;
489
0
        }
490
0
        if (p.tag->data_size != ctx->taglen) {
491
0
            ERR_raise(ERR_LIB_PROV, PROV_R_INVALID_TAG_LENGTH);
492
0
            return 0;
493
0
        }
494
0
        memcpy(p.tag->data, ctx->tag, ctx->taglen);
495
0
    }
496
15
    return 1;
497
15
}
498
499
static int aes_ocb_cipher(void *vctx, unsigned char *out, size_t *outl,
500
    size_t outsize, const unsigned char *in, size_t inl)
501
0
{
502
0
    PROV_AES_OCB_CTX *ctx = (PROV_AES_OCB_CTX *)vctx;
503
504
0
    if (!ossl_prov_is_running())
505
0
        return 0;
506
507
    /*
508
     * EVP_Cipher() MUST CHECK THE TAG
509
     * in == NULL indicates finalize, so hand it to the finalize path
510
     * (which checks the tag on decrypt / produces it on encrypt)
511
     */
512
0
    if (in == NULL)
513
0
        return aes_ocb_block_final(vctx, out, outl, outsize);
514
515
0
    if (outsize < inl) {
516
0
        ERR_raise(ERR_LIB_PROV, PROV_R_OUTPUT_BUFFER_TOO_SMALL);
517
0
        return 0;
518
0
    }
519
520
    /*
521
     * Mirror the streaming handler: refuse if the key has not been set,
522
     * and push the buffered IV into the OCB context before any data is
523
     * processed.  Without this, CRYPTO_ocb128_encrypt/decrypt runs with
524
     * Offset_0 = 0 regardless of the caller's IV -- catastrophic
525
     * (key, nonce) reuse, and a subsequent EVP_*Final_ex() emits a tag
526
     * that is a function of (key, iv) only.
527
     */
528
0
    if (!ctx->key_set || !update_iv(ctx)) {
529
0
        ERR_raise(ERR_LIB_PROV, PROV_R_CIPHER_OPERATION_FAILED);
530
0
        return 0;
531
0
    }
532
533
0
    if (!aes_generic_ocb_cipher(ctx, in, out, inl)) {
534
0
        ERR_raise(ERR_LIB_PROV, PROV_R_CIPHER_OPERATION_FAILED);
535
0
        return 0;
536
0
    }
537
538
0
    *outl = inl;
539
0
    return 1;
540
0
}
541
542
#define IMPLEMENT_cipher(mode, UCMODE, flags, kbits, blkbits, ivbits)           \
543
    static OSSL_FUNC_cipher_get_params_fn aes_##kbits##_##mode##_get_params;    \
544
    static int aes_##kbits##_##mode##_get_params(OSSL_PARAM params[])           \
545
210
    {                                                                           \
546
210
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE, \
547
210
            flags, kbits, blkbits, ivbits);                                     \
548
210
    }                                                                           \
cipher_aes_ocb.c:aes_256_ocb_get_params
Line
Count
Source
545
70
    {                                                                           \
546
70
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE, \
547
70
            flags, kbits, blkbits, ivbits);                                     \
548
70
    }                                                                           \
cipher_aes_ocb.c:aes_192_ocb_get_params
Line
Count
Source
545
70
    {                                                                           \
546
70
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE, \
547
70
            flags, kbits, blkbits, ivbits);                                     \
548
70
    }                                                                           \
cipher_aes_ocb.c:aes_128_ocb_get_params
Line
Count
Source
545
70
    {                                                                           \
546
70
        return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE, \
547
70
            flags, kbits, blkbits, ivbits);                                     \
548
70
    }                                                                           \
549
    static OSSL_FUNC_cipher_newctx_fn aes_##kbits##_##mode##_newctx;            \
550
    static void *aes_##kbits##_##mode##_newctx(void *provctx)                   \
551
21
    {                                                                           \
552
21
        return aes_##mode##_newctx(provctx, kbits, blkbits, ivbits,             \
553
21
            EVP_CIPH_##UCMODE##_MODE, flags);                                   \
554
21
    }                                                                           \
cipher_aes_ocb.c:aes_256_ocb_newctx
Line
Count
Source
551
16
    {                                                                           \
552
16
        return aes_##mode##_newctx(provctx, kbits, blkbits, ivbits,             \
553
16
            EVP_CIPH_##UCMODE##_MODE, flags);                                   \
554
16
    }                                                                           \
cipher_aes_ocb.c:aes_192_ocb_newctx
Line
Count
Source
551
2
    {                                                                           \
552
2
        return aes_##mode##_newctx(provctx, kbits, blkbits, ivbits,             \
553
2
            EVP_CIPH_##UCMODE##_MODE, flags);                                   \
554
2
    }                                                                           \
cipher_aes_ocb.c:aes_128_ocb_newctx
Line
Count
Source
551
3
    {                                                                           \
552
3
        return aes_##mode##_newctx(provctx, kbits, blkbits, ivbits,             \
553
3
            EVP_CIPH_##UCMODE##_MODE, flags);                                   \
554
3
    }                                                                           \
555
    const OSSL_DISPATCH ossl_##aes##kbits##mode##_functions[] = {               \
556
        { OSSL_FUNC_CIPHER_NEWCTX,                                              \
557
            (void (*)(void))aes_##kbits##_##mode##_newctx },                    \
558
        { OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void))aes_##mode##_einit },  \
559
        { OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void))aes_##mode##_dinit },  \
560
        { OSSL_FUNC_CIPHER_UPDATE, (void (*)(void))aes_##mode##_block_update }, \
561
        { OSSL_FUNC_CIPHER_FINAL, (void (*)(void))aes_##mode##_block_final },   \
562
        { OSSL_FUNC_CIPHER_CIPHER, (void (*)(void))aes_ocb_cipher },            \
563
        { OSSL_FUNC_CIPHER_FREECTX, (void (*)(void))aes_##mode##_freectx },     \
564
        { OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void))aes_##mode##_dupctx },       \
565
        { OSSL_FUNC_CIPHER_GET_PARAMS,                                          \
566
            (void (*)(void))aes_##kbits##_##mode##_get_params },                \
567
        { OSSL_FUNC_CIPHER_GET_CTX_PARAMS,                                      \
568
            (void (*)(void))aes_##mode##_get_ctx_params },                      \
569
        { OSSL_FUNC_CIPHER_SET_CTX_PARAMS,                                      \
570
            (void (*)(void))aes_##mode##_set_ctx_params },                      \
571
        { OSSL_FUNC_CIPHER_GETTABLE_PARAMS,                                     \
572
            (void (*)(void))ossl_cipher_generic_gettable_params },              \
573
        { OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS,                                 \
574
            (void (*)(void))cipher_ocb_gettable_ctx_params },                   \
575
        { OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS,                                 \
576
            (void (*)(void))cipher_ocb_settable_ctx_params },                   \
577
        OSSL_DISPATCH_END                                                       \
578
    }
579
580
IMPLEMENT_cipher(ocb, OCB, AES_OCB_FLAGS, 256, 128, OCB_DEFAULT_IV_LEN * 8);
581
IMPLEMENT_cipher(ocb, OCB, AES_OCB_FLAGS, 192, 128, OCB_DEFAULT_IV_LEN * 8);
582
IMPLEMENT_cipher(ocb, OCB, AES_OCB_FLAGS, 128, 128, OCB_DEFAULT_IV_LEN * 8);