]>
git.ipfire.org Git - thirdparty/openssl.git/blob - providers/common/ciphers/cipher_tdes_hw.c
92b6de24220ff0a272155999bc73663c3dd5c5b4
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 "cipher_locl.h"
11 #include "internal/ciphers/cipher_tdes.h"
17 int cipher_hw_tdes_ede3_initkey(PROV_CIPHER_CTX
*ctx
, const unsigned char *key
,
20 PROV_TDES_CTX
*tctx
= (PROV_TDES_CTX
*)ctx
;
21 DES_cblock
*deskey
= (DES_cblock
*)key
;
23 tctx
->tstream
.cbc
= NULL
;
24 # if defined(SPARC_DES_CAPABLE)
25 if (SPARC_DES_CAPABLE
) {
26 if (ctx
->mode
== EVP_CIPH_CBC_MODE
) {
27 des_t4_key_expand(&deskey
[0], &tctx
->ks1
);
28 des_t4_key_expand(&deskey
[1], &tctx
->ks2
);
29 des_t4_key_expand(&deskey
[2], &tctx
->ks3
);
30 tctx
->tstream
.cbc
= ctx
->enc
? des_t4_ede3_cbc_encrypt
:
31 des_t4_ede3_cbc_decrypt
;
36 DES_set_key_unchecked(&deskey
[0], &tctx
->ks1
);
37 DES_set_key_unchecked(&deskey
[1], &tctx
->ks2
);
38 DES_set_key_unchecked(&deskey
[2], &tctx
->ks3
);
42 int cipher_hw_tdes_cbc(PROV_CIPHER_CTX
*ctx
, unsigned char *out
,
43 const unsigned char *in
, size_t inl
)
45 PROV_TDES_CTX
*tctx
= (PROV_TDES_CTX
*)ctx
;
47 if (tctx
->tstream
.cbc
!= NULL
) {
48 (*tctx
->tstream
.cbc
) (in
, out
, inl
, tctx
->tks
.ks
, ctx
->iv
);
52 while (inl
>= MAXCHUNK
) {
53 DES_ede3_cbc_encrypt(in
, out
, (long)MAXCHUNK
, &tctx
->ks1
, &tctx
->ks2
,
54 &tctx
->ks3
, (DES_cblock
*)ctx
->iv
, ctx
->enc
);
60 DES_ede3_cbc_encrypt(in
, out
, (long)inl
, &tctx
->ks1
, &tctx
->ks2
,
61 &tctx
->ks3
, (DES_cblock
*)ctx
->iv
, ctx
->enc
);
65 int cipher_hw_tdes_ecb(PROV_CIPHER_CTX
*ctx
, unsigned char *out
,
66 const unsigned char *in
, size_t len
)
69 PROV_TDES_CTX
*tctx
= (PROV_TDES_CTX
*)ctx
;
71 if (len
< DES_BLOCK_SIZE
)
74 for (i
= 0, len
-= DES_BLOCK_SIZE
; i
<= len
; i
+= DES_BLOCK_SIZE
) {
75 DES_ecb3_encrypt((const_DES_cblock
*)(in
+ i
), (DES_cblock
*)(out
+ i
),
76 &tctx
->ks1
, &tctx
->ks2
, &tctx
->ks3
, ctx
->enc
);
81 PROV_CIPHER_HW_tdes_mode(ede3
, ecb
)
82 PROV_CIPHER_HW_tdes_mode(ede3
, cbc
)