1ENCRYPT(3)                  Cryptographic Functions                 ENCRYPT(3)
2
3
4

NAME

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

SYNOPSIS

9       #define _XOPEN_SOURCE
10       #include <unistd.h>
11
12       void encrypt(char block[64], int edflag);
13
14       #define _XOPEN_SOURCE
15       #include <stdlib.h>
16
17       void setkey(const char *key);
18
19       #define _GNU_SOURCE
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() func‐
29       tion sets the key used by encrypt().  The key parameter used here is an
30       array  of 64 bytes, each of which has numerical value 1 or 0. The bytes
31       key[n] where n=8*i-1 are ignored, so that the effective key  length  is
32       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  parameter  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              struct crypt_data {
43                    char keysched[16 * 8];
44                    char sb0[32768];
45                    char sb1[32768];
46                    char sb2[32768];
47                    char sb3[32768];
48                    char crypt_3_buf[14];
49                    char current_salt[2];
50                    long int current_saltbits;
51                    int  direction, initialized;
52              };
53       Before calling setkey_r() set data->initialized to zero.
54

RETURN VALUE

56       These functions do not return any value.
57

ERRORS

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

EXAMPLE

66       You need to link with libcrypt to compile this example  with  glibc2.2.
67       To do useful work the key[] and txt[] arrays must be filled with a use‐
68       ful bit pattern. Note that the <crypt.h> header  unconditionally  gives
69       the prototypes for setkey() and encrypt().
70
71       #include <crypt.h>
72
73       main() {
74         char key[64];      /* bit pattern for key */
75         char txt[64];      /* bit pattern for messages */
76         setkey(key);
77         encrypt(txt, 0);   /* encode */
78         encrypt(txt, 1);   /* decode */
79       }
80

NOTE

82       In glibc2.2 these functions use the DES algorithm.
83

CONFORMING TO

85       The  functions  encrypt()  and  setkey()  conform  to  SVr4, SUSv2, and
86       POSIX.1-2001.  The functions encrypt_r() and setkey_r() are GNU  exten‐
87       sions.
88

SEE ALSO

90       cbc_crypt(3), crypt(3), ecb_crypt(3), fcrypt(3), feature_test_macros(7)
91
92
93
94glibc2                            2003-04-04                        ENCRYPT(3)
Impressum