diff options
Diffstat (limited to 'cipher')
-rw-r--r-- | cipher/ChangeLog | 4 | ||||
-rw-r--r-- | cipher/rndriscos.c | 44 |
2 files changed, 20 insertions, 28 deletions
diff --git a/cipher/ChangeLog b/cipher/ChangeLog index 98b40ded2..8aca3418d 100644 --- a/cipher/ChangeLog +++ b/cipher/ChangeLog @@ -1,10 +1,8 @@ 2002-08-03 Stefan Bellon <[email protected]> * idea-stub.c (idea_get_info): RISC OS' Norcroft C needs a cast. - * random.c (getfnc_gather_random): Added RISC OS support. - - * rndriscos.c: Removed dynload code. + * rndriscos.c: Removed dynload code and tidied up a bit. 2002-08-03 Werner Koch <[email protected]> diff --git a/cipher/rndriscos.c b/cipher/rndriscos.c index 3aa16d523..98142b313 100644 --- a/cipher/rndriscos.c +++ b/cipher/rndriscos.c @@ -22,51 +22,49 @@ #ifdef USE_RNDRISCOS -#include <stdio.h> -#include <stdlib.h> -#include <errno.h> #include <string.h> #include <kernel.h> #include <swis.h> #include "util.h" -#include "algorithms.h" static int init_device(void); #define CryptRandom_Byte 0x51980 +static const char * const path[] = { + "GnuPG:CryptRandom", + "GnuPG:CryptRand", + "System:Modules.CryptRandom" + "System:Modules.CryptRand", + NULL +}; + /**************** * Used to load the CryptRandom module if it isn't already loaded */ static int init_device(void) { - _kernel_swi_regs r; + int i; /* Is CryptRandom already loaded? */ - r.r[0] = 18; - r.r[1] = (int) "CryptRandom"; - if (!_kernel_swi(OS_Module, &r, &r)) + if (!_swix(OS_Module, _INR(0,1), 18, "CryptRandom")) return 1; - /* Is it named CryptRand and inside GnuPG$Path? */ - r.r[0] = 1; - r.r[1] = (int) "GnuPG:CryptRand"; - if (!_kernel_swi(OS_Module, &r, &r)) - return 1; - - /* Is it named CryptRandom and inside GnuPG$Path? */ - r.r[0] = 1; - r.r[1] = (int) "GnuPG:CryptRandom"; - if (!_kernel_swi(OS_Module, &r, &r)) - return 1; + /* 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; /* Can't find CryptRandom in the default locations */ g10_log_fatal("Can't load module CryptRandom.\n"); + + return 0; /* never reached, but don't throw a warning */ } /**************** + * Get the random bytes from module */ int rndriscos_gather_random(void (*add)(const void*, size_t, int), int requester, @@ -75,8 +73,6 @@ rndriscos_gather_random(void (*add)(const void*, size_t, int), int requester, static int initialized = 0; int n; byte buffer[768]; - _kernel_swi_regs r; - _kernel_oserror *e; if (!initialized) initialized = init_device(); @@ -84,11 +80,9 @@ rndriscos_gather_random(void (*add)(const void*, size_t, int), int requester, while (length) { int nbytes = length < sizeof(buffer) ? length : sizeof(buffer); - for (n = 0; n < nbytes; n++) { - if (e = _kernel_swi(CryptRandom_Byte, &r, &r)) + for (n = 0; n < nbytes; ++n) + if (_swix(CryptRandom_Byte, _OUT(0), &buffer[n])) g10_log_fatal("CryptRandom module isn't working as expected!\n"); - buffer[n] = (byte) r.r[0]; - } (*add)(buffer, n, requester); length -= n; |