Coverage Report

Created: 2025-11-11 06:20

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