]> git.ipfire.org Git - thirdparty/openssl.git/blame - providers/implementations/ciphers/cipher_tdes.h
Update copyright year
[thirdparty/openssl.git] / providers / implementations / ciphers / cipher_tdes.h
CommitLineData
4a42e264 1/*
a28d06f3 2 * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
4a42e264
SL
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>
23c48d94 11#include <openssl/core_dispatch.h>
cc731bc3 12#include "crypto/des_platform.h"
4a42e264
SL
13
14#define DES_BLOCK_SIZE 8
15#define TDES_IVLEN 8
a054d15c 16#define TDES_FLAGS 0
4a42e264
SL
17
18typedef 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
592dcfd3 31#define IMPLEMENT_tdes_cipher(type, UCTYPE, lcmode, UCMODE, flags, \
4a42e264 32 kbits, blkbits, ivbits, block) \
592dcfd3 33static OSSL_FUNC_cipher_newctx_fn tdes_##type##_##lcmode##_newctx; \
4a42e264
SL
34static void *tdes_##type##_##lcmode##_newctx(void *provctx) \
35{ \
e36b3c2f 36 return ossl_tdes_newctx(provctx, EVP_CIPH_##UCMODE##_MODE, kbits, blkbits, \
7d6766cb
P
37 ivbits, flags, \
38 ossl_prov_cipher_hw_tdes_##type##_##lcmode()); \
4a42e264 39} \
592dcfd3 40static OSSL_FUNC_cipher_get_params_fn tdes_##type##_##lcmode##_get_params; \
4a42e264
SL
41static int tdes_##type##_##lcmode##_get_params(OSSL_PARAM params[]) \
42{ \
592dcfd3
P
43 return ossl_cipher_generic_get_params(params, EVP_CIPH_##UCMODE##_MODE, \
44 flags, kbits, blkbits, ivbits); \
4a42e264 45} \
1be63951 46const OSSL_DISPATCH ossl_tdes_##type##_##lcmode##_functions[] = { \
e36b3c2f
SL
47 { OSSL_FUNC_CIPHER_ENCRYPT_INIT, (void (*)(void))ossl_tdes_einit }, \
48 { OSSL_FUNC_CIPHER_DECRYPT_INIT, (void (*)(void))ossl_tdes_dinit }, \
4a42e264 49 { OSSL_FUNC_CIPHER_UPDATE, \
592dcfd3 50 (void (*)(void))ossl_cipher_generic_##block##_update }, \
e36b3c2f
SL
51 { OSSL_FUNC_CIPHER_FINAL, \
52 (void (*)(void))ossl_cipher_generic_##block##_final }, \
592dcfd3 53 { OSSL_FUNC_CIPHER_CIPHER, (void (*)(void))ossl_cipher_generic_cipher }, \
4a42e264
SL
54 { OSSL_FUNC_CIPHER_NEWCTX, \
55 (void (*)(void))tdes_##type##_##lcmode##_newctx }, \
e36b3c2f
SL
56 { OSSL_FUNC_CIPHER_DUPCTX, (void (*)(void))ossl_tdes_dupctx }, \
57 { OSSL_FUNC_CIPHER_FREECTX, (void (*)(void))ossl_tdes_freectx }, \
4a42e264
SL
58 { OSSL_FUNC_CIPHER_GET_PARAMS, \
59 (void (*)(void))tdes_##type##_##lcmode##_get_params }, \
60 { OSSL_FUNC_CIPHER_GETTABLE_PARAMS, \
592dcfd3 61 (void (*)(void))ossl_cipher_generic_gettable_params }, \
e36b3c2f
SL
62 { OSSL_FUNC_CIPHER_GET_CTX_PARAMS, \
63 (void (*)(void))ossl_tdes_get_ctx_params }, \
4a42e264 64 { OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS, \
e36b3c2f 65 (void (*)(void))ossl_tdes_gettable_ctx_params }, \
4a42e264 66 { OSSL_FUNC_CIPHER_SET_CTX_PARAMS, \
592dcfd3 67 (void (*)(void))ossl_cipher_generic_set_ctx_params }, \
4a42e264 68 { OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS, \
592dcfd3 69 (void (*)(void))ossl_cipher_generic_settable_ctx_params }, \
4a42e264
SL
70 { 0, NULL } \
71}
72
e36b3c2f
SL
73void *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);
75OSSL_FUNC_cipher_dupctx_fn ossl_tdes_dupctx;
76OSSL_FUNC_cipher_freectx_fn ossl_tdes_freectx;
77OSSL_FUNC_cipher_encrypt_init_fn ossl_tdes_einit;
78OSSL_FUNC_cipher_decrypt_init_fn ossl_tdes_dinit;
79OSSL_FUNC_cipher_get_ctx_params_fn ossl_tdes_get_ctx_params;
80OSSL_FUNC_cipher_gettable_ctx_params_fn ossl_tdes_gettable_ctx_params;
4a42e264 81
592dcfd3 82#define PROV_CIPHER_HW_tdes_mode(type, mode) \
4a42e264 83static const PROV_CIPHER_HW type##_##mode = { \
592dcfd3
P
84 ossl_cipher_hw_tdes_##type##_initkey, \
85 ossl_cipher_hw_tdes_##mode, \
86 ossl_cipher_hw_tdes_copyctx \
4a42e264 87}; \
7d6766cb 88const PROV_CIPHER_HW *ossl_prov_cipher_hw_tdes_##type##_##mode(void) \
4a42e264
SL
89{ \
90 return &type##_##mode; \
91}
92
592dcfd3
P
93int ossl_cipher_hw_tdes_ede3_initkey(PROV_CIPHER_CTX *ctx,
94 const unsigned char *key, size_t keylen);
95void ossl_cipher_hw_tdes_copyctx(PROV_CIPHER_CTX *dst,
96 const PROV_CIPHER_CTX *src);
97int ossl_cipher_hw_tdes_cbc(PROV_CIPHER_CTX *ctx, unsigned char *out,
98 const unsigned char *in, size_t inl);
99int ossl_cipher_hw_tdes_ecb(PROV_CIPHER_CTX *ctx, unsigned char *out,
100 const unsigned char *in, size_t len);
4a42e264 101
7d6766cb
P
102const PROV_CIPHER_HW *ossl_prov_cipher_hw_tdes_ede3_cbc(void);
103const PROV_CIPHER_HW *ossl_prov_cipher_hw_tdes_ede3_ecb(void);