1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-11-04 20:38:50 +01:00
gnupg/cipher/rndriscos.c

73 lines
2.1 KiB
C
Raw Normal View History

2002-06-29 15:31:13 +02: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 20:35:16 +02:00
#ifdef USE_RNDRISCOS
2002-06-29 15:31:13 +02:00
#include <string.h>
#include <kernel.h>
#include <swis.h>
#include "util.h"
#define CryptRandom_Byte 0x51980
2002-10-31 17:58:47 +01:00
static const char * const cryptrandom_path[] = {
"GnuPG:CryptRandom",
"GnuPG:CryptRand",
2002-10-31 17:58:47 +01:00
"System:310.Modules.CryptRandom",
"System:310.Modules.CryptRand",
"System:Modules.CryptRandom",
"System:Modules.CryptRand",
NULL
};
2002-06-29 15:31:13 +02:00
/****************
* Get the random bytes from module
2002-06-29 15:31:13 +02:00
*/
2002-08-03 20:35:16 +02:00
int
rndriscos_gather_random(void (*add)(const void*, size_t, int), int requester,
size_t length, int level)
2002-06-29 15:31:13 +02:00
{
2002-10-31 17:58:47 +01:00
static int rndriscos_initialized = 0;
2002-06-29 15:31:13 +02:00
int n;
byte buffer[768];
2002-10-31 17:58:47 +01:00
if (!rndriscos_initialized)
rndriscos_initialized = riscos_load_module("CryptRandom",
cryptrandom_path, 1);
2002-06-29 15:31:13 +02:00
while (length) {
int nbytes = length < sizeof(buffer) ? length : sizeof(buffer);
for (n = 0; n < nbytes; ++n)
if (_swix(CryptRandom_Byte, _OUT(0), &buffer[n]))
2002-06-29 15:31:13 +02:00
g10_log_fatal("CryptRandom module isn't working as expected!\n");
(*add)(buffer, n, requester);
length -= n;
}
2002-10-31 17:58:47 +01:00
wipememory(buffer, sizeof(buffer)); /* burn the buffer */
2002-06-29 15:31:13 +02:00
return 0; /* success */
}
2002-08-03 20:35:16 +02:00
#endif /*USE_RNDRISCOS */