2002-06-29 13:31:13 +00:00
|
|
|
/* rndriscos.c - raw random number for RISC OS
|
|
|
|
* Copyright (C) 2001 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* This file is part of GnuPG.
|
|
|
|
*
|
|
|
|
* GnuPG is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GnuPG is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
2002-08-03 18:35:16 +00:00
|
|
|
|
|
|
|
#ifdef USE_RNDRISCOS
|
|
|
|
|
2002-06-29 13:31:13 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <kernel.h>
|
|
|
|
#include <swis.h>
|
|
|
|
#include "util.h"
|
|
|
|
|
|
|
|
static int init_device(void);
|
|
|
|
|
|
|
|
#define CryptRandom_Byte 0x51980
|
|
|
|
|
2002-08-03 21:53:33 +00:00
|
|
|
static const char * const path[] = {
|
|
|
|
"GnuPG:CryptRandom",
|
|
|
|
"GnuPG:CryptRand",
|
|
|
|
"System:Modules.CryptRandom"
|
|
|
|
"System:Modules.CryptRand",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2002-06-29 13:31:13 +00:00
|
|
|
/****************
|
|
|
|
* Used to load the CryptRandom module if it isn't already loaded
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
init_device(void)
|
|
|
|
{
|
2002-08-03 21:53:33 +00:00
|
|
|
int i;
|
2002-06-29 13:31:13 +00:00
|
|
|
|
|
|
|
/* Is CryptRandom already loaded? */
|
2002-08-03 21:53:33 +00:00
|
|
|
if (!_swix(OS_Module, _INR(0,1), 18, "CryptRandom"))
|
2002-06-29 13:31:13 +00:00
|
|
|
return 1;
|
|
|
|
|
2002-08-03 21:53:33 +00:00
|
|
|
/* Check all the places where the module could be located */
|
|
|
|
for (i=0; path[i]; ++i)
|
|
|
|
if (!_swix(OS_Module, _INR(0,1), 1, path[i]))
|
|
|
|
return 1;
|
2002-06-29 13:31:13 +00:00
|
|
|
|
|
|
|
/* Can't find CryptRandom in the default locations */
|
|
|
|
g10_log_fatal("Can't load module CryptRandom.\n");
|
2002-08-03 21:53:33 +00:00
|
|
|
|
|
|
|
return 0; /* never reached, but don't throw a warning */
|
2002-06-29 13:31:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/****************
|
2002-08-03 21:53:33 +00:00
|
|
|
* Get the random bytes from module
|
2002-06-29 13:31:13 +00:00
|
|
|
*/
|
2002-08-03 18:35:16 +00:00
|
|
|
int
|
|
|
|
rndriscos_gather_random(void (*add)(const void*, size_t, int), int requester,
|
|
|
|
size_t length, int level)
|
2002-06-29 13:31:13 +00:00
|
|
|
{
|
|
|
|
static int initialized = 0;
|
|
|
|
int n;
|
|
|
|
byte buffer[768];
|
|
|
|
|
|
|
|
if (!initialized)
|
|
|
|
initialized = init_device();
|
|
|
|
|
|
|
|
while (length) {
|
|
|
|
int nbytes = length < sizeof(buffer) ? length : sizeof(buffer);
|
|
|
|
|
2002-08-03 21:53:33 +00:00
|
|
|
for (n = 0; n < nbytes; ++n)
|
|
|
|
if (_swix(CryptRandom_Byte, _OUT(0), &buffer[n]))
|
2002-06-29 13:31:13 +00:00
|
|
|
g10_log_fatal("CryptRandom module isn't working as expected!\n");
|
|
|
|
|
|
|
|
(*add)(buffer, n, requester);
|
|
|
|
length -= n;
|
|
|
|
}
|
* blowfish.c (burn_stack), cast5.c (burn_stack), des.c (burn_stack), md5.c
(burn_stack), random.c (burn_stack, read_pool, fast_random_poll),
rijndael.c (burn_stack), rmd160.c (burn_stack), rndegd.c
(rndegd_gather_random), rndlinux.c (rndlinux_gather_random), rndriscos.c
(rndriscos_gather_random), sha1.c (burn_stack), tiger.c (burn_stack),
twofish.c (burn_stack): Replace various calls to memset() with the more
secure wipememory().
2002-11-06 15:28:12 +00:00
|
|
|
wipememory(buffer, sizeof(buffer));
|
2002-06-29 13:31:13 +00:00
|
|
|
|
|
|
|
return 0; /* success */
|
|
|
|
}
|
|
|
|
|
2002-08-03 18:35:16 +00:00
|
|
|
#endif /*USE_RNDRISCOS */
|