blob: 1f44689d3fdb7b818d5dd302e96eccfcc81346f4 [file] [log] [blame]
rsc83c45062005-02-11 19:43:43 +00001.TH ENCRYPT 3
rscd93fca62005-02-11 19:21:47 +00002.SH NAME
3encrypt, decrypt, netcrypt \- DES encryption
4.SH SYNOPSIS
5.B #include <u.h>
6.br
7.B #include <libc.h>
8.PP
9.B
10int encrypt(void *key, void *data, int len)
11.PP
12.B
13int decrypt(void *key, void *data, int len)
14.PP
15.B
16int netcrypt(void *key, void *data)
17.SH DESCRIPTION
18.I Encrypt
19and
20.I decrypt
21perform DES encryption and decryption.
22.I Key
23is an array of
24.B DESKEYLEN
25(defined as 7 in
26.BR <auth.h> )
27bytes containing the encryption key.
28.I Data
29is an array of
30.I len
31bytes;
32it must be at least 8 bytes long.
33The bytes are encrypted or decrypted in place.
34.PP
35The DES algorithm encrypts an individual 8-byte block of data.
36.I Encrypt
37uses the following method to encrypt data longer than 8 bytes.
38The first 8 bytes are encrypted as usual.
39The last byte of the encrypted result
40is prefixed to the next 7 unencrypted bytes to make the next 8
41bytes to encrypt.
42This is repeated until fewer than 7 bytes remain unencrypted.
43Any remaining unencrypted bytes are encrypted with enough of the preceding
44encrypted bytes to make a full 8-byte block.
45.I Decrypt
46uses the inverse algorithm.
47.PP
48.I Netcrypt
49performs the same encryption as a SecureNet Key.
50.I Data
51points to an
52.SM ASCII
53string of decimal digits with numeric value between 0 and 10000.
54These digits are copied into an 8-byte buffer with trailing binary zero fill
55and encrypted as one DES block.
56The first four bytes are each formatted as two digit
57.SM ASCII
58hexadecimal numbers,
59and the string is copied into
60.IR data .
61.SH SOURCE
rsc83c45062005-02-11 19:43:43 +000062.B \*9/src/lib9
rscd93fca62005-02-11 19:21:47 +000063.SH DIAGNOSTICS
64These routines return 1 if the data was encrypted,
65and 0 if the encryption fails.
66.I Encrypt
67and
68.I decrypt
69fail if the data passed is less than 8 bytes long.
70.I Netcrypt
71can fail if it is passed invalid data.
72.\" .SH SEE ALSO
73.\" .IR securenet (8)
74.SH BUGS
75The implementation is broken in a way that makes
76it unsuitable for anything but authentication.
77.PP
78To avoid name conflicts with the underlying system,
79.IR encrypt
80and
81.IR decrypt
82are preprocessor macros defined as
83.IR p9encrypt
84and
85.IR p9decrypt ;
86see
87.IR intro (3).