Coverage Report

Created: 2024-11-21 07:03

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