]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/encrypt.3
Import of man-pages 1.70
[thirdparty/man-pages.git] / 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 "glibc2" "Cryptographic Functions"
25 .SH NAME
26 encrypt, setkey, encrypt_r, setkey_r \- encrypt 64-bit messages
27 .SH SYNOPSIS
28 .B #define _XOPEN_SOURCE
29 .br
30 .B #include <unistd.h>
31 .sp
32 .BI "void encrypt(char " block "[64], int " edflag );
33 .sp
34 .B #define _XOPEN_SOURCE
35 .br
36 .B #include <stdlib.h>
37 .sp
38 .BI "void setkey(const char *" key );
39 .sp
40 .B #define _GNU_SOURCE
41 .br
42 .BI "#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 ", struct crypt_data *" data );
47 .sp
48 Each of these requires linking with
49 .BR -lcrypt .
50 .SH DESCRIPTION
51 These functions encrypt and decrypt 64-bit messages. The
52 .B setkey()
53 function sets the key used by
54 .BR encrypt() .
55 The
56 .I key
57 parameter used here is an array of 64 bytes, each of which has
58 numerical value 1 or 0. The bytes key[n] where n=8*i-1 are ignored,
59 so that the effective key length is 56 bits.
60 .PP
61 The encrypt() function modifies the passed buffer, encoding if
62 .I edflag
63 is 0, and decoding if 1 is being passed. Like the key parameter also
64 .I block
65 is a bit vector representation of the actual value that is encoded.
66 The result is returned in that same vector.
67 .PP
68 These two functions are not reentrant, that is, the key data is
69 kept in static storage. The functions
70 .B setkey_r()
71 and
72 .B encrypt_r()
73 are the reentrant versions. They use the following
74 structure to hold the key data:
75 .RS
76 .nf
77 struct crypt_data {
78 char keysched[16 * 8];
79 char sb0[32768];
80 char sb1[32768];
81 char sb2[32768];
82 char sb3[32768];
83 char crypt_3_buf[14];
84 char current_salt[2];
85 long int current_saltbits;
86 int direction, initialized;
87 };
88 .fi
89 .RE
90 Before calling
91 .B setkey_r()
92 set
93 .I data->initialized
94 to zero.
95 .SH "RETURN VALUE"
96 These functions do not return any value.
97 .SH ERRORS
98 Set
99 .I errno
100 to zero before calling the above functions.
101 On success, it is unchanged.
102 .TP
103 .BR ENOSYS
104 The function is not provided.
105 (For example because of former USA export restrictions.)
106 .SH EXAMPLE
107 You need to link with libcrypt to compile this example with glibc2.2.
108 To do useful work the key[] and txt[] array must be filled with a
109 useful bit pattern. Note that the <crypt.h> header unconditionally
110 gives the prototypes for setkey() and encrypt().
111 .sp
112 .nf
113 #include <crypt.h>
114
115 main() {
116 char key[64]; /* bit pattern for key */
117 char txt[64]; /* bit pattern for messages */
118 setkey(key);
119 encrypt(txt, 0); /* encode */
120 encrypt(txt, 1); /* decode */
121 }
122 .fi
123 .SH "NOTE"
124 In glibc2.2 these functions use the DES algorithm.
125 .SH "CONFORMING TO"
126 The functions
127 .B encrypt()
128 and
129 .B setkey()
130 conform to SVID, SUSv2, and POSIX 1003.1-2001.
131 The functions
132 .B encrypt_r()
133 and
134 .B setkey_r()
135 are GNU extensions.
136 .SH "SEE ALSO"
137 .BR cbc_crypt (3),
138 .BR crypt (3),
139 .BR ecb_crypt (3),
140 .BR fcrypt (3)