OSDN Git Service

LDP: Update original to LDP v3.68
[linuxjm/LDP_man-pages.git] / original / man3 / encrypt.3
1 .\" Copyright 2000 Nicolás Lichtmaier <nick@debian.org>
2 .\" Created 2000-07-22 00:52-0300
3 .\"
4 .\" %%%LICENSE_START(GPLv2+_DOC_FULL)
5 .\" This is free documentation; you can redistribute it and/or
6 .\" modify it under the terms of the GNU General Public License as
7 .\" published by the Free Software Foundation; either version 2 of
8 .\" the License, or (at your option) any later version.
9 .\"
10 .\" The GNU General Public License's references to "object code"
11 .\" and "executables" are to be interpreted as the output of any
12 .\" document formatting or typesetting system, including
13 .\" intermediate and printed output.
14 .\"
15 .\" This manual is distributed in the hope that it will be useful,
16 .\" but WITHOUT ANY WARRANTY; without even the implied warranty of
17 .\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 .\" GNU General Public License for more details.
19 .\"
20 .\" You should have received a copy of the GNU General Public
21 .\" License along with this manual; if not, see
22 .\" <http://www.gnu.org/licenses/>.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Modified 2002-07-23 19:21:35 CEST 2002 Walter Harms
26 .\" <walter.harms@informatik.uni-oldenburg.de>
27 .\"
28 .\" Modified 2003-04-04, aeb
29 .\"
30 .TH ENCRYPT 3 2013-07-22 "" "Linux Programmer's Manual"
31 .SH NAME
32 encrypt, setkey, encrypt_r, setkey_r \- encrypt 64-bit messages
33 .SH SYNOPSIS
34 .BR "#define _XOPEN_SOURCE" "       /* See feature_test_macros(7) */"
35 .br
36 .B #include <unistd.h>
37 .sp
38 .BI "void encrypt(char " block "[64], int " edflag );
39 .sp
40 .BR "#define _XOPEN_SOURCE" "       /* See feature_test_macros(7) */"
41 .br
42 .B #include <stdlib.h>
43 .sp
44 .BI "void setkey(const char *" key );
45 .sp
46 .BR "#define _GNU_SOURCE" "         /* See feature_test_macros(7) */"
47 .br
48 .B "#include <crypt.h>"
49 .sp
50 .BI "void setkey_r(const char *" key ", struct crypt_data *" data );
51 .br
52 .BI "void encrypt_r(char *" block ", int " edflag \
53 ", struct crypt_data *" data );
54 .sp
55 Each of these requires linking with \fI\-lcrypt\fP.
56 .SH DESCRIPTION
57 These functions encrypt and decrypt 64-bit messages.
58 The
59 .BR setkey ()
60 function sets the key used by
61 .BR encrypt ().
62 The
63 .I key
64 argument used here is an array of 64 bytes, each of which has
65 numerical value 1 or 0.
66 The bytes key[n] where n=8*i-1 are ignored,
67 so that the effective key length is 56 bits.
68 .PP
69 The
70 .BR encrypt ()
71 function modifies the passed buffer, encoding if
72 .I edflag
73 is 0, and decoding if 1 is being passed.
74 Like the
75 .I key
76 argument, also
77 .I block
78 is a bit vector representation of the actual value that is encoded.
79 The result is returned in that same vector.
80 .PP
81 These two functions are not reentrant, that is, the key data is
82 kept in static storage.
83 The functions
84 .BR setkey_r ()
85 and
86 .BR encrypt_r ()
87 are the reentrant versions.
88 They use the following
89 structure to hold the key data:
90 .in +4n
91 .nf
92
93 struct crypt_data {
94     char     keysched[16 * 8];
95     char     sb0[32768];
96     char     sb1[32768];
97     char     sb2[32768];
98     char     sb3[32768];
99     char     crypt_3_buf[14];
100     char     current_salt[2];
101     long int current_saltbits;
102     int      direction;
103     int      initialized;
104 };
105 .fi
106 .in
107 .PP
108 Before calling
109 .BR setkey_r ()
110 set
111 .I data\->initialized
112 to zero.
113 .SH RETURN VALUE
114 These functions do not return any value.
115 .SH ERRORS
116 Set
117 .I errno
118 to zero before calling the above functions.
119 On success, it is unchanged.
120 .TP
121 .B ENOSYS
122 The function is not provided.
123 (For example because of former USA export restrictions.)
124 .SH ATTRIBUTES
125 .SS Multithreading (see pthreads(7))
126 The
127 .BR encrypt ()
128 and
129 .BR setkey ()
130 functions are not thread-safe.
131 .LP
132 The
133 .BR encrypt_r ()
134 and
135 .BR setkey_r ()
136 functions are thread-safe.
137 .SH CONFORMING TO
138 The functions
139 .BR encrypt ()
140 and
141 .BR setkey ()
142 conform to SVr4, SUSv2, and POSIX.1-2001.
143 The functions
144 .BR encrypt_r ()
145 and
146 .BR setkey_r ()
147 are GNU extensions.
148 .SH NOTES
149 In glibc 2.2 these functions use the DES algorithm.
150 .SH EXAMPLE
151 You need to link with libcrypt to compile this example with glibc.
152 To do useful work the
153 .I key[]
154 and
155 .I txt[]
156 arrays must be filled with a useful bit pattern.
157 .sp
158 .nf
159 #define _XOPEN_SOURCE
160 #include <unistd.h>
161 #include <stdlib.h>
162
163 int
164 main(void)
165 {
166     char key[64];      /* bit pattern for key */
167     char txt[64];      /* bit pattern for messages */
168
169     setkey(key);
170     encrypt(txt, 0);   /* encode */
171     encrypt(txt, 1);   /* decode */
172 }
173 .fi
174 .SH SEE ALSO
175 .BR cbc_crypt (3),
176 .BR crypt (3),
177 .BR ecb_crypt (3),
178 .\" .BR fcrypt (3)
179 .SH COLOPHON
180 This page is part of release 3.68 of the Linux
181 .I man-pages
182 project.
183 A description of the project,
184 information about reporting bugs,
185 and the latest version of this page,
186 can be found at
187 \%http://www.kernel.org/doc/man\-pages/.