Coverage Report

Created: 2025-06-13 06:58

/src/openssl31/providers/implementations/ciphers/cipher_tdes.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2019-2021 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
#include <openssl/des.h>
11
#include <openssl/core_dispatch.h>
12
#include "crypto/des_platform.h"
13
14
0
#define DES_BLOCK_SIZE 8
15
0
#define TDES_IVLEN 8
16
#define TDES_FLAGS PROV_CIPHER_FLAG_RAND_KEY
17
18
typedef struct prov_tdes_ctx_st {
19
    PROV_CIPHER_CTX base;      /* Must be first */
20
    union {
21
        OSSL_UNION_ALIGN;
22
        DES_key_schedule ks[3];
23
    } tks;
24
    union {
25
        void (*cbc) (const void *, void *, size_t,
26
                     const DES_key_schedule *, unsigned char *);
27
    } tstream;
28
29
} PROV_TDES_CTX;
30
31
#define IMPLEMENT_tdes_cipher(type, UCTYPE, lcmode, UCMODE, flags,             \
32
                              kbits, blkbits, ivbits, block)                   \
33
static OSSL_FUNC_cipher_newctx_fn tdes_##type##_##lcmode##_newctx;             \
34
1.91k
static void *tdes_##type##_##lcmode##_newctx(void *provctx)                    \
35
1.91k
{                                                                              \
36
1.91k
    return ossl_tdes_newctx(provctx, EVP_CIPH_##UCMODE##_MODE, kbits, blkbits, \
37
1.91k
                       ivbits, flags,                                          \
38
1.91k
                       ossl_prov_cipher_hw_tdes_##type##_##lcmode());          \
39
1.91k
}                                                                              \
Unexecuted instantiation: cipher_tdes.c:tdes_ede3_ecb_newctx
cipher_tdes.c:tdes_ede3_cbc_newctx
Line
Count
Source
34
1.91k
static void *tdes_##type##_##lcmode##_newctx(void *provctx)                    \
35
1.91k
{                                                                              \
36
1.91k
    return ossl_tdes_newctx(provctx, EVP_CIPH_##UCMODE##_MODE, kbits, blkbits, \
37
1.91k
                       ivbits, flags,                                          \
38
1.91k
                       ossl_prov_cipher_hw_tdes_##type##_##lcmode());          \
39
1.91k
}                                                                              \
Unexecuted instantiation: cipher_tdes_default.c:tdes_ede3_ofb_newctx
Unexecuted instantiation: cipher_tdes_default.c:tdes_ede3_cfb_newctx
Unexecuted instantiation: cipher_tdes_default.c:tdes_ede3_cfb1_newctx
Unexecuted instantiation: cipher_tdes_default.c:tdes_ede3_cfb8_newctx
Unexecuted instantiation: cipher_tdes_default.c:tdes_ede2_ecb_newctx
Unexecuted instantiation: cipher_tdes_default.c:tdes_ede2_cbc_newctx
Unexecuted instantiation: cipher_tdes_default.c:tdes_ede2_ofb_newctx
Unexecuted instantiation: cipher_tdes_default.c:tdes_ede2_cfb_newctx
40
static OSSL_FUNC_cipher_get_params_fn tdes_##type##_##lcmode##_get_params;     \
41
31.3k
static int tdes_##type##_##lcmode##_get_params(OSSL_PARAM params[])            \
42
31.3k
{                                                                              \
43
31.3k
    return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,    \
44
31.3k
                                          flags, kbits, blkbits, ivbits);      \
45
31.3k
}                                                                              \
cipher_tdes.c:tdes_ede3_ecb_get_params
Line
Count
Source
41
25
static int tdes_##type##_##lcmode##_get_params(OSSL_PARAM params[])            \
42
25
{                                                                              \
43
25
    return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,    \
44
25
                                          flags, kbits, blkbits, ivbits);      \
45
25
}                                                                              \
cipher_tdes.c:tdes_ede3_cbc_get_params
Line
Count
Source
41
31.0k
static int tdes_##type##_##lcmode##_get_params(OSSL_PARAM params[])            \
42
31.0k
{                                                                              \
43
31.0k
    return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,    \
44
31.0k
                                          flags, kbits, blkbits, ivbits);      \
45
31.0k
}                                                                              \
cipher_tdes_default.c:tdes_ede3_ofb_get_params
Line
Count
Source
41
25
static int tdes_##type##_##lcmode##_get_params(OSSL_PARAM params[])            \
42
25
{                                                                              \
43
25
    return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,    \
44
25
                                          flags, kbits, blkbits, ivbits);      \
45
25
}                                                                              \
cipher_tdes_default.c:tdes_ede3_cfb_get_params
Line
Count
Source
41
25
static int tdes_##type##_##lcmode##_get_params(OSSL_PARAM params[])            \
42
25
{                                                                              \
43
25
    return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,    \
44
25
                                          flags, kbits, blkbits, ivbits);      \
45
25
}                                                                              \
cipher_tdes_default.c:tdes_ede3_cfb1_get_params
Line
Count
Source
41
25
static int tdes_##type##_##lcmode##_get_params(OSSL_PARAM params[])            \
42
25
{                                                                              \
43
25
    return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,    \
44
25
                                          flags, kbits, blkbits, ivbits);      \
45
25
}                                                                              \
cipher_tdes_default.c:tdes_ede3_cfb8_get_params
Line
Count
Source
41
25
static int tdes_##type##_##lcmode##_get_params(OSSL_PARAM params[])            \
42
25
{                                                                              \
43
25
    return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,    \
44
25
                                          flags, kbits, blkbits, ivbits);      \
45
25
}                                                                              \
cipher_tdes_default.c:tdes_ede2_ecb_get_params
Line
Count
Source
41
25
static int tdes_##type##_##lcmode##_get_params(OSSL_PARAM params[])            \
42
25
{                                                                              \
43
25
    return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,    \
44
25
                                          flags, kbits, blkbits, ivbits);      \
45
25
}                                                                              \
cipher_tdes_default.c:tdes_ede2_cbc_get_params
Line
Count
Source
41
25
static int tdes_##type##_##lcmode##_get_params(OSSL_PARAM params[])            \
42
25
{                                                                              \
43
25
    return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,    \
44
25
                                          flags, kbits, blkbits, ivbits);      \
45
25
}                                                                              \
cipher_tdes_default.c:tdes_ede2_ofb_get_params
Line
Count
Source
41
25
static int tdes_##type##_##lcmode##_get_params(OSSL_PARAM params[])            \
42
25
{                                                                              \
43
25
    return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,    \
44
25
                                          flags, kbits, blkbits, ivbits);      \
45
25
}                                                                              \
cipher_tdes_default.c:tdes_ede2_cfb_get_params
Line
Count
Source
41
25
static int tdes_##type##_##lcmode##_get_params(OSSL_PARAM params[])            \
42
25
{                                                                              \
43
25
    return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE,    \
44
25
                                          flags, kbits, blkbits, ivbits);      \
45
25
}                                                                              \
46
const OSSL_DISPATCH ossl_tdes_##type##_##lcmode##_functions[] = {              \
47
    { OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void))ossl_tdes_einit },        \
48
    { OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void))ossl_tdes_dinit },        \
49
    { OSSL_FUNC_CIPHER_UPDATE,                                                 \
50
      (void (*)(void))ossl_cipher_generic_##block##_update },                  \
51
    { OSSL_FUNC_CIPHER_FINAL,                                                  \
52
      (void (*)(void))ossl_cipher_generic_##block##_final },                   \
53
    { OSSL_FUNC_CIPHER_CIPHER, (void (*)(void))ossl_cipher_generic_cipher },   \
54
    { OSSL_FUNC_CIPHER_NEWCTX,                                                 \
55
      (void (*)(void))tdes_##type##_##lcmode##_newctx },                       \
56
    { OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void))ossl_tdes_dupctx },             \
57
    { OSSL_FUNC_CIPHER_FREECTX, (void (*)(void))ossl_tdes_freectx },           \
58
    { OSSL_FUNC_CIPHER_GET_PARAMS,                                             \
59
      (void (*)(void))tdes_##type##_##lcmode##_get_params },                   \
60
    { OSSL_FUNC_CIPHER_GETTABLE_PARAMS,                                        \
61
      (void (*)(void))ossl_cipher_generic_gettable_params },                   \
62
    { OSSL_FUNC_CIPHER_GET_CTX_PARAMS,                                         \
63
      (void (*)(void))ossl_tdes_get_ctx_params },                              \
64
    { OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS,                                    \
65
      (void (*)(void))ossl_tdes_gettable_ctx_params },                         \
66
    { OSSL_FUNC_CIPHER_SET_CTX_PARAMS,                                         \
67
     (void (*)(void))ossl_cipher_generic_set_ctx_params },                     \
68
    { OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS,                                    \
69
     (void (*)(void))ossl_cipher_generic_settable_ctx_params },                \
70
    { 0, NULL }                                                                \
71
}
72
73
void *ossl_tdes_newctx(void *provctx, int mode, size_t kbits, size_t blkbits,
74
                       size_t ivbits, uint64_t flags, const PROV_CIPHER_HW *hw);
75
OSSL_FUNC_cipher_dupctx_fn ossl_tdes_dupctx;
76
OSSL_FUNC_cipher_freectx_fn ossl_tdes_freectx;
77
OSSL_FUNC_cipher_encrypt_init_fn ossl_tdes_einit;
78
OSSL_FUNC_cipher_decrypt_init_fn ossl_tdes_dinit;
79
OSSL_FUNC_cipher_get_ctx_params_fn ossl_tdes_get_ctx_params;
80
OSSL_FUNC_cipher_gettable_ctx_params_fn ossl_tdes_gettable_ctx_params;
81
82
#define PROV_CIPHER_HW_tdes_mode(type, mode)                                   \
83
static const PROV_CIPHER_HW type##_##mode = {                                  \
84
    ossl_cipher_hw_tdes_##type##_initkey,                                      \
85
    ossl_cipher_hw_tdes_##mode,                                                \
86
    ossl_cipher_hw_tdes_copyctx                                                \
87
};                                                                             \
88
1.91k
const PROV_CIPHER_HW *ossl_prov_cipher_hw_tdes_##type##_##mode(void)           \
89
1.91k
{                                                                              \
90
1.91k
    return &type##_##mode;                                                     \
91
1.91k
}
Unexecuted instantiation: ossl_prov_cipher_hw_tdes_ede3_ofb
Unexecuted instantiation: ossl_prov_cipher_hw_tdes_ede3_cfb
Unexecuted instantiation: ossl_prov_cipher_hw_tdes_ede3_cfb1
Unexecuted instantiation: ossl_prov_cipher_hw_tdes_ede3_cfb8
Unexecuted instantiation: ossl_prov_cipher_hw_tdes_ede2_ecb
Unexecuted instantiation: ossl_prov_cipher_hw_tdes_ede2_cbc
Unexecuted instantiation: ossl_prov_cipher_hw_tdes_ede2_ofb
Unexecuted instantiation: ossl_prov_cipher_hw_tdes_ede2_cfb
Unexecuted instantiation: ossl_prov_cipher_hw_tdes_ede3_ecb
ossl_prov_cipher_hw_tdes_ede3_cbc
Line
Count
Source
88
1.91k
const PROV_CIPHER_HW *ossl_prov_cipher_hw_tdes_##type##_##mode(void)           \
89
1.91k
{                                                                              \
90
1.91k
    return &type##_##mode;                                                     \
91
1.91k
}
Unexecuted instantiation: ossl_prov_cipher_hw_tdes_wrap_cbc
92
93
int ossl_cipher_hw_tdes_ede3_initkey(PROV_CIPHER_CTX *ctx,
94
                                     const unsigned char *key, size_t keylen);
95
void ossl_cipher_hw_tdes_copyctx(PROV_CIPHER_CTX *dst,
96
                                 const PROV_CIPHER_CTX *src);
97
int ossl_cipher_hw_tdes_cbc(PROV_CIPHER_CTX *ctx, unsigned char *out,
98
                            const unsigned char *in, size_t inl);
99
int ossl_cipher_hw_tdes_ecb(PROV_CIPHER_CTX *ctx, unsigned char *out,
100
                            const unsigned char *in, size_t len);
101
102
const PROV_CIPHER_HW *ossl_prov_cipher_hw_tdes_ede3_cbc(void);
103
const PROV_CIPHER_HW *ossl_prov_cipher_hw_tdes_ede3_ecb(void);