]>
git.ipfire.org Git - thirdparty/openssl.git/blob - crypto/evp/e_xcbc_d.c
2 * Copyright 1995-2020 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"
17 #include "internal/cryptlib.h"
19 #ifndef OPENSSL_NO_DES
21 # include <openssl/evp.h>
22 # include <openssl/objects.h>
23 # include "crypto/evp.h"
24 # include <openssl/des.h>
25 # include "evp_local.h"
27 static int desx_cbc_init_key(EVP_CIPHER_CTX
*ctx
, const unsigned char *key
,
28 const unsigned char *iv
, int enc
);
29 static int desx_cbc_cipher(EVP_CIPHER_CTX
*ctx
, unsigned char *out
,
30 const unsigned char *in
, size_t inl
);
33 DES_key_schedule ks
; /* key schedule */
38 # define data(ctx) EVP_C_DATA(DESX_CBC_KEY,ctx)
40 static const EVP_CIPHER d_xcbc_cipher
= {
48 EVP_CIPHER_set_asn1_iv
,
49 EVP_CIPHER_get_asn1_iv
,
54 const EVP_CIPHER
*EVP_desx_cbc(void)
56 return &d_xcbc_cipher
;
59 static int desx_cbc_init_key(EVP_CIPHER_CTX
*ctx
, const unsigned char *key
,
60 const unsigned char *iv
, int enc
)
62 DES_cblock
*deskey
= (DES_cblock
*)key
;
64 DES_set_key_unchecked(deskey
, &data(ctx
)->ks
);
65 memcpy(&data(ctx
)->inw
[0], &key
[8], 8);
66 memcpy(&data(ctx
)->outw
[0], &key
[16], 8);
71 static int desx_cbc_cipher(EVP_CIPHER_CTX
*ctx
, unsigned char *out
,
72 const unsigned char *in
, size_t inl
)
74 while (inl
>= EVP_MAXCHUNK
) {
75 DES_xcbc_encrypt(in
, out
, (long)EVP_MAXCHUNK
, &data(ctx
)->ks
,
76 (DES_cblock
*)ctx
->iv
,
77 &data(ctx
)->inw
, &data(ctx
)->outw
,
78 EVP_CIPHER_CTX_encrypting(ctx
));
84 DES_xcbc_encrypt(in
, out
, (long)inl
, &data(ctx
)->ks
,
85 (DES_cblock
*)ctx
->iv
,
86 &data(ctx
)->inw
, &data(ctx
)->outw
,
87 EVP_CIPHER_CTX_encrypting(ctx
));