X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=crypt.c;h=17026cc63525c5527f63fb95c27242dc272add23;hp=f33f769f6f035c18946c21fea064b37052802583;hb=0a0a3db1d4a541abe8442fd3cbfcae6636874d1b;hpb=f0e41e36c3f1a3a5bb6ff66d92d2814391d8f908 diff --git a/crypt.c b/crypt.c index f33f769f..17026cc6 100644 --- a/crypt.c +++ b/crypt.c @@ -317,6 +317,30 @@ int sc_recv_bin_buffer(struct stream_cipher_context *scc, char *buf, return ret; } +void sc_crypt(struct stream_cipher *sc, struct iovec *src, struct iovec *dst) +{ + size_t len = src->iov_len, l1, l2; + RC4_KEY *key = &sc->key; + + assert(len > 0); + assert(len < ((typeof(src->iov_len))-1) / 2); + l1 = ROUND_DOWN(len, RC4_ALIGN); + l2 = ROUND_UP(len, RC4_ALIGN); + + *dst = (typeof(*dst)) { + /* Add one for the terminating zero byte. */ + .iov_base = para_malloc(l2 + 1), + .iov_len = len + }; + RC4(key, l1, src->iov_base, dst->iov_base); + if (len > l1) { + unsigned char remainder[RC4_ALIGN] = ""; + memcpy(remainder, src->iov_base + l1, len - l1); + RC4(key, len - l1, remainder, dst->iov_base + l1); + } + ((char *)dst->iov_base)[len] = '\0'; +} + void hash_function(const char *data, unsigned long len, unsigned char *hash) { SHA_CTX c;