]> git.proxmox.com Git - efi-boot-shim.git/blob - Cryptlib/Include/openssl/des.h
New upstream version 15+1533136590.3beb971
[efi-boot-shim.git] / Cryptlib / Include / openssl / des.h
1 /*
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
3 *
4 * Licensed under the OpenSSL license (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 HEADER_DES_H
11 # define HEADER_DES_H
12
13 # include <openssl/opensslconf.h>
14
15 # ifndef OPENSSL_NO_DES
16 # ifdef __cplusplus
17 extern "C" {
18 # endif
19 # include <openssl/e_os2.h>
20
21 typedef unsigned int DES_LONG;
22
23 # ifdef OPENSSL_BUILD_SHLIBCRYPTO
24 # undef OPENSSL_EXTERN
25 # define OPENSSL_EXTERN OPENSSL_EXPORT
26 # endif
27
28 typedef unsigned char DES_cblock[8];
29 typedef /* const */ unsigned char const_DES_cblock[8];
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
45 # define DES_KEY_SZ (sizeof(DES_cblock))
46 # define DES_SCHEDULE_SZ (sizeof(DES_key_schedule))
47
48 # define DES_ENCRYPT 1
49 # define DES_DECRYPT 0
50
51 # define DES_CBC_MODE 0
52 # define DES_PCBC_MODE 1
53
54 # define DES_ecb2_encrypt(i,o,k1,k2,e) \
55 DES_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
56
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))
59
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))
62
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))
65
66 OPENSSL_DECLARE_GLOBAL(int, DES_check_key); /* defaults to false */
67 # define DES_check_key OPENSSL_GLOBAL_REF(DES_check_key)
68
69 const char *DES_options(void);
70 void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output,
71 DES_key_schedule *ks1, DES_key_schedule *ks2,
72 DES_key_schedule *ks3, int enc);
73 DES_LONG DES_cbc_cksum(const unsigned char *input, DES_cblock *output,
74 long length, DES_key_schedule *schedule,
75 const_DES_cblock *ivec);
76 /* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */
77 void DES_cbc_encrypt(const unsigned char *input, unsigned char *output,
78 long length, DES_key_schedule *schedule,
79 DES_cblock *ivec, int enc);
80 void DES_ncbc_encrypt(const unsigned char *input, unsigned char *output,
81 long length, DES_key_schedule *schedule,
82 DES_cblock *ivec, int enc);
83 void DES_xcbc_encrypt(const unsigned char *input, unsigned char *output,
84 long length, DES_key_schedule *schedule,
85 DES_cblock *ivec, const_DES_cblock *inw,
86 const_DES_cblock *outw, int enc);
87 void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
88 long length, DES_key_schedule *schedule,
89 DES_cblock *ivec, int enc);
90 void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
91 DES_key_schedule *ks, int enc);
92
93 /*
94 * This is the DES encryption function that gets called by just about every
95 * other DES routine in the library. You should not use this function except
96 * to implement 'modes' of DES. I say this because the functions that call
97 * this routine do the conversion from 'char *' to long, and this needs to be
98 * done to make sure 'non-aligned' memory access do not occur. The
99 * characters are loaded 'little endian'. Data is a pointer to 2 unsigned
100 * long's and ks is the DES_key_schedule to use. enc, is non zero specifies
101 * encryption, zero if decryption.
102 */
103 void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc);
104
105 /*
106 * This functions is the same as DES_encrypt1() except that the DES initial
107 * permutation (IP) and final permutation (FP) have been left out. As for
108 * DES_encrypt1(), you should not use this function. It is used by the
109 * routines in the library that implement triple DES. IP() DES_encrypt2()
110 * DES_encrypt2() DES_encrypt2() FP() is the same as DES_encrypt1()
111 * DES_encrypt1() DES_encrypt1() except faster :-).
112 */
113 void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc);
114
115 void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
116 DES_key_schedule *ks2, DES_key_schedule *ks3);
117 void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
118 DES_key_schedule *ks2, DES_key_schedule *ks3);
119 void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
120 long length,
121 DES_key_schedule *ks1, DES_key_schedule *ks2,
122 DES_key_schedule *ks3, DES_cblock *ivec, int enc);
123 void DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out,
124 long length, DES_key_schedule *ks1,
125 DES_key_schedule *ks2, DES_key_schedule *ks3,
126 DES_cblock *ivec, int *num, int enc);
127 void DES_ede3_cfb_encrypt(const unsigned char *in, unsigned char *out,
128 int numbits, long length, DES_key_schedule *ks1,
129 DES_key_schedule *ks2, DES_key_schedule *ks3,
130 DES_cblock *ivec, int enc);
131 void DES_ede3_ofb64_encrypt(const unsigned char *in, unsigned char *out,
132 long length, DES_key_schedule *ks1,
133 DES_key_schedule *ks2, DES_key_schedule *ks3,
134 DES_cblock *ivec, int *num);
135 char *DES_fcrypt(const char *buf, const char *salt, char *ret);
136 char *DES_crypt(const char *buf, const char *salt);
137 void DES_ofb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
138 long length, DES_key_schedule *schedule,
139 DES_cblock *ivec);
140 void DES_pcbc_encrypt(const unsigned char *input, unsigned char *output,
141 long length, DES_key_schedule *schedule,
142 DES_cblock *ivec, int enc);
143 DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[],
144 long length, int out_count, DES_cblock *seed);
145 int DES_random_key(DES_cblock *ret);
146 void DES_set_odd_parity(DES_cblock *key);
147 int DES_check_key_parity(const_DES_cblock *key);
148 int DES_is_weak_key(const_DES_cblock *key);
149 /*
150 * DES_set_key (= set_key = DES_key_sched = key_sched) calls
151 * DES_set_key_checked if global variable DES_check_key is set,
152 * DES_set_key_unchecked otherwise.
153 */
154 int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule);
155 int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule);
156 int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule);
157 void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule);
158 void DES_string_to_key(const char *str, DES_cblock *key);
159 void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2);
160 void DES_cfb64_encrypt(const unsigned char *in, unsigned char *out,
161 long length, DES_key_schedule *schedule,
162 DES_cblock *ivec, int *num, int enc);
163 void DES_ofb64_encrypt(const unsigned char *in, unsigned char *out,
164 long length, DES_key_schedule *schedule,
165 DES_cblock *ivec, int *num);
166
167 # define DES_fixup_key_parity DES_set_odd_parity
168
169 # ifdef __cplusplus
170 }
171 # endif
172 # endif
173
174 #endif