Add sideband implementation.
[paraslash.git] / crypt.c
diff --git a/crypt.c b/crypt.c
index 431de6fe807f5a08acb8d4e62e0e6e3c160b6e1c..b754c0919e6fbccca77c0d662bddf59c6351fca6 100644 (file)
--- a/crypt.c
+++ b/crypt.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2011 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2005-2012 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -7,7 +7,6 @@
 /** \file crypt.c Openssl-based encryption/decryption routines. */
 
 #include <regex.h>
-#include <stdbool.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <openssl/rand.h>
@@ -299,7 +298,7 @@ int sc_send_bin_buffer(struct stream_cipher_context *scc, char *buf,
                memcpy(remainder, buf + l1, len - l1);
                RC4(&scc->send->key, len - l1, remainder, tmp + l1);
        }
-       ret = write_all(scc->fd, (char *)tmp, &len);
+       ret = xwrite(scc->fd, (char *)tmp, len);
        free(tmp);
        return ret;
 }
@@ -318,6 +317,23 @@ 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)
+{
+       RC4_KEY *key = &sc->key;
+
+       *dst = (typeof(*dst)) {
+               /*
+                * Add one for the terminating zero byte. Integer overflow is
+                * no problem here as para_malloc() aborts when given a zero
+                * size argument.
+                */
+               .iov_base = para_malloc(src->iov_len + 1),
+               .iov_len = src->iov_len
+       };
+       RC4(key, src->iov_len, src->iov_base, dst->iov_base);
+       ((char *)dst->iov_base)[dst->iov_len] = '\0';
+}
+
 void hash_function(const char *data, unsigned long len, unsigned char *hash)
 {
        SHA_CTX c;