|
1 .\" Portions Copyright © 2005-2006 Nokia. All rights reserved. |
|
2 .\" FreeSec: libcrypt for NetBSD |
|
3 .\" |
|
4 .\" Copyright (c) 1994 David Burren |
|
5 .\" All rights reserved. |
|
6 .\" |
|
7 .\" Redistribution and use in source and binary forms, with or without |
|
8 .\" modification, are permitted provided that the following conditions |
|
9 .\" are met: |
|
10 .\" 1. Redistributions of source code must retain the above copyright |
|
11 .\" notice, this list of conditions and the following disclaimer. |
|
12 .\" 2. Redistributions in binary form must reproduce the above copyright |
|
13 .\" notice, this list of conditions and the following disclaimer in the |
|
14 .\" documentation and/or other materials provided with the distribution. |
|
15 .\" 4. Neither the name of the author nor the names of other contributors |
|
16 .\" may be used to endorse or promote products derived from this software |
|
17 .\" without specific prior written permission. |
|
18 .\" |
|
19 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
|
20 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
|
21 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|
22 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
|
23 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|
24 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|
25 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|
26 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|
27 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|
28 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|
29 .\" SUCH DAMAGE. |
|
30 .\" |
|
31 .\" $FreeBSD: src/lib/libcrypt/crypt.3,v 1.31 2005/02/09 18:03:14 ru Exp $ |
|
32 .\" |
|
33 .Dd January 19, 1997 |
|
34 .Dt ENCRYPT 3 |
|
35 .Os |
|
36 .Sh NAME |
|
37 .Nm encrypt, setkey |
|
38 .Nd encrypt 64-bit messages |
|
39 .Sh LIBRARY |
|
40 .Lb libcrypt |
|
41 .Sh SYNOPSIS |
|
42 .In unistd.h |
|
43 .Ft void |
|
44 .Fn encrypt "char block[64]" "int edflag" |
|
45 .In stdlib.h |
|
46 .Ft void |
|
47 .Fn setkey "const char *key" |
|
48 .Sh RETURN VALUES |
|
49 The |
|
50 .Fn encrypt |
|
51 and |
|
52 .Fn setkey |
|
53 functions do not return any value. |
|
54 .Sh DESCRIPTION |
|
55 .Fn encrypt() |
|
56 function encrypts and decrypts 64-bit messages. The algorithm used to perform |
|
57 encryption/decryption is Data Encryption Standard (DES). |
|
58 .Pp |
|
59 .Fn setkey() |
|
60 is invoked to set the key for the DES machine. |
|
61 .Fn setkey()' |
|
62 s |
|
63 .Fn key |
|
64 parameter is an array of 64 bytes, and the numerical value of each byte in this |
|
65 array is either 0 or 1. The 56-bit key for the DES algorithm is computed from the |
|
66 .Fn key |
|
67 parameter. |
|
68 .Pp |
|
69 .Fn encrypt |
|
70 function either encrypts or decrypts the data block. The exact operation depends |
|
71 on the value of |
|
72 .Fn edflag |
|
73 parameter. |
|
74 .Fn block |
|
75 is encrypted if |
|
76 .Fn edflag |
|
77 parameter is 0, and decrypted if 1 is being passed as the value of |
|
78 .Fn edflag |
|
79 parameter. |
|
80 .Fn block |
|
81 is an array of 64 bytes, wherein the numerical value of each byte is either 0 or 1. |
|
82 Like the |
|
83 .Fn setkey' |
|
84 s |
|
85 .Fn key |
|
86 parameter, |
|
87 .Fn block |
|
88 is a bit vector representation of the actual value that is encoded. It is modified in place |
|
89 to return the result. |
|
90 .Pp |
|
91 .Fn encrypt |
|
92 and |
|
93 .Fn setkey |
|
94 are not reentrant as the key is stored statically. |
|
95 |
|
96 .Sh ERRORS |
|
97 .Fn errno |
|
98 should be set to zero prior to calling any of the above functions. The behavior of |
|
99 .Fn encrypt |
|
100 will be undefined if size of |
|
101 .Fn block |
|
102 argument is not 64. |
|
103 .Sh EXAMPLE |
|
104 .Bd -literal -offset indent |
|
105 #include <stdlib.h> |
|
106 #include <unistd.h> |
|
107 |
|
108 void encrypt_user() |
|
109 { |
|
110 /* bit vector containing the key */ |
|
111 char key[64] = |
|
112 { |
|
113 0, 0, 0, 0, 0, 0, 0, 1, |
|
114 0, 0, 1, 1, 0, 0, 0, 1, |
|
115 1, 1, 0, 1, 1, 0, 0, 1, |
|
116 0, 1, 1, 0, 0, 0, 0, 1, |
|
117 1, 0, 0, 1, 1, 1, 0, 1, |
|
118 1, 1, 0, 0, 0, 0, 0, 1, |
|
119 0, 0, 1, 1, 0, 1, 1, 1, |
|
120 0, 1, 1, 0, 1, 1, 1, 0 |
|
121 }; |
|
122 |
|
123 /* bit vector containing the data block to be encrypted */ |
|
124 char block[64] = |
|
125 { |
|
126 0, 1, 0, 1, 1, 1, 0, 0, |
|
127 1, 1, 0, 1, 0, 1, 0, 1, |
|
128 0, 1, 0, 0, 1, 1, 0, 0, |
|
129 1, 0, 1, 0, 1, 0, 0, 0, |
|
130 0, 0, 1, 1, 1, 1, 0, 1, |
|
131 1, 1, 1, 0, 1, 1, 1, 1, |
|
132 0, 1, 0, 1, 0, 1, 1, 1, |
|
133 1, 1, 0, 1, 1, 0, 1, 0 |
|
134 }; |
|
135 |
|
136 setkey(key); /* Set the key for DES encryption */ |
|
137 |
|
138 /* Perform encryption/decryption of the message block */ |
|
139 encrypt(block, 0); /* Encryption. The input block is modified in place |
|
140 * to return the output to the user |
|
141 */ |
|
142 |
|
143 encrypt(block, 1); /* Decryption. The input block is modified in place |
|
144 * to return the result of the decryption operation |
|
145 */ |
|
146 } |
|
147 .Ed |
|
148 .Sh SEE ALSO |
|
149 .Sh HISTORY |
|
150 .Sh BUGS |
|
151 If |
|
152 .Fn encrypt |
|
153 is called without priorly invoking |
|
154 .Fn setkey |
|
155 the implementation assumes a bit vector consisting of all zeroes as the key |
|
156 for the DES algorithm. In this scenaro the outcome of |
|
157 .Fn encrypt |
|
158 function is different from that of Linux's. |