diff options
author | rsc <devnull@localhost> | 2004-03-21 14:04:56 +0000 |
---|---|---|
committer | rsc <devnull@localhost> | 2004-03-21 14:04:56 +0000 |
commit | 0fc65b37a1e7585ca2347bf61dcb8bc3a6b146a4 (patch) | |
tree | dd9189a823998f494082adb769451f12be056566 /src/libsec/port/desCBC.c | |
parent | 768206abfcf505fb034a0151bf263bc0b1f2380c (diff) | |
download | plan9port-0fc65b37a1e7585ca2347bf61dcb8bc3a6b146a4.tar.gz plan9port-0fc65b37a1e7585ca2347bf61dcb8bc3a6b146a4.tar.bz2 plan9port-0fc65b37a1e7585ca2347bf61dcb8bc3a6b146a4.zip |
Add most of libsec.
Diffstat (limited to 'src/libsec/port/desCBC.c')
-rw-r--r-- | src/libsec/port/desCBC.c | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/src/libsec/port/desCBC.c b/src/libsec/port/desCBC.c new file mode 100644 index 00000000..ecee29e8 --- /dev/null +++ b/src/libsec/port/desCBC.c @@ -0,0 +1,59 @@ +#include "os.h" +#include <mp.h> +#include <libsec.h> + +// Because of the way that non multiple of 8 +// buffers are handled, the decryptor must +// be fed buffers of the same size as the +// encryptor + + +// If the length is not a multiple of 8, I encrypt +// the overflow to be compatible with lacy's cryptlib +void +desCBCencrypt(uchar *p, int len, DESstate *s) +{ + uchar *p2, *ip, *eip; + + for(; len >= 8; len -= 8){ + p2 = p; + ip = s->ivec; + for(eip = ip+8; ip < eip; ) + *p2++ ^= *ip++; + block_cipher(s->expanded, p, 0); + memmove(s->ivec, p, 8); + p += 8; + } + + if(len > 0){ + ip = s->ivec; + block_cipher(s->expanded, ip, 0); + for(eip = ip+len; ip < eip; ) + *p++ ^= *ip++; + } +} + +void +desCBCdecrypt(uchar *p, int len, DESstate *s) +{ + uchar *ip, *eip, *tp; + uchar tmp[8]; + + for(; len >= 8; len -= 8){ + memmove(tmp, p, 8); + block_cipher(s->expanded, p, 1); + tp = tmp; + ip = s->ivec; + for(eip = ip+8; ip < eip; ){ + *p++ ^= *ip; + *ip++ = *tp++; + } + } + + if(len > 0){ + ip = s->ivec; + block_cipher(s->expanded, ip, 0); + for(eip = ip+len; ip < eip; ) + *p++ ^= *ip++; + } +} |