string: Clean up for_each_line() and related functions.
[paraslash.git] / crypt.h
diff --git a/crypt.h b/crypt.h
index c46666950c12a92a1a4d14223f769762281af1fd..77806af6983895c13f3120f4f65c1c1d46b9b11d 100644 (file)
--- a/crypt.h
+++ b/crypt.h
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2005-2012 Andre Noll <maan@systemlinux.org>
+ * Copyright (C) 2005-2013 Andre Noll <maan@systemlinux.org>
  *
  * Licensed under the GPL v2. For licencing details see COPYING.
  */
@@ -128,6 +128,36 @@ struct stream_cipher_context {
  */
 struct stream_cipher *sc_new(const unsigned char *data, int len);
 
+/**
+ * Encrypt or decrypt a buffer using a stream cipher.
+ *
+ * \param sc Crypto key.
+ * \param src The source buffer and length.
+ * \param dst The destination buffer and length, filled out by the function.
+ *
+ * It is up to the implementation to decide whether the crypt operation is
+ * performed in place. The caller can tell by looking if the buffers given by
+ * \a src and \a dst coincide after the call. If (and only if) the crypt
+ * operation was not performed in place, the function allocated a new buffer
+ * for the result, so dst->iov_base is different from src->iov_base. In this
+ * case, the destination buffer must be freed by the caller when it is no
+ * longer needed.
+ */
+void sc_crypt(struct stream_cipher *sc, struct iovec *src, struct iovec *dst);
+
+/**
+ * Wrapper for \ref sc_crypt() that can be used as a sideband transformation.
+ *
+ * \param src Passed verbatim to \ref sc_crypt().
+ * \param dst Passed verbatim to \ref sc_crypt().
+ * \param trafo_context Must point to an initialized stream cipher.
+ */
+_static_inline_ void sc_trafo(struct iovec *src, struct iovec *dst,
+               void *trafo_context)
+{
+       sc_crypt(trafo_context, src, dst);
+}
+
 /**
  * Deallocate a stream cipher structure.
  *
@@ -200,7 +230,6 @@ int sc_recv_bin_buffer(struct stream_cipher_context *scc, char *buf,
  */
 int sc_recv_buffer(struct stream_cipher_context *scc, char *buf, size_t size);
 
-
 /** Size of the hash value in bytes. */
 #define HASH_SIZE 20