2 * Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
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
11 * DES low level APIs are deprecated for public use, but still ok for internal
14 #include "internal/deprecated.h"
16 #include <openssl/des.h>
17 #include "cipher_tdes_default.h"
20 * Note the PROV_TDES_CTX has been used for the DESX cipher, just to reduce
24 #define ks2 tks.ks[1].ks[0].cblock
25 #define ks3 tks.ks[2].ks[0].cblock
27 static int cipher_hw_desx_cbc_initkey(PROV_CIPHER_CTX *ctx,
28 const unsigned char *key, size_t keylen)
30 PROV_TDES_CTX *tctx = (PROV_TDES_CTX *)ctx;
31 DES_cblock *deskey = (DES_cblock *)key;
33 DES_set_key_unchecked(deskey, &tctx->ks1);
34 memcpy(&tctx->ks2, &key[8], 8);
35 memcpy(&tctx->ks3, &key[16], 8);
40 static int cipher_hw_desx_cbc(PROV_CIPHER_CTX *ctx, unsigned char *out,
41 const unsigned char *in, size_t inl)
43 PROV_TDES_CTX *tctx = (PROV_TDES_CTX *)ctx;
45 while (inl >= MAXCHUNK) {
46 DES_xcbc_encrypt(in, out, (long)MAXCHUNK, &tctx->ks1,
47 (DES_cblock *)ctx->iv, &tctx->ks2, &tctx->ks3,
54 DES_xcbc_encrypt(in, out, (long)inl, &tctx->ks1,
55 (DES_cblock *)ctx->iv, &tctx->ks2, &tctx->ks3,
60 static const PROV_CIPHER_HW desx_cbc =
62 cipher_hw_desx_cbc_initkey,
65 const PROV_CIPHER_HW *PROV_CIPHER_HW_tdes_desx_cbc(void)