xref: /freebsd/crypto/openssl/include/openssl/des.h (revision 1719886f6d08408b834d270c59ffcfd821c8f63a)
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
23 extern "C" {
24 #  endif
25 #  include <openssl/e_os2.h>
26 
27 #  ifndef OPENSSL_NO_DEPRECATED_3_0
28 typedef unsigned int DES_LONG;
29 
30 #   ifdef OPENSSL_BUILD_SHLIBCRYPTO
31 #    undef OPENSSL_EXTERN
32 #    define OPENSSL_EXTERN OPENSSL_EXPORT
33 #   endif
34 
35 typedef unsigned char DES_cblock[8];
36 typedef /* 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 
42 typedef 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
76 OSSL_DEPRECATEDIN_3_0 const char *DES_options(void);
77 OSSL_DEPRECATEDIN_3_0
78 void 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);
81 OSSL_DEPRECATEDIN_3_0
82 DES_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
88 OSSL_DEPRECATEDIN_3_0
89 void DES_cbc_encrypt(const unsigned char *input, unsigned char *output,
90                      long length, DES_key_schedule *schedule, DES_cblock *ivec,
91                      int enc);
92 OSSL_DEPRECATEDIN_3_0
93 void DES_ncbc_encrypt(const unsigned char *input, unsigned char *output,
94                       long length, DES_key_schedule *schedule, DES_cblock *ivec,
95                       int enc);
96 OSSL_DEPRECATEDIN_3_0
97 void 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);
100 OSSL_DEPRECATEDIN_3_0
101 void 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);
104 OSSL_DEPRECATEDIN_3_0
105 void 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
120 OSSL_DEPRECATEDIN_3_0
121 void 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
133 OSSL_DEPRECATEDIN_3_0
134 void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc);
135 OSSL_DEPRECATEDIN_3_0
136 void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1, DES_key_schedule *ks2,
137                   DES_key_schedule *ks3);
138 OSSL_DEPRECATEDIN_3_0
139 void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1, DES_key_schedule *ks2,
140                   DES_key_schedule *ks3);
141 OSSL_DEPRECATEDIN_3_0
142 void 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);
146 OSSL_DEPRECATEDIN_3_0
147 void 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);
151 OSSL_DEPRECATEDIN_3_0
152 void 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);
156 OSSL_DEPRECATEDIN_3_0
157 void 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);
161 OSSL_DEPRECATEDIN_3_0
162 char *DES_fcrypt(const char *buf, const char *salt, char *ret);
163 OSSL_DEPRECATEDIN_3_0
164 char *DES_crypt(const char *buf, const char *salt);
165 OSSL_DEPRECATEDIN_3_0
166 void DES_ofb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
167                      long length, DES_key_schedule *schedule, DES_cblock *ivec);
168 OSSL_DEPRECATEDIN_3_0
169 void DES_pcbc_encrypt(const unsigned char *input, unsigned char *output,
170                       long length, DES_key_schedule *schedule,
171                       DES_cblock *ivec, int enc);
172 OSSL_DEPRECATEDIN_3_0
173 DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[],
174                         long length, int out_count, DES_cblock *seed);
175 OSSL_DEPRECATEDIN_3_0 int DES_random_key(DES_cblock *ret);
176 OSSL_DEPRECATEDIN_3_0 void DES_set_odd_parity(DES_cblock *key);
177 OSSL_DEPRECATEDIN_3_0 int DES_check_key_parity(const_DES_cblock *key);
178 OSSL_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
185 OSSL_DEPRECATEDIN_3_0
186 int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule);
187 OSSL_DEPRECATEDIN_3_0
188 int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule);
189 OSSL_DEPRECATEDIN_3_0
190 int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule);
191 OSSL_DEPRECATEDIN_3_0
192 void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule);
193 OSSL_DEPRECATEDIN_3_0 void DES_string_to_key(const char *str, DES_cblock *key);
194 OSSL_DEPRECATEDIN_3_0
195 void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2);
196 OSSL_DEPRECATEDIN_3_0
197 void 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);
200 OSSL_DEPRECATEDIN_3_0
201 void 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