X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=crypt.h;h=ac110882488afb54fb7541ed02944be2c5f3881b;hp=833bbf1b87e5d8a34fff91d4558820ee33191d27;hb=4744d937c4160898d1fe151257606430750e580c;hpb=4ad9b98ca90d603eecb5c9c403e0f7bbdc3be6a6 diff --git a/crypt.h b/crypt.h index 833bbf1b..ac110882 100644 --- a/crypt.h +++ b/crypt.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2011 Andre Noll + * Copyright (C) 2005-2012 Andre Noll * * 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