X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=blobdiff_plain;f=crypt.h;h=77806af6983895c13f3120f4f65c1c1d46b9b11d;hp=4696ee4a118c5791cfa40ae5cef2c4eb634807ef;hb=23b121a85984baa9252f4b4c0b8c4f186e394bb7;hpb=d49cd9a91015766cb19d7d43bb04048265925fe5 diff --git a/crypt.h b/crypt.h index 4696ee4a..77806af6 100644 --- a/crypt.h +++ b/crypt.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2011 Andre Noll + * Copyright (C) 2005-2013 Andre Noll * * Licensed under the GPL v2. For licencing details see COPYING. */ @@ -7,13 +7,14 @@ /** \file crypt.h Public crypto interface. */ -/** \cond used to distinguish between loading of private/public key */ +/* These are used to distinguish between loading of private/public key. */ + +/** The key to load is a public key. */ #define LOAD_PUBLIC_KEY 0 +/** The key to load is a private key. */ #define LOAD_PRIVATE_KEY 1 +/** The size of the challenge sent to the client. */ #define CHALLENGE_SIZE 64 -/** \endcond **/ - -/* asymetric (public key) crypto */ /** Opaque structure for public and private keys. */ struct asymmetric_key; @@ -127,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. * @@ -199,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