OSDN Git Service

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