1/*
2 * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
3 *
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
8 */
9
10#ifndef OPENSSL_DES_H
11# define OPENSSL_DES_H
12# pragma once
13
14# include <openssl/macros.h>
15# ifndef OPENSSL_NO_DEPRECATED_3_0
16# define HEADER_DES_H
17# endif
18
19# include <openssl/opensslconf.h>
20
21# ifndef OPENSSL_NO_DES
22# ifdef __cplusplus
23extern "C" {
24# endif
25# include <openssl/e_os2.h>
26
27# ifndef OPENSSL_NO_DEPRECATED_3_0
28typedef unsigned int DES_LONG;
29
30# ifdef OPENSSL_BUILD_SHLIBCRYPTO
31# undef OPENSSL_EXTERN
32# define OPENSSL_EXTERN OPENSSL_EXPORT
33# endif
34
35typedef unsigned char DES_cblock[8];
36typedef /* const */ unsigned char const_DES_cblock[8];
37/*
38 * With "const", gcc 2.8.1 on Solaris thinks that DES_cblock * and
39 * const_DES_cblock * are incompatible pointer types.
40 */
41
42typedef struct DES_ks {
43 union {
44 DES_cblock cblock;
45 /*
46 * make sure things are correct size on machines with 8 byte longs
47 */
48 DES_LONG deslong[2];
49 } ks[16];
50} DES_key_schedule;
51
52# define DES_KEY_SZ (sizeof(DES_cblock))
53# define DES_SCHEDULE_SZ (sizeof(DES_key_schedule))
54
55# define DES_ENCRYPT 1
56# define DES_DECRYPT 0
57
58# define DES_CBC_MODE 0
59# define DES_PCBC_MODE 1
60
61# define DES_ecb2_encrypt(i,o,k1,k2,e) \
62 DES_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
63
64# define DES_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
65 DES_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
66
67# define DES_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
68 DES_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
69
70# define DES_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
71 DES_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
72
73# define DES_fixup_key_parity DES_set_odd_parity
74# endif
75# ifndef OPENSSL_NO_DEPRECATED_3_0
76OSSL_DEPRECATEDIN_3_0 const char *DES_options(void);
77OSSL_DEPRECATEDIN_3_0
78void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output,
79 DES_key_schedule *ks1, DES_key_schedule *ks2,
80 DES_key_schedule *ks3, int enc);
81OSSL_DEPRECATEDIN_3_0
82DES_LONG DES_cbc_cksum(const unsigned char *input, DES_cblock *output,
83 long length, DES_key_schedule *schedule,
84 const_DES_cblock *ivec);
85# endif
86/* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */
87# ifndef OPENSSL_NO_DEPRECATED_3_0
88OSSL_DEPRECATEDIN_3_0
89void DES_cbc_encrypt(const unsigned char *input, unsigned char *output,
90 long length, DES_key_schedule *schedule, DES_cblock *ivec,
91 int enc);
92OSSL_DEPRECATEDIN_3_0
93void DES_ncbc_encrypt(const unsigned char *input, unsigned char *output,
94 long length, DES_key_schedule *schedule, DES_cblock *ivec,
95 int enc);
96OSSL_DEPRECATEDIN_3_0
97void DES_xcbc_encrypt(const unsigned char *input, unsigned char *output,
98 long length, DES_key_schedule *schedule, DES_cblock *ivec,
99 const_DES_cblock *inw, const_DES_cblock *outw, int enc);
100OSSL_DEPRECATEDIN_3_0
101void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
102 long length, DES_key_schedule *schedule, DES_cblock *ivec,
103 int enc);
104OSSL_DEPRECATEDIN_3_0
105void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
106 DES_key_schedule *ks, int enc);
107# endif
108
109/*
110 * This is the DES encryption function that gets called by just about every
111 * other DES routine in the library. You should not use this function except
112 * to implement 'modes' of DES. I say this because the functions that call
113 * this routine do the conversion from 'char *' to long, and this needs to be
114 * done to make sure 'non-aligned' memory access do not occur. The
115 * characters are loaded 'little endian'. Data is a pointer to 2 unsigned
116 * long's and ks is the DES_key_schedule to use. enc, is non zero specifies
117 * encryption, zero if decryption.
118 */
119# ifndef OPENSSL_NO_DEPRECATED_3_0
120OSSL_DEPRECATEDIN_3_0
121void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc);
122# endif
123
124/*
125 * This functions is the same as DES_encrypt1() except that the DES initial
126 * permutation (IP) and final permutation (FP) have been left out. As for
127 * DES_encrypt1(), you should not use this function. It is used by the
128 * routines in the library that implement triple DES. IP() DES_encrypt2()
129 * DES_encrypt2() DES_encrypt2() FP() is the same as DES_encrypt1()
130 * DES_encrypt1() DES_encrypt1() except faster :-).
131 */
132# ifndef OPENSSL_NO_DEPRECATED_3_0
133OSSL_DEPRECATEDIN_3_0
134void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc);
135OSSL_DEPRECATEDIN_3_0
136void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1, DES_key_schedule *ks2,
137 DES_key_schedule *ks3);
138OSSL_DEPRECATEDIN_3_0
139void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1, DES_key_schedule *ks2,
140 DES_key_schedule *ks3);
141OSSL_DEPRECATEDIN_3_0
142void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
143 long length, DES_key_schedule *ks1,
144 DES_key_schedule *ks2, DES_key_schedule *ks3,
145 DES_cblock *ivec, int enc);
146OSSL_DEPRECATEDIN_3_0
147void DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out,
148 long length, DES_key_schedule *ks1,
149 DES_key_schedule *ks2, DES_key_schedule *ks3,
150 DES_cblock *ivec, int *num, int enc);
151OSSL_DEPRECATEDIN_3_0
152void DES_ede3_cfb_encrypt(const unsigned char *in, unsigned char *out,
153 int numbits, long length, DES_key_schedule *ks1,
154 DES_key_schedule *ks2, DES_key_schedule *ks3,
155 DES_cblock *ivec, int enc);
156OSSL_DEPRECATEDIN_3_0
157void DES_ede3_ofb64_encrypt(const unsigned char *in, unsigned char *out,
158 long length, DES_key_schedule *ks1,
159 DES_key_schedule *ks2, DES_key_schedule *ks3,
160 DES_cblock *ivec, int *num);
161OSSL_DEPRECATEDIN_3_0
162char *DES_fcrypt(const char *buf, const char *salt, char *ret);
163OSSL_DEPRECATEDIN_3_0
164char *DES_crypt(const char *buf, const char *salt);
165OSSL_DEPRECATEDIN_3_0
166void DES_ofb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
167 long length, DES_key_schedule *schedule, DES_cblock *ivec);
168OSSL_DEPRECATEDIN_3_0
169void DES_pcbc_encrypt(const unsigned char *input, unsigned char *output,
170 long length, DES_key_schedule *schedule,
171 DES_cblock *ivec, int enc);
172OSSL_DEPRECATEDIN_3_0
173DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[],
174 long length, int out_count, DES_cblock *seed);
175OSSL_DEPRECATEDIN_3_0 int DES_random_key(DES_cblock *ret);
176OSSL_DEPRECATEDIN_3_0 void DES_set_odd_parity(DES_cblock *key);
177OSSL_DEPRECATEDIN_3_0 int DES_check_key_parity(const_DES_cblock *key);
178OSSL_DEPRECATEDIN_3_0 int DES_is_weak_key(const_DES_cblock *key);
179# endif
180/*
181 * DES_set_key (= set_key = DES_key_sched = key_sched) calls
182 * DES_set_key_checked
183 */
184# ifndef OPENSSL_NO_DEPRECATED_3_0
185OSSL_DEPRECATEDIN_3_0
186int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule);
187OSSL_DEPRECATEDIN_3_0
188int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule);
189OSSL_DEPRECATEDIN_3_0
190int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule);
191OSSL_DEPRECATEDIN_3_0
192void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule);
193OSSL_DEPRECATEDIN_3_0 void DES_string_to_key(const char *str, DES_cblock *key);
194OSSL_DEPRECATEDIN_3_0
195void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2);
196OSSL_DEPRECATEDIN_3_0
197void DES_cfb64_encrypt(const unsigned char *in, unsigned char *out,
198 long length, DES_key_schedule *schedule,
199 DES_cblock *ivec, int *num, int enc);
200OSSL_DEPRECATEDIN_3_0
201void DES_ofb64_encrypt(const unsigned char *in, unsigned char *out,
202 long length, DES_key_schedule *schedule,
203 DES_cblock *ivec, int *num);
204# endif
205
206# ifdef __cplusplus
207}
208# endif
209# endif
210
211#endif
212