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