1ENCRYPT(3)                 Linux Programmer's Manual                ENCRYPT(3)
2
3
4

NAME

6       encrypt, setkey, encrypt_r, setkey_r - encrypt 64-bit messages
7

SYNOPSIS

9       #define _XOPEN_SOURCE       /* See feature_test_macros(7) */
10       #include <unistd.h>
11
12       void encrypt(char block[64], int edflag);
13
14       #define _XOPEN_SOURCE       /* See feature_test_macros(7) */
15       #include <stdlib.h>
16
17       void setkey(const char *key);
18
19       #define _GNU_SOURCE         /* See feature_test_macros(7) */
20       #include <crypt.h>
21
22       void setkey_r(const char *key, struct crypt_data *data);
23       void encrypt_r(char *block, int edflag, struct crypt_data *data);
24
25       Each of these requires linking with -lcrypt.
26

DESCRIPTION

28       These  functions  encrypt  and  decrypt  64-bit messages.  The setkey()
29       function sets the key used by encrypt().  The key argument used here is
30       an  array  of  64 bytes, each of which has numerical value 1 or 0.  The
31       bytes key[n] where n=8*i-1 are  ignored,  so  that  the  effective  key
32       length is 56 bits.
33
34       The  encrypt()  function modifies the passed buffer, encoding if edflag
35       is 0, and decoding if 1 is being passed.  Like the key  argument,  also
36       block  is  a  bit  vector  representation  of  the actual value that is
37       encoded.  The result is returned in that same vector.
38
39       These two functions are not reentrant, that is, the key data is kept in
40       static storage.  The functions setkey_r() and encrypt_r() are the reen‐
41       trant versions.  They use the following structure to hold the key data:
42
43           struct crypt_data {
44               char     keysched[16 * 8];
45               char     sb0[32768];
46               char     sb1[32768];
47               char     sb2[32768];
48               char     sb3[32768];
49               char     crypt_3_buf[14];
50               char     current_salt[2];
51               long int current_saltbits;
52               int      direction;
53               int      initialized;
54           };
55
56       Before calling setkey_r() set data->initialized to zero.
57

RETURN VALUE

59       These functions do not return any value.
60

ERRORS

62       Set errno to zero before calling the above functions.  On  success,  it
63       is unchanged.
64
65       ENOSYS The  function  is  not provided.  (For example because of former
66              USA export restrictions.)
67

ATTRIBUTES

69   Multithreading (see pthreads(7))
70       The encrypt() and setkey() functions are not thread-safe.
71
72       The encrypt_r() and setkey_r() functions are thread-safe.
73

CONFORMING TO

75       The functions encrypt()  and  setkey()  conform  to  SVr4,  SUSv2,  and
76       POSIX.1-2001.   The functions encrypt_r() and setkey_r() are GNU exten‐
77       sions.
78

NOTES

80       In glibc 2.2 these functions use the DES algorithm.
81

EXAMPLE

83       You need to link with libcrypt to compile this example with glibc.   To
84       do  useful work the key[] and txt[] arrays must be filled with a useful
85       bit pattern.
86
87       #define _XOPEN_SOURCE
88       #include <unistd.h>
89       #include <stdlib.h>
90
91       int
92       main(void)
93       {
94           char key[64];      /* bit pattern for key */
95           char txt[64];      /* bit pattern for messages */
96
97           setkey(key);
98           encrypt(txt, 0);   /* encode */
99           encrypt(txt, 1);   /* decode */
100       }
101

SEE ALSO

103       cbc_crypt(3), crypt(3), ecb_crypt(3),
104

COLOPHON

106       This page is part of release 3.53 of the Linux  man-pages  project.   A
107       description  of  the project, and information about reporting bugs, can
108       be found at http://www.kernel.org/doc/man-pages/.
109
110
111
112                                  2013-07-22                        ENCRYPT(3)
Impressum