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