1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-03 22:56:33 +02:00

Applied Stefan's patches to support RISCOS.

This commit is contained in:
Werner Koch 2001-08-20 11:53:05 +00:00
parent aa1514852a
commit 23589ae0a2
56 changed files with 1593 additions and 109 deletions

View file

@ -1,3 +1,18 @@
2001-08-20 Werner Koch <wk@gnupg.org>
Applied patches from Stefan Bellon <sbellon@sbellon.de> to support
the RISCOS. Nearly all of these patches are identified by the
__riscos__ macro.
* blowfish.c, twofish.c: Added pragmas for use with a Norcraft
compiler.
* dynload.c, md5.c, rmd160.c, sha1.c: Minor patches for RISCOS.
* rndriscos.c: New.
* rnd-internal.h: Added prototype.
* random.c (fast_random_poll): Use '#if defined' instead of just
'defined'; needed for RISCOS.
* primegen.c (gen_prime): count? are now ints for consistence
with is_prime().
2001-08-08 Werner Koch <wk@gnupg.org>
* rndw32.c (gather_random): Use toolhelp in addition to the NT

View file

@ -502,7 +502,10 @@ selftest(void)
return NULL;
}
#ifdef __riscos__
/* need to switch off CSE optimisation for Norcroft C (Acorn/Pace) */
#pragma no_optimise_cse
#endif /* __riscos__ */
static int
do_bf_setkey( BLOWFISH_context *c, byte *key, unsigned keylen )
@ -587,6 +590,10 @@ do_bf_setkey( BLOWFISH_context *c, byte *key, unsigned keylen )
return 0;
}
#ifdef __riscos__
#pragma optimise_cse
#endif /* __riscos__ */
static int
bf_setkey( BLOWFISH_context *c, byte *key, unsigned keylen )
{

View file

@ -178,10 +178,10 @@ register_cipher_extension( const char *mainpgm, const char *fname )
if( !mainpgm_path && mainpgm && *mainpgm )
mainpgm_path = m_strdup(mainpgm);
#endif
if( *fname != '/' ) { /* do tilde expansion etc */
if( *fname != DIRSEP_C ) { /* do tilde expansion etc */
char *tmp;
if( strchr(fname, '/') )
if( strchr(fname, DIRSEP_C) )
tmp = make_filename(fname, NULL);
else
tmp = make_filename(GNUPG_LIBDIR, fname, NULL);
@ -392,7 +392,13 @@ load_extension( EXTLIST el )
return -1;
}
#ifdef __riscos__
typedef
const char *(*DIGESTS_CAST)(int, size_t*,byte**, int*, int*,
void (**)(void*),
void (**)(void*,byte*,size_t),
void (**)(void*),byte *(**)(void*));
#endif /* __riscos__ */
int
enum_gnupgext_digests( void **enum_context,
@ -435,7 +441,11 @@ enum_gnupgext_digests( void **enum_context,
if( vers != 1 || class != 10 )
continue;
inner_loop:
#ifndef __riscos__
*r_get_info = ctx->sym;
#else /* __riscos__ */
*r_get_info = (DIGESTS_CAST) ctx->sym;
#endif /* __riscos__ */
while( (sym = (*r->enumfunc)(11, &ctx->seq2, &class, &vers)) ) {
if( vers != 1 || class != 11 )
continue;
@ -451,6 +461,14 @@ enum_gnupgext_digests( void **enum_context,
return 0;
}
#ifdef __riscos__
typedef
const char *(*CIPHERS_CAST)(int, size_t*, size_t*, size_t*,
int (**)( void *, byte *, unsigned),
void (**)( void *, byte *, byte *),
void (**)( void *, byte *, byte *));
#endif /* __riscos__ */
const char *
enum_gnupgext_ciphers( void **enum_context, int *algo,
size_t *keylen, size_t *blocksize, size_t *contextsize,
@ -495,7 +513,11 @@ enum_gnupgext_ciphers( void **enum_context, int *algo,
if( vers != 1 || class != 20 )
continue;
inner_loop:
#ifndef __riscos__
finfo = ctx->sym;
#else /* __riscos__ */
finfo = (CIPHERS_CAST) ctx->sym;
#endif /* __riscos__ */
while( (sym = (*r->enumfunc)(21, &ctx->seq2, &class, &vers)) ) {
const char *algname;
if( vers != 1 || class != 21 )
@ -516,6 +538,19 @@ enum_gnupgext_ciphers( void **enum_context, int *algo,
return NULL;
}
#ifdef __riscos__
typedef
const char *(*PUBKEYS_CAST)(int, int *, int *, int *, int *, int *,
int (**)(int, unsigned, MPI *, MPI **),
int (**)(int, MPI *),
int (**)(int, MPI *, MPI , MPI *),
int (**)(int, MPI *, MPI *, MPI *),
int (**)(int, MPI *, MPI , MPI *),
int (**)(int, MPI , MPI *, MPI *,
int (*)(void*,MPI), void *),
unsigned (**)( int , MPI *));
#endif /* __riscos__ */
const char *
enum_gnupgext_pubkeys( void **enum_context, int *algo,
int *npkey, int *nskey, int *nenc, int *nsig, int *use,
@ -568,7 +603,11 @@ enum_gnupgext_pubkeys( void **enum_context, int *algo,
if( vers != 1 || class != 30 )
continue;
inner_loop:
#ifndef __riscos__
finfo = ctx->sym;
#else /* __riscos__ */
finfo = (PUBKEYS_CAST) ctx->sym;
#endif /* __riscos__ */
while( (sym = (*r->enumfunc)(31, &ctx->seq2, &class, &vers)) ) {
const char *algname;
if( vers != 1 || class != 31 )

View file

@ -401,7 +401,11 @@ gnupgext_enum_func( int what, int *sequence, int *class, int *vers )
*vers = func_table[i].version;
switch( *class ) {
case 11: case 21: case 31: ret = &func_table[i].value; break;
#ifndef __riscos__
default: ret = func_table[i].func; break;
#else /* __riscos__ */
default: ret = (void *) func_table[i].func; break;
#endif /* __riscos__ */
}
i++;
} while( what && what != *class );

View file

@ -298,7 +298,7 @@ gen_prime( unsigned nbits, int secret, int randomlevel )
MPI prime, ptest, pminus1, val_2, val_3, result;
int i;
unsigned x, step;
unsigned count1, count2;
int count1, count2;
int *mods;
if( 0 && DBG_CIPHER )

View file

@ -26,5 +26,6 @@ void rndw32_constructor(void);
void rndos2_constructor(void);
void rndatari_constructor(void);
void rndmvs_constructor(void);
void rndriscos_constructor(void);
#endif /*G10_RAND_INTERNAL_H*/

View file

@ -568,19 +568,19 @@ fast_random_poll()
}
/* fall back to the generic function */
#if HAVE_GETHRTIME
#ifdef HAVE_GETHRTIME
{ hrtime_t tv;
tv = gethrtime();
add_randomness( &tv, sizeof(tv), 1 );
}
#elif HAVE_GETTIMEOFDAY
#elif defined (HAVE_GETTIMEOFDAY)
{ struct timeval tv;
if( gettimeofday( &tv, NULL ) )
BUG();
add_randomness( &tv.tv_sec, sizeof(tv.tv_sec), 1 );
add_randomness( &tv.tv_usec, sizeof(tv.tv_usec), 1 );
}
#elif HAVE_CLOCK_GETTIME
#elif defined (HAVE_CLOCK_GETTIME)
{ struct timespec tv;
if( clock_gettime( CLOCK_REALTIME, &tv ) == -1 )
BUG();

View file

@ -625,7 +625,11 @@ gnupgext_enum_func( int what, int *sequence, int *class, int *vers )
ret = &func_table[i].value;
break;
default:
#ifndef __riscos__
ret = func_table[i].func;
#else /* __riscos__ */
ret = (void *) func_table[i].func;
#endif /* __riscos__ */
break;
}
i++;

136
cipher/rndriscos.c Normal file
View file

@ -0,0 +1,136 @@
/* 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>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <kernel.h>
#include <sys/swis.h>
#include "util.h"
#include "dynload.h"
static int init_device(void);
static int gather_random(void (*add)(const void*, size_t, int), int requester,
size_t length, int level);
#define CryptRandom_Byte 0x51980
/****************
* Used to load the CryptRandom module if it isn't already loaded
*/
static int
init_device(void)
{
_kernel_swi_regs r;
r.r[0] = 18;
r.r[1] = (int) "CryptRandom";
if (_kernel_swi(OS_Module, &r, &r)) {
r.r[0] = 1;
r.r[1] = (int) "GnuPG:CryptRand";
if (_kernel_swi(OS_Module, &r, &r))
g10_log_fatal("Can't load module CryptRandom.\n");
}
return 1;
}
/****************
*/
static int
gather_random(void (*add)(const void*, size_t, int), int requester,
size_t length, int level)
{
static int initialized = 0;
int n;
byte buffer[768];
_kernel_swi_regs r;
_kernel_oserror *e;
if (!initialized)
initialized = init_device();
while (length) {
int nbytes = length < sizeof(buffer) ? length : sizeof(buffer);
for (n = 0; n < nbytes; n++) {
if (e = _kernel_swi(CryptRandom_Byte, &r, &r))
g10_log_fatal("CryptRandom module isn't working as expected!\n");
buffer[n] = (byte) r.r[0];
}
(*add)(buffer, n, requester);
length -= n;
}
memset(buffer, 0, sizeof(buffer));
return 0; /* success */
}
#ifndef IS_MODULE
static
#endif
const char * const gnupgext_version = "RNDRISCOS ($Revision$)";
static struct {
int class;
int version;
void *func;
} func_table[] = {
{ 40, 1, (void *) gather_random },
};
#ifndef IS_MODULE
static
#endif
void *
gnupgext_enum_func( int what, int *sequence, int *class, int *vers )
{
void *ret;
int i = *sequence;
do {
if ( i >= DIM(func_table) || i < 0 ) {
return NULL;
}
*class = func_table[i].class;
*vers = func_table[i].version;
ret = func_table[i].func;
i++;
} while ( what && what != *class );
*sequence = i;
return ret;
}
#ifndef IS_MODULE
void
rndriscos_constructor(void)
{
register_internal_cipher_extension( gnupgext_version,
gnupgext_enum_func );
}
#endif

View file

@ -87,7 +87,7 @@ test_keys( RSA_secret_key *sk, unsigned nbits )
/****************
* Generate a key pair with a key of size NBITS
* Returns: 2 structures filles with all needed values
* Returns: 2 structures filled with all needed values
*/
static void
generate( RSA_secret_key *sk, unsigned nbits )

View file

@ -398,7 +398,11 @@ gnupgext_enum_func( int what, int *sequence, int *class, int *vers )
ret = &func_table[i].value;
break;
default:
#ifndef __riscos__
ret = func_table[i].func;
#else /* __riscos__ */
ret = (void *) func_table[i].func;
#endif /* __riscos__ */
break;
}
i++;

View file

@ -562,6 +562,11 @@ burn_stack (int bytes)
/* Perform the key setup. Note that this works only with 128- and 256-bit
* keys, despite the API that looks like it might support other sizes. */
#ifdef __riscos__
/* need to switch off CSE optimisation for Norcroft C (Acorn/Pace) */
#pragma no_optimise_cse
#endif /* __riscos__ */
static int
do_twofish_setkey (TWOFISH_context *ctx, const byte *key, unsigned int keylen)
{
@ -697,6 +702,10 @@ do_twofish_setkey (TWOFISH_context *ctx, const byte *key, unsigned int keylen)
return 0;
}
#ifdef __riscos__
#pragma optimise_cse
#endif /* __riscos__ */
static int
twofish_setkey (TWOFISH_context *ctx, const byte *key, unsigned int keylen)
{
@ -767,6 +776,11 @@ twofish_setkey (TWOFISH_context *ctx, const byte *key, unsigned int keylen)
/* Encrypt one block. in and out may be the same. */
#ifdef __riscos__
/* need to switch off CSE optimisation for Norcroft C (Acorn/Pace) */
#pragma no_optimise_cse
#endif /* __riscos__ */
static void
do_twofish_encrypt (const TWOFISH_context *ctx, byte *out, const byte *in)
{
@ -799,6 +813,10 @@ do_twofish_encrypt (const TWOFISH_context *ctx, byte *out, const byte *in)
OUTUNPACK (3, b, 7);
}
#ifdef __riscos__
#pragma optimise_cse
#endif /* __riscos__ */
static void
twofish_encrypt (const TWOFISH_context *ctx, byte *out, const byte *in)
{
@ -808,6 +826,11 @@ twofish_encrypt (const TWOFISH_context *ctx, byte *out, const byte *in)
/* Decrypt one block. in and out may be the same. */
#ifdef __riscos__
/* need to switch off CSE optimisation for Norcroft C (Acorn/Pace) - bug */
#pragma no_optimise_cse
#endif /* __riscos__ */
static void
do_twofish_decrypt (const TWOFISH_context *ctx, byte *out, const byte *in)
{
@ -840,6 +863,10 @@ do_twofish_decrypt (const TWOFISH_context *ctx, byte *out, const byte *in)
OUTUNPACK (3, d, 3);
}
#ifdef __riscos__
#pragma optimise_cse
#endif /* __riscos__ */
static void
twofish_decrypt (const TWOFISH_context *ctx, byte *out, const byte *in)
{
@ -1093,7 +1120,11 @@ gnupgext_enum_func ( int what, int *sequence, int *class, int *vers )
ret = &func_table[i].value;
break;
default:
#ifndef __riscos__
ret = func_table[i].func;
#else /* __riscos__ */
ret = (void *) func_table[i].func;
#endif /* __riscos__ */
break;
}
i++;