summaryrefslogtreecommitdiff
path: root/beecrypt/fips186.c
diff options
context:
space:
mode:
Diffstat (limited to 'beecrypt/fips186.c')
-rw-r--r--beecrypt/fips186.c61
1 files changed, 24 insertions, 37 deletions
diff --git a/beecrypt/fips186.c b/beecrypt/fips186.c
index 2911b3510..90937f277 100644
--- a/beecrypt/fips186.c
+++ b/beecrypt/fips186.c
@@ -3,7 +3,7 @@
*
* NIST FIPS 186 pseudo-random generator, code
*
- * Copyright (c) 1998-2000 Virtual Unlimited B.V.
+ * Copyright (c) 1998, 1999, 2000 Virtual Unlimited B.V.
*
* Author: Bob Deblier <bob@virtualunlimited.com>
*
@@ -30,7 +30,10 @@
#include "mp32opt.h"
#if HAVE_STDLIB_H
-#include <stdlib.h>
+# include <stdlib.h>
+#endif
+#if HAVE_MALLOC_H
+# include <malloc.h>
#endif
static uint32 fips186hinit[5] = { 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0, 0x67452301 };
@@ -47,30 +50,24 @@ int fips186Setup(fips186Param* fp)
{
if (fp)
{
- const entropySource* es = entropySourceDefault();
-
#ifdef _REENTRANT
# if WIN32
if (!(fp->lock = CreateMutex(NULL, FALSE, NULL)))
return -1;
# else
- # if HAVE_SYNCH_H
+ # if defined(HAVE_SYNCH_H)
if (mutex_init(&fp->lock, USYNC_THREAD, (void *) 0))
return -1;
- # elif HAVE_PTHREAD_H
+ # elif defined(HAVE_PTHREAD_H)
if (pthread_mutex_init(&fp->lock, (pthread_mutexattr_t *) 0))
return -1;
- # else
- # error need locking mechanism
# endif
# endif
#endif
- if (es)
- {
- fp->digestsize = 0;
- return es->next(fp->state, FIPS186_STATE_SIZE);
- }
+ fp->digestsize = 0;
+
+ return entropyGatherNext(fp->state, FIPS186_STATE_SIZE);
}
return -1;
}
@@ -84,32 +81,28 @@ int fips186Seed(fips186Param* fp, const uint32* data, int size)
if (WaitForSingleObject(fp->lock, INFINITE) != WAIT_OBJECT_0)
return -1;
# else
- # if HAVE_SYNCH_H
+ # if defined(HAVE_SYNCH_H)
if (mutex_lock(&fp->lock))
return -1;
- # elif HAVE_PTHREAD_H
+ # elif defined(HAVE_PTHREAD_H)
if (pthread_mutex_lock(&fp->lock))
return -1;
- # else
- # error need locking mechanism
# endif
# endif
#endif
if (data)
- mp32addx(FIPS186_STATE_SIZE, fp->state, size, data);
+ (void) mp32addx(FIPS186_STATE_SIZE, fp->state, size, data);
#ifdef _REENTRANT
# if WIN32
if (!ReleaseMutex(fp->lock))
return -1;
# else
- # if HAVE_SYNCH_H
+ # if defined(HAVE_SYNCH_H)
if (mutex_unlock(&fp->lock))
return -1;
- # elif HAVE_PTHREAD_H
+ # elif defined(HAVE_PTHREAD_H)
if (pthread_mutex_unlock(&fp->lock))
return -1;
- # else
- # error need locking mechanism
# endif
# endif
#endif
@@ -127,14 +120,12 @@ int fips186Next(fips186Param* fp, uint32* data, int size)
if (WaitForSingleObject(fp->lock, INFINITE) != WAIT_OBJECT_0)
return -1;
# else
- # if HAVE_SYNCH_H
+ # if defined(HAVE_SYNCH_H)
if (mutex_lock(&fp->lock))
return -1;
- # elif HAVE_PTHREAD_H
+ # elif defined(HAVE_PTHREAD_H)
if (pthread_mutex_lock(&fp->lock))
return -1;
- # else
- # error need locking mechanism
# endif
# endif
#endif
@@ -144,14 +135,14 @@ int fips186Next(fips186Param* fp, uint32* data, int size)
if (fp->digestsize == 0)
{
- fips186init(&fp->param);
+ (void) fips186init(&fp->param);
/* copy the 512 bits of state data into the sha1Param */
mp32copy(FIPS186_STATE_SIZE, fp->param.data, fp->state);
/* process the data */
sha1Process(&fp->param);
/* set state to state + digest + 1 mod 2^512 */
- mp32addx(FIPS186_STATE_SIZE, fp->state, 5, fp->param.h);
- mp32addw(FIPS186_STATE_SIZE, fp->state, 1);
+ (void) mp32addx(FIPS186_STATE_SIZE, fp->state, 5, fp->param.h);
+ (void) mp32addw(FIPS186_STATE_SIZE, fp->state, 1);
/* we now have 5 words of pseudo-random data */
fp->digestsize = 5;
}
@@ -167,14 +158,12 @@ int fips186Next(fips186Param* fp, uint32* data, int size)
if (!ReleaseMutex(fp->lock))
return -1;
# else
- # if HAVE_SYNCH_H
+ # if defined(HAVE_SYNCH_H)
if (mutex_unlock(&fp->lock))
return -1;
- # elif HAVE_PTHREAD_H
+ # elif defined(HAVE_PTHREAD_H)
if (pthread_mutex_unlock(&fp->lock))
return -1;
- # else
- # error need locking mechanism
# endif
# endif
#endif
@@ -192,14 +181,12 @@ int fips186Cleanup(fips186Param* fp)
if (!CloseHandle(fp->lock))
return -1;
# else
- # if HAVE_SYNCH_H
+ # if defined(HAVE_SYNCH_H)
if (mutex_destroy(&fp->lock))
return -1;
- # elif HAVE_PTHREAD_H
+ # elif defined(HAVE_PTHREAD_H)
if (pthread_mutex_destroy(&fp->lock))
return -1;
- # else
- # error need locking mechanism
# endif
# endif
#endif