]> git.ipfire.org Git - thirdparty/openssl.git/blame - crypto/evp/e_xcbc_d.c
Reorganize private crypto header files
[thirdparty/openssl.git] / crypto / evp / e_xcbc_d.c
CommitLineData
62867571
RS
1/*
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
d02b48c6 3 *
4a8b0c55 4 * Licensed under the Apache License 2.0 (the "License"). You may not use
62867571
RS
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
d02b48c6
RE
8 */
9
10#include <stdio.h>
b39fc560 11#include "internal/cryptlib.h"
9e9e8cb6
RL
12
13#ifndef OPENSSL_NO_DES
14
0f113f3e
MC
15# include <openssl/evp.h>
16# include <openssl/objects.h>
25f2138b 17# include "crypto/evp.h"
0f113f3e 18# include <openssl/des.h>
d02b48c6 19
1921eaad 20static int desx_cbc_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
0f113f3e 21 const unsigned char *iv, int enc);
be06a934 22static int desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
0f113f3e 23 const unsigned char *in, size_t inl);
dbad1690 24
0f113f3e
MC
25typedef struct {
26 DES_key_schedule ks; /* key schedule */
c2e4f17c
RL
27 DES_cblock inw;
28 DES_cblock outw;
0f113f3e 29} DESX_CBC_KEY;
dbad1690 30
6435f0f6 31# define data(ctx) EVP_C_DATA(DESX_CBC_KEY,ctx)
dbad1690 32
0f113f3e
MC
33static const EVP_CIPHER d_xcbc_cipher = {
34 NID_desx_cbc,
35 8, 24, 8,
36 EVP_CIPH_CBC_MODE,
37 desx_cbc_init_key,
38 desx_cbc_cipher,
39 NULL,
40 sizeof(DESX_CBC_KEY),
41 EVP_CIPHER_set_asn1_iv,
42 EVP_CIPHER_get_asn1_iv,
43 NULL,
44 NULL
45};
d02b48c6 46
13588350 47const EVP_CIPHER *EVP_desx_cbc(void)
0f113f3e 48{
26a7d938 49 return &d_xcbc_cipher;
0f113f3e
MC
50}
51
1921eaad 52static int desx_cbc_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
0f113f3e
MC
53 const unsigned char *iv, int enc)
54{
55 DES_cblock *deskey = (DES_cblock *)key;
edf0bfb5 56
0f113f3e
MC
57 DES_set_key_unchecked(deskey, &data(ctx)->ks);
58 memcpy(&data(ctx)->inw[0], &key[8], 8);
59 memcpy(&data(ctx)->outw[0], &key[16], 8);
360370d9 60
0f113f3e
MC
61 return 1;
62}
d02b48c6 63
be06a934 64static int desx_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
0f113f3e
MC
65 const unsigned char *in, size_t inl)
66{
67 while (inl >= EVP_MAXCHUNK) {
68 DES_xcbc_encrypt(in, out, (long)EVP_MAXCHUNK, &data(ctx)->ks,
6435f0f6
RL
69 (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx),
70 &data(ctx)->inw, &data(ctx)->outw,
71 EVP_CIPHER_CTX_encrypting(ctx));
0f113f3e
MC
72 inl -= EVP_MAXCHUNK;
73 in += EVP_MAXCHUNK;
74 out += EVP_MAXCHUNK;
75 }
76 if (inl)
77 DES_xcbc_encrypt(in, out, (long)inl, &data(ctx)->ks,
6435f0f6
RL
78 (DES_cblock *)EVP_CIPHER_CTX_iv_noconst(ctx),
79 &data(ctx)->inw, &data(ctx)->outw,
80 EVP_CIPHER_CTX_encrypting(ctx));
0f113f3e
MC
81 return 1;
82}
d02f751c 83#endif