/** \file crypt.c Openssl-based encryption/decryption routines. */
#include <regex.h>
-#include <dirent.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <openssl/rand.h>
#include <openssl/err.h>
#include <openssl/rc4.h>
#include <openssl/pem.h>
+#include <openssl/sha.h>
#include "para.h"
#include "error.h"
return ret < 0? -E_ENCRYPT : ret;
}
-#define RC4_ALIGN 8
struct stream_cipher {
RC4_KEY key;
};
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.
*
*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);
+}