aboutsummaryrefslogtreecommitdiffstats
path: root/cipher
diff options
context:
space:
mode:
Diffstat (limited to 'cipher')
-rw-r--r--cipher/ChangeLog15
-rw-r--r--cipher/blowfish.c9
-rw-r--r--cipher/dynload.c45
-rw-r--r--cipher/md5.c4
-rw-r--r--cipher/primegen.c2
-rw-r--r--cipher/rand-internal.h1
-rw-r--r--cipher/random.c6
-rw-r--r--cipher/rmd160.c4
-rw-r--r--cipher/rndriscos.c136
-rw-r--r--cipher/rsa.c2
-rw-r--r--cipher/sha1.c4
-rw-r--r--cipher/twofish.c31
12 files changed, 250 insertions, 9 deletions
diff --git a/cipher/ChangeLog b/cipher/ChangeLog
index 2329dfe4b..c50dba0ce 100644
--- a/cipher/ChangeLog
+++ b/cipher/ChangeLog
@@ -1,3 +1,18 @@
+2001-08-20 Werner Koch <[email protected]>
+
+ Applied patches from Stefan Bellon <[email protected]> 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 <[email protected]>
* rndw32.c (gather_random): Use toolhelp in addition to the NT
diff --git a/cipher/blowfish.c b/cipher/blowfish.c
index c19d8f341..d8ad1d00d 100644
--- a/cipher/blowfish.c
+++ b/cipher/blowfish.c
@@ -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 )
{
diff --git a/cipher/dynload.c b/cipher/dynload.c
index 955367f1d..09cd1366a 100644
--- a/cipher/dynload.c
+++ b/cipher/dynload.c
@@ -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 )
diff --git a/cipher/md5.c b/cipher/md5.c
index 78bf28832..6e27c7205 100644
--- a/cipher/md5.c
+++ b/cipher/md5.c
@@ -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 );
diff --git a/cipher/primegen.c b/cipher/primegen.c
index 96048a398..f44d89d14 100644
--- a/cipher/primegen.c
+++ b/cipher/primegen.c
@@ -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 )
diff --git a/cipher/rand-internal.h b/cipher/rand-internal.h
index 69f96b3dc..6f5b52bae 100644
--- a/cipher/rand-internal.h
+++ b/cipher/rand-internal.h
@@ -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*/
diff --git a/cipher/random.c b/cipher/random.c
index ffafd9a87..76db0d017 100644
--- a/cipher/random.c
+++ b/cipher/random.c
@@ -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();
diff --git a/cipher/rmd160.c b/cipher/rmd160.c
index 1fd0b98f9..e35647af6 100644
--- a/cipher/rmd160.c
+++ b/cipher/rmd160.c
@@ -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++;
diff --git a/cipher/rndriscos.c b/cipher/rndriscos.c
new file mode 100644
index 000000000..33cad6c0a
--- /dev/null
+++ b/cipher/rndriscos.c
@@ -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
+
diff --git a/cipher/rsa.c b/cipher/rsa.c
index e8d404732..9e6343f4f 100644
--- a/cipher/rsa.c
+++ b/cipher/rsa.c
@@ -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 )
diff --git a/cipher/sha1.c b/cipher/sha1.c
index f5dd59d91..77749e4ee 100644
--- a/cipher/sha1.c
+++ b/cipher/sha1.c
@@ -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++;
diff --git a/cipher/twofish.c b/cipher/twofish.c
index 3cd59da61..175f7c414 100644
--- a/cipher/twofish.c
+++ b/cipher/twofish.c
@@ -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++;