]> git.ipfire.org Git - thirdparty/openssl.git/blame - include/openssl/des.h
Copyright consolidation 03/10
[thirdparty/openssl.git] / include / openssl / des.h
CommitLineData
21dcbebc
RS
1/*
2 * Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
d02b48c6 3 *
21dcbebc
RS
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
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
17extern "C" {
0f113f3e 18# endif
3c27208f 19# include <openssl/e_os2.h>
f5d7a031 20
3e9e810f 21typedef 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
28typedef unsigned char DES_cblock[8];
29typedef /* 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
35typedef 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
0f113f3e
MC
66OPENSSL_DECLARE_GLOBAL(int, DES_check_key); /* defaults to false */
67# define DES_check_key OPENSSL_GLOBAL_REF(DES_check_key)
c2e4f17c
RL
68
69const char *DES_options(void);
70void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output,
0f113f3e
MC
71 DES_key_schedule *ks1, DES_key_schedule *ks2,
72 DES_key_schedule *ks3, int enc);
73DES_LONG DES_cbc_cksum(const unsigned char *input, DES_cblock *output,
74 long length, DES_key_schedule *schedule,
75 const_DES_cblock *ivec);
c2e4f17c 76/* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */
0f113f3e
MC
77void DES_cbc_encrypt(const unsigned char *input, unsigned char *output,
78 long length, DES_key_schedule *schedule,
79 DES_cblock *ivec, int enc);
80void DES_ncbc_encrypt(const unsigned char *input, unsigned char *output,
81 long length, DES_key_schedule *schedule,
82 DES_cblock *ivec, int enc);
83void 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);
87void 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);
90void 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 */
103void 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 */
113void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc);
c2e4f17c
RL
114
115void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
0f113f3e 116 DES_key_schedule *ks2, DES_key_schedule *ks3);
c2e4f17c 117void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
0f113f3e
MC
118 DES_key_schedule *ks2, DES_key_schedule *ks3);
119void 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);
0f113f3e
MC
123void 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);
127void 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);
131void 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);
0f113f3e
MC
135char *DES_fcrypt(const char *buf, const char *salt, char *ret);
136char *DES_crypt(const char *buf, const char *salt);
137void DES_ofb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
138 long length, DES_key_schedule *schedule,
139 DES_cblock *ivec);
140void DES_pcbc_encrypt(const unsigned char *input, unsigned char *output,
141 long length, DES_key_schedule *schedule,
142 DES_cblock *ivec, int enc);
143DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[],
144 long length, int out_count, DES_cblock *seed);
c2e4f17c
RL
145int DES_random_key(DES_cblock *ret);
146void DES_set_odd_parity(DES_cblock *key);
147int DES_check_key_parity(const_DES_cblock *key);
148int DES_is_weak_key(const_DES_cblock *key);
0f113f3e
MC
149/*
150 * DES_set_key (= set_key = DES_key_sched = key_sched) calls
c2e4f17c 151 * DES_set_key_checked if global variable DES_check_key is set,
0f113f3e
MC
152 * DES_set_key_unchecked otherwise.
153 */
154int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule);
155int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule);
156int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule);
157void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule);
158void DES_string_to_key(const char *str, DES_cblock *key);
159void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2);
160void 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);
163void DES_ofb64_encrypt(const unsigned char *in, unsigned char *out,
164 long length, DES_key_schedule *schedule,
165 DES_cblock *ivec, int *num);
d02b48c6 166
0f113f3e 167# define DES_fixup_key_parity DES_set_odd_parity
37b7185b 168
3c27208f 169# ifdef __cplusplus
d02b48c6 170}
3c27208f
RS
171# endif
172# endif
d02b48c6
RE
173
174#endif