]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/encrypt.3
errno.3: Mention that errno(1) is part of the 'moreutils' package
[thirdparty/man-pages.git] / man3 / encrypt.3
CommitLineData
e00c3a07 1.\" Copyright 2000 Nicolás Lichtmaier <nick@debian.org>
fea681da
MK
2.\" Created 2000-07-22 00:52-0300
3.\"
1dd72f9c 4.\" %%%LICENSE_START(GPLv2+_DOC_FULL)
fea681da
MK
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.\"
faede11f
MK
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/>.
6a8d8745 23.\" %%%LICENSE_END
faede11f 24.\"
fea681da
MK
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.\"
09b8afdc 30.TH ENCRYPT 3 2018-04-30 "" "Linux Programmer's Manual"
fea681da
MK
31.SH NAME
32encrypt, setkey, encrypt_r, setkey_r \- encrypt 64-bit messages
33.SH SYNOPSIS
3f89e93d 34.nf
b80f966b 35.BR "#define _XOPEN_SOURCE" " /* See feature_test_macros(7) */"
fea681da 36.B #include <unistd.h>
68e4db0a 37.PP
fea681da 38.BI "void encrypt(char " block "[64], int " edflag );
f90f031e 39
b80f966b 40.BR "#define _XOPEN_SOURCE" " /* See feature_test_macros(7) */"
fea681da 41.B #include <stdlib.h>
68e4db0a 42.PP
fea681da 43.BI "void setkey(const char *" key );
f90f031e 44
b80f966b 45.BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
0daa9e92 46.B "#include <crypt.h>"
68e4db0a 47.PP
b9f02710 48.BI "void setkey_r(const char *" key ", struct crypt_data *" data );
b9f02710
MK
49.BI "void encrypt_r(char *" block ", int " edflag \
50", struct crypt_data *" data );
3f89e93d 51.fi
68e4db0a 52.PP
e9329f6d 53Each of these requires linking with \fI\-lcrypt\fP.
fea681da 54.SH DESCRIPTION
c13182ef
MK
55These functions encrypt and decrypt 64-bit messages.
56The
63aa9df0 57.BR setkey ()
fea681da 58function sets the key used by
63aa9df0 59.BR encrypt ().
fea681da
MK
60The
61.I key
c4bb193f 62argument used here is an array of 64 bytes, each of which has
c13182ef
MK
63numerical value 1 or 0.
64The bytes key[n] where n=8*i-1 are ignored,
fea681da
MK
65so that the effective key length is 56 bits.
66.PP
c13182ef
MK
67The
68.BR encrypt ()
b5cc2ffb 69function modifies the passed buffer, encoding if
fea681da 70.I edflag
c13182ef 71is 0, and decoding if 1 is being passed.
c4bb193f
MK
72Like the
73.I key
74argument, also
fea681da
MK
75.I block
76is a bit vector representation of the actual value that is encoded.
77The result is returned in that same vector.
78.PP
79These two functions are not reentrant, that is, the key data is
c13182ef
MK
80kept in static storage.
81The functions
63aa9df0 82.BR setkey_r ()
fea681da 83and
63aa9df0 84.BR encrypt_r ()
c13182ef
MK
85are the reentrant versions.
86They use the following
fea681da 87structure to hold the key data:
e646a1ba 88.PP
bd191423 89.in +4n
e646a1ba 90.EX
fea681da 91struct crypt_data {
42ca79eb
MK
92 char keysched[16 * 8];
93 char sb0[32768];
94 char sb1[32768];
95 char sb2[32768];
96 char sb3[32768];
97 char crypt_3_buf[14];
98 char current_salt[2];
99 long int current_saltbits;
100 int direction;
101 int initialized;
fea681da 102};
b8302363 103.EE
bd191423 104.in
e5056894 105.PP
fea681da 106Before calling
63aa9df0 107.BR setkey_r ()
fea681da 108set
94e9d9fe 109.I data\->initialized
fea681da 110to zero.
47297adb 111.SH RETURN VALUE
fea681da
MK
112These functions do not return any value.
113.SH ERRORS
114Set
115.I errno
116to zero before calling the above functions.
117On success, it is unchanged.
118.TP
0daa9e92 119.B ENOSYS
fea681da
MK
120The function is not provided.
121(For example because of former USA export restrictions.)
4fc2f647 122.SH ATTRIBUTES
38688339
MK
123For an explanation of the terms used in this section, see
124.BR attributes (7).
125.TS
126allbox;
127lbw23 lb lb
128l l l.
129Interface Attribute Value
130T{
131.BR encrypt (),
4fc2f647 132.BR setkey ()
89456d09 133T} Thread safety MT-Unsafe race:crypt
38688339
MK
134T{
135.BR encrypt_r (),
4fc2f647 136.BR setkey_r ()
38688339
MK
137T} Thread safety MT-Safe
138.TE
47297adb 139.SH CONFORMING TO
d0aab8a9
MK
140.BR encrypt (),
141.BR setkey ():
142POSIX.1-2001, POSIX.1-2008, SUS, SVr4.
847e0d88 143.PP
2b2581ee
MK
144The functions
145.BR encrypt_r ()
146and
147.BR setkey_r ()
148are GNU extensions.
149.SH NOTES
629a86ec 150.SS Availability in glibc
924f7667
MK
151See
152.BR crypt (3).
629a86ec 153.SS Features in glibc
a53a30b7 154In glibc 2.2, these functions use the DES algorithm.
fea681da 155.SH EXAMPLE
207050fa 156.EX
5aa145bd 157#define _XOPEN_SOURCE
ec5308ca 158#include <stdio.h>
5aa145bd 159#include <stdlib.h>
ec5308ca
RS
160#include <unistd.h>
161#include <crypt.h>
fea681da 162
cf0a9ace 163int
c13182ef 164main(void)
cf0a9ace 165{
ec5308ca
RS
166 char key[64];
167 char orig[9] = "eggplant";
168 char buf[64];
169 char txt[9];
170 int i, j;
171
172 for (i = 0; i < 64; i++) {
173 key[i] = rand() & 1;
174 }
175
176 for (i = 0; i < 8; i++) {
177 for (j = 0; j < 8; j++) {
178 buf[i * 8 + j] = orig[i] >> j & 1;
179 }
180 setkey(key);
181 }
182 printf("Before encrypting: %s\\n", orig);
183
184 encrypt(buf, 0);
185 for (i = 0; i < 8; i++) {
186 for (j = 0, txt[i] = \(aq\\0\(aq; j < 8; j++) {
187 txt[i] |= buf[i * 8 + j] << j;
188 }
189 txt[8] = \(aq\\0\(aq;
190 }
191 printf("After encrypting: %s\\n", txt);
cf0a9ace 192
ec5308ca
RS
193 encrypt(buf, 1);
194 for (i = 0; i < 8; i++) {
195 for (j = 0, txt[i] = \(aq\\0\(aq; j < 8; j++) {
196 txt[i] |= buf[i * 8 + j] << j;
197 }
198 txt[8] = \(aq\\0\(aq;
199 }
200 printf("After decrypting: %s\\n", txt);
201 exit(EXIT_SUCCESS);
fea681da 202}
207050fa 203.EE
47297adb 204.SH SEE ALSO
fea681da
MK
205.BR cbc_crypt (3),
206.BR crypt (3),
207.BR ecb_crypt (3),
0a4f8b7b 208.\" .BR fcrypt (3)