X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;f=crypt.c;h=8e1814dd3d82e5fd1d50301402faea6b0d9a9934;hb=54cf5827521ddf1d4be9bed2da196ca58e773e4e;hp=99804470783c04e3758e8800f87f083c4e54f623;hpb=e4db7671a91a7552c642acc979f0eb278f8d467f;p=paraslash.git diff --git a/crypt.c b/crypt.c index 99804470..8e1814dd 100644 --- a/crypt.c +++ b/crypt.c @@ -7,13 +7,13 @@ /** \file crypt.c Openssl-based encryption/decryption routines. */ #include -#include #include #include #include #include #include #include +#include #include "para.h" #include "error.h" @@ -219,7 +219,6 @@ int pub_encrypt(struct asymmetric_key *pub, unsigned char *inbuf, return ret < 0? -E_ENCRYPT : ret; } -#define RC4_ALIGN 8 struct stream_cipher { RC4_KEY key; }; @@ -249,6 +248,13 @@ void sc_free(struct stream_cipher *sc) free(sc); } +/** + * The RC4() implementation of openssl apparently reads and writes data in + * blocks of 8 bytes. So we have to make sure our buffer sizes are a multiple + * of this. + */ +#define RC4_ALIGN 8 + /** * Encrypt and send a buffer. * @@ -364,3 +370,22 @@ int sc_recv_buffer(struct stream_cipher_context *scc, char *buf, size_t size) *buf = '\0'; return n; } + +/** + * Compute the hash of the given input data. + * + * \param data Pointer to the data to compute the hash value from. + * \param len The length of \a data in bytes. + * \param hash Result pointer. + * + * \a hash must point to an area at least \p HASH_SIZE bytes large. + * + * \sa sha(3), openssl(1). + * */ +void hash_function(const char *data, unsigned long len, unsigned char *hash) +{ + SHA_CTX c; + SHA1_Init(&c); + SHA1_Update(&c, data, len); + SHA1_Final(hash, &c); +}