|
|
|
|
@ -22,9 +22,18 @@
|
|
|
|
|
*
|
|
|
|
|
* Implements cryptographic functions.
|
|
|
|
|
* Based on the libtomcrypt library ( http://libtom.org/?page=features&newsitems=5&whatfile=crypt )
|
|
|
|
|
*
|
|
|
|
|
* Implementation of function using NSS is not linked with libtomcrypt.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "suricata-common.h"
|
|
|
|
|
#include "suricata.h"
|
|
|
|
|
#include "util-crypt.h"
|
|
|
|
|
#ifdef HAVE_NSS
|
|
|
|
|
#include <sechash.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#ifndef HAVE_NSS
|
|
|
|
|
|
|
|
|
|
#define F0(x,y,z) (z ^ (x & (y ^ z)))
|
|
|
|
|
#define F1(x,y,z) (x ^ y ^ z)
|
|
|
|
|
@ -227,6 +236,32 @@ unsigned char* ComputeSHA1(unsigned char* buff, int bufflen)
|
|
|
|
|
return lResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#else /* HAVE_NSS */
|
|
|
|
|
|
|
|
|
|
unsigned char* ComputeSHA1(unsigned char* buff, int bufflen)
|
|
|
|
|
{
|
|
|
|
|
HASHContext *sha1_ctx = HASH_Create(HASH_AlgSHA1);
|
|
|
|
|
unsigned char* lResult = NULL;
|
|
|
|
|
unsigned int rlen;
|
|
|
|
|
if (sha1_ctx == NULL) {
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lResult = (unsigned char*) SCMalloc((sizeof(unsigned char) * 20));
|
|
|
|
|
if (lResult == NULL) {
|
|
|
|
|
HASH_Destroy(sha1_ctx);
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
HASH_Begin(sha1_ctx);
|
|
|
|
|
HASH_Update(sha1_ctx, buff, bufflen);
|
|
|
|
|
HASH_End(sha1_ctx, lResult, &rlen, (sizeof(unsigned char) * 20));
|
|
|
|
|
HASH_Destroy(sha1_ctx);
|
|
|
|
|
|
|
|
|
|
return lResult;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* HAVE_NSS */
|
|
|
|
|
|
|
|
|
|
static const char *b64codes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
|
|
|
|
|
|
|
|
int Base64Encode(const unsigned char *in, unsigned long inlen,
|
|
|
|
|
|