aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/rand
diff options
context:
space:
mode:
authorRalf S. Engelschall <rse@openssl.org>1998-12-21 11:00:56 +0000
committerRalf S. Engelschall <rse@openssl.org>1998-12-21 11:00:56 +0000
commitdfeab0689f69c0b4bd3480ffd37a9cacc2f17d9c (patch)
tree2f74e0cfd76a9e092548a9bf52e579aef984299b /crypto/rand
parent58964a492275ca9a59a0cd9c8155cb2491b4b909 (diff)
downloadopenssl-dfeab0689f69c0b4bd3480ffd37a9cacc2f17d9c.tar.gz
Import of old SSLeay release: SSLeay 0.9.1b (unreleased)
Diffstat (limited to 'crypto/rand')
-rw-r--r--crypto/rand/Makefile.ssl4
-rw-r--r--crypto/rand/md_rand.c44
-rw-r--r--crypto/rand/rand.h19
-rw-r--r--crypto/rand/rand_lib.c104
-rw-r--r--crypto/rand/randfile.c3
5 files changed, 161 insertions, 13 deletions
diff --git a/crypto/rand/Makefile.ssl b/crypto/rand/Makefile.ssl
index d04f0a9b43..ef693aec16 100644
--- a/crypto/rand/Makefile.ssl
+++ b/crypto/rand/Makefile.ssl
@@ -20,8 +20,8 @@ TEST= randtest.c
APPS=
LIB=$(TOP)/libcrypto.a
-LIBSRC=md_rand.c randfile.c
-LIBOBJ=md_rand.o randfile.o
+LIBSRC=md_rand.c randfile.c rand_lib.c
+LIBOBJ=md_rand.o randfile.o rand_lib.o
SRC= $(LIBSRC)
diff --git a/crypto/rand/md_rand.c b/crypto/rand/md_rand.c
index f44b36a8b9..35defdea30 100644
--- a/crypto/rand/md_rand.c
+++ b/crypto/rand/md_rand.c
@@ -88,6 +88,7 @@ We need a message digest of some type
#define MD_Init(a) MD5_Init(a)
#define MD_Update(a,b,c) MD5_Update(a,b,c)
#define MD_Final(a,b) MD5_Final(a,b)
+#define MD(a,b,c) MD5(a,b,c)
#elif defined(USE_SHA1_RAND)
#include "sha.h"
#define MD_DIGEST_LENGTH SHA_DIGEST_LENGTH
@@ -95,6 +96,7 @@ We need a message digest of some type
#define MD_Init(a) SHA1_Init(a)
#define MD_Update(a,b,c) SHA1_Update(a,b,c)
#define MD_Final(a,b) SHA1_Final(a,b)
+#define MD(a,b,c) SHA1(a,b,c)
#elif defined(USE_MDC2_RAND)
#include "mdc2.h"
#define MD_DIGEST_LENGTH MDC2_DIGEST_LENGTH
@@ -102,6 +104,7 @@ We need a message digest of some type
#define MD_Init(a) MDC2_Init(a)
#define MD_Update(a,b,c) MDC2_Update(a,b,c)
#define MD_Final(a,b) MDC2_Final(a,b)
+#define MD(a,b,c) MDC2(a,b,c)
#elif defined(USE_MD2_RAND)
#include "md2.h"
#define MD_DIGEST_LENGTH MD2_DIGEST_LENGTH
@@ -109,31 +112,48 @@ We need a message digest of some type
#define MD_Init(a) MD2_Init(a)
#define MD_Update(a,b,c) MD2_Update(a,b,c)
#define MD_Final(a,b) MD2_Final(a,b)
+#define MD(a,b,c) MD2(a,b,c)
#endif
#include "rand.h"
-/*#define NORAND 1 */
-/*#define PREDICT 1 */
+/* #define NORAND 1 */
+/* #define PREDICT 1 */
#define STATE_SIZE 1023
static int state_num=0,state_index=0;
static unsigned char state[STATE_SIZE+MD_DIGEST_LENGTH];
static unsigned char md[MD_DIGEST_LENGTH];
-static int md_count=0;
+static long md_count[2]={0,0};
-char *RAND_version="RAND part of SSLeay 0.9.0b 29-Jun-1998";
+char *RAND_version="RAND part of SSLeay 0.9.1a 06-Jul-1998";
-void RAND_cleanup()
+static void ssleay_rand_cleanup(void);
+static void ssleay_rand_seed(unsigned char *buf, int num);
+static void ssleay_rand_bytes(unsigned char *buf, int num);
+
+RAND_METHOD rand_ssleay={
+ ssleay_rand_seed,
+ ssleay_rand_bytes,
+ ssleay_rand_cleanup,
+ };
+
+RAND_METHOD *RAND_SSLeay()
+ {
+ return(&rand_ssleay);
+ }
+
+static void ssleay_rand_cleanup()
{
memset(state,0,sizeof(state));
state_num=0;
state_index=0;
memset(md,0,MD_DIGEST_LENGTH);
- md_count=0;
+ md_count[0]=0;
+ md_count[1]=0;
}
-void RAND_seed(buf,num)
+static void ssleay_rand_seed(buf,num)
unsigned char *buf;
int num;
{
@@ -178,7 +198,9 @@ int num;
MD_Update(&m,&(state[st_idx]),j);
MD_Update(&m,buf,j);
+ MD_Update(&m,(unsigned char *)&(md_count[0]),sizeof(md_count));
MD_Final(md,&m);
+ md_count[1]++;
buf+=j;
@@ -195,7 +217,7 @@ int num;
memset((char *)&m,0,sizeof(m));
}
-void RAND_bytes(buf,num)
+static void ssleay_rand_bytes(buf,num)
unsigned char *buf;
int num;
{
@@ -277,6 +299,7 @@ int num;
num-=j;
MD_Init(&m);
MD_Update(&m,&(md[MD_DIGEST_LENGTH/2]),MD_DIGEST_LENGTH/2);
+ MD_Update(&m,(unsigned char *)&(md_count[0]),sizeof(md_count));
#ifndef PURIFY
MD_Update(&m,buf,j); /* purify complains */
#endif
@@ -300,7 +323,8 @@ int num;
}
MD_Init(&m);
- MD_Update(&m,(unsigned char *)&md_count,sizeof(md_count)); md_count++;
+ MD_Update(&m,(unsigned char *)&(md_count[0]),sizeof(md_count));
+ md_count[0]++;
MD_Update(&m,md,MD_DIGEST_LENGTH);
MD_Final(md,&m);
memset(&m,0,sizeof(m));
@@ -385,7 +409,7 @@ void RAND_screen(void)
GetBitmapBits(hBitmap, size, bmbits);
/* Get the MD5 of the bitmap */
- MD5(bmbits,size,md);
+ MD(bmbits,size,md);
/* Seed the random generator with the MD5 digest */
RAND_seed(md, MD_DIGEST_LENGTH);
diff --git a/crypto/rand/rand.h b/crypto/rand/rand.h
index 477d7a150a..f5edcb9a54 100644
--- a/crypto/rand/rand.h
+++ b/crypto/rand/rand.h
@@ -63,7 +63,23 @@
extern "C" {
#endif
+typedef struct rand_meth_st
+ {
#ifndef NOPROTO
+ void (*seed)(unsigned char *buf, int num);
+ void (*bytes)(unsigned char *buf, int num);
+ void (*cleanup)(void);
+#else
+ void (*seed)();
+ void (*bytes)();
+ void (*cleanup)();
+#endif
+ } RAND_METHOD;
+
+#ifndef NOPROTO
+void RAND_set_rand_method(RAND_METHOD *meth);
+RAND_METHOD *RAND_get_rand_method(void );
+RAND_METHOD *RAND_SSLeay(void);
void RAND_cleanup(void );
void RAND_bytes( unsigned char *buf,int num);
void RAND_seed( unsigned char *buf,int num);
@@ -74,6 +90,9 @@ char *RAND_file_name(char *file,int num);
void RAND_screen(void);
#endif
#else
+void RAND_set_rand_method();
+RAND_METHOD *RAND_get_rand_method();
+RAND_METHOD *RAND_SSLeay();
void RAND_cleanup();
void RAND_bytes();
void RAND_seed();
diff --git a/crypto/rand/rand_lib.c b/crypto/rand/rand_lib.c
new file mode 100644
index 0000000000..c4b44e5186
--- /dev/null
+++ b/crypto/rand/rand_lib.c
@@ -0,0 +1,104 @@
+/* crypto/rand/rand_lib.c */
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
+ * All rights reserved.
+ *
+ * This package is an SSL implementation written
+ * by Eric Young (eay@cryptsoft.com).
+ * The implementation was written so as to conform with Netscapes SSL.
+ *
+ * This library is free for commercial and non-commercial use as long as
+ * the following conditions are aheared to. The following conditions
+ * apply to all code found in this distribution, be it the RC4, RSA,
+ * lhash, DES, etc., code; not just the SSL code. The SSL documentation
+ * included with this distribution is covered by the same copyright terms
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).
+ *
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.
+ * If this package is used in a product, Eric Young should be given attribution
+ * as the author of the parts of the library used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * "This product includes cryptographic software written by
+ * Eric Young (eay@cryptsoft.com)"
+ * The word 'cryptographic' can be left out if the rouines from the library
+ * being used are not cryptographic related :-).
+ * 4. If you include any Windows specific code (or a derivative thereof) from
+ * the apps directory (application code) you must include an acknowledgement:
+ * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed. i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+#include <stdio.h>
+#include "cryptlib.h"
+#include <sys/types.h>
+#include <time.h>
+#include "rand.h"
+
+#ifdef NO_RAND
+static RAND_METHOD *rand_meth=NULL;
+#else
+extern RAND_METHOD rand_ssleay;
+static RAND_METHOD *rand_meth= &rand_ssleay;
+#endif
+
+void RAND_set_rand_method(meth)
+RAND_METHOD *meth;
+ {
+ rand_meth=meth;
+ }
+
+RAND_METHOD *RAND_get_rand_method()
+ {
+ return(rand_meth);
+ }
+
+void RAND_cleanup()
+ {
+ if (rand_meth != NULL)
+ rand_meth->cleanup();
+ }
+
+void RAND_seed(buf,num)
+unsigned char *buf;
+int num;
+ {
+ if (rand_meth != NULL)
+ rand_meth->seed(buf,num);
+ }
+
+void RAND_bytes(buf,num)
+unsigned char *buf;
+int num;
+ {
+ if (rand_meth != NULL)
+ rand_meth->bytes(buf,num);
+ }
+
diff --git a/crypto/rand/randfile.c b/crypto/rand/randfile.c
index f2b3746363..4b38b2bf64 100644
--- a/crypto/rand/randfile.c
+++ b/crypto/rand/randfile.c
@@ -58,6 +58,7 @@
#include <stdio.h>
#include "cryptlib.h"
+#include <sys/types.h>
#include <sys/stat.h>
#include <sys/types.h>
#include "rand.h"
@@ -86,7 +87,7 @@ long bytes;
if (i < 0) return(0);
if (bytes <= 0) return(ret);
- in=fopen(file,"r");
+ in=fopen(file,"br");
if (in == NULL) goto err;
for (;;)
{