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 "prov/ciphercommon.h"
17 #include "cipher_tdes.h"
23 int cipher_hw_tdes_ede3_initkey(PROV_CIPHER_CTX *ctx, const unsigned char *key,
26 PROV_TDES_CTX *tctx = (PROV_TDES_CTX *)ctx;
27 DES_cblock *deskey = (DES_cblock *)key;
29 tctx->tstream.cbc = NULL;
30 # if defined(SPARC_DES_CAPABLE)
31 if (SPARC_DES_CAPABLE) {
32 if (ctx->mode == EVP_CIPH_CBC_MODE) {
33 des_t4_key_expand(&deskey[0], &tctx->ks1);
34 des_t4_key_expand(&deskey[1], &tctx->ks2);
35 des_t4_key_expand(&deskey[2], &tctx->ks3);
36 tctx->tstream.cbc = ctx->enc ? des_t4_ede3_cbc_encrypt :
37 des_t4_ede3_cbc_decrypt;
42 DES_set_key_unchecked(&deskey[0], &tctx->ks1);
43 DES_set_key_unchecked(&deskey[1], &tctx->ks2);
44 DES_set_key_unchecked(&deskey[2], &tctx->ks3);
48 int cipher_hw_tdes_cbc(PROV_CIPHER_CTX *ctx, unsigned char *out,
49 const unsigned char *in, size_t inl)
51 PROV_TDES_CTX *tctx = (PROV_TDES_CTX *)ctx;
53 if (tctx->tstream.cbc != NULL) {
54 (*tctx->tstream.cbc) (in, out, inl, tctx->tks.ks, ctx->iv);
58 while (inl >= MAXCHUNK) {
59 DES_ede3_cbc_encrypt(in, out, (long)MAXCHUNK, &tctx->ks1, &tctx->ks2,
60 &tctx->ks3, (DES_cblock *)ctx->iv, ctx->enc);
66 DES_ede3_cbc_encrypt(in, out, (long)inl, &tctx->ks1, &tctx->ks2,
67 &tctx->ks3, (DES_cblock *)ctx->iv, ctx->enc);
71 int cipher_hw_tdes_ecb(PROV_CIPHER_CTX *ctx, unsigned char *out,
72 const unsigned char *in, size_t len)
75 PROV_TDES_CTX *tctx = (PROV_TDES_CTX *)ctx;
77 if (len < DES_BLOCK_SIZE)
80 for (i = 0, len -= DES_BLOCK_SIZE; i <= len; i += DES_BLOCK_SIZE) {
81 DES_ecb3_encrypt((const_DES_cblock *)(in + i), (DES_cblock *)(out + i),
82 &tctx->ks1, &tctx->ks2, &tctx->ks3, ctx->enc);
87 PROV_CIPHER_HW_tdes_mode(ede3, ecb)
88 PROV_CIPHER_HW_tdes_mode(ede3, cbc)