APG v2.2.0

This commit is contained in:
Adel I. Mirzazhanov
2003-07-28 16:26:03 +07:00
committed by skinc
parent 900ff5ea18
commit df3f864b46
33 changed files with 1655 additions and 386 deletions

19
rnd.c
View File

@@ -1,5 +1,5 @@
/*
** Copyright (c) 1999, 2000, 2001, 2002
** Copyright (c) 1999, 2000, 2001, 2002, 2003
** Adel I. Mirzazhanov. All rights reserved
**
** Redistribution and use in source and binary forms, with or without
@@ -29,7 +29,9 @@
#include <stdio.h>
#include <stdlib.h>
#if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32) && !defined(__WIN32__)
#include <strings.h>
#endif
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
@@ -77,7 +79,11 @@ randint(int n)
UINT32
x917cast_rnd (void)
{
#if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32) && !defined(__WIN32__)
struct timeval local_time;
#else
clock_t local_time[2]; /* clock ticks for win32 */
#endif
UINT32 I[2] = {0L,0L};
UINT32 I_plus_s[2] = {0L,0L};
UINT32 Xi[2] = {0L,0L};
@@ -94,7 +100,12 @@ u8 ro_key[16] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
* ENCRYPTION KEY HEX : 0x000102030405060708090A0B0C0D0E0F (128-bit) *
* YOU CAN CHANGE IT IF YOU WANT *
**********************************************************************/
#if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32) && !defined(__WIN32__)
(void) gettimeofday (&local_time, 0);
#else
local_time[0] = clock();
local_time[1] = clock();
#endif
cast_setkey(&ky, (u8*)&ro_key[0], 16);
cast_encrypt (&ky, (u8 *)&local_time, (u8*)&I[0]); /* I=Ek(D), D-time */
I_plus_s[0] = I[0] ^ __rnd_seed[0]; /* I0 (+) s0 */
@@ -173,14 +184,14 @@ x917_setseed (UINT32 seed, int quiet)
if ( (dr = fopen(APG_DEVRANDOM, "r")) != NULL)
{
(void) fread( (void *)&drs[0], 8, 1, dr);
(void)fread( (void *)&drs[0], 8, 1, dr);
__rnd_seed[0] = seed ^ drs[0];
__rnd_seed[1] = seed ^ drs[1];
(void) fclose(dr);
}
else if ( (dr = fopen(APG_DEVURANDOM, "r")) != NULL)
{
(void) fread( (void *)&drs[0], 8, 1, dr);
(void)fread( (void *)&drs[0], 8, 1, dr);
__rnd_seed[0] = seed ^ drs[0];
__rnd_seed[1] = seed ^ drs[1];
(void) fclose(dr);
@@ -188,12 +199,14 @@ x917_setseed (UINT32 seed, int quiet)
else
{
#ifndef CLISERV
#if !defined(WIN32) && !defined(_WIN32) && !defined(__WIN32) && !defined(__WIN32__)
if (quiet != TRUE)
{
fprintf(stderr,"CAN NOT USE RANDOM DEVICE TO GENERATE RANDOM SEED\n");
fprintf(stderr,"USING LOCAL TIME AND PID FOR SEED GENERATION !!!\n");
fflush(stderr);
}
#endif /* WIN32 */
#endif /* CLISERV */
__rnd_seed[0] = seed ^ pid;
__rnd_seed[1] = seed ^ pid;