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