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
10 #include <openssl/des.h>
11 #include "cipher_tdes_default.h"
14 * Note the PROV_TDES_CTX has been used for the DESX cipher, just to reduce
18 #define ks2 tks.ks[1].ks[0].cblock
19 #define ks3 tks.ks[2].ks[0].cblock
21 static int cipher_hw_desx_cbc_initkey(PROV_CIPHER_CTX
*ctx
,
22 const unsigned char *key
, size_t keylen
)
24 PROV_TDES_CTX
*tctx
= (PROV_TDES_CTX
*)ctx
;
25 DES_cblock
*deskey
= (DES_cblock
*)key
;
27 DES_set_key_unchecked(deskey
, &tctx
->ks1
);
28 memcpy(&tctx
->ks2
, &key
[8], 8);
29 memcpy(&tctx
->ks3
, &key
[16], 8);
34 static int cipher_hw_desx_cbc(PROV_CIPHER_CTX
*ctx
, unsigned char *out
,
35 const unsigned char *in
, size_t inl
)
37 PROV_TDES_CTX
*tctx
= (PROV_TDES_CTX
*)ctx
;
39 while (inl
>= MAXCHUNK
) {
40 DES_xcbc_encrypt(in
, out
, (long)MAXCHUNK
, &tctx
->ks1
,
41 (DES_cblock
*)ctx
->iv
, &tctx
->ks2
, &tctx
->ks3
,
48 DES_xcbc_encrypt(in
, out
, (long)inl
, &tctx
->ks1
,
49 (DES_cblock
*)ctx
->iv
, &tctx
->ks2
, &tctx
->ks3
,
54 static const PROV_CIPHER_HW desx_cbc
=
56 cipher_hw_desx_cbc_initkey
,
59 const PROV_CIPHER_HW
*PROV_CIPHER_HW_tdes_desx_cbc(void)