diff options
author | rsc <devnull@localhost> | 2005-02-08 21:02:40 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2005-02-08 21:02:40 +0000 |
commit | 641405320f4601f50e0d728805e14fb6f8196710 (patch) | |
tree | d7f20c6713facf6df8da47fa62558df6b500715d /src/lib9 | |
parent | 648bb6f75a801e6d605fcd061f0b14fecc07a8be (diff) | |
download | plan9port-641405320f4601f50e0d728805e14fb6f8196710.tar.gz plan9port-641405320f4601f50e0d728805e14fb6f8196710.tar.bz2 plan9port-641405320f4601f50e0d728805e14fb6f8196710.zip |
add crypt
Diffstat (limited to 'src/lib9')
-rwxr-xr-x | src/lib9/crypt.c | 68 | ||||
-rw-r--r-- | src/lib9/mkfile | 1 |
2 files changed, 69 insertions, 0 deletions
diff --git a/src/lib9/crypt.c b/src/lib9/crypt.c new file mode 100755 index 00000000..0524c942 --- /dev/null +++ b/src/lib9/crypt.c @@ -0,0 +1,68 @@ +/* + * Data Encryption Standard + * D.P.Mitchell 83/06/08. + * + * block_cipher(key, block, decrypting) + * + * these routines use the non-standard 7 byte format + * for DES keys. + */ +#include <u.h> +#include <libc.h> +#include <auth.h> +#include <libsec.h> + +/* + * destructively encrypt the buffer, which + * must be at least 8 characters long. + */ +int +encrypt(void *key, void *vbuf, int n) +{ + ulong ekey[32]; + uchar *buf; + int i, r; + + if(n < 8) + return 0; + key_setup(key, ekey); + buf = vbuf; + n--; + r = n % 7; + n /= 7; + for(i = 0; i < n; i++){ + block_cipher(ekey, buf, 0); + buf += 7; + } + if(r) + block_cipher(ekey, buf - 7 + r, 0); + return 1; +} + +/* + * destructively decrypt the buffer, which + * must be at least 8 characters long. + */ +int +decrypt(void *key, void *vbuf, int n) +{ + ulong ekey[128]; + uchar *buf; + int i, r; + + if(n < 8) + return 0; + key_setup(key, ekey); + buf = vbuf; + n--; + r = n % 7; + n /= 7; + buf += n * 7; + if(r) + block_cipher(ekey, buf - 7 + r, 1); + for(i = 0; i < n; i++){ + buf -= 7; + block_cipher(ekey, buf, 1); + } + return 1; +} diff --git a/src/lib9/mkfile b/src/lib9/mkfile index 361ab5b7..3ed220ab 100644 --- a/src/lib9/mkfile +++ b/src/lib9/mkfile @@ -84,6 +84,7 @@ LIB9OFILES=\ convM2S.$O\ convS2M.$O\ create.$O\ + crypt.$O\ ctime.$O\ date.$O\ dial.$O\ |