зеркало из https://github.com/mozilla/gecko-dev.git
Get freebl and mpi to build for WinCE. Use NSPR for I/O in sysrand.
This commit is contained in:
Родитель
e61fb92200
Коммит
d378f5131e
|
@ -49,6 +49,11 @@
|
|||
#define USE_LONG
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32_WCE)
|
||||
#undef WORD
|
||||
#define WORD ARC4WORD
|
||||
#endif
|
||||
|
||||
#if defined(NSS_USE_HYBRID) && !defined(SOLARIS) && !defined(NSS_USE_64)
|
||||
typedef unsigned long long WORD;
|
||||
#else
|
||||
|
|
|
@ -36,7 +36,7 @@
|
|||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
*
|
||||
* $Id: mpi.h,v 1.19 2001/03/13 19:01:52 relyea%netscape.com Exp $
|
||||
* $Id: mpi.h,v 1.20 2002/04/04 00:19:43 nelsonb%netscape.com Exp $
|
||||
*/
|
||||
|
||||
#ifndef _H_MPI_
|
||||
|
@ -60,8 +60,10 @@
|
|||
#undef ULLONG_MAX
|
||||
#endif
|
||||
|
||||
#ifdef macintosh
|
||||
#if defined( macintosh )
|
||||
#include <Types.h>
|
||||
#elif defined( _WIN32_WCE)
|
||||
/* #include <sys/types.h> What do we need here ?? */
|
||||
#else
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
* the GPL. If you do not delete the provisions above, a recipient
|
||||
* may use your version of this file under either the MPL or the
|
||||
* GPL.
|
||||
* $Id: mpmontg.c,v 1.10 2000/12/28 03:41:50 nelsonb%netscape.com Exp $
|
||||
* $Id: mpmontg.c,v 1.11 2002/04/04 00:19:43 nelsonb%netscape.com Exp $
|
||||
*/
|
||||
|
||||
/* This file implements moduluar exponentiation using Montgomery's
|
||||
|
@ -56,6 +56,12 @@
|
|||
#define MAX_WINDOW_BITS 6
|
||||
#define MAX_ODD_INTS 32 /* 2 ** (WINDOW_BITS - 1) */
|
||||
|
||||
#if defined(_WIN32_WCE)
|
||||
#define ABORT res = MP_UNDEF; goto CLEANUP
|
||||
#else
|
||||
#define ABORT abort()
|
||||
#endif
|
||||
|
||||
typedef struct {
|
||||
mp_int N; /* modulus N */
|
||||
mp_digit n0prime; /* n0' = - (n0 ** -1) mod MP_RADIX */
|
||||
|
@ -272,7 +278,7 @@ mp_err mp_exptmod_f(const mp_int * montBase,
|
|||
} else if (smallExp & 8) {
|
||||
SQR; MUL(smallExp/16); SQR; SQR; SQR;
|
||||
} else {
|
||||
abort();
|
||||
ABORT;
|
||||
}
|
||||
} else if (window_bits == 5) {
|
||||
if (!smallExp) {
|
||||
|
@ -288,7 +294,7 @@ mp_err mp_exptmod_f(const mp_int * montBase,
|
|||
} else if (smallExp & 0x10) {
|
||||
SQR; MUL(smallExp/32); SQR; SQR; SQR; SQR;
|
||||
} else {
|
||||
abort();
|
||||
ABORT;
|
||||
}
|
||||
} else if (window_bits == 6) {
|
||||
if (!smallExp) {
|
||||
|
@ -306,10 +312,10 @@ mp_err mp_exptmod_f(const mp_int * montBase,
|
|||
} else if (smallExp & 0x20) {
|
||||
SQR; MUL(smallExp/64); SQR; SQR; SQR; SQR; SQR;
|
||||
} else {
|
||||
abort();
|
||||
ABORT;
|
||||
}
|
||||
} else {
|
||||
abort();
|
||||
ABORT;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -416,7 +422,7 @@ mp_err mp_exptmod_i(const mp_int * montBase,
|
|||
SQR(pa1,pa2); MUL(smallExp/16,pa2,pa1); SQR(pa1,pa2);
|
||||
SQR(pa2,pa1); SQR(pa1,pa2); SWAPPA;
|
||||
} else {
|
||||
abort();
|
||||
ABORT;
|
||||
}
|
||||
} else if (window_bits == 5) {
|
||||
if (!smallExp) {
|
||||
|
@ -438,7 +444,7 @@ mp_err mp_exptmod_i(const mp_int * montBase,
|
|||
SQR(pa1,pa2); MUL(smallExp/32,pa2,pa1); SQR(pa1,pa2);
|
||||
SQR(pa2,pa1); SQR(pa1,pa2); SQR(pa2,pa1);
|
||||
} else {
|
||||
abort();
|
||||
ABORT;
|
||||
}
|
||||
} else if (window_bits == 6) {
|
||||
if (!smallExp) {
|
||||
|
@ -464,10 +470,10 @@ mp_err mp_exptmod_i(const mp_int * montBase,
|
|||
SQR(pa1,pa2); MUL(smallExp/64,pa2,pa1); SQR(pa1,pa2);
|
||||
SQR(pa2,pa1); SQR(pa1,pa2); SQR(pa2,pa1); SQR(pa1,pa2); SWAPPA;
|
||||
} else {
|
||||
abort();
|
||||
ABORT;
|
||||
}
|
||||
} else {
|
||||
abort();
|
||||
ABORT;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,10 +34,16 @@
|
|||
#include "secrng.h"
|
||||
#ifdef XP_WIN
|
||||
#include <windows.h>
|
||||
|
||||
#if defined(_WIN32_WCE)
|
||||
#include <stdlib.h> /* Win CE puts lots of stuff here. */
|
||||
#include "prprf.h" /* for PR_snprintf */
|
||||
#else
|
||||
#include <time.h>
|
||||
#include <io.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
|
@ -46,6 +52,13 @@
|
|||
#include <dos.h>
|
||||
#endif
|
||||
|
||||
#include "prio.h"
|
||||
|
||||
static PRInt32 filesToRead;
|
||||
static DWORD totalFileBytes;
|
||||
static DWORD maxFileBytes = 250000;
|
||||
static DWORD dwNumFiles, dwReadEvery;
|
||||
|
||||
static BOOL
|
||||
CurrentClockTickTime(LPDWORD lpdwHigh, LPDWORD lpdwLow)
|
||||
{
|
||||
|
@ -116,7 +129,6 @@ size_t RNG_GetNoise(void *buf, size_t maxbuf)
|
|||
DWORD dwHigh, dwLow, dwVal;
|
||||
int n = 0;
|
||||
int nBytes;
|
||||
time_t sTime;
|
||||
|
||||
if (maxbuf <= 0)
|
||||
return 0;
|
||||
|
@ -151,18 +163,81 @@ size_t RNG_GetNoise(void *buf, size_t maxbuf)
|
|||
if (maxbuf <= 0)
|
||||
return n;
|
||||
|
||||
#if defined(_WIN32_WCE)
|
||||
{
|
||||
// get the number of milliseconds elapsed since Windows CE was started.
|
||||
DWORD tickCount = GetTickCount();
|
||||
nBytes = (sizeof tickCount) > maxbuf ? maxbuf : (sizeof tickCount);
|
||||
memcpy(((char *)buf) + n, &tickCount, nBytes);
|
||||
n += nBytes;
|
||||
}
|
||||
#else
|
||||
{
|
||||
time_t sTime;
|
||||
// get the time in seconds since midnight Jan 1, 1970
|
||||
time(&sTime);
|
||||
nBytes = sizeof(sTime) > maxbuf ? maxbuf : sizeof(sTime);
|
||||
memcpy(((char *)buf) + n, &sTime, nBytes);
|
||||
n += nBytes;
|
||||
}
|
||||
#endif
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
#if defined(_WIN32_WCE)
|
||||
static BOOL
|
||||
EnumSystemFiles(void (*func)(const char *))
|
||||
EnumSystemFilesWithNSPR(const char * dirName,
|
||||
BOOL recursive,
|
||||
PRInt32 (*func)(const char *))
|
||||
{
|
||||
PRDir * pDir;
|
||||
PRDirEntry * pEntry;
|
||||
BOOL rv = FALSE;
|
||||
|
||||
pDir = PR_OpenDir(dirName);
|
||||
if (!pDir)
|
||||
return rv;
|
||||
while ((pEntry = PR_ReadDir(pDir, PR_SKIP_BOTH|PR_SKIP_HIDDEN)) != NULL) {
|
||||
PRStatus status;
|
||||
PRInt32 count;
|
||||
PRInt32 stop;
|
||||
PRFileInfo fileInfo;
|
||||
char szFileName[_MAX_PATH];
|
||||
|
||||
count = (PRInt32)PR_snprintf(szFileName, sizeof szFileName, "%s\\%s",
|
||||
dirName, PR_DirName(pEntry));
|
||||
if (count < 1)
|
||||
continue;
|
||||
status = PR_GetFileInfo(szFileName, &fileInfo);
|
||||
if (status != PR_SUCCESS)
|
||||
continue;
|
||||
if (fileInfo.type == PR_FILE_FILE) {
|
||||
stop = (*func)(szFileName);
|
||||
rv = TRUE;
|
||||
if (stop)
|
||||
break;
|
||||
continue;
|
||||
}
|
||||
if (recursive && fileInfo.type == PR_FILE_DIRECTORY) {
|
||||
rv |= EnumSystemFilesWithNSPR(szFileName, recursive, func);
|
||||
}
|
||||
}
|
||||
PR_CloseDir(pDir);
|
||||
return rv;
|
||||
}
|
||||
#endif
|
||||
|
||||
static BOOL
|
||||
EnumSystemFiles(PRInt32 (*func)(const char *))
|
||||
{
|
||||
#if defined(_WIN32_WCE)
|
||||
BOOL rv = FALSE;
|
||||
rv |= EnumSystemFilesWithNSPR("\\Windows\\Temporary Internet Files", TRUE, func);
|
||||
rv |= EnumSystemFilesWithNSPR("\\Temp", FALSE, func);
|
||||
rv |= EnumSystemFilesWithNSPR("\\Windows", FALSE, func);
|
||||
return rv;
|
||||
#else
|
||||
int iStatus;
|
||||
char szSysDir[_MAX_PATH];
|
||||
char szFileName[_MAX_PATH];
|
||||
|
@ -207,23 +282,31 @@ EnumSystemFiles(void (*func)(const char *))
|
|||
#endif
|
||||
|
||||
return TRUE;
|
||||
#endif
|
||||
}
|
||||
|
||||
static DWORD dwNumFiles, dwReadEvery;
|
||||
|
||||
static void
|
||||
static PRInt32
|
||||
CountFiles(const char *file)
|
||||
{
|
||||
dwNumFiles++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
static PRInt32
|
||||
ReadFiles(const char *file)
|
||||
{
|
||||
if ((dwNumFiles % dwReadEvery) == 0)
|
||||
if ((dwNumFiles % dwReadEvery) == 0) {
|
||||
++filesToRead;
|
||||
}
|
||||
if (filesToRead) {
|
||||
DWORD prevFileBytes = totalFileBytes;
|
||||
RNG_FileForRNG(file);
|
||||
|
||||
if (prevFileBytes < totalFileBytes) {
|
||||
--filesToRead;
|
||||
}
|
||||
}
|
||||
dwNumFiles++;
|
||||
return (totalFileBytes >= maxFileBytes);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -237,6 +320,7 @@ ReadSystemFiles()
|
|||
RNG_RandomUpdate(&dwNumFiles, sizeof(dwNumFiles));
|
||||
|
||||
// now read 10 files
|
||||
filesToRead = 10;
|
||||
if (dwNumFiles == 0)
|
||||
return;
|
||||
|
||||
|
@ -255,12 +339,14 @@ void RNG_SystemInfoForRNG(void)
|
|||
int nBytes;
|
||||
#ifdef _WIN32
|
||||
MEMORYSTATUS sMem;
|
||||
HANDLE hVal;
|
||||
#if !defined(_WIN32_WCE)
|
||||
DWORD dwSerialNum;
|
||||
DWORD dwComponentLen;
|
||||
DWORD dwSysFlags;
|
||||
char volName[128];
|
||||
DWORD dwSectors, dwBytes, dwFreeClusters, dwNumClusters;
|
||||
HANDLE hVal;
|
||||
#endif
|
||||
#else
|
||||
int iVal;
|
||||
HTASK hTask;
|
||||
|
@ -275,10 +361,10 @@ void RNG_SystemInfoForRNG(void)
|
|||
sMem.dwLength = sizeof(sMem);
|
||||
GlobalMemoryStatus(&sMem); // assorted memory stats
|
||||
RNG_RandomUpdate(&sMem, sizeof(sMem));
|
||||
|
||||
#if !defined(_WIN32_WCE)
|
||||
dwVal = GetLogicalDrives();
|
||||
RNG_RandomUpdate(&dwVal, sizeof(dwVal)); // bitfields in bits 0-25
|
||||
|
||||
#endif
|
||||
#else
|
||||
dwVal = GetFreeSpace(0);
|
||||
RNG_RandomUpdate(&dwVal, sizeof(dwVal));
|
||||
|
@ -290,10 +376,11 @@ void RNG_SystemInfoForRNG(void)
|
|||
#endif
|
||||
|
||||
#ifdef _WIN32
|
||||
#if !defined(_WIN32_WCE)
|
||||
dwVal = sizeof(buffer);
|
||||
if (GetComputerName(buffer, &dwVal))
|
||||
RNG_RandomUpdate(buffer, dwVal);
|
||||
|
||||
#endif
|
||||
/* XXX This is code that got yanked because of NSPR20. We should put it
|
||||
* back someday.
|
||||
*/
|
||||
|
@ -326,6 +413,7 @@ void RNG_SystemInfoForRNG(void)
|
|||
dwVal = GetCurrentProcessId(); // process ID (4 bytes)
|
||||
RNG_RandomUpdate(&dwVal, sizeof(dwVal));
|
||||
|
||||
#if !defined(_WIN32_WCE)
|
||||
volName[0] = '\0';
|
||||
buffer[0] = '\0';
|
||||
GetVolumeInformation(NULL,
|
||||
|
@ -349,7 +437,7 @@ void RNG_SystemInfoForRNG(void)
|
|||
RNG_RandomUpdate(&dwFreeClusters, sizeof(dwFreeClusters));
|
||||
RNG_RandomUpdate(&dwNumClusters, sizeof(dwNumClusters));
|
||||
}
|
||||
|
||||
#endif
|
||||
#else /* is WIN16 */
|
||||
hTask = GetCurrentTask();
|
||||
RNG_RandomUpdate((void *)&hTask, sizeof(hTask));
|
||||
|
@ -374,38 +462,36 @@ void RNG_SystemInfoForRNG(void)
|
|||
|
||||
void RNG_FileForRNG(const char *filename)
|
||||
{
|
||||
FILE* file;
|
||||
PRFileDesc * file;
|
||||
int nBytes;
|
||||
struct stat stat_buf;
|
||||
PRFileInfo infoBuf;
|
||||
unsigned char buffer[1024];
|
||||
|
||||
static DWORD totalFileBytes = 0;
|
||||
|
||||
/* windows doesn't initialize all the bytes in the stat buf,
|
||||
* so initialize them all here to avoid UMRs.
|
||||
*/
|
||||
memset(&stat_buf, 0, sizeof stat_buf);
|
||||
memset(&infoBuf, 0, sizeof infoBuf);
|
||||
|
||||
if (stat((char *)filename, &stat_buf) < 0)
|
||||
if (PR_GetFileInfo(filename, &infoBuf) < 0)
|
||||
return;
|
||||
|
||||
RNG_RandomUpdate((unsigned char*)&stat_buf, sizeof(stat_buf));
|
||||
RNG_RandomUpdate((unsigned char*)&infoBuf, sizeof(infoBuf));
|
||||
|
||||
file = fopen((char *)filename, "r");
|
||||
file = PR_Open(filename, PR_RDONLY, 0);
|
||||
if (file != NULL) {
|
||||
for (;;) {
|
||||
size_t bytes = fread(buffer, 1, sizeof(buffer), file);
|
||||
PRInt32 bytes = PR_Read(file, buffer, sizeof buffer);
|
||||
|
||||
if (bytes == 0)
|
||||
if (bytes <= 0)
|
||||
break;
|
||||
|
||||
RNG_RandomUpdate(buffer, bytes);
|
||||
totalFileBytes += bytes;
|
||||
if (totalFileBytes > 250000)
|
||||
if (totalFileBytes > maxFileBytes)
|
||||
break;
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
PR_Close(file);
|
||||
}
|
||||
|
||||
nBytes = RNG_GetNoise(buffer, 20); // get up to 20 bytes
|
||||
|
|
Загрузка…
Ссылка в новой задаче