diff -uNr a/mpi/bin/README b/mpi/bin/README --- a/mpi/bin/README false +++ b/mpi/bin/README b130326ce04125d505761664bf84f3b71836fb198bf39cfecdf464d02103b26015149cabb3d4107d59d4ebf6cc94e8e456916766cc095ee4db35605718454d79 @@ -0,0 +1 @@ +bin \ No newline at end of file diff -uNr a/mpi/errors.c b/mpi/errors.c --- a/mpi/errors.c 2637e827d61ac5be58c3cc88799eaf49daed6c957ed6c6647b6d8d787e4f7fd731cdd16db53cb1fa15e35230e918cd62da33b4dd410cc073ca4092bc973f5ad1 +++ b/mpi/errors.c false @@ -1,113 +0,0 @@ -/* errors.c - error strings - * Copyright (C) 1998, 1999, 2000, 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 3 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, see . - */ - -#include -#include -#include -#include - -#include "errors.h" - -#ifndef HAVE_STRERROR -char * -strerror( int n ) -{ - extern char *sys_errlist[]; - extern int sys_nerr; - static char buf[15]; - - if( n >= 0 && n < sys_nerr ) - return sys_errlist[n]; - strcpy( buf, "Unknown error" ); - return buf; -} -#endif /* !HAVE_STRERROR */ - -const char * -g10_errstr( int err ) -{ - static char buf[50]; - const char *p; - -#define X(n,s) case G10ERR_##n : p = s; break; - switch( err ) { - case -1: p = "eof"; break; - case 0: p = "okay"; break; - X(GENERAL, N_("general error")) - X(UNKNOWN_PACKET, N_("unknown packet type")) - X(UNKNOWN_VERSION,N_("unknown version")) - X(PUBKEY_ALGO ,N_("unknown pubkey algorithm")) - X(DIGEST_ALGO ,N_("unknown digest algorithm")) - X(BAD_PUBKEY ,N_("bad public key")) - X(BAD_SECKEY ,N_("bad secret key")) - X(BAD_SIGN ,N_("bad signature")) - X(CHECKSUM , N_("checksum error")) - X(BAD_PASS , N_("bad passphrase")) - X(NO_PUBKEY ,N_("public key not found")) - X(CIPHER_ALGO ,N_("unknown cipher algorithm")) - X(KEYRING_OPEN ,N_("can't open the keyring")) - X(INVALID_PACKET ,N_("invalid packet")) - X(INVALID_ARMOR ,N_("invalid armor")) - X(NO_USER_ID ,N_("no such user id")) - X(NO_SECKEY ,N_("secret key not available")) - X(WRONG_SECKEY ,N_("wrong secret key used")) - X(UNSUPPORTED ,N_("not supported")) - X(BAD_KEY ,N_("bad key")) - X(READ_FILE ,N_("file read error")) - X(WRITE_FILE ,N_("file write error")) - X(COMPR_ALGO ,N_("unknown compress algorithm")) - X(OPEN_FILE ,N_("file open error")) - X(CREATE_FILE ,N_("file create error")) - X(PASSPHRASE ,N_("invalid passphrase")) - X(NI_PUBKEY ,N_("unimplemented pubkey algorithm")) - X(NI_CIPHER ,N_("unimplemented cipher algorithm")) - X(SIG_CLASS ,N_("unknown signature class")) - X(TRUSTDB ,N_("trust database error")) - X(BAD_MPI ,N_("bad MPI")) - X(RESOURCE_LIMIT ,N_("resource limit")) - X(INV_KEYRING ,N_("invalid keyring")) - X(BAD_CERT ,N_("bad certificate")) - X(INV_USER_ID ,N_("malformed user id")) - X(CLOSE_FILE ,N_("file close error")) - X(RENAME_FILE ,N_("file rename error")) - X(DELETE_FILE ,N_("file delete error")) - X(UNEXPECTED ,N_("unexpected data")) - X(TIME_CONFLICT ,N_("timestamp conflict")) - X(WR_PUBKEY_ALGO ,N_("unusable pubkey algorithm")) - X(FILE_EXISTS ,N_("file exists")) - X(WEAK_KEY ,N_("weak key")) - X(INV_ARG ,N_("invalid argument")) - X(BAD_URI ,N_("bad URI")) - X(INVALID_URI ,N_("unsupported URI")) - X(NETWORK ,N_("network error")) - X(SELFTEST_FAILED,"selftest failed") - X(NOT_ENCRYPTED ,N_("not encrypted")) - X(NOT_PROCESSED ,N_("not processed")) - /* the key cannot be used for a specific usage */ - X(UNU_PUBKEY ,N_("unusable public key")) - X(UNU_SECKEY ,N_("unusable secret key")) - X(KEYSERVER ,N_("keyserver error")) - X(CANCELED ,N_("canceled")) - X(NO_CARD ,N_("no card")) - X(NO_DATA ,N_("no data")) - default: p = buf; sprintf(buf, "g10err=%d", err); break; - } -#undef X - return _(p); -} diff -uNr a/mpi/include/compat.h b/mpi/include/compat.h --- a/mpi/include/compat.h cbb804cbf1d96718eebc82abded7fb63514ba10efd2eb136a606d85bd1896dbeaa0d631cd87bf01c8c1e014350f5664309ec9136a0d4c6edf63c039227450926 +++ b/mpi/include/compat.h false @@ -1,25 +0,0 @@ -#ifndef _COMPAT_H_ -#define _COMPAT_H_ - -/* Note this isn't identical to a C locale isspace() without \f and - \v, but works for the purposes used here. */ -#define ascii_isspace(a) ((a)==' ' || (a)=='\n' || (a)=='\r' || (a)=='\t') - -int hextobyte( const char *s ); -int ascii_toupper (int c); -int ascii_tolower (int c); -int ascii_strcasecmp( const char *a, const char *b ); -int ascii_strncasecmp( const char *a, const char *b, size_t n); - -#ifndef HAVE_STRSEP -char *strsep (char **stringp, const char *delim); -#endif - -#if __GNUC__ >= 4 -char *xstrconcat (const char *s1, ...) __attribute__ ((sentinel(0))); -#else -char *xstrconcat (const char *s1, ...); -#endif - - -#endif /* !_COMPAT_H_ */ diff -uNr a/mpi/include/config.h b/mpi/include/config.h --- a/mpi/include/config.h f16ecf4fd4cffb8cb4c97bee3a486e8feaaa6ce8c2d70fdf6ab80687847ae8700b2dc199476459401505048d1642b4d94fd2e4152d911e8b6d54065da09efe66 +++ b/mpi/include/config.h false @@ -1,89 +0,0 @@ -/* config.h. - ORIGINALLY Generated from config.h.in by configure. - Cleaned up by hand. The price of this is that the knobs must - now be turned by hand. -*/ - -#ifndef GNUPG_CONFIG_H_INCLUDED -#define GNUPG_CONFIG_H_INCLUDED - -/* Define to 1 if you have the `atexit' function. */ -#define HAVE_ATEXIT 1 - -/* Defined if the mlock() call does not work */ -/* #undef HAVE_BROKEN_MLOCK */ - -/* Defined if a `byte' is typedef'd */ -/* #undef HAVE_BYTE_TYPEDEF */ - -/* defined if we run on some of the PCDOS like systems (DOS, Windoze. OS/2) - with special properties like no file modes */ -/* #undef HAVE_DOSISH_SYSTEM */ - -/* Define to 1 if fseeko (and presumably ftello) exists and is declared. */ -#define HAVE_FSEEKO 1 - -/* Define to 1 if you have the `getpagesize' function. */ -#define HAVE_GETPAGESIZE 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_INTTYPES_H 1 - -/* Define to 1 if you have the header file. */ -#define HAVE_LIMITS_H 1 - -/* Define to 1 if you have the header file. */ -// #undef HAVE_LOCALE_H - -/* Define to 1 if you have the `memmove' function. */ -#define HAVE_MEMMOVE 1 - -/* Defined if the system supports an mlock() call */ -#define HAVE_MLOCK 1 - -/* Define to 1 if you have the `mmap' function. */ -#define HAVE_MMAP 1 - -/* Define to 1 if you have the `plock' function. */ -/* #undef HAVE_PLOCK */ - -/* Define to 1 if you have the `raise' function. */ -#define HAVE_RAISE 1 - -/* Define to 1 if you have the `stpcpy' function. */ -#define HAVE_STPCPY 1 - -/* Define to 1 if you have the `strcasecmp' function. */ -#define HAVE_STRCASECMP 1 - -/* Define to 1 if you have the `strerror' function. */ -#define HAVE_STRERROR 1 - -/* Define to 1 if you have the `strlwr' function. */ -/* #undef HAVE_STRLWR */ - -/* Define to 1 if you have the `strncasecmp' function. */ -#define HAVE_STRNCASECMP 1 - -/* Define to 1 if you have the `strsep' function. */ -#define HAVE_STRSEP 1 - -/* Define to 1 if you have the `strtoul' function. */ -#define HAVE_STRTOUL 1 - -/* Define to 1 if you have the `sysconf' function. */ -#define HAVE_SYSCONF 1 - -/* Defined if a `u16' is typedef'd */ -/* #undef HAVE_U16_TYPEDEF */ - -/* Defined if a `u32' is typedef'd */ -/* #undef HAVE_U32_TYPEDEF */ - -/* Defined if a `ulong' is typedef'd */ -#define HAVE_ULONG_TYPEDEF 1 - -/* Defined if a `ushort' is typedef'd */ -#define HAVE_USHORT_TYPEDEF 1 - -#endif /*GNUPG_CONFIG_H_INCLUDED*/ diff -uNr a/mpi/include/errors.h b/mpi/include/errors.h --- a/mpi/include/errors.h 6c4fab042db987c280ea86471c8549a167903cb11073d0b74a426dc78ce9e65a1b66fb2815722acb069df807506181548960e60c33ee27c64246672a8457f752 +++ b/mpi/include/errors.h false @@ -1,89 +0,0 @@ -/* errors.h - erro code - * Copyright (C) 1998, 1999, 2000, 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 3 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, see . - */ -#ifndef G10_ERRORS_H -#define G10_ERRORS_H - -#define G10ERR_GENERAL 1 -#define G10ERR_UNKNOWN_PACKET 2 -#define G10ERR_UNKNOWN_VERSION 3 /* Unknown version (in packet) */ -#define G10ERR_PUBKEY_ALGO 4 /* Unknown pubkey algorithm */ -#define G10ERR_DIGEST_ALGO 5 /* Unknown digest algorithm */ -#define G10ERR_BAD_PUBKEY 6 /* Bad public key */ -#define G10ERR_BAD_SECKEY 7 /* Bad secret key */ -#define G10ERR_BAD_SIGN 8 /* Bad signature */ -#define G10ERR_NO_PUBKEY 9 /* public key not found */ -#define G10ERR_CHECKSUM 10 /* checksum error */ -#define G10ERR_BAD_PASS 11 /* Bad passphrase */ -#define G10ERR_CIPHER_ALGO 12 /* Unknown cipher algorithm */ -#define G10ERR_KEYRING_OPEN 13 -#define G10ERR_INVALID_PACKET 14 -#define G10ERR_INVALID_ARMOR 15 -#define G10ERR_NO_USER_ID 16 -#define G10ERR_NO_SECKEY 17 /* secret key not available */ -#define G10ERR_WRONG_SECKEY 18 /* wrong seckey used */ -#define G10ERR_UNSUPPORTED 19 -#define G10ERR_BAD_KEY 20 /* bad (session) key */ -#define G10ERR_READ_FILE 21 -#define G10ERR_WRITE_FILE 22 -#define G10ERR_COMPR_ALGO 23 /* Unknown compress algorithm */ -#define G10ERR_OPEN_FILE 24 -#define G10ERR_CREATE_FILE 25 -#define G10ERR_PASSPHRASE 26 /* invalid passphrase */ -#define G10ERR_NI_PUBKEY 27 -#define G10ERR_NI_CIPHER 28 -#define G10ERR_SIG_CLASS 29 -#define G10ERR_BAD_MPI 30 -#define G10ERR_RESOURCE_LIMIT 31 -#define G10ERR_INV_KEYRING 32 -#define G10ERR_TRUSTDB 33 /* a problem with the trustdb */ -#define G10ERR_BAD_CERT 34 /* bad certicate */ -#define G10ERR_INV_USER_ID 35 -#define G10ERR_CLOSE_FILE 36 -#define G10ERR_RENAME_FILE 37 -#define G10ERR_DELETE_FILE 38 -#define G10ERR_UNEXPECTED 39 -#define G10ERR_TIME_CONFLICT 40 -#define G10ERR_WR_PUBKEY_ALGO 41 /* unusabe pubkey algo */ -#define G10ERR_FILE_EXISTS 42 -#define G10ERR_WEAK_KEY 43 /* NOTE: hardcoded into the cipher modules */ -#define G10ERR_WRONG_KEYLEN 44 /* NOTE: hardcoded into the cipher modules */ -#define G10ERR_INV_ARG 45 -#define G10ERR_BAD_URI 46 /* syntax error in URI */ -#define G10ERR_INVALID_URI 47 /* e.g. unsupported scheme */ -#define G10ERR_NETWORK 48 /* general network error */ -#define G10ERR_UNKNOWN_HOST 49 -#define G10ERR_SELFTEST_FAILED 50 -#define G10ERR_NOT_ENCRYPTED 51 -#define G10ERR_NOT_PROCESSED 52 -#define G10ERR_UNU_PUBKEY 53 -#define G10ERR_UNU_SECKEY 54 -#define G10ERR_KEYSERVER 55 -#define G10ERR_CANCELED 56 -#define G10ERR_NO_CARD 57 -#define G10ERR_NO_DATA 58 - -#ifndef HAVE_STRERROR -char *strerror (int n); -#endif - -#ifdef _WIN32 -const char * w32_strerror (int w32_errno); -#endif - -#endif /*G10_ERRORS_H*/ diff -uNr a/mpi/include/iobuf.h b/mpi/include/iobuf.h --- a/mpi/include/iobuf.h 42269e10b09731558fe6d6e4f8d52f3c3ce10ad1c67496e22f7ec0e19c6d6586f1491921486e90a468905a68d6414d7b7f68914582206ccc2ce2e3ed1e2d3f3d +++ b/mpi/include/iobuf.h false @@ -1,161 +0,0 @@ -/* iobuf.h - I/O buffer - * Copyright (C) 1998, 1999, 2000, 2001, 2004 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 3 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, see . - */ - -#ifndef G10_IOBUF_H -#define G10_IOBUF_H - -#include "types.h" - - -#define DBG_IOBUF iobuf_debug_mode - -#define IOBUFCTRL_INIT 1 -#define IOBUFCTRL_FREE 2 -#define IOBUFCTRL_UNDERFLOW 3 -#define IOBUFCTRL_FLUSH 4 -#define IOBUFCTRL_DESC 5 -#define IOBUFCTRL_CANCEL 6 -#define IOBUFCTRL_USER 16 - -typedef struct iobuf_struct *IOBUF; -typedef struct iobuf_struct *iobuf_t; - -/* fixme: we should hide most of this stuff */ -struct iobuf_struct { - int use; /* 1 input , 2 output, 3 temp */ - off_t nlimit; - off_t nbytes; /* used together with nlimit */ - off_t ntotal; /* total bytes read (position of stream) */ - int nofast; /* used by the iobuf_get() */ - void *directfp; - struct { - size_t size; /* allocated size */ - size_t start; /* number of invalid bytes at the begin of the buffer */ - size_t len; /* currently filled to this size */ - byte *buf; - } d; - int filter_eof; - int error; - int (*filter)( void *opaque, int control, - IOBUF chain, byte *buf, size_t *len); - void *filter_ov; /* value for opaque */ - int filter_ov_owner; - char *real_fname; - IOBUF chain; /* next iobuf used for i/o if any (passed to filter) */ - int no, subno; - const char *desc; - void *opaque; /* can be used to hold any information */ - /* this value is copied to all instances */ - struct { - size_t size; /* allocated size */ - size_t start; /* number of invalid bytes at the begin of the buffer */ - size_t len; /* currently filled to this size */ - byte *buf; - } unget; -}; - -#ifndef EXTERN_UNLESS_MAIN_MODULE -#if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE) -#define EXTERN_UNLESS_MAIN_MODULE extern -#else -#define EXTERN_UNLESS_MAIN_MODULE -#endif -#endif -EXTERN_UNLESS_MAIN_MODULE int iobuf_debug_mode; - -void iobuf_enable_special_filenames ( int yes ); -int iobuf_is_pipe_filename (const char *fname); -IOBUF iobuf_alloc(int use, size_t bufsize); -IOBUF iobuf_temp(void); -IOBUF iobuf_temp_with_content( const char *buffer, size_t length ); -IOBUF iobuf_open( const char *fname ); -IOBUF iobuf_fdopen( int fd, const char *mode ); -IOBUF iobuf_sockopen( int fd, const char *mode ); -IOBUF iobuf_create( const char *fname ); -IOBUF iobuf_append( const char *fname ); -IOBUF iobuf_openrw( const char *fname ); -int iobuf_ioctl ( IOBUF a, int cmd, int intval, void *ptrval ); -int iobuf_close( IOBUF iobuf ); -int iobuf_cancel( IOBUF iobuf ); - -int iobuf_push_filter( IOBUF a, int (*f)(void *opaque, int control, - IOBUF chain, byte *buf, size_t *len), void *ov ); -int iobuf_push_filter2( IOBUF a, - int (*f)(void *opaque, int control, - IOBUF chain, byte *buf, size_t *len), - void *ov, int rel_ov ); -int iobuf_flush(IOBUF a); -void iobuf_clear_eof(IOBUF a); -#define iobuf_set_error(a) do { (a)->error = 1; } while(0) -#define iobuf_error(a) ((a)->error) - -void iobuf_set_limit( IOBUF a, off_t nlimit ); - -off_t iobuf_tell( IOBUF a ); -int iobuf_seek( IOBUF a, off_t newpos ); - -int iobuf_readbyte(IOBUF a); -int iobuf_read(IOBUF a, byte *buf, unsigned buflen ); -unsigned iobuf_read_line( IOBUF a, byte **addr_of_buffer, - unsigned *length_of_buffer, unsigned *max_length ); -int iobuf_peek(IOBUF a, byte *buf, unsigned buflen ); -int iobuf_writebyte(IOBUF a, unsigned c); -int iobuf_write(IOBUF a, byte *buf, unsigned buflen ); -int iobuf_writestr(IOBUF a, const char *buf ); - -void iobuf_flush_temp( IOBUF temp ); -int iobuf_write_temp( IOBUF a, IOBUF temp ); -size_t iobuf_temp_to_buffer( IOBUF a, byte *buffer, size_t buflen ); -void iobuf_unget_and_close_temp( IOBUF a, IOBUF temp ); - -int iobuf_get_fd (IOBUF a); -off_t iobuf_get_filelength (IOBUF a, int *overflow); -#define IOBUF_FILELENGTH_LIMIT 0xffffffff -const char *iobuf_get_real_fname( IOBUF a ); -const char *iobuf_get_fname( IOBUF a ); - -void iobuf_set_partial_block_mode( IOBUF a, size_t len ); - -int iobuf_translate_file_handle ( int fd, int for_write ); - -/* Get a byte form the iobuf; must check for eof prior to this function. - * This function returns values in the range 0 .. 255 or -1 to indicate EOF - * iobuf_get_noeof() does not return -1 to indicate EOF, but masks the - * returned value to be in the range 0..255. - */ -#define iobuf_get(a) \ - ( ((a)->nofast || (a)->d.start >= (a)->d.len )? \ - iobuf_readbyte((a)) : ( (a)->nbytes++, (a)->d.buf[(a)->d.start++] ) ) -#define iobuf_get_noeof(a) (iobuf_get((a))&0xff) - -/* write a byte to the iobuf and return true on write error - * This macro does only write the low order byte - */ -#define iobuf_put(a,c) iobuf_writebyte(a,c) - -#define iobuf_where(a) "[don't know]" -#define iobuf_id(a) ((a)->no) - -#define iobuf_get_temp_buffer(a) ( (a)->d.buf ) -#define iobuf_get_temp_length(a) ( (a)->d.len ) -#define iobuf_is_temp(a) ( (a)->use == 3 ) - -void iobuf_skip_rest (IOBUF a, unsigned long n, int partial); - -#endif /*G10_IOBUF_H*/ diff -uNr a/mpi/include/knobs.h b/mpi/include/knobs.h --- a/mpi/include/knobs.h false +++ b/mpi/include/knobs.h a441a78465e16d369e66f080d444bc97ef7c0e0d9208e88565d8646a1b31bacac8b39411c4092c2fc56bd07cdf8fd686940f18424bf1928c9220b68b46840330 @@ -0,0 +1,75 @@ +/* knobs.h -- Originally generated from config.h.in by autoconf. + * But there is no more autoconf in this project. + * + * No Such Labs. (C) 2015. See README. + * + * This program 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 3 of the License, or + * (at your option) any later version. + * + * This program 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, see . +*/ + +#ifndef GNUPG_CONFIG_H_INCLUDED +#define GNUPG_CONFIG_H_INCLUDED + +/* Report memory usage. */ +//#define M_DEBUG 1 + +/* Define to 1 if you have the `atexit' function. */ +#define HAVE_ATEXIT 1 + +/* Defined if the mlock() call does not work */ +/* #undef HAVE_BROKEN_MLOCK */ + +/* Defined if a `byte' is typedef'd */ +/* #undef HAVE_BYTE_TYPEDEF */ + +/* defined if we run on some of the PCDOS like systems (DOS, Windoze. OS/2) + with special properties like no file modes */ +/* #undef HAVE_DOSISH_SYSTEM */ + +/* Define to 1 if you have the `getpagesize' function. */ +#define HAVE_GETPAGESIZE 1 + +/* Define to 1 if you have the header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define to 1 if you have the `memmove' function. */ +#define HAVE_MEMMOVE 1 + +/* Defined if the system supports an mlock() call */ +#define HAVE_MLOCK 1 + +/* Define to 1 if you have the `mmap' function. */ +#define HAVE_MMAP 1 + +/* Define to 1 if you have the `plock' function. */ +/* #undef HAVE_PLOCK */ + +/* Define to 1 if you have the `raise' function. */ +#define HAVE_RAISE 1 + +/* Define to 1 if you have the `sysconf' function. */ +#define HAVE_SYSCONF 1 + +/* Defined if a `u16' is typedef'd */ +/* #undef HAVE_U16_TYPEDEF */ + +/* Defined if a `u32' is typedef'd */ +/* #undef HAVE_U32_TYPEDEF */ + +/* Defined if a `ulong' is typedef'd */ +#define HAVE_ULONG_TYPEDEF 1 + +/* Defined if a `ushort' is typedef'd */ +#define HAVE_USHORT_TYPEDEF 1 + +#endif /*GNUPG_CONFIG_H_INCLUDED*/ diff -uNr a/mpi/include/longlong.h b/mpi/include/longlong.h --- a/mpi/include/longlong.h 042ba62021e6a33fa5f28447d8d268d4fd9a66d49bd10b904aa5f5c9fb6a30345f5cfea787fba1145b328f56e77c39e4d7c3d6df94ccd4b7696b9fe2c8aa7055 +++ b/mpi/include/longlong.h a4a9188becde0bef5a0f54061c6758b618a85ce7c483af33f5d7655eb1ce7165a8ffc185bf37ae4d3781deab518db3d4fe946692406de0bd73212331ef400f27 @@ -1,22 +1,24 @@ /* longlong.h -- definitions for mixed size 32/64 bit arithmetic. - Note: I added some stuff for use with gnupg - -Copyright (C) 1991, 1992, 1993, 1994, 1996, 1998, - 2000, 2001, 2002, 2003 Free Software Foundation, Inc. - -This file is free software; you can redistribute it and/or modify -it under the terms of the GNU Lesser General Public License as published by -the Free Software Foundation; either version 2.1 of the License, or (at your -option) any later version. - -This file 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 Lesser General Public -License for more details. - -You should have received a copy of the GNU Lesser General Public License -along with this file; if not, see . */ - + * Modified by No Such Labs. (C) 2015. See README. + * + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. + * + * This program 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 3 of the License, or + * (at your option) any later version. + * + * This program 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, see . +*/ /* You have to define the following before including this file: diff -uNr a/mpi/include/memory.h b/mpi/include/memory.h --- a/mpi/include/memory.h b48416427e71fe46868283490813e4d0a22da9f4b17eff706673a9b05380ae2d85ec9b183db47eaa8aa197b7c7629eb873e63e5f8a66208bf230a794b6967fab +++ b/mpi/include/memory.h 6580645f16fea9a37eff8460584fca09f39b1ec9ba88e00aa0207c75267f7190810cf45f2733c9960aaec0daaac7fe74785f38287aa61cb4cd5d4f50ea1158c9 @@ -1,34 +1,36 @@ /* memory.h - memory allocation - * Copyright (C) 1998, 1999, 2000, 2001, 2005 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GNUPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GNUPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GNUPG is distributed in the hope that it will be useful, + * This program 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, see . + * along with this program. If not, see . */ #ifndef G10_MEMORY_H #define G10_MEMORY_H #ifdef M_DEBUG + #ifndef STR #define STR(v) #v #endif -#ifndef __riscos__ + #define M_DBGINFO(a) __FUNCTION__ "["__FILE__ ":" STR(a) "]" -#else /* __riscos__ */ -#define M_DBGINFO(a) "["__FILE__ ":" STR(a) "]" -#endif /* __riscos__ */ + #define xmalloc(n) m_debug_alloc((n), M_DBGINFO( __LINE__ ) ) #define xtrymalloc(n) m_debug_trymalloc ((n), M_DBGINFO( __LINE__ )) #define xmalloc_clear(n) m_debug_alloc_clear((n), M_DBGINFO(__LINE__) ) @@ -91,12 +93,8 @@ #define DBG_MEMSTAT memory_stat_debug_mode #ifndef EXTERN_UNLESS_MAIN_MODULE -#if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE) -#define EXTERN_UNLESS_MAIN_MODULE extern -#else #define EXTERN_UNLESS_MAIN_MODULE #endif -#endif EXTERN_UNLESS_MAIN_MODULE int memory_debug_mode; EXTERN_UNLESS_MAIN_MODULE int memory_stat_debug_mode; diff -uNr a/mpi/include/mpi-asm-defs.h b/mpi/include/mpi-asm-defs.h --- a/mpi/include/mpi-asm-defs.h fb2afc7686790fa12e3143e79c4728dac3e43c4056c647650d216b7ec7350f7651f6c44c4393858e8bab02719b7674ad7f29e1fcb10511de0a5ae4a2c12af5a6 +++ b/mpi/include/mpi-asm-defs.h false @@ -1,10 +0,0 @@ -/* This file defines some basic constants for the MPI machinery. We - * need to define the types on a per-CPU basis, so it is done with - * this file here. */ -#define BYTES_PER_MPI_LIMB (SIZEOF_UNSIGNED_LONG) - - - - - - diff -uNr a/mpi/include/mpi.h b/mpi/include/mpi.h --- a/mpi/include/mpi.h e539ef777487b66317cd23b7d19f883a9bab67a9cb984dfb5d1a5df4575a66cb44b7ec199ac0829b1270edfa68f182d646ce944c14f5c401654e1e0f68271baf +++ b/mpi/include/mpi.h 0bc1be9f757231b114821a55b106387358b919237dcedc3c4f23c0df61f7acd00656cefba6a48313304fcfbce2abf528ec2fba998c0f67784de486d00b8f6cc2 @@ -1,47 +1,36 @@ /* mpi.h - Multi Precision Integers - * Copyright (C) 1994, 1996, 1998, 1999, - * 2000, 2001 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GNUPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GNUPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GNUPG is distributed in the hope that it will be useful, + * This program 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, see . - * - * Note: This code is heavily based on the GNU MP Library. - * Actually it's the same code with only minor changes in the - * way the data is stored; this is to support the abstraction - * of an optional secure memory allocation which may be used - * to avoid revealing of sensitive data due to paging etc. - * The GNU MP Library itself is published under the LGPL; - * however I decided to publish this code under the plain GPL. + * along with this program. If not, see . */ #ifndef G10_MPI_H #define G10_MPI_H -#include #include -#include "iobuf.h" +#include "knobs.h" #include "types.h" #include "memory.h" #ifndef EXTERN_UNLESS_MAIN_MODULE -#if defined (__riscos__) && !defined (INCLUDED_BY_MAIN_MODULE) -#define EXTERN_UNLESS_MAIN_MODULE extern -#else #define EXTERN_UNLESS_MAIN_MODULE #endif -#endif #define DBG_MPI mpi_debug_mode EXTERN_UNLESS_MAIN_MODULE int mpi_debug_mode; @@ -92,18 +81,10 @@ unsigned int mpi_get_flags (MPI a); /*-- mpicoder.c --*/ -int mpi_write( IOBUF out, MPI a ); -#ifdef M_DEBUG -#define mpi_read(a,b,c) mpi_debug_read((a),(b),(c), M_DBGINFO( __LINE__ ) ) -MPI mpi_debug_read(IOBUF inp, unsigned *nread, int secure, const char *info); -#else -MPI mpi_read(IOBUF inp, unsigned *nread, int secure); -#endif MPI mpi_read_from_buffer(byte *buffer, unsigned *ret_nread, int secure); int mpi_fromstr(MPI val, const char *str); int mpi_print( FILE *fp, MPI a, int mode ); -void g10_log_mpidump( const char *text, MPI a ); -u32 mpi_get_keyid( MPI a, u32 *keyid ); +//void g10_log_mpidump( const char *text, MPI a ); byte *mpi_get_buffer( MPI a, unsigned *nbytes, int *sign ); byte *mpi_get_secure_buffer( MPI a, unsigned *nbytes, int *sign ); void mpi_set_buffer( MPI a, const byte *buffer, unsigned nbytes, int sign ); diff -uNr a/mpi/include/mpi-inline.h b/mpi/include/mpi-inline.h --- a/mpi/include/mpi-inline.h df6064b02a11c90fb20945dad1ecc4753a231f894d6cf60e133d6196d924442e0fa08c1d38421a97511f4007a9545c6a980960a20817e6eaecf4ce36e920f151 +++ b/mpi/include/mpi-inline.h f1a5f8ee7289d1aa4526a7ae2cabe769ee43fa525ae47658a12d6856b51174d174c96cd1e93be6836bb29f53725be73649a0af667cdd4e71a08431b984bda8c4 @@ -1,28 +1,23 @@ /* mpi-inline.h - Internal to the Multi Precision Integers - * Copyright (C) 1994, 1996, 1998, 1999 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . - * - * Note: This code is heavily based on the GNU MP Library. - * Actually it's the same code with only minor changes in the - * way the data is stored; this is to support the abstraction - * of an optional secure memory allocation which may be used - * to avoid revealing of sensitive data due to paging etc. - * The GNU MP Library itself is published under the LGPL; - * however I decided to publish this code under the plain GPL. + * along with this program. If not, see . */ #ifndef G10_MPI_INLINE_H diff -uNr a/mpi/include/mpi-internal.h b/mpi/include/mpi-internal.h --- a/mpi/include/mpi-internal.h 98c4253d69c7531f96dc7631d3d26c5733d5104a3ddbd9eafd622f8aacd8619e71abb55d0c951b148e9d33887dab0edf2cbd9c9b38ca908bc8e04ed930943fde +++ b/mpi/include/mpi-internal.h d1b3eaed32dc555d5f779ede28a995d2ac6bf3a5bf87362955675b11bad91a928fbf62b7fc7fca5ef1a2c8d33409978ef73d5d879564ed3829c5fc6dacd6cdfd @@ -1,36 +1,32 @@ /* mpi-internal.h - Internal to the Multi Precision Integers - * Copyright (C) 1994, 1996 Free Software Foundation, Inc. - * Copyright (C) 1998, 2000 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . - * - * Note: This code is heavily based on the GNU MP Library. - * Actually it's the same code with only minor changes in the - * way the data is stored; this is to support the abstraction - * of an optional secure memory allocation which may be used - * to avoid revealing of sensitive data due to paging etc. - * The GNU MP Library itself is published under the LGPL; - * however I decided to publish this code under the plain GPL. + * along with this program. If not, see . */ #ifndef G10_MPI_INTERNAL_H #define G10_MPI_INTERNAL_H #include "mpi.h" -#include "mpi-asm-defs.h" + +/* from the old mpi-asm-defs.h */ +#define BYTES_PER_MPI_LIMB (SIZEOF_UNSIGNED_LONG) #if BYTES_PER_MPI_LIMB == SIZEOF_UNSIGNED_INT typedef unsigned int mpi_limb_t; diff -uNr a/mpi/include/ttyio.h b/mpi/include/ttyio.h --- a/mpi/include/ttyio.h 85d1de1e79681b0cece4caea7ca324374fb41317c449585e8cd4d23fae4ef10923285545645fac2921d3c53a0c897e33da32d895b9bd0b761f696d0d8e036479 +++ b/mpi/include/ttyio.h false @@ -1,58 +0,0 @@ -/* ttyio.h - * Copyright (C) 1998, 1999, 2000, 2001, 2005 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 3 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, see . - */ -#ifndef G10_TTYIO_H -#define G10_TTYIO_H - -#ifdef HAVE_LIBREADLINE -#include -#include -#endif - -const char *tty_get_ttyname (void); -int tty_batchmode( int onoff ); -#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 ) - void tty_printf (const char *fmt, ... ) __attribute__ ((format (printf,1,2))); - void tty_fprintf (FILE *fp, const char *fmt, ... ) - __attribute__ ((format (printf,2,3))); -#else - void tty_printf (const char *fmt, ... ); - void tty_fprintf (FILE *fp, const char *fmt, ... ); -#endif -void tty_print_string( const byte *p, size_t n ); -void tty_print_utf8_string( const byte *p, size_t n ); -void tty_print_utf8_string2( const byte *p, size_t n, size_t max_n ); -char *tty_get( const char *prompt ); -char *tty_get_hidden( const char *prompt ); -void tty_kill_prompt(void); -int tty_get_answer_is_yes( const char *prompt ); -int tty_no_terminal(int onoff); - -#ifdef HAVE_LIBREADLINE -void tty_enable_completion(rl_completion_func_t *completer); -void tty_disable_completion(void); -#else -/* Use a macro to stub out these functions since a macro has no need - to typedef a "rl_completion_func_t" which would be undefined - without readline. */ -#define tty_enable_completion(x) -#define tty_disable_completion() -#endif -void tty_cleanup_after_signal (void); - -#endif /*G10_TTYIO_H*/ diff -uNr a/mpi/include/types.h b/mpi/include/types.h --- a/mpi/include/types.h d355f8bb711647e95451cf2d53f8c496013d9c797acc81560fae155c5850823c880d647347426a4562da568a6cde708fdccbd1e881568816156c0801c7e47fd7 +++ b/mpi/include/types.h 7080ab52c460bb847f724212473d3f0b93aa44175577e977e937bc2246e11be0b0ba2439b9e1053a1c898b606617717260d61937d7ba70b034b77ced2149ea83 @@ -1,20 +1,23 @@ /* types.h - some common typedefs - * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GNUPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GNUPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GNUPG is distributed in the hope that it will be useful, + * This program 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, see . + * along with this program. If not, see . */ #ifndef G10_TYPES_H @@ -46,14 +49,7 @@ #ifndef HAVE_BYTE_TYPEDEF #undef byte /* maybe there is a macro with this name */ -#ifndef __riscos__ typedef unsigned char byte; -#else -/* Norcroft treats char = unsigned char as legal assignment - but char* = unsigned char* as illegal assignment - and the same applies to the signed variants as well */ -typedef char byte; -#endif #define HAVE_BYTE_TYPEDEF #endif diff -uNr a/mpi/include/util.h b/mpi/include/util.h --- a/mpi/include/util.h 5b4adedb0dda25d37413fd81037ef2d94722cee3b58b5a5314da3816308540588319a280819e272845d154b6f2fdbdcece3a73c15b2802f33bc6bfe484f0b4a5 +++ b/mpi/include/util.h 60f97fc937b6974e1ad4aa0d6728491d71127244d9ff43369612222359802a7816f57fe6060354582782a04ce62b6568babac0a0bf886fd6d8cbe3a17f540bca @@ -1,22 +1,25 @@ /* util.h - * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, - * 2006 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GNUPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GNUPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GNUPG is distributed in the hope that it will be useful, + * This program 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, see . + * along with this program. If not, see . */ + #ifndef G10_UTIL_H #define G10_UTIL_H @@ -25,244 +28,25 @@ #endif #include "types.h" -#include "errors.h" #include "types.h" #include "mpi.h" -#include "compat.h" -typedef struct { - int *argc; /* pointer to argc (value subject to change) */ - char ***argv; /* pointer to argv (value subject to change) */ - unsigned flags; /* Global flags (DO NOT CHANGE) */ - int err; /* print error about last option */ - /* 1 = warning, 2 = abort */ - int r_opt; /* return option */ - int r_type; /* type of return value (0 = no argument found)*/ - union { - int ret_int; - long ret_long; - ulong ret_ulong; - char *ret_str; - } r; /* Return values */ - struct { - int idx; - int inarg; - int stopped; - const char *last; - void *aliases; - const void *cur_alias; - } internal; /* DO NOT CHANGE */ -} ARGPARSE_ARGS; - -typedef struct { - int short_opt; - const char *long_opt; - unsigned flags; - const char *description; /* optional option description */ -} ARGPARSE_OPTS; - -/*-- logger.c --*/ -void log_set_logfile( const char *name, int fd ); -FILE *log_stream(void); -void g10_log_print_prefix(const char *text); -void log_set_name( const char *name ); -const char *log_get_name(void); -void log_set_pid( int pid ); -int log_get_errorcount( int clear ); -void log_inc_errorcount(void); -int log_set_strict(int val); -void g10_log_hexdump( const char *text, const char *buf, size_t len ); - -#if defined (__riscos__) \ - || (__GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )) - void g10_log_bug( const char *fmt, ... ) - __attribute__ ((noreturn, format (printf,1,2))); - void g10_log_bug0( const char *, int, const char * ) __attribute__ ((noreturn)); - void g10_log_fatal( const char *fmt, ... ) - __attribute__ ((noreturn, format (printf,1,2))); - void g10_log_error( const char *fmt, ... ) __attribute__ ((format (printf,1,2))); - void g10_log_info( const char *fmt, ... ) __attribute__ ((format (printf,1,2))); - void g10_log_warning( const char *fmt, ... ) __attribute__ ((format (printf,1,2))); - void g10_log_debug( const char *fmt, ... ) __attribute__ ((format (printf,1,2))); -#ifndef __riscos__ -#define BUG() g10_log_bug0( __FILE__ , __LINE__, __FUNCTION__ ) -#else -#define BUG() g10_log_bug0( __FILE__ , __LINE__, __func__ ) -#endif -#else - void g10_log_bug( const char *fmt, ... ); - void g10_log_bug0( const char *, int ); - void g10_log_fatal( const char *fmt, ... ); - void g10_log_error( const char *fmt, ... ); - void g10_log_info( const char *fmt, ... ); - void g10_log_warning( const char *fmt, ... ); - void g10_log_debug( const char *fmt, ... ); -#define BUG() g10_log_bug0( __FILE__ , __LINE__ ) -#endif +#define log_hexdump printf +#define log_bug printf +#define log_bug0 printf +#define log_fatal printf +#define log_error printf +#define log_info printf +#define log_warning printf +#define log_debug printf + +#define g10_log_print_prefix printf -#define log_hexdump g10_log_hexdump -#define log_bug g10_log_bug -#define log_bug0 g10_log_bug0 -#define log_fatal g10_log_fatal -#define log_error g10_log_error -#define log_info g10_log_info -#define log_warning g10_log_warning -#define log_debug g10_log_debug - - -/*-- errors.c --*/ -const char * g10_errstr( int no ); - -/*-- argparse.c --*/ -int arg_parse( ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts); -int optfile_parse( FILE *fp, const char *filename, unsigned *lineno, - ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts); -void usage( int level ); -const char *default_strusage( int level ); - - -/*-- (main program) --*/ -const char *strusage( int level ); - - -/*-- dotlock.c --*/ -struct dotlock_handle; -typedef struct dotlock_handle *DOTLOCK; - -void disable_dotlock(void); -DOTLOCK create_dotlock( const char *file_to_lock ); -void destroy_dotlock ( DOTLOCK h ); -int make_dotlock( DOTLOCK h, long timeout ); -int release_dotlock( DOTLOCK h ); -void remove_lockfiles (void); - -/*-- fileutil.c --*/ -char * make_basename(const char *filepath, const char *inputpath); -char * make_dirname(const char *filepath); -char *make_filename( const char *first_part, ... ); -int compare_filenames( const char *a, const char *b ); -int same_file_p (const char *name1, const char *name2); -const char *print_fname_stdin( const char *s ); -const char *print_fname_stdout( const char *s ); -int is_file_compressed(const char *s, int *r_status); - -/*-- miscutil.c --*/ -u32 make_timestamp(void); -u32 scan_isodatestr( const char *string ); -u32 isotime2seconds (const char *string); -const char *strtimevalue( u32 stamp ); -const char *strtimestamp( u32 stamp ); /* GMT */ -const char *isotimestamp( u32 stamp ); /* GMT with hh:mm:ss */ -const char *asctimestamp( u32 stamp ); /* localized */ -void print_string( FILE *fp, const byte *p, size_t n, int delim ); -void print_string2( FILE *fp, const byte *p, size_t n, int delim, int delim2 ); -void print_utf8_string( FILE *fp, const byte *p, size_t n ); -void print_utf8_string2( FILE *fp, const byte *p, size_t n, int delim); -char *make_printable_string( const byte *p, size_t n, int delim ); -int answer_is_yes_no_default( const char *s, int def_answer ); -int answer_is_yes( const char *s ); -int answer_is_yes_no_quit( const char *s ); -int answer_is_okay_cancel (const char *s, int def_answer); -int match_multistr(const char *multistr,const char *match); - -/*-- strgutil.c --*/ -void free_strlist( STRLIST sl ); -#define FREE_STRLIST(a) do { free_strlist((a)); (a) = NULL ; } while(0) -STRLIST add_to_strlist( STRLIST *list, const char *string ); -STRLIST add_to_strlist2( STRLIST *list, const char *string, int is_utf8 ); -STRLIST append_to_strlist( STRLIST *list, const char *string ); -STRLIST append_to_strlist2( STRLIST *list, const char *string, int is_utf8 ); -STRLIST strlist_prev( STRLIST head, STRLIST node ); -STRLIST strlist_last( STRLIST node ); -char *pop_strlist( STRLIST *list ); -const char *memistr( const char *buf, size_t buflen, const char *sub ); -const char *ascii_memistr( const char *buf, size_t buflen, const char *sub ); -char *mem2str( char *, const void *, size_t); -char *trim_spaces( char *string ); -unsigned int trim_trailing_chars( byte *line, unsigned int len, - const char *trimchars); -unsigned int trim_trailing_ws( byte *line, unsigned len ); -unsigned int check_trailing_chars( const byte *line, unsigned int len, - const char *trimchars ); -unsigned int check_trailing_ws( const byte *line, unsigned int len ); -int string_count_chr( const char *string, int c ); -int set_native_charset( const char *newset ); -const char* get_native_charset(void); -char *native_to_utf8( const char *string ); -char *utf8_to_native( const char *string, size_t length, int delim); -char *string_to_utf8 (const char *string); - -int ascii_isupper (int c); -int ascii_islower (int c); -int ascii_memcasecmp( const char *a, const char *b, size_t n); -#ifndef HAVE_STPCPY -char *stpcpy(char *a,const char *b); -#endif -#ifndef HAVE_STRLWR -char *strlwr(char *a); -#endif -#ifndef HAVE_STRCASECMP -int strcasecmp( const char *, const char *b); -#endif -#ifndef HAVE_STRNCASECMP -int strncasecmp (const char *, const char *b, size_t n); -#endif -#ifndef HAVE_STRTOUL -#define strtoul(a,b,c) ((unsigned long)strtol((a),(b),(c))) -#endif #ifndef HAVE_MEMMOVE #define memmove(d, s, n) bcopy((s), (d), (n)) #endif -/*-- membuf.c --*/ -/* The definition of the structure is private, we only need it here, - so it can be allocated on the stack. */ -struct private_membuf_s { - size_t len; - size_t size; - char *buf; - int out_of_core; -}; - -typedef struct private_membuf_s membuf_t; - -void init_membuf (membuf_t *mb, int initiallen); -void put_membuf (membuf_t *mb, const void *buf, size_t len); -void *get_membuf (membuf_t *mb, size_t *len); - - - -#if defined (_WIN32) -/*-- w32reg.c --*/ -char *read_w32_registry_string( const char *root, - const char *dir, const char *name ); -int write_w32_registry_string(const char *root, const char *dir, - const char *name, const char *value); - -#endif /*_WIN32*/ - -/*-- strgutil.c --*/ -char *xasprintf (const char *fmt, ...); -char *xtryasprintf (const char *fmt, ...); - - -/*-- pka.c --*/ -char *get_pka_info (const char *address, unsigned char *fpr); - -/*-- cert.c --*/ -int get_cert(const char *name,size_t max_size,IOBUF *iobuf, - unsigned char **fpr,size_t *fpr_len,char **url); - -/*-- convert.c --*/ -int hex2bin (const char *string, void *buffer, size_t length); -int hexcolon2bin (const char *string, void *buffer, size_t length); -char *bin2hex (const void *buffer, size_t length, char *stringbuf); -char *bin2hexcolon (const void *buffer, size_t length, char *stringbuf); -const char *hex2str (const char *hexstring, - char *buffer, size_t bufsize, size_t *buflen); -char *hex2str_alloc (const char *hexstring, size_t *r_count); - /**** other missing stuff ****/ #ifndef HAVE_ATEXIT /* For SunOS */ @@ -273,10 +57,6 @@ #define raise(a) kill(getpid(), (a)) #endif -/*-- Replacement functions from funcname.c --*/ - - - /******** some macros ************/ #ifndef STR #define STR(v) #v @@ -302,33 +82,5 @@ *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10)) #define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1)) -/******* RISC OS stuff ***********/ -#ifdef __riscos__ -int riscos_load_module(const char *name, const char * const path[], int fatal); -int riscos_get_filetype_from_string(const char *string, int len); -int riscos_get_filetype(const char *filename); -void riscos_set_filetype_by_number(const char *filename, int type); -void riscos_set_filetype_by_mimetype(const char *filename, const char *mimetype); -pid_t riscos_getpid(void); -int riscos_kill(pid_t pid, int sig); -int riscos_access(const char *path, int amode); -int riscos_getchar(void); -char *riscos_make_basename(const char *filepath, const char *inputpath); -int riscos_check_regexp(const char *exp, const char *string, int debug); -int riscos_fdopenfile(const char *filename, const int allow_write); -void riscos_close_fds(void); -int riscos_renamefile(const char *old, const char *new); -char *riscos_gstrans(const char *old); -void riscos_not_implemented(const char *feature); -#ifdef DEBUG -void riscos_dump_fdlist(void); -void riscos_list_openfiles(void); -#endif -#ifndef __RISCOS__C__ -#define getpid riscos_getpid -#define kill(a,b) riscos_kill((a),(b)) -#define access(a,b) riscos_access((a),(b)) -#endif /* !__RISCOS__C__ */ -#endif /* __riscos__ */ #endif /*G10_UTIL_H*/ diff -uNr a/mpi/iobuf.c b/mpi/iobuf.c --- a/mpi/iobuf.c c5dddd9d52900ba3d847422f9dba2799be2954ad9cca3b9aa6fb1654dd89ee00575c52d15bd65e98d3054d4646943372ca8ad591f610ea7761d21fe4c3ae6187 +++ b/mpi/iobuf.c false @@ -1,2326 +0,0 @@ -/* iobuf.c - file handling - * Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2008, - * 2009 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 3 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, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef HAVE_DOSISH_SYSTEM -#include -#endif -#ifdef __riscos__ -#include -#include -#endif /* __riscos__ */ - -#include "memory.h" -#include "util.h" -#include "iobuf.h" - -/* The size of the internal buffers. - NOTE: If you change this value you MUST also adjust the regression - test "armored_key_8192" in armor.test! */ -#define IOBUF_BUFFER_SIZE 8192 - - -#undef FILE_FILTER_USES_STDIO - -#ifdef HAVE_DOSISH_SYSTEM -#define USE_SETMODE 1 -#endif - -#ifdef FILE_FILTER_USES_STDIO -#define my_fileno(a) fileno ((a)) -#define my_fopen_ro(a,b) fopen ((a),(b)) -#define my_fopen(a,b) fopen ((a),(b)) -typedef FILE *FILEP_OR_FD; -#define INVALID_FP NULL -#define FILEP_OR_FD_FOR_STDIN (stdin) -#define FILEP_OR_FD_FOR_STDOUT (stdout) -typedef struct { - FILE *fp; /* open file handle */ - int keep_open; - int no_cache; - int print_only_name; /* flags indicating that fname is not a real file*/ - char fname[1]; /* name of the file */ - } file_filter_ctx_t ; -#else -#define my_fileno(a) (a) -#define my_fopen_ro(a,b) fd_cache_open ((a),(b)) -#define my_fopen(a,b) direct_open ((a),(b)) -#ifdef HAVE_DOSISH_SYSTEM -typedef HANDLE FILEP_OR_FD; -#define INVALID_FP ((HANDLE)-1) -#define FILEP_OR_FD_FOR_STDIN (GetStdHandle (STD_INPUT_HANDLE)) -#define FILEP_OR_FD_FOR_STDOUT (GetStdHandle (STD_OUTPUT_HANDLE)) -#undef USE_SETMODE -#else -typedef int FILEP_OR_FD; -#define INVALID_FP (-1) -#define FILEP_OR_FD_FOR_STDIN (0) -#define FILEP_OR_FD_FOR_STDOUT (1) -#endif -typedef struct { - FILEP_OR_FD fp; /* open file handle */ - int keep_open; - int no_cache; - int eof_seen; - int print_only_name; /* flags indicating that fname is not a real file*/ - char fname[1]; /* name of the file */ - } file_filter_ctx_t ; - - struct close_cache_s { - struct close_cache_s *next; - FILEP_OR_FD fp; - char fname[1]; - }; - typedef struct close_cache_s *CLOSE_CACHE; - static CLOSE_CACHE close_cache; -#endif - -#ifdef _WIN32 -typedef struct { - int sock; - int keep_open; - int no_cache; - int eof_seen; - int print_only_name; /* flags indicating that fname is not a real file*/ - char fname[1]; /* name of the file */ -} sock_filter_ctx_t ; -#endif /*_WIN32*/ - -/* The first partial length header block must be of size 512 - * to make it easier (and efficienter) we use a min. block size of 512 - * for all chunks (but the last one) */ -#define OP_MIN_PARTIAL_CHUNK 512 -#define OP_MIN_PARTIAL_CHUNK_2POW 9 - -typedef struct { - int use; - size_t size; - size_t count; - int partial; /* 1 = partial header, 2 in last partial packet */ - char *buffer; /* used for partial header */ - size_t buflen; /* used size of buffer */ - int first_c; /* of partial header (which is > 0)*/ - int eof; -} block_filter_ctx_t; - -static int special_names_enabled; - -static int underflow(IOBUF a); -static int translate_file_handle ( int fd, int for_write ); - - - -#ifndef FILE_FILTER_USES_STDIO - -/* This is a replacement for strcmp. Under W32 it does not - distinguish between backslash and slash. */ -static int -fd_cache_strcmp (const char *a, const char *b) -{ -#ifdef HAVE_DOSISH_SYSTEM - for (; *a && *b; a++, b++) - { - if (*a != *b && !((*a == '/' && *b == '\\') - || (*a == '\\' && *b == '/')) ) - break; - } - return *(const unsigned char *)a - *(const unsigned char *)b; -#else - return strcmp (a, b); -#endif -} - -/* - * Invalidate (i.e. close) a cached iobuf or all iobufs if NULL is - * used for FNAME. - */ -static int -fd_cache_invalidate (const char *fname) -{ - CLOSE_CACHE cc; - int err=0; - - if (!fname) { - if( DBG_IOBUF ) - log_debug ("fd_cache_invalidate (all)\n"); - - for (cc=close_cache; cc; cc = cc->next ) { - if ( cc->fp != INVALID_FP ) { -#ifdef HAVE_DOSISH_SYSTEM - CloseHandle (cc->fp); -#else - close(cc->fp); -#endif - cc->fp = INVALID_FP; - } - } - return err; - } - - if( DBG_IOBUF ) - log_debug ("fd_cache_invalidate (%s)\n", fname); - - for (cc=close_cache; cc; cc = cc->next ) { - if ( cc->fp != INVALID_FP && !fd_cache_strcmp (cc->fname, fname) ) { - if( DBG_IOBUF ) - log_debug (" did (%s)\n", cc->fname); -#ifdef HAVE_DOSISH_SYSTEM - if(CloseHandle (cc->fp)==0) - err=-1; -#else - err=close(cc->fp); -#endif - cc->fp = INVALID_FP; - } - } - - return err; -} - -static int -fd_cache_synchronize(const char *fname) -{ - int err=0; - -#ifndef HAVE_DOSISH_SYSTEM - CLOSE_CACHE cc; - - if( DBG_IOBUF ) - log_debug ("fd_cache_synchronize (%s)\n", fname); - - for (cc=close_cache; cc; cc = cc->next ) - { - if ( cc->fp != INVALID_FP && !fd_cache_strcmp (cc->fname, fname) ) - { - if( DBG_IOBUF ) - log_debug (" did (%s)\n", cc->fname); - - err=fsync(cc->fp); - } - } -#endif - - return err; -} - -static FILEP_OR_FD -direct_open (const char *fname, const char *mode) -{ -#ifdef HAVE_DOSISH_SYSTEM - unsigned long da, cd, sm; - HANDLE hfile; - - /* Note, that we do not handle all mode combinations */ - - /* According to the ReactOS source it seems that open() of the - * standard MSW32 crt does open the file in share mode which is - * something new for MS applications ;-) - */ - if ( strchr (mode, '+') ) { - fd_cache_invalidate (fname); - da = GENERIC_READ|GENERIC_WRITE; - cd = OPEN_EXISTING; - sm = FILE_SHARE_READ | FILE_SHARE_WRITE; - } - else if ( strchr (mode, 'w') ) { - fd_cache_invalidate (fname); - da = GENERIC_WRITE; - cd = CREATE_ALWAYS; - sm = FILE_SHARE_WRITE; - } - else { - da = GENERIC_READ; - cd = OPEN_EXISTING; - sm = FILE_SHARE_READ; - } - - hfile = CreateFile (fname, da, sm, NULL, cd, FILE_ATTRIBUTE_NORMAL, NULL); - return hfile; -#else - int oflag; - int cflag = S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH; - - /* Note, that we do not handle all mode combinations */ - if ( strchr (mode, '+') ) { - fd_cache_invalidate (fname); - oflag = O_RDWR; - } - else if ( strchr (mode, 'w') ) { - fd_cache_invalidate (fname); - oflag = O_WRONLY | O_CREAT | O_TRUNC; - } - else { - oflag = O_RDONLY; - } -#ifdef O_BINARY - if (strchr (mode, 'b')) - oflag |= O_BINARY; -#endif -#ifndef __riscos__ - return open (fname, oflag, cflag ); -#else - { - struct stat buf; - int rc = stat( fname, &buf ); - - /* Don't allow iobufs on directories */ - if( !rc && S_ISDIR(buf.st_mode) && !S_ISREG(buf.st_mode) ) - return __set_errno( EISDIR ); - else - return open( fname, oflag, cflag ); - } -#endif -#endif -} - - -/* - * Instead of closing an FD we keep it open and cache it for later reuse - * Note that this caching strategy only works if the process does not chdir. - */ -static void -fd_cache_close (const char *fname, FILEP_OR_FD fp) -{ - CLOSE_CACHE cc; - - assert (fp); - if ( !fname || !*fname ) { -#ifdef HAVE_DOSISH_SYSTEM - CloseHandle (fp); -#else - close(fp); -#endif - if( DBG_IOBUF ) - log_debug ("fd_cache_close (%d) real\n", (int)fp); - return; - } - /* try to reuse a slot */ - for (cc=close_cache; cc; cc = cc->next ) { - if ( cc->fp == INVALID_FP && !fd_cache_strcmp (cc->fname, fname) ) { - cc->fp = fp; - if( DBG_IOBUF ) - log_debug ("fd_cache_close (%s) used existing slot\n", fname); - return; - } - } - /* add a new one */ - if( DBG_IOBUF ) - log_debug ("fd_cache_close (%s) new slot created\n", fname); - cc = xmalloc_clear (sizeof *cc + strlen (fname)); - strcpy (cc->fname, fname); - cc->fp = fp; - cc->next = close_cache; - close_cache = cc; -} - -/* - * Do an direct_open on FNAME but first try to reuse one from the fd_cache - */ -static FILEP_OR_FD -fd_cache_open (const char *fname, const char *mode) -{ - CLOSE_CACHE cc; - - assert (fname); - for (cc=close_cache; cc; cc = cc->next ) { - if ( cc->fp != INVALID_FP && !fd_cache_strcmp (cc->fname, fname) ) { - FILEP_OR_FD fp = cc->fp; - cc->fp = INVALID_FP; - if( DBG_IOBUF ) - log_debug ("fd_cache_open (%s) using cached fp\n", fname); -#ifdef HAVE_DOSISH_SYSTEM - if (SetFilePointer (fp, 0, NULL, FILE_BEGIN) == 0xffffffff ) { - log_error ("rewind file failed on handle %p: %s\n", - fp, w32_strerror (errno)); - fp = INVALID_FP; - } -#else - if ( lseek (fp, 0, SEEK_SET) == (off_t)-1 ) { - log_error("can't rewind fd %d: %s\n", fp, strerror(errno) ); - fp = INVALID_FP; - } -#endif - return fp; - } - } - if( DBG_IOBUF ) - log_debug ("fd_cache_open (%s) not cached\n", fname); - return direct_open (fname, mode); -} - - -#endif /*FILE_FILTER_USES_STDIO*/ - - -/**************** - * Read data from a file into buf which has an allocated length of *LEN. - * return the number of read bytes in *LEN. OPAQUE is the FILE * of - * the stream. A is not used. - * control may be: - * IOBUFCTRL_INIT: called just before the function is linked into the - * list of function. This can be used to prepare internal - * data structures of the function. - * IOBUFCTRL_FREE: called just before the function is removed from the - * list of functions and can be used to release internal - * data structures or close a file etc. - * IOBUFCTRL_UNDERFLOW: called by iobuf_underflow to fill the buffer - * with new stuff. *RET_LEN is the available size of the - * buffer, and should be set to the number of bytes - * which were put into the buffer. The function - * returns 0 to indicate success, -1 on EOF and - * G10ERR_xxxxx for other errors. - * - * IOBUFCTRL_FLUSH: called by iobuf_flush() to write out the collected stuff. - * *RET_LAN is the number of bytes in BUF. - * - * IOBUFCTRL_CANCEL: send to all filters on behalf of iobuf_cancel. The - * filter may take appropriate action on this message. - */ -static int -file_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len) -{ - file_filter_ctx_t *a = opaque; - FILEP_OR_FD f = a->fp; - size_t size = *ret_len; - size_t nbytes = 0; - int rc = 0; - -#ifdef FILE_FILTER_USES_STDIO - if( control == IOBUFCTRL_UNDERFLOW ) { - assert( size ); /* need a buffer */ - if ( feof(f)) { /* On terminals you could easiely read as many EOFs as you call */ - rc = -1; /* fread() or fgetc() repeatly. Every call will block until you press */ - *ret_len = 0; /* CTRL-D. So we catch this case before we call fread() again. */ - } - else { - clearerr( f ); - nbytes = fread( buf, 1, size, f ); - if( feof(f) && !nbytes ) { - rc = -1; /* okay: we can return EOF now. */ - } - else if( ferror(f) && errno != EPIPE ) { - log_error("%s: read error: %s\n", - a->fname, strerror(errno)); - rc = G10ERR_READ_FILE; - } - *ret_len = nbytes; - } - } - else if( control == IOBUFCTRL_FLUSH ) { - if( size ) { - clearerr( f ); - nbytes = fwrite( buf, 1, size, f ); - if( ferror(f) ) { - log_error("%s: write error: %s\n", a->fname, strerror(errno)); - rc = G10ERR_WRITE_FILE; - } - } - *ret_len = nbytes; - } - else if( control == IOBUFCTRL_INIT ) { - a->keep_open = a->no_cache = 0; - } - else if( control == IOBUFCTRL_DESC ) { - *(char**)buf = "file_filter"; - } - else if( control == IOBUFCTRL_FREE ) { - if( f != stdin && f != stdout ) { - if( DBG_IOBUF ) - log_debug("%s: close fd %d\n", a->fname, fileno(f) ); - if (!a->keep_open) - fclose(f); - } - f = NULL; - xfree(a); /* we can free our context now */ - } -#else /* !stdio implementation */ - - if( control == IOBUFCTRL_UNDERFLOW ) { - assert( size ); /* need a buffer */ - if ( a->eof_seen) { - rc = -1; - *ret_len = 0; - } - else { -#ifdef HAVE_DOSISH_SYSTEM - unsigned long nread; - - nbytes = 0; - if ( !ReadFile ( f, buf, size, &nread, NULL ) ) { - if ((int)GetLastError () != ERROR_BROKEN_PIPE) { - log_error ("%s: read error: %s\n", a->fname, - w32_strerror (0)); - rc = G10ERR_READ_FILE; - } - } - else if ( !nread ) { - a->eof_seen = 1; - rc = -1; - } - else { - nbytes = nread; - } - -#else - - int n; - - nbytes = 0; - do { - n = read ( f, buf, size ); - } while (n == -1 && errno == EINTR ); - if ( n == -1 ) { /* error */ - if (errno != EPIPE) { - log_error("%s: read error: %s\n", - a->fname, strerror(errno)); - rc = G10ERR_READ_FILE; - } - } - else if ( !n ) { /* eof */ - a->eof_seen = 1; - rc = -1; - } - else { - nbytes = n; - } -#endif - *ret_len = nbytes; - } - } - else if( control == IOBUFCTRL_FLUSH ) { - if( size ) { -#ifdef HAVE_DOSISH_SYSTEM - byte *p = buf; - unsigned long n; - - nbytes = size; - do { - if (size && !WriteFile (f, p, nbytes, &n, NULL)) { - log_error ("%s: write error: %s\n", a->fname, - w32_strerror (0)); - rc = G10ERR_WRITE_FILE; - break; - } - p += n; - nbytes -= n; - } while ( nbytes ); - nbytes = p - buf; -#else - byte *p = buf; - int n; - - nbytes = size; - do { - do { - n = write ( f, p, nbytes ); - } while ( n == -1 && errno == EINTR ); - if ( n > 0 ) { - p += n; - nbytes -= n; - } - } while ( n != -1 && nbytes ); - if( n == -1 ) { - log_error("%s: write error: %s\n", a->fname, strerror(errno)); - rc = G10ERR_WRITE_FILE; - } - nbytes = p - buf; -#endif - } - *ret_len = nbytes; - } - else if ( control == IOBUFCTRL_INIT ) { - a->eof_seen = 0; - a->keep_open = 0; - a->no_cache = 0; - } - else if ( control == IOBUFCTRL_DESC ) { - *(char**)buf = "file_filter(fd)"; - } - else if ( control == IOBUFCTRL_FREE ) { -#ifdef HAVE_DOSISH_SYSTEM - if ( f != FILEP_OR_FD_FOR_STDIN && f != FILEP_OR_FD_FOR_STDOUT ) { - if( DBG_IOBUF ) - log_debug("%s: close handle %p\n", a->fname, f ); - if (!a->keep_open) - fd_cache_close (a->no_cache?NULL:a->fname, f); - } -#else - if ( (int)f != 0 && (int)f != 1 ) { - if( DBG_IOBUF ) - log_debug("%s: close fd %d\n", a->fname, f ); - if (!a->keep_open) - fd_cache_close (a->no_cache?NULL:a->fname, f); - } - f = INVALID_FP; -#endif - xfree (a); /* we can free our context now */ - } -#endif /* !stdio implementation */ - return rc; -} - -#ifdef _WIN32 -/* Becuase sockets are an special object under Lose32 we have to - * use a special filter */ -static int -sock_filter (void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len) -{ - sock_filter_ctx_t *a = opaque; - size_t size = *ret_len; - size_t nbytes = 0; - int rc = 0; - - if( control == IOBUFCTRL_UNDERFLOW ) { - assert( size ); /* need a buffer */ - if ( a->eof_seen) { - rc = -1; - *ret_len = 0; - } - else { - int nread; - - nread = recv ( a->sock, buf, size, 0 ); - if ( nread == SOCKET_ERROR ) { - int ec = (int)WSAGetLastError (); - log_error("socket read error: ec=%d\n", ec); - rc = G10ERR_READ_FILE; - } - else if ( !nread ) { - a->eof_seen = 1; - rc = -1; - } - else { - nbytes = nread; - } - *ret_len = nbytes; - } - } - else if( control == IOBUFCTRL_FLUSH ) { - if( size ) { - byte *p = buf; - int n; - - nbytes = size; - do { - n = send (a->sock, p, nbytes, 0); - if ( n == SOCKET_ERROR ) { - int ec = (int)WSAGetLastError (); - log_error("socket write error: ec=%d\n", ec); - rc = G10ERR_WRITE_FILE; - break; - } - p += n; - nbytes -= n; - } while ( nbytes ); - nbytes = p - buf; - } - *ret_len = nbytes; - } - else if ( control == IOBUFCTRL_INIT ) { - a->eof_seen = 0; - a->keep_open = 0; - a->no_cache = 0; - } - else if ( control == IOBUFCTRL_DESC ) { - *(char**)buf = "sock_filter"; - } - else if ( control == IOBUFCTRL_FREE ) { - if (!a->keep_open) - closesocket (a->sock); - xfree (a); /* we can free our context now */ - } - return rc; -} -#endif /*_WIN32*/ - -/**************** - * This is used to implement the block write mode. - * Block reading is done on a byte by byte basis in readbyte(), - * without a filter - */ -static int -block_filter(void *opaque, int control, IOBUF chain, byte *buf, size_t *ret_len) -{ - block_filter_ctx_t *a = opaque; - size_t size = *ret_len; - int c, needed, rc = 0; - char *p; - - if( control == IOBUFCTRL_UNDERFLOW ) { - size_t n=0; - - p = buf; - assert( size ); /* need a buffer */ - if( a->eof ) /* don't read any further */ - rc = -1; - while( !rc && size ) { - if( !a->size ) { /* get the length bytes */ - if( a->partial == 2 ) { - a->eof = 1; - if( !n ) - rc = -1; - break; - } - else if( a->partial ) { - /* These OpenPGP introduced huffman like encoded length - * bytes are really a mess :-( */ - if( a->first_c ) { - c = a->first_c; - a->first_c = 0; - } - else if( (c = iobuf_get(chain)) == -1 ) { - log_error("block_filter: 1st length byte missing\n"); - rc = G10ERR_READ_FILE; - break; - } - if( c < 192 ) { - a->size = c; - a->partial = 2; - if( !a->size ) { - a->eof = 1; - if( !n ) - rc = -1; - break; - } - } - else if( c < 224 ) { - a->size = (c - 192) * 256; - if( (c = iobuf_get(chain)) == -1 ) { - log_error("block_filter: 2nd length byte missing\n"); - rc = G10ERR_READ_FILE; - break; - } - a->size += c + 192; - a->partial = 2; - if( !a->size ) { - a->eof = 1; - if( !n ) - rc = -1; - break; - } - } - else if( c == 255 ) { - a->size = iobuf_get(chain) << 24; - a->size |= iobuf_get(chain) << 16; - a->size |= iobuf_get(chain) << 8; - if( (c = iobuf_get(chain)) == -1 ) { - log_error("block_filter: invalid 4 byte length\n"); - rc = G10ERR_READ_FILE; - break; - } - a->size |= c; - a->partial = 2; - if( !a->size ) { - a->eof = 1; - if( !n ) - rc = -1; - break; - } - } - else { /* next partial body length */ - a->size = 1 << (c & 0x1f); - } - /* log_debug("partial: ctx=%p c=%02x size=%u\n", a, c, a->size);*/ - } - else - BUG(); - } - - while( !rc && size && a->size ) { - needed = size < a->size ? size : a->size; - c = iobuf_read( chain, p, needed ); - if( c < needed ) { - if( c == -1 ) c = 0; - log_error("block_filter %p: read error (size=%lu,a->size=%lu)\n", - a, (ulong)size+c, (ulong)a->size+c); - rc = G10ERR_READ_FILE; - } - else { - size -= c; - a->size -= c; - p += c; - n += c; - } - } - } - *ret_len = n; - } - else if( control == IOBUFCTRL_FLUSH ) { - if( a->partial ) { /* the complicated openpgp scheme */ - size_t blen, n, nbytes = size + a->buflen; - - assert( a->buflen <= OP_MIN_PARTIAL_CHUNK ); - if( nbytes < OP_MIN_PARTIAL_CHUNK ) { - /* not enough to write a partial block out; so we store it*/ - if( !a->buffer ) - a->buffer = xmalloc( OP_MIN_PARTIAL_CHUNK ); - memcpy( a->buffer + a->buflen, buf, size ); - a->buflen += size; - } - else { /* okay, we can write out something */ - /* do this in a loop to use the most efficient block lengths */ - p = buf; - do { - /* find the best matching block length - this is limited - * by the size of the internal buffering */ - for( blen=OP_MIN_PARTIAL_CHUNK*2, - c=OP_MIN_PARTIAL_CHUNK_2POW+1; blen <= nbytes; - blen *=2, c++ ) - ; - blen /= 2; c--; - /* write the partial length header */ - assert( c <= 0x1f ); /*;-)*/ - c |= 0xe0; - iobuf_put( chain, c ); - if( (n=a->buflen) ) { /* write stuff from the buffer */ - assert( n == OP_MIN_PARTIAL_CHUNK); - if( iobuf_write(chain, a->buffer, n ) ) - rc = G10ERR_WRITE_FILE; - a->buflen = 0; - nbytes -= n; - } - if( (n = nbytes) > blen ) - n = blen; - if( n && iobuf_write(chain, p, n ) ) - rc = G10ERR_WRITE_FILE; - p += n; - nbytes -= n; - } while( !rc && nbytes >= OP_MIN_PARTIAL_CHUNK ); - /* store the rest in the buffer */ - if( !rc && nbytes ) { - assert( !a->buflen ); - assert( nbytes < OP_MIN_PARTIAL_CHUNK ); - if( !a->buffer ) - a->buffer = xmalloc( OP_MIN_PARTIAL_CHUNK ); - memcpy( a->buffer, p, nbytes ); - a->buflen = nbytes; - } - } - } - else - BUG(); - } - else if( control == IOBUFCTRL_INIT ) { - if( DBG_IOBUF ) - log_debug("init block_filter %p\n", a ); - if( a->partial ) - a->count = 0; - else if( a->use == 1 ) - a->count = a->size = 0; - else - a->count = a->size; /* force first length bytes */ - a->eof = 0; - a->buffer = NULL; - a->buflen = 0; - } - else if( control == IOBUFCTRL_DESC ) { - *(char**)buf = "block_filter"; - } - else if( control == IOBUFCTRL_FREE ) { - if( a->use == 2 ) { /* write the end markers */ - if( a->partial ) { - u32 len; - /* write out the remaining bytes without a partial header - * the length of this header may be 0 - but if it is - * the first block we are not allowed to use a partial header - * and frankly we can't do so, because this length must be - * a power of 2. This is _really_ complicated because we - * have to check the possible length of a packet prior - * to it's creation: a chain of filters becomes complicated - * and we need a lot of code to handle compressed packets etc. - * :-((((((( - */ - /* construct header */ - len = a->buflen; - /*log_debug("partial: remaining length=%u\n", len );*/ - if( len < 192 ) - rc = iobuf_put(chain, len ); - else if( len < 8384 ) { - if( !(rc=iobuf_put( chain, ((len-192) / 256) + 192)) ) - rc = iobuf_put( chain, ((len-192) % 256)); - } - else { /* use a 4 byte header */ - if( !(rc=iobuf_put( chain, 0xff )) ) - if( !(rc=iobuf_put( chain, (len >> 24)&0xff )) ) - if( !(rc=iobuf_put( chain, (len >> 16)&0xff )) ) - if( !(rc=iobuf_put( chain, (len >> 8)&0xff ))) - rc=iobuf_put( chain, len & 0xff ); - } - if( !rc && len ) - rc = iobuf_write(chain, a->buffer, len ); - if( rc ) { - log_error("block_filter: write error: %s\n",strerror(errno)); - rc = G10ERR_WRITE_FILE; - } - xfree( a->buffer ); a->buffer = NULL; a->buflen = 0; - } - else - BUG(); - } - else if( a->size ) { - log_error("block_filter: pending bytes!\n"); - } - if( DBG_IOBUF ) - log_debug("free block_filter %p\n", a ); - xfree(a); /* we can free our context now */ - } - - return rc; -} - - -static void -print_chain( IOBUF a ) -{ - if( !DBG_IOBUF ) - return; - for(; a; a = a->chain ) { - size_t dummy_len = 0; - const char *desc = "[none]"; - - if( a->filter ) - a->filter( a->filter_ov, IOBUFCTRL_DESC, NULL, - (byte*)&desc, &dummy_len ); - - log_debug("iobuf chain: %d.%d `%s' filter_eof=%d start=%d len=%d\n", - a->no, a->subno, desc?desc:"?", a->filter_eof, - (int)a->d.start, (int)a->d.len ); - } -} - -int -iobuf_print_chain( IOBUF a ) -{ - print_chain(a); - return 0; -} - -/**************** - * Allocate a new io buffer, with no function assigned. - * Use is the desired usage: 1 for input, 2 for output, 3 for temp buffer - * BUFSIZE is a suggested buffer size. - */ -IOBUF -iobuf_alloc(int use, size_t bufsize) -{ - IOBUF a; - static int number=0; - - a = xmalloc_clear(sizeof *a); - a->use = use; - a->d.buf = xmalloc( bufsize ); - a->d.size = bufsize; - a->no = ++number; - a->subno = 0; - a->opaque = NULL; - a->real_fname = NULL; - return a; -} - -int -iobuf_close ( IOBUF a ) -{ - IOBUF a2; - size_t dummy_len=0; - int rc=0; - - if( a && a->directfp ) { - fclose( a->directfp ); - xfree( a->real_fname ); - if( DBG_IOBUF ) - log_debug("iobuf_close -> %p\n", a->directfp ); - return 0; - } - - for( ; a && !rc ; a = a2 ) { - a2 = a->chain; - if( a->use == 2 && (rc=iobuf_flush(a)) ) - log_error("iobuf_flush failed on close: %s\n", g10_errstr(rc)); - - if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: close `%s'\n", a->no, a->subno, - a->desc?a->desc:"?"); - if( a->filter && (rc = a->filter(a->filter_ov, IOBUFCTRL_FREE, - a->chain, NULL, &dummy_len)) ) - log_error("IOBUFCTRL_FREE failed on close: %s\n", g10_errstr(rc) ); - xfree(a->real_fname); - if (a->d.buf) { - memset (a->d.buf, 0, a->d.size); /* erase the buffer */ - xfree(a->d.buf); - } - xfree(a); - } - return rc; -} - -int -iobuf_cancel( IOBUF a ) -{ - const char *s; - IOBUF a2; - int rc; -#if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__) - char *remove_name = NULL; -#endif - - if( a && a->use == 2 ) { - s = iobuf_get_real_fname(a); - if( s && *s ) { -#if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__) - remove_name = xstrdup ( s ); -#else - remove(s); -#endif - } - } - - /* send a cancel message to all filters */ - for( a2 = a; a2 ; a2 = a2->chain ) { - size_t dummy; - if( a2->filter ) - a2->filter( a2->filter_ov, IOBUFCTRL_CANCEL, a2->chain, - NULL, &dummy ); - } - - rc = iobuf_close(a); -#if defined(HAVE_DOSISH_SYSTEM) || defined(__riscos__) - if ( remove_name ) { - /* Argg, MSDOS does not allow to remove open files. So - * we have to do it here */ - remove ( remove_name ); - xfree ( remove_name ); - } -#endif - return rc; -} - - -/**************** - * create a temporary iobuf, which can be used to collect stuff - * in an iobuf and later be written by iobuf_write_temp() to another - * iobuf. - */ -IOBUF -iobuf_temp() -{ - IOBUF a; - - a = iobuf_alloc(3, IOBUF_BUFFER_SIZE ); - - return a; -} - -IOBUF -iobuf_temp_with_content( const char *buffer, size_t length ) -{ - IOBUF a; - - a = iobuf_alloc(3, length ); - memcpy( a->d.buf, buffer, length ); - a->d.len = length; - - return a; -} - -void -iobuf_enable_special_filenames ( int yes ) -{ - special_names_enabled = yes; -} - -/* - * see whether the filename has the for "-&nnnn", where n is a - * non-zero number. - * Returns this number or -1 if it is not the case. - */ -static int -check_special_filename ( const char *fname ) -{ - if ( special_names_enabled - && fname && *fname == '-' && fname[1] == '&' ) { - int i; - - fname += 2; - for (i=0; digitp (fname+i); i++ ) - ; - if ( !fname[i] ) - return atoi (fname); - } - return -1; -} - -/* This fucntion returns true if FNAME indicates a PIPE (stdout or - stderr) or a special file name if those are enabled. */ -int -iobuf_is_pipe_filename (const char *fname) -{ - if (!fname || (*fname=='-' && !fname[1]) ) - return 1; - return check_special_filename (fname) != -1; -} - -/**************** - * Create a head iobuf for reading from a file - * returns: NULL if an error occures and sets errno - */ -IOBUF -iobuf_open( const char *fname ) -{ - IOBUF a; - FILEP_OR_FD fp; - file_filter_ctx_t *fcx; - size_t len; - int print_only = 0; - int fd; - - if( !fname || (*fname=='-' && !fname[1]) ) { - fp = FILEP_OR_FD_FOR_STDIN; -#ifdef USE_SETMODE - setmode ( my_fileno(fp) , O_BINARY ); -#endif - fname = "[stdin]"; - print_only = 1; - } - else if ( (fd = check_special_filename ( fname )) != -1 ) - return iobuf_fdopen ( translate_file_handle (fd,0), "rb" ); - else if( (fp = my_fopen_ro(fname, "rb")) == INVALID_FP ) - return NULL; - a = iobuf_alloc(1, IOBUF_BUFFER_SIZE ); - fcx = xmalloc( sizeof *fcx + strlen(fname) ); - fcx->fp = fp; - fcx->print_only_name = print_only; - strcpy(fcx->fname, fname ); - if( !print_only ) - a->real_fname = xstrdup( fname ); - a->filter = file_filter; - a->filter_ov = fcx; - file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len ); - file_filter( fcx, IOBUFCTRL_INIT, NULL, NULL, &len ); - if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: open `%s' fd=%d\n", - a->no, a->subno, fname, (int)my_fileno(fcx->fp) ); - - return a; -} - -/**************** - * Create a head iobuf for reading from a file - * returns: NULL if an error occures and sets errno - */ -IOBUF -iobuf_fdopen( int fd, const char *mode ) -{ - IOBUF a; - FILEP_OR_FD fp; - file_filter_ctx_t *fcx; - size_t len; - -#ifdef FILE_FILTER_USES_STDIO - if( !(fp = fdopen(fd, mode)) ) - return NULL; -#else - fp = (FILEP_OR_FD)fd; -#endif - a = iobuf_alloc( strchr( mode, 'w')? 2:1, IOBUF_BUFFER_SIZE ); - fcx = xmalloc( sizeof *fcx + 20 ); - fcx->fp = fp; - fcx->print_only_name = 1; - sprintf(fcx->fname, "[fd %d]", fd ); - a->filter = file_filter; - a->filter_ov = fcx; - file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len ); - file_filter( fcx, IOBUFCTRL_INIT, NULL, NULL, &len ); - if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: fdopen `%s'\n", a->no, a->subno, fcx->fname ); - iobuf_ioctl (a,3,1,NULL); /* disable fd caching */ - return a; -} - - -IOBUF -iobuf_sockopen ( int fd, const char *mode ) -{ - IOBUF a; -#ifdef _WIN32 - sock_filter_ctx_t *scx; - size_t len; - - a = iobuf_alloc( strchr( mode, 'w')? 2:1, IOBUF_BUFFER_SIZE ); - scx = xmalloc( sizeof *scx + 25 ); - scx->sock = fd; - scx->print_only_name = 1; - sprintf(scx->fname, "[sock %d]", fd ); - a->filter = sock_filter; - a->filter_ov = scx; - sock_filter( scx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len ); - sock_filter( scx, IOBUFCTRL_INIT, NULL, NULL, &len ); - if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: sockopen `%s'\n", a->no, a->subno, scx->fname); - iobuf_ioctl (a,3,1,NULL); /* disable fd caching */ -#else - a = iobuf_fdopen (fd, mode); -#endif - return a; -} - -/**************** - * create an iobuf for writing to a file; the file will be created. - */ -IOBUF -iobuf_create( const char *fname ) -{ - IOBUF a; - FILEP_OR_FD fp; - file_filter_ctx_t *fcx; - size_t len; - int print_only = 0; - int fd; - - if( !fname || (*fname=='-' && !fname[1]) ) { - fp = FILEP_OR_FD_FOR_STDOUT; -#ifdef USE_SETMODE - setmode ( my_fileno(fp) , O_BINARY ); -#endif - fname = "[stdout]"; - print_only = 1; - } - else if ( (fd = check_special_filename ( fname )) != -1 ) - return iobuf_fdopen ( translate_file_handle (fd, 1), "wb" ); - else if( (fp = my_fopen(fname, "wb")) == INVALID_FP ) - return NULL; - a = iobuf_alloc(2, IOBUF_BUFFER_SIZE ); - fcx = xmalloc( sizeof *fcx + strlen(fname) ); - fcx->fp = fp; - fcx->print_only_name = print_only; - strcpy(fcx->fname, fname ); - if( !print_only ) - a->real_fname = xstrdup( fname ); - a->filter = file_filter; - a->filter_ov = fcx; - file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len ); - file_filter( fcx, IOBUFCTRL_INIT, NULL, NULL, &len ); - if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: create `%s'\n", a->no, a->subno, - a->desc?a->desc:"?" ); - - return a; -} - -/**************** - * append to an iobuf; if the file does not exist, create it. - * cannot be used for stdout. - * Note: This is not used. - */ -#if 0 /* not used */ -IOBUF -iobuf_append( const char *fname ) -{ - IOBUF a; - FILE *fp; - file_filter_ctx_t *fcx; - size_t len; - - if( !fname ) - return NULL; - else if( !(fp = my_fopen(fname, "ab")) ) - return NULL; - a = iobuf_alloc(2, IOBUF_BUFFER_SIZE ); - fcx = xmalloc( sizeof *fcx + strlen(fname) ); - fcx->fp = fp; - strcpy(fcx->fname, fname ); - a->real_fname = xstrdup( fname ); - a->filter = file_filter; - a->filter_ov = fcx; - file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len ); - file_filter( fcx, IOBUFCTRL_INIT, NULL, NULL, &len ); - if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: append `%s'\n", a->no, a->subno, - a->desc?a->desc:"?" ); - - return a; -} -#endif - -IOBUF -iobuf_openrw( const char *fname ) -{ - IOBUF a; - FILEP_OR_FD fp; - file_filter_ctx_t *fcx; - size_t len; - - if( !fname ) - return NULL; - else if( (fp = my_fopen(fname, "r+b")) == INVALID_FP ) - return NULL; - a = iobuf_alloc(2, IOBUF_BUFFER_SIZE ); - fcx = xmalloc( sizeof *fcx + strlen(fname) ); - fcx->fp = fp; - strcpy(fcx->fname, fname ); - a->real_fname = xstrdup( fname ); - a->filter = file_filter; - a->filter_ov = fcx; - file_filter( fcx, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &len ); - file_filter( fcx, IOBUFCTRL_INIT, NULL, NULL, &len ); - if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: openrw `%s'\n", a->no, a->subno, - a->desc?a->desc:"?"); - - return a; -} - - -int -iobuf_ioctl ( IOBUF a, int cmd, int intval, void *ptrval ) -{ - if ( cmd == 1 ) { /* keep system filepointer/descriptor open */ - if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: ioctl `%s' keep=%d\n", - a? a->no:-1, a?a->subno:-1, - a&&a->desc?a->desc:"?", intval ); - for( ; a; a = a->chain ) - if( !a->chain && a->filter == file_filter ) { - file_filter_ctx_t *b = a->filter_ov; - b->keep_open = intval; - return 0; - } -#ifdef _WIN32 - else if( !a->chain && a->filter == sock_filter ) { - sock_filter_ctx_t *b = a->filter_ov; - b->keep_open = intval; - return 0; - } -#endif - } - else if ( cmd == 2 ) { /* invalidate cache */ - if( DBG_IOBUF ) - log_debug("iobuf-*.*: ioctl `%s' invalidate\n", - ptrval? (char*)ptrval:"[all]"); - if ( !a && !intval ) { -#ifndef FILE_FILTER_USES_STDIO - return fd_cache_invalidate (ptrval); -#endif - return 0; - } - } - else if ( cmd == 3 ) { /* disallow/allow caching */ - if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: ioctl `%s' no_cache=%d\n", - a? a->no:-1, a?a->subno:-1, - a&&a->desc?a->desc:"?", intval ); - for( ; a; a = a->chain ) - if( !a->chain && a->filter == file_filter ) { - file_filter_ctx_t *b = a->filter_ov; - b->no_cache = intval; - return 0; - } -#ifdef _WIN32 - else if( !a->chain && a->filter == sock_filter ) { - sock_filter_ctx_t *b = a->filter_ov; - b->no_cache = intval; - return 0; - } -#endif - } - else if(cmd==4) - { - /* Do a fsync on the open fd and return any errors to the - caller of iobuf_ioctl */ - if( DBG_IOBUF ) - log_debug("iobuf-*.*: ioctl `%s' fsync\n", - ptrval? (char*)ptrval:""); - - if(!a && !intval && ptrval) - { -#ifndef FILE_FILTER_USES_STDIO - return fd_cache_synchronize (ptrval); -#else - return 0; -#endif - } - } - - return -1; -} - - -/**************** - * Register an i/o filter. - */ -int -iobuf_push_filter( IOBUF a, - int (*f)(void *opaque, int control, - IOBUF chain, byte *buf, size_t *len), void *ov ) -{ - return iobuf_push_filter2( a, f, ov, 0 ); -} - -int -iobuf_push_filter2( IOBUF a, - int (*f)(void *opaque, int control, - IOBUF chain, byte *buf, size_t *len), - void *ov, int rel_ov ) -{ - IOBUF b; - size_t dummy_len=0; - int rc=0; - - if( a->directfp ) - BUG(); - - if( a->use == 2 && (rc=iobuf_flush(a)) ) - return rc; - /* make a copy of the current stream, so that - * A is the new stream and B the original one. - * The contents of the buffers are transferred to the - * new stream. - */ - b = xmalloc(sizeof *b); - memcpy(b, a, sizeof *b ); - /* fixme: it is stupid to keep a copy of the name at every level - * but we need the name somewhere because the name known by file_filter - * may have been released when we need the name of the file */ - b->real_fname = a->real_fname? xstrdup(a->real_fname):NULL; - /* remove the filter stuff from the new stream */ - a->filter = NULL; - a->filter_ov = NULL; - a->filter_ov_owner = 0; - a->filter_eof = 0; - if( a->use == 3 ) - a->use = 2; /* make a write stream from a temp stream */ - - if( a->use == 2 ) { /* allocate a fresh buffer for the original stream */ - b->d.buf = xmalloc( a->d.size ); - b->d.len = 0; - b->d.start = 0; - } - else { /* allocate a fresh buffer for the new stream */ - a->d.buf = xmalloc( a->d.size ); - a->d.len = 0; - a->d.start = 0; - } - /* disable nlimit for the new stream */ - a->ntotal = b->ntotal + b->nbytes; - a->nlimit = a->nbytes = 0; - a->nofast &= ~1; - /* make a link from the new stream to the original stream */ - a->chain = b; - a->opaque = b->opaque; - - /* setup the function on the new stream */ - a->filter = f; - a->filter_ov = ov; - a->filter_ov_owner = rel_ov; - - a->subno = b->subno + 1; - f( ov, IOBUFCTRL_DESC, NULL, (byte*)&a->desc, &dummy_len ); - - if( DBG_IOBUF ) { - log_debug("iobuf-%d.%d: push `%s'\n", a->no, a->subno, - a->desc?a->desc:"?" ); - print_chain( a ); - } - - /* now we can initialize the new function if we have one */ - if( a->filter && (rc = a->filter(a->filter_ov, IOBUFCTRL_INIT, a->chain, - NULL, &dummy_len)) ) - log_error("IOBUFCTRL_INIT failed: %s\n", g10_errstr(rc) ); - return rc; -} - -/**************** - * Remove an i/o filter. - */ -static int -pop_filter( IOBUF a, int (*f)(void *opaque, int control, - IOBUF chain, byte *buf, size_t *len), void *ov ) -{ - IOBUF b; - size_t dummy_len=0; - int rc=0; - - if( a->directfp ) - BUG(); - - if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: pop `%s'\n", a->no, a->subno, - a->desc?a->desc:"?" ); - if( !a->filter ) { /* this is simple */ - b = a->chain; - assert(b); - xfree(a->d.buf); - xfree(a->real_fname); - memcpy(a,b, sizeof *a); - xfree(b); - return 0; - } - for(b=a ; b; b = b->chain ) - if( b->filter == f && (!ov || b->filter_ov == ov) ) - break; - if( !b ) - log_bug("pop_filter(): filter function not found\n"); - - /* flush this stream if it is an output stream */ - if( a->use == 2 && (rc=iobuf_flush(b)) ) { - log_error("iobuf_flush failed in pop_filter: %s\n", g10_errstr(rc)); - return rc; - } - /* and tell the filter to free it self */ - if( b->filter && (rc = b->filter(b->filter_ov, IOBUFCTRL_FREE, b->chain, - NULL, &dummy_len)) ) { - log_error("IOBUFCTRL_FREE failed: %s\n", g10_errstr(rc) ); - return rc; - } - if( b->filter_ov && b->filter_ov_owner ) { - xfree( b->filter_ov ); - b->filter_ov = NULL; - } - - - /* and see how to remove it */ - if( a == b && !b->chain ) - log_bug("can't remove the last filter from the chain\n"); - else if( a == b ) { /* remove the first iobuf from the chain */ - /* everything from b is copied to a. This is save because - * a flush has been done on the to be removed entry - */ - b = a->chain; - xfree(a->d.buf); - xfree(a->real_fname); - memcpy(a,b, sizeof *a); - xfree(b); - if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: popped filter\n", a->no, a->subno ); - } - else if( !b->chain ) { /* remove the last iobuf from the chain */ - log_bug("Ohh jeee, trying to remove a head filter\n"); - } - else { /* remove an intermediate iobuf from the chain */ - log_bug("Ohh jeee, trying to remove an intermediate filter\n"); - } - - return rc; -} - - -/**************** - * read underflow: read more bytes into the buffer and return - * the first byte or -1 on EOF. - */ -static int -underflow(IOBUF a) -{ - size_t len; - int rc; - - assert( a->d.start == a->d.len ); - if( a->use == 3 ) - return -1; /* EOF because a temp buffer can't do an underflow */ - - if( a->filter_eof ) { - if( a->chain ) { - IOBUF b = a->chain; - if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: pop `%s' in underflow\n", - a->no, a->subno, a->desc?a->desc:"?" ); - xfree(a->d.buf); - xfree(a->real_fname); - memcpy(a, b, sizeof *a); - xfree(b); - print_chain(a); - } - else - a->filter_eof = 0; /* for the top level filter */ - if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: underflow: eof (due to filter eof)\n", - a->no, a->subno ); - return -1; /* return one(!) EOF */ - } - if( a->error ) { - if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: error\n", a->no, a->subno ); - return -1; - } - - if( a->directfp ) { - FILE *fp = a->directfp; - - len = fread( a->d.buf, 1, a->d.size, fp); - if( len < a->d.size ) { - if( ferror(fp) ) - a->error = 1; - } - a->d.len = len; - a->d.start = 0; - return len? a->d.buf[a->d.start++] : -1; - } - - - if( a->filter ) { - len = a->d.size; - if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: underflow: req=%lu\n", - a->no, a->subno, (ulong)len ); - rc = a->filter( a->filter_ov, IOBUFCTRL_UNDERFLOW, a->chain, - a->d.buf, &len ); - if( DBG_IOBUF ) { - log_debug("iobuf-%d.%d: underflow: got=%lu rc=%d\n", - a->no, a->subno, (ulong)len, rc ); -/* if( a->no == 1 ) */ -/* log_hexdump (" data:", a->d.buf, len); */ - } - if( a->use == 1 && rc == -1 ) { /* EOF: we can remove the filter */ - size_t dummy_len=0; - - /* and tell the filter to free itself */ - if( (rc = a->filter(a->filter_ov, IOBUFCTRL_FREE, a->chain, - NULL, &dummy_len)) ) - log_error("IOBUFCTRL_FREE failed: %s\n", g10_errstr(rc) ); - if( a->filter_ov && a->filter_ov_owner ) { - xfree( a->filter_ov ); - a->filter_ov = NULL; - } - a->filter = NULL; - a->desc = NULL; - a->filter_ov = NULL; - a->filter_eof = 1; - if( !len && a->chain ) { - IOBUF b = a->chain; - if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: pop in underflow (!len)\n", - a->no, a->subno); - xfree(a->d.buf); - xfree(a->real_fname); - memcpy(a,b, sizeof *a); - xfree(b); - print_chain(a); - } - } - else if( rc ) - a->error = 1; - - if( !len ) { - if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: underflow: eof\n", a->no, a->subno ); - return -1; - } - a->d.len = len; - a->d.start = 0; - return a->d.buf[a->d.start++]; - } - else { - if( DBG_IOBUF ) - log_debug("iobuf-%d.%d: underflow: eof (no filter)\n", - a->no, a->subno ); - return -1; /* no filter; return EOF */ - } -} - - -int -iobuf_flush(IOBUF a) -{ - size_t len; - int rc; - - if( a->directfp ) - return 0; - - if( a->use == 3 ) { /* increase the temp buffer */ - char *newbuf; - size_t newsize = a->d.size + IOBUF_BUFFER_SIZE; - - if( DBG_IOBUF ) - log_debug("increasing temp iobuf from %lu to %lu\n", - (ulong)a->d.size, (ulong)newsize ); - newbuf = xmalloc( newsize ); - memcpy( newbuf, a->d.buf, a->d.len ); - xfree(a->d.buf); - a->d.buf = newbuf; - a->d.size = newsize; - return 0; - } - else if( a->use != 2 ) - log_bug("flush on non-output iobuf\n"); - else if( !a->filter ) - log_bug("iobuf_flush: no filter\n"); - len = a->d.len; - rc = a->filter( a->filter_ov, IOBUFCTRL_FLUSH, a->chain, a->d.buf, &len ); - if( !rc && len != a->d.len ) { - log_info("iobuf_flush did not write all!\n"); - rc = G10ERR_WRITE_FILE; - } - else if( rc ) - a->error = 1; - a->d.len = 0; - - return rc; -} - - -/**************** - * Read a byte from the iobuf; returns -1 on EOF - */ -int -iobuf_readbyte(IOBUF a) -{ - int c; - - /* nlimit does not work together with unget */ - /* nbytes is also not valid! */ - if( a->unget.buf ) { - if( a->unget.start < a->unget.len ) - return a->unget.buf[a->unget.start++]; - xfree(a->unget.buf); - a->unget.buf = NULL; - a->nofast &= ~2; - } - - if( a->nlimit && a->nbytes >= a->nlimit ) - return -1; /* forced EOF */ - - if( a->d.start < a->d.len ) { - c = a->d.buf[a->d.start++]; - } - else if( (c=underflow(a)) == -1 ) - return -1; /* EOF */ - - a->nbytes++; - return c; -} - - -int -iobuf_read(IOBUF a, byte *buf, unsigned buflen ) -{ - int c, n; - - if( a->unget.buf || a->nlimit ) { - /* handle special cases */ - for(n=0 ; n < buflen; n++ ) { - if( (c = iobuf_readbyte(a)) == -1 ) { - if( !n ) - return -1; /* eof */ - break; - } - else - if( buf ) *buf = c; - if( buf ) buf++; - } - return n; - } - - n = 0; - do { - if( n < buflen && a->d.start < a->d.len ) { - unsigned size = a->d.len - a->d.start; - if( size > buflen - n ) - size = buflen - n; - if( buf ) - memcpy( buf, a->d.buf + a->d.start, size ); - n += size; - a->d.start += size; - if( buf ) - buf += size; - } - if( n < buflen ) { - if( (c=underflow(a)) == -1 ) { - a->nbytes += n; - return n? n : -1/*EOF*/; - } - if( buf ) - *buf++ = c; - n++; - } - } while( n < buflen ); - a->nbytes += n; - return n; -} - - -/**************** - * Have a look at the iobuf. - * NOTE: This only works in special cases. - */ -int -iobuf_peek(IOBUF a, byte *buf, unsigned buflen ) -{ - int n=0; - - if( a->filter_eof ) - return -1; - - if( !(a->d.start < a->d.len) ) { - if( underflow(a) == -1 ) - return -1; - /* and unget this character */ - assert(a->d.start == 1); - a->d.start = 0; - } - - for(n=0 ; n < buflen && (a->d.start+n) < a->d.len ; n++, buf++ ) - *buf = a->d.buf[n]; - return n; -} - - - - -int -iobuf_writebyte(IOBUF a, unsigned c) -{ - - if( a->directfp ) - BUG(); - - if( a->d.len == a->d.size ) - if( iobuf_flush(a) ) - return -1; - - assert( a->d.len < a->d.size ); - a->d.buf[a->d.len++] = c; - return 0; -} - - -int -iobuf_write(IOBUF a, byte *buf, unsigned buflen ) -{ - - if( a->directfp ) - BUG(); - - do { - if( buflen && a->d.len < a->d.size ) { - unsigned size = a->d.size - a->d.len; - if( size > buflen ) size = buflen; - memcpy( a->d.buf + a->d.len, buf, size ); - buflen -= size; - buf += size; - a->d.len += size; - } - if( buflen ) { - if( iobuf_flush(a) ) - return -1; - } - } while( buflen ); - return 0; -} - - -int -iobuf_writestr(IOBUF a, const char *buf ) -{ - for( ; *buf; buf++ ) - if( iobuf_writebyte(a, *buf) ) - return -1; - return 0; -} - - - -/**************** - * copy the contents of TEMP to A. - */ -int -iobuf_write_temp( IOBUF a, IOBUF temp ) -{ - while( temp->chain ) - pop_filter( temp, temp->filter, NULL ); - return iobuf_write(a, temp->d.buf, temp->d.len ); -} - -/**************** - * copy the contents of the temp io stream to BUFFER. - */ -size_t -iobuf_temp_to_buffer( IOBUF a, byte *buffer, size_t buflen ) -{ - size_t n = a->d.len; - - if( n > buflen ) - n = buflen; - memcpy( buffer, a->d.buf, n ); - return n; -} - - -/**************** - * Call this function to terminate processing of the temp stream - * without closing it. This removes all filters from the stream - * makes sure that iobuf_get_temp_{buffer,length}() returns correct - * values. - */ -void -iobuf_flush_temp( IOBUF temp ) -{ - while( temp->chain ) - pop_filter( temp, temp->filter, NULL ); -} - - -/**************** - * Set a limit on how many bytes may be read from the input stream A. - * Setting the limit to 0 disables this feature. - */ -void -iobuf_set_limit( IOBUF a, off_t nlimit ) -{ - if( nlimit ) - a->nofast |= 1; - else - a->nofast &= ~1; - a->nlimit = nlimit; - a->ntotal += a->nbytes; - a->nbytes = 0; -} - - - -/* Return the length of an open file A. IF OVERFLOW is not NULL it - will be set to true if the file is larger than what off_t can cope - with. The function return 0 on error or on overflow condition. */ -off_t -iobuf_get_filelength (IOBUF a, int *overflow ) -{ - struct stat st; - - if (overflow) - *overflow = 0; - - if( a->directfp ) { - FILE *fp = a->directfp; - - if( !fstat(fileno(fp), &st) ) - return st.st_size; - log_error("fstat() failed: %s\n", strerror(errno) ); - return 0; - } - - /* Hmmm: file_filter may have already been removed */ - for( ; a; a = a->chain ) - if( !a->chain && a->filter == file_filter ) { - file_filter_ctx_t *b = a->filter_ov; - FILEP_OR_FD fp = b->fp; - -#if defined(HAVE_DOSISH_SYSTEM) && !defined(FILE_FILTER_USES_STDIO) - ulong size; - static int (* __stdcall get_file_size_ex) - (void *handle, LARGE_INTEGER *size); - static int get_file_size_ex_initialized; - - if (!get_file_size_ex_initialized) - { - void *handle; - - handle = dlopen ("kernel32.dll", RTLD_LAZY); - if (handle) - { - get_file_size_ex = dlsym (handle, "GetFileSizeEx"); - if (!get_file_size_ex) - dlclose (handle); - } - get_file_size_ex_initialized = 1; - } - - if (get_file_size_ex) - { - /* This is a newer system with GetFileSizeEx; we use - this then becuase it seem that GetFileSize won't - return a proper error in case a file is larger than - 4GB. */ - LARGE_INTEGER size; - - if (get_file_size_ex (fp, &size)) - { - if (!size.u.HighPart) - return size.u.LowPart; - if (overflow) - *overflow = 1; - return 0; - } - } - else - { - if ((size=GetFileSize (fp, NULL)) != 0xffffffff) - return size; - } - log_error ("GetFileSize for handle %p failed: %s\n", - fp, w32_strerror (0)); -#else - if( !fstat(my_fileno(fp), &st) ) - return st.st_size; - log_error("fstat() failed: %s\n", strerror(errno) ); -#endif - break; - } - - return 0; -} - - -/* Return the file descriptor of the underlying file or -1 if it is - not available. */ -int -iobuf_get_fd (IOBUF a) -{ - if (a->directfp) - return fileno ( (FILE*)a->directfp ); - - for ( ; a; a = a->chain ) - if (!a->chain && a->filter == file_filter) - { - file_filter_ctx_t *b = a->filter_ov; - FILEP_OR_FD fp = b->fp; - - return my_fileno (fp); - } - - return -1; -} - - -/**************** - * Tell the file position, where the next read will take place - */ -off_t -iobuf_tell( IOBUF a ) -{ - return a->ntotal + a->nbytes; -} - - -#if !defined(HAVE_FSEEKO) && !defined(fseeko) - -#ifdef HAVE_LIMITS_H -# include -#endif -#ifndef LONG_MAX -# define LONG_MAX ((long) ((unsigned long) -1 >> 1)) -#endif -#ifndef LONG_MIN -# define LONG_MIN (-1 - LONG_MAX) -#endif - -/**************** - * A substitute for fseeko, for hosts that don't have it. - */ -static int -fseeko( FILE *stream, off_t newpos, int whence ) -{ - while( newpos != (long) newpos ) { - long pos = newpos < 0 ? LONG_MIN : LONG_MAX; - if( fseek( stream, pos, whence ) != 0 ) - return -1; - newpos -= pos; - whence = SEEK_CUR; - } - return fseek( stream, (long)newpos, whence ); -} -#endif - -/**************** - * This is a very limited implementation. It simply discards all internal - * buffering and removes all filters but the first one. - */ -int -iobuf_seek( IOBUF a, off_t newpos ) -{ - file_filter_ctx_t *b = NULL; - - if( a->directfp ) { - FILE *fp = a->directfp; - if( fseeko( fp, newpos, SEEK_SET ) ) { - log_error("can't seek: %s\n", strerror(errno) ); - return -1; - } - clearerr(fp); - } - else { - for( ; a; a = a->chain ) { - if( !a->chain && a->filter == file_filter ) { - b = a->filter_ov; - break; - } - } - if( !a ) - return -1; -#ifdef FILE_FILTER_USES_STDIO - if( fseeko( b->fp, newpos, SEEK_SET ) ) { - log_error("can't fseek: %s\n", strerror(errno) ); - return -1; - } -#else -#ifdef HAVE_DOSISH_SYSTEM - if (SetFilePointer (b->fp, newpos, NULL, FILE_BEGIN) == 0xffffffff ) { - log_error ("SetFilePointer failed on handle %p: %s\n", - b->fp, w32_strerror (0)); - return -1; - } -#else - if ( lseek (b->fp, newpos, SEEK_SET) == (off_t)-1 ) { - log_error("can't lseek: %s\n", strerror(errno) ); - return -1; - } -#endif -#endif - } - a->d.len = 0; /* discard buffer */ - a->d.start = 0; - a->nbytes = 0; - a->nlimit = 0; - a->nofast &= ~1; - a->ntotal = newpos; - a->error = 0; - /* remove filters, but the last */ - if( a->chain ) - log_debug("pop_filter called in iobuf_seek - please report\n"); - while( a->chain ) - pop_filter( a, a->filter, NULL ); - - return 0; -} - - - - - - -/**************** - * Retrieve the real filename - */ -const char * -iobuf_get_real_fname( IOBUF a ) -{ - if( a->real_fname ) - return a->real_fname; - - /* the old solution */ - for( ; a; a = a->chain ) - if( !a->chain && a->filter == file_filter ) { - file_filter_ctx_t *b = a->filter_ov; - return b->print_only_name? NULL : b->fname; - } - - return NULL; -} - - -/**************** - * Retrieve the filename - */ -const char * -iobuf_get_fname( IOBUF a ) -{ - for( ; a; a = a->chain ) - if( !a->chain && a->filter == file_filter ) { - file_filter_ctx_t *b = a->filter_ov; - return b->fname; - } - - return NULL; -} - - -/**************** - * enable partial block mode as described in the OpenPGP draft. - * LEN is the first length byte on read, but ignored on writes. - */ -void -iobuf_set_partial_block_mode( IOBUF a, size_t len ) -{ - block_filter_ctx_t *ctx = xmalloc_clear( sizeof *ctx ); - - assert( a->use == 1 || a->use == 2 ); - ctx->use = a->use; - if( !len ) { - if( a->use == 1 ) - log_debug("pop_filter called in set_partial_block_mode" - " - please report\n"); - pop_filter(a, block_filter, NULL ); - } - else { - ctx->partial = 1; - ctx->size = 0; - ctx->first_c = len; - iobuf_push_filter(a, block_filter, ctx ); - } -} - - -/**************** - * Same as fgets() but if the buffer is too short a larger one will - * be allocated up to some limit *max_length. - * A line is considered a byte stream ending in a LF. - * Returns the length of the line. EOF is indicated by a line of - * length zero. The last LF may be missing due to an EOF. - * is max_length is zero on return, the line has been truncated. - * - * Note: The buffer is allocated with enough space to append a CR,LF,EOL - */ -unsigned -iobuf_read_line( IOBUF a, byte **addr_of_buffer, - unsigned *length_of_buffer, unsigned *max_length ) -{ - int c; - char *buffer = *addr_of_buffer; - unsigned length = *length_of_buffer; - unsigned nbytes = 0; - unsigned maxlen = *max_length; - char *p; - - if( !buffer ) { /* must allocate a new buffer */ - length = 256; - buffer = xmalloc( length ); - *addr_of_buffer = buffer; - *length_of_buffer = length; - } - - length -= 3; /* reserve 3 bytes (cr,lf,eol) */ - p = buffer; - while( (c=iobuf_get(a)) != -1 ) { - if( nbytes == length ) { /* increase the buffer */ - if( length > maxlen ) { /* this is out limit */ - /* skip the rest of the line */ - while( c != '\n' && (c=iobuf_get(a)) != -1 ) - ; - *p++ = '\n'; /* always append a LF (we have reserved space) */ - nbytes++; - *max_length = 0; /* indicate truncation */ - break; - } - length += 3; /* correct for the reserved byte */ - length += length < 1024? 256 : 1024; - buffer = xrealloc( buffer, length ); - *addr_of_buffer = buffer; - *length_of_buffer = length; - length -= 3; /* and reserve again */ - p = buffer + nbytes; - } - *p++ = c; - nbytes++; - if( c == '\n' ) - break; - } - *p = 0; /* make sure the line is a string */ - - return nbytes; -} - -/* This is the non iobuf specific function */ -int -iobuf_translate_file_handle ( int fd, int for_write ) -{ -#ifdef _WIN32 - { - int x; - - if ( fd <= 2 ) - return fd; /* do not do this for error, stdin, stdout, stderr */ - - x = _open_osfhandle ( fd, for_write? 1:0 ); - if (x==-1 ) - log_error ("failed to translate osfhandle %p\n", (void*)fd ); - else { - /*log_info ("_open_osfhandle %p yields %d%s\n", - (void*)fd, x, for_write? " for writing":"" );*/ - fd = x; - } - } -#endif - return fd; -} - -static int -translate_file_handle ( int fd, int for_write ) -{ -#ifdef _WIN32 -#ifdef FILE_FILTER_USES_STDIO - fd = iobuf_translate_file_handle (fd, for_write); -#else - { - int x; - - if ( fd == 0 ) - x = (int)GetStdHandle (STD_INPUT_HANDLE); - else if (fd == 1) - x = (int)GetStdHandle (STD_OUTPUT_HANDLE); - else if (fd == 2) - x = (int)GetStdHandle (STD_ERROR_HANDLE); - else - x = fd; - - if (x == -1) - log_debug ("GetStdHandle(%d) failed: %s\n", - fd, w32_strerror (0)); - - fd = x; - } -#endif -#endif - return fd; -} - - -void -iobuf_skip_rest(IOBUF a, unsigned long n, int partial) -{ - if ( partial ) { - for (;;) { - if (a->nofast || a->d.start >= a->d.len) { - if (iobuf_readbyte (a) == -1) { - break; - } - } else { - unsigned long count = a->d.len - a->d.start; - a->nbytes += count; - a->d.start = a->d.len; - } - } - } else { - unsigned long remaining = n; - while (remaining > 0) { - if (a->nofast || a->d.start >= a->d.len) { - if (iobuf_readbyte (a) == -1) { - break; - } - --remaining; - } else { - unsigned long count = a->d.len - a->d.start; - if (count > remaining) { - count = remaining; - } - a->nbytes += count; - a->d.start += count; - remaining -= count; - } - } - } -} diff -uNr a/mpi/logger.c b/mpi/logger.c --- a/mpi/logger.c a4ca272e00eba069786cb1edfb3f7054c5b31630a22ae66c012878d4bcee96b11298141730589f0a0ddb04eeff1c2f4eef5a25d88447226f32eaa5346595ea96 +++ b/mpi/logger.c false @@ -1,262 +0,0 @@ -/* logger.c - log functions - * Copyright (C) 1998, 1999 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 3 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, see . - */ - -#include -#include -#include -#include -#include -#include - -#include "util.h" - -static char pidstring[15]; -static char *pgm_name; -static int errorcount; -static int strict; -static FILE *logfp; - -/**************** - * Set the logfile to use (not yet implemneted) or, if logfile is NULL, - * the Fd where logoutputs should go. - */ -void -log_set_logfile( const char *name, int fd ) -{ - if( name ) - BUG(); - - if( logfp && logfp != stderr && logfp != stdout ) - fclose( logfp ); - if( fd == 1 ) - logfp = stdout; - else if( fd == 2 ) - logfp = stderr; - else - logfp = fdopen( fd, "a" ); - if( !logfp ) { - logfp = stderr; - log_fatal("can't open fd %d for logging: %s\n", fd, strerror(errno)); - } -} - -FILE * -log_stream() -{ - if( !logfp ) - logfp = stderr; - return logfp; -} - - -void -log_set_name( const char *name ) -{ - xfree(pgm_name); - if( name ) - pgm_name = xstrdup(name); - else - pgm_name = NULL; -} - -const char * -log_get_name(void) -{ - return pgm_name? pgm_name : ""; -} - - -void -log_set_pid( int pid ) -{ - if( pid ) - sprintf(pidstring,"[%u]", (unsigned)pid ); - else - *pidstring = 0; -} - -int -log_get_errorcount( int clear) -{ - int n = errorcount; - if( clear ) - errorcount = 0; - return n; -} - -void -log_inc_errorcount() -{ - errorcount++; -} - -int -log_set_strict(int val) -{ - int old=strict; - strict=val; - return old; -} - -void -g10_log_print_prefix(const char *text) -{ - if( !logfp ) - logfp = stderr; - if( pgm_name ) - fprintf(logfp, "%s%s: %s", pgm_name, pidstring, text ); - else - fprintf(logfp, "?%s: %s", pidstring, text ); -#ifdef __riscos__ - fflush( logfp ); -#endif /* __riscos__ */ -} - - -void -g10_log_info( const char *fmt, ... ) -{ - va_list arg_ptr ; - - g10_log_print_prefix(""); - va_start( arg_ptr, fmt ) ; - vfprintf(logfp,fmt,arg_ptr) ; - va_end(arg_ptr); -#ifdef __riscos__ - fflush( logfp ); -#endif /* __riscos__ */ -} - - -void -g10_log_warning( const char *fmt, ... ) -{ - va_list arg_ptr ; - - if(strict) - { - errorcount++; - g10_log_print_prefix(_("ERROR: ")); - } - else - g10_log_print_prefix(_("WARNING: ")); - - va_start( arg_ptr, fmt ) ; - vfprintf(logfp,fmt,arg_ptr) ; - va_end(arg_ptr); -#ifdef __riscos__ - fflush( logfp ); -#endif /* __riscos__ */ -} - - -void -g10_log_error( const char *fmt, ... ) -{ - va_list arg_ptr ; - - g10_log_print_prefix(""); - va_start( arg_ptr, fmt ) ; - vfprintf(logfp,fmt,arg_ptr) ; - va_end(arg_ptr); - errorcount++; -#ifdef __riscos__ - fflush( logfp ); -#endif /* __riscos__ */ -} - - -void -g10_log_fatal( const char *fmt, ... ) -{ - va_list arg_ptr ; - - g10_log_print_prefix("fatal: "); - va_start( arg_ptr, fmt ) ; - vfprintf(logfp,fmt,arg_ptr) ; - va_end(arg_ptr); - secmem_dump_stats(); -#ifdef __riscos__ - fflush( logfp ); -#endif /* __riscos__ */ - exit(2); -} - -void -g10_log_bug( const char *fmt, ... ) -{ - va_list arg_ptr ; - - putc('\n', stderr ); - g10_log_print_prefix("Ohhhh jeeee: "); - va_start( arg_ptr, fmt ) ; - vfprintf(stderr,fmt,arg_ptr) ; - va_end(arg_ptr); - fflush(stderr); - secmem_dump_stats(); - abort(); -} - -#if defined (__riscos__) \ - || ( __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 5 )) -void -g10_log_bug0( const char *file, int line, const char *func ) -{ - log_bug(_("... this is a bug (%s:%d:%s)\n"), file, line, func ); -} -#else -void -g10_log_bug0( const char *file, int line ) -{ - log_bug(_("you found a bug ... (%s:%d)\n"), file, line); -} -#endif - -void -g10_log_debug( const char *fmt, ... ) -{ - va_list arg_ptr ; - - g10_log_print_prefix("DBG: "); - va_start( arg_ptr, fmt ) ; - vfprintf(logfp,fmt,arg_ptr) ; - va_end(arg_ptr); -#ifdef __riscos__ - fflush( logfp ); -#endif /* __riscos__ */ -} - - - -void -g10_log_hexdump( const char *text, const char *buf, size_t len ) -{ - int i; - - g10_log_print_prefix(text); - for(i=0; i < len; i++ ) - fprintf(logfp, " %02X", ((const byte*)buf)[i] ); - fputc('\n', logfp); -#ifdef __riscos__ - fflush( logfp ); -#endif /* __riscos__ */ -} - - - diff -uNr a/mpi/Makefile b/mpi/Makefile --- a/mpi/Makefile d946187edc8013acec997499092eb30464487922925230fbfe5d21ea6cd76320625e947b8f47cf19ec4c47987cc5dcd0c22e6dbfb4b40e4b0f93189c29b5bfc9 +++ b/mpi/Makefile 50746fe355731da38601bcf9cee34ddba73d8c28b950912f6a4fbd5d2f614cbeb8a245f4ec0e9e97ee7d21aa0a39cf1337a519b78eb81b27c77a750ea893ba8b @@ -17,6 +17,7 @@ $(PROGRAM): $(OBJECTS) ar rcs $(DIST)/$(PROGRAM) $(OBJECTS) + #ld -o $(DIST)/$(PROGRAM).o $(OBJECTS) -lc clean : rm -rf nul core *flymake* $(BUILD)/*.o $(DIST)/$(PROGRAM) *~ bin/* diff -uNr a/mpi/memory.c b/mpi/memory.c --- a/mpi/memory.c 9dea2170de57ac92123d3dac0fd5930bc5c1a5ac88ca1c2fda88c8555091a38e5862fd7ac5bced9393349f66ab970707b27d759fe0041f358a0d205e066ecde0 +++ b/mpi/memory.c 4e3dcb1355d54a4a2cc9eebddfeeab38e3edd49f20ef18a7ddca12cb57497820ae200708b20fa697cec54e4b65cd8ad3f2487add90defc420eb33b94ab460304 @@ -1,23 +1,26 @@ /* memory.c - memory allocation - * Copyright (C) 1998, 1999, 2001, 2005 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . - * - * - * We use our own memory allocation functions instead of plain malloc(), + * along with this program. If not, see . + */ + +/* We use our own memory allocation functions instead of plain malloc(), * so that we can provide some special enhancements: * a) functions to provide memory from a secure memory. * b) by looking at the requested allocation size we @@ -27,17 +30,16 @@ * d) memory checking if compiled with M_GUARD */ -#include #include #include -#include #include +#include +#include "knobs.h" #include "types.h" #include "memory.h" #include "util.h" - #define MAGIC_NOR_BYTE 0x55 #define MAGIC_SEC_BYTE 0xcc #define MAGIC_END_BYTE 0xaa @@ -76,14 +78,10 @@ #define FNAMEXM(a) m_debug_ ##a #define FNAMEPRT , const char *info #define FNAMEARG , info -#ifndef __riscos__ + #define store_len(p,n,m) do { add_entry(p,n,m, \ info, __FUNCTION__); } while(0) #else -#define store_len(p,n,m) do { add_entry(p,n,m, \ - info, __func__ ); } while(0) -#endif -#else #define FNAME(a) m_ ##a #define FNAMEX(a) x ##a #define FNAMEXM(a) xm ##a @@ -337,11 +335,7 @@ for( e = memtbl, n = 0; n < memtbl_len; n++, e++ ) { if( e->inuse ) { -#ifndef __riscos__ check_mem(e->user_p-4-EXTRA_ALIGN, info); -#else - check_mem((const byte *) e->user_p-4-EXTRA_ALIGN, info); -#endif } } } @@ -411,10 +405,7 @@ log_info ("(this may be caused by too many secret keys used " "simultaneously or due to excessive large key sizes)\n"); } -#if defined(M_GUARD) && defined(__riscos__) - abort(); -#endif - exit (2); + exit(2); } /**************** @@ -678,4 +669,3 @@ out_of_core (nbytes, 1); return xmalloc_secure_clear (nbytes); } - diff -uNr a/mpi/mpi-add.c b/mpi/mpi-add.c --- a/mpi/mpi-add.c ffcea4f2389eb4919df50fc60423606d2835e4be6a853fa885754cf04c397fe96d4a688eccd591c60bc687846ae1e230304d3554b3e504e2e53662270342c591 +++ b/mpi/mpi-add.c 956452037539c9b7f45834858a92e436fb65d7482b6b44d2624e2279e9203b59d992a0d405f778638b5e03adb9f51a545d5c5b55cc31d59453523fbd75f2be5b @@ -1,35 +1,29 @@ /* mpi-add.c - MPI functions - * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. - * Copyright (C) 1994, 1996 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . - * - * Note: This code is heavily based on the GNU MP Library. - * Actually it's the same code with only minor changes in the - * way the data is stored; this is to support the abstraction - * of an optional secure memory allocation which may be used - * to avoid revealing of sensitive data due to paging etc. - * The GNU MP Library itself is published under the LGPL; - * however I decided to publish this code under the plain GPL. + * along with this program. If not, see . */ -#include #include #include +#include "knobs.h" #include "mpi-internal.h" diff -uNr a/mpi/mpi-bit.c b/mpi/mpi-bit.c --- a/mpi/mpi-bit.c a48f6dcd95712d600a89efae6dc7425b5cade2869b48aa49d6d6fc5c42d63ec462e2a1fcb08cb1df5468a9a5ad8c8dd419dc7fb8f5758ad0d93007960b19a153 +++ b/mpi/mpi-bit.c d3ab216d028e41835d4511cd451a4d774b268dc38a17322dcdeeed542a949e5dbaeecbb377daa353b7e31ada19ebe05247ff696ca571d2862dd26c631aa124ee @@ -1,26 +1,30 @@ /* mpi-bit.c - MPI bit level fucntions - * Copyright (C) 1998, 1999 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . + * along with this program. If not, see . */ -#include #include #include #include + +#include "knobs.h" #include "mpi-internal.h" #include "longlong.h" diff -uNr a/mpi/mpi-cmp.c b/mpi/mpi-cmp.c --- a/mpi/mpi-cmp.c 83c978461ca2fc606eab05035db9a67d600396f013e5ce0db8cc110d8881e9be513d540b27daecc8b0293178d7ab27ee52f5c947a0b9976863b9094f82ebd522 +++ b/mpi/mpi-cmp.c c16f3eacac322384cd8d5ac67d1a3f287e5a32ea9cd3a8af650f97952739d9bc361bc1808390c5b1e6f914fc119bbcdab020f7b403b9adb2a03593569da5326d @@ -1,25 +1,29 @@ /* mpi-cmp.c - MPI functions - * Copyright (C) 1998, 1999 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . + * along with this program. If not, see . */ -#include #include #include + +#include "knobs.h" #include "mpi-internal.h" int diff -uNr a/mpi/mpicoder.c b/mpi/mpicoder.c --- a/mpi/mpicoder.c 6a4860ea723098a2e2ba703d8748f6d26c22d1ae72647a5ccca67ab93976390b0d992ba870796be3da3b736b1a11b36f700a93214ae5926ec2652d1edee390a3 +++ b/mpi/mpicoder.c 86d94794c314885a11e11adbaeb4f4c4e4576bdecd18e35fa758ac471d151322e051d57488df4910bdf315b1670f5b3e0d6e1423856209fc6ec05cae1704e6b8 @@ -1,31 +1,33 @@ /* mpicoder.c - Coder for the external representation of MPIs - * Copyright (C) 1998, 1999, 2005 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . + * along with this program. If not, see . */ -#include #include #include #include #include +#include "knobs.h" #include "mpi.h" #include "mpi-internal.h" -#include "iobuf.h" #include "memory.h" #include "util.h" @@ -35,110 +37,6 @@ #define MAX_EXTERN_MPI_BITS 16384 -/**************** - * write an mpi to out. - */ -int -mpi_write( IOBUF out, MPI a ) -{ - int rc; - unsigned nbits = mpi_get_nbits(a); - byte *p, *buf; - unsigned n; - - if( nbits > MAX_EXTERN_MPI_BITS ) - log_bug("mpi_encode: mpi too large (%u bits)\n", nbits); - - iobuf_put(out, (nbits >>8) ); - iobuf_put(out, (nbits) ); - - p = buf = mpi_get_buffer( a, &n, NULL ); - rc = iobuf_write( out, p, n ); - xfree(buf); - return rc; -} - - -/**************** - * Read an external representation of an mpi and return the MPI - * The external format is a 16 bit unsigned value stored in network byte order, - * giving the number of bits for the following integer. The integer is stored - * with MSB first (left padded with zeroes to align on a byte boundary). - */ -MPI -#ifdef M_DEBUG -mpi_debug_read(IOBUF inp, unsigned *ret_nread, int secure, const char *info) -#else -mpi_read(IOBUF inp, unsigned *ret_nread, int secure) -#endif -{ - int c, i, j; - unsigned int nmax = *ret_nread; - unsigned nbits, nbytes, nlimbs, nread=0; - mpi_limb_t a; - MPI val = NULL; - - if (nread == nmax) - goto overflow; - if( (c = iobuf_get(inp)) == -1 ) - goto leave; - nread++; - nbits = c << 8; - - if (nread == nmax) - goto overflow; - if( (c = iobuf_get(inp)) == -1 ) - goto leave; - nread++; - nbits |= c; - - if( nbits > MAX_EXTERN_MPI_BITS ) { - log_error("mpi too large for this implementation (%u bits)\n", nbits); - goto leave; - } - - nbytes = (nbits+7) / 8; - nlimbs = (nbytes+BYTES_PER_MPI_LIMB-1) / BYTES_PER_MPI_LIMB; -#ifdef M_DEBUG - val = secure? mpi_debug_alloc_secure( nlimbs, info ) - : mpi_debug_alloc( nlimbs, info ); -#else - val = secure? mpi_alloc_secure( nlimbs ) - : mpi_alloc( nlimbs ); -#endif - i = BYTES_PER_MPI_LIMB - nbytes % BYTES_PER_MPI_LIMB; - i %= BYTES_PER_MPI_LIMB; - val->nbits = nbits; - j= val->nlimbs = nlimbs; - val->sign = 0; - for( ; j > 0; j-- ) { - a = 0; - for(; i < BYTES_PER_MPI_LIMB; i++ ) { - if (nread == nmax) { -#ifdef M_DEBUG - mpi_debug_free (val); -#else - mpi_free (val); -#endif - val = NULL; - goto overflow; - } - a <<= 8; - a |= iobuf_get(inp) & 0xff; nread++; - } - i = 0; - val->d[j-1] = a; - } - - leave: - *ret_nread = nread; - return val; - overflow: - log_error ("mpi larger than indicated length (%u bytes)\n", nmax); - *ret_nread = nread; - return val; -} - MPI mpi_read_from_buffer(byte *buffer, unsigned int *ret_nread, int secure) @@ -309,6 +207,7 @@ } +/* void g10_log_mpidump( const char *text, MPI a ) { @@ -318,31 +217,7 @@ mpi_print(fp, a, 1 ); fputc('\n', fp); } - -/**************** - * Special function to get the low 8 bytes from an mpi. - * This can be used as a keyid; KEYID is an 2 element array. - * Return the low 4 bytes. - */ -u32 -mpi_get_keyid( MPI a, u32 *keyid ) -{ -#if BYTES_PER_MPI_LIMB == 4 - if( keyid ) { - keyid[0] = a->nlimbs >= 2? a->d[1] : 0; - keyid[1] = a->nlimbs >= 1? a->d[0] : 0; - } - return a->nlimbs >= 1? a->d[0] : 0; -#elif BYTES_PER_MPI_LIMB == 8 - if( keyid ) { - keyid[0] = a->nlimbs? (u32)(a->d[0] >> 32) : 0; - keyid[1] = a->nlimbs? (u32)(a->d[0] & 0xffffffff) : 0; - } - return a->nlimbs? (u32)(a->d[0] & 0xffffffff) : 0; -#else -#error Make this function work with other LIMB sizes -#endif -} +*/ /**************** diff -uNr a/mpi/mpi-div.c b/mpi/mpi-div.c --- a/mpi/mpi-div.c b320709b57b3cf0c00bc98277b037494c62fed93fd99bca0412ea633f8662844d35ed62990cbe1fc02a47dee5795d3a7b6b401440f6e80a8a00243868815c06a +++ b/mpi/mpi-div.c c35f9c1dd65bd4564ac028b876d7351cd30f72780afd03fd6a764b0fccfe57c10ae496d64407f04953364788fa2824759239cc598a44466537a379e57e0bad8c @@ -1,34 +1,29 @@ /* mpi-div.c - MPI functions - * Copyright (C) 1994, 1996 Free Software Foundation, Inc. - * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . - * - * Note: This code is heavily based on the GNU MP Library. - * Actually it's the same code with only minor changes in the - * way the data is stored; this is to support the abstraction - * of an optional secure memory allocation which may be used - * to avoid revealing of sensitive data due to paging etc. - * The GNU MP Library itself is published under the LGPL; - * however I decided to publish this code under the plain GPL. + * along with this program. If not, see . */ -#include #include #include + +#include "knobs.h" #include "mpi-internal.h" #include "longlong.h" diff -uNr a/mpi/mpi-gcd.c b/mpi/mpi-gcd.c --- a/mpi/mpi-gcd.c f582de56ee9bc1d4cf2eea35bdabdcd61e0cc93dd186950709e32fc707d2f769669bafdcfbf2ad074596ba474bf1e7af5e29ea81cff2316acbfcd27a0f93f185 +++ b/mpi/mpi-gcd.c 6dff8d166d0d34557bbaf7e739b83aec2f73e2383424d08ce2d10c6a1609095381a27b8c38029950548942c3d4b5faadcbe62322bc623154fa1911b3eaa3fe38 @@ -1,25 +1,29 @@ /* mpi-gcd.c - MPI functions - * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . + * along with this program. If not, see . */ -#include #include #include + +#include "knobs.h" #include "mpi-internal.h" /**************** diff -uNr a/mpi/mpih-add1.c b/mpi/mpih-add1.c --- a/mpi/mpih-add1.c fb06ea790bd2b2c18013b3fb51f05a5c1577f45fdd67644e7745c3373fa26fa90de8f30fd9221e978ba9676423ed1c4c27c0407f22a50e10f216ae9bbf4ac3f3 +++ b/mpi/mpih-add1.c 15e95347519c17744e8346a37975e5b482e833625862c1e01629e07d3e80cdbdee590f6bcbed8214092d395979e38ef50cefe58b2dc64472a2b3860bc374ee2d @@ -1,34 +1,29 @@ /* mpihelp-add_1.c - MPI helper functions - * Copyright (C) 1994, 1996, 1997, 1998, - * 2000 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . - * - * Note: This code is heavily based on the GNU MP Library. - * Actually it's the same code with only minor changes in the - * way the data is stored; this is to support the abstraction - * of an optional secure memory allocation which may be used - * to avoid revealing of sensitive data due to paging etc. - * The GNU MP Library itself is published under the LGPL; - * however I decided to publish this code under the plain GPL. + * along with this program. If not, see . */ -#include #include #include + +#include "knobs.h" #include "mpi-internal.h" #include "longlong.h" diff -uNr a/mpi/mpih-cmp.c b/mpi/mpih-cmp.c --- a/mpi/mpih-cmp.c 88a21583524c37a7febb2eedaf38f0942183a201ee8df8b9e04a8098e892dd88b7f8566e40cc8bf042d5713e2f78886526cc23de79c61463e7763685f280c37e +++ b/mpi/mpih-cmp.c e0f453becb6712c9a4c33bf2969cccefbf5097f29992a486d12726b509d90a3f2f91e53729feb9c2f3b8452e5c2a2348b409ceeff253adefe2e5a627e1b19cc1 @@ -1,35 +1,29 @@ /* mpihelp-sub.c - MPI helper functions - * Copyright (C) 1994, 1996 Free Software Foundation, Inc. - * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . - * - * Note: This code is heavily based on the GNU MP Library. - * Actually it's the same code with only minor changes in the - * way the data is stored; this is to support the abstraction - * of an optional secure memory allocation which may be used - * to avoid revealing of sensitive data due to paging etc. - * The GNU MP Library itself is published under the LGPL; - * however I decided to publish this code under the plain GPL. + * along with this program. If not, see . */ -#include #include #include +#include "knobs.h" #include "mpi-internal.h" /**************** diff -uNr a/mpi/mpih-div.c b/mpi/mpih-div.c --- a/mpi/mpih-div.c aa4e2efa1e53416aedf9cbf7a73a00fbde7a8266f532002dc046b0b995cf49d060496c45c74944ec3f41cf0dd441884ff6230260978fcbf227903eb7213b074a +++ b/mpi/mpih-div.c 62bde6ddf9feeccd5c2afb41fb0b86b32b558cb48d58107ae9ab1ed46c3769731c0804bd460565b85e731146c8d942e082ee12b69fcffd1b973a08f79bcae4d0 @@ -1,34 +1,29 @@ /* mpihelp-div.c - MPI helper functions - * Copyright (C) 1994, 1996 Free Software Foundation, Inc. - * Copyright (C) 1998, 1999 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . - * - * Note: This code is heavily based on the GNU MP Library. - * Actually it's the same code with only minor changes in the - * way the data is stored; this is to support the abstraction - * of an optional secure memory allocation which may be used - * to avoid revealing of sensitive data due to paging etc. - * The GNU MP Library itself is published under the LGPL; - * however I decided to publish this code under the plain GPL. + * along with this program. If not, see . */ -#include #include #include + +#include "knobs.h" #include "mpi-internal.h" #include "longlong.h" diff -uNr a/mpi/mpih-lshift.c b/mpi/mpih-lshift.c --- a/mpi/mpih-lshift.c 3222bfc241fa6104936cc585fda392f220d88031fa0fdf460bb201a3aa7295e6d1dc75007bf53d2e501734d9faaa31934eed944ce7452a6aa3afcd3a333d3c13 +++ b/mpi/mpih-lshift.c 25e8efcbae822d6b21202c4e4d2a1d1d0370c3676af7518ea81c8a59d87e0df7caf2b81e43f307ef8910bc63d4c482cc6f94794b73ea68c19e69391613405eba @@ -1,33 +1,29 @@ /* mpihelp-lshift.c - MPI helper functions - * Copyright (C) 1994, 1996, 1998, 2001 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . - * - * Note: This code is heavily based on the GNU MP Library. - * Actually it's the same code with only minor changes in the - * way the data is stored; this is to support the abstraction - * of an optional secure memory allocation which may be used - * to avoid revealing of sensitive data due to paging etc. - * The GNU MP Library itself is published under the LGPL; - * however I decided to publish this code under the plain GPL. + * along with this program. If not, see . */ -#include #include #include + +#include "knobs.h" #include "mpi-internal.h" /* Shift U (pointed to by UP and USIZE digits long) CNT bits to the left diff -uNr a/mpi/mpih-mul1.c b/mpi/mpih-mul1.c --- a/mpi/mpih-mul1.c 86b925acdaedfaaf9c7f7ff783da4a049c62c8f63929bf288fdc8e4760dc9b451440ed5ed5f8549e8b2ccbd4f00175f068de9dc337eedfd8fad8348d21f3ed13 +++ b/mpi/mpih-mul1.c e8d6c90380880315a6bf877ba13b073a93159645c447b67723cc6b76ece8499c13758759085900049695be381076a06880c6b1721ebae6e36263eccbc56260c5 @@ -1,33 +1,29 @@ /* mpihelp-mul_1.c - MPI helper functions - * Copyright (C) 1994, 1996, 1997, 1998, 2001 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . - * - * Note: This code is heavily based on the GNU MP Library. - * Actually it's the same code with only minor changes in the - * way the data is stored; this is to support the abstraction - * of an optional secure memory allocation which may be used - * to avoid revealing of sensitive data due to paging etc. - * The GNU MP Library itself is published under the LGPL; - * however I decided to publish this code under the plain GPL. + * along with this program. If not, see . */ -#include #include #include + +#include "knobs.h" #include "mpi-internal.h" #include "longlong.h" diff -uNr a/mpi/mpih-mul2.c b/mpi/mpih-mul2.c --- a/mpi/mpih-mul2.c 340744f79d1466a916fca829c66f86915b808800bf3ebe2ccadaba1d5fd89ef5c5db486c94b0f01ace52f13d7a74784b68214499f5ac120ac8449fc9eb5c61c3 +++ b/mpi/mpih-mul2.c 95cd771c444012e1f8e329fc4a7687d1a0f5e3b2d0635c07d7c47913af09d55040478fef672766f5ccbf2fbbff74fea0b95f57d37bc4a3d0dcf3fd8c7f3288ab @@ -1,33 +1,29 @@ /* mpihelp-mul_2.c - MPI helper functions - * Copyright (C) 1994, 1996, 1997, 1998, 2001 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . - * - * Note: This code is heavily based on the GNU MP Library. - * Actually it's the same code with only minor changes in the - * way the data is stored; this is to support the abstraction - * of an optional secure memory allocation which may be used - * to avoid revealing of sensitive data due to paging etc. - * The GNU MP Library itself is published under the LGPL; - * however I decided to publish this code under the plain GPL. + * along with this program. If not, see . */ -#include #include #include + +#include "knobs.h" #include "mpi-internal.h" #include "longlong.h" diff -uNr a/mpi/mpih-mul3.c b/mpi/mpih-mul3.c --- a/mpi/mpih-mul3.c 683f47357b0f57e3dc50aefc32bdcd8c20e7a9a4c3dc48d3ba9e5715e12836b6ce53b8dff653bdb86cdd197daab9af7532def5bb06d861bdf48f4dc705ac6aa4 +++ b/mpi/mpih-mul3.c c86699c63f32a4627023a4ad8b89138fcbef21e066e98e73c8f652b62f521c67110ceb48121ef5f7a586745328e8777b8170699e1417d70fb54849c5dfe88811 @@ -1,33 +1,29 @@ /* mpihelp-mul_3.c - MPI helper functions - * Copyright (C) 1994, 1996, 1997, 1998, 2001 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . - * - * Note: This code is heavily based on the GNU MP Library. - * Actually it's the same code with only minor changes in the - * way the data is stored; this is to support the abstraction - * of an optional secure memory allocation which may be used - * to avoid revealing of sensitive data due to paging etc. - * The GNU MP Library itself is published under the LGPL; - * however I decided to publish this code under the plain GPL. + * along with this program. If not, see . */ -#include #include #include + +#include "knobs.h" #include "mpi-internal.h" #include "longlong.h" diff -uNr a/mpi/mpih-mul.c b/mpi/mpih-mul.c --- a/mpi/mpih-mul.c 2d6f3c1ecb3331cdfb54c9efa53246cac6a6dfa16465d2e354c6801974964229cb173e7aff19c4c92e896b8c65cfbc6da79ef03c20022772f5c299f1c3cbc063 +++ b/mpi/mpih-mul.c 8d2390541b928fc4b9e92c17766530734ce64b823a3aff6e648c0cfeef6367a9fc18a0de2754378b04dbd6072d862cecb447c372cefaad1d39d5d619b2ff6abd @@ -1,40 +1,34 @@ /* mpihelp-mul.c - MPI helper functions - * Copyright (C) 1994, 1996, 1998, 1999, - * 2000 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . - * - * Note: This code is heavily based on the GNU MP Library. - * Actually it's the same code with only minor changes in the - * way the data is stored; this is to support the abstraction - * of an optional secure memory allocation which may be used - * to avoid revealing of sensitive data due to paging etc. - * The GNU MP Library itself is published under the LGPL; - * however I decided to publish this code under the plain GPL. + * along with this program. If not, see . */ -#include #include #include #include + +#include "knobs.h" #include "mpi-internal.h" #include "longlong.h" - #define MPN_MUL_N_RECURSE(prodp, up, vp, size, tspace) \ do { \ if( (size) < KARATSUBA_THRESHOLD ) \ @@ -52,8 +46,6 @@ } while (0); - - /* Multiply the natural numbers u (pointed to by UP) and v (pointed to by VP), * both with SIZE limbs, and store the result at PRODP. 2 * SIZE limbs are * always stored. Return the most significant limb. diff -uNr a/mpi/mpih-rshift.c b/mpi/mpih-rshift.c --- a/mpi/mpih-rshift.c b98cf2fb49b284c7ffda191d6e1a336e87bc9d5c302753c04e704de455793bd9736d6318e1c314fc8cf97baebc830eae998c35382afb2810126c1cc9bd18bdce +++ b/mpi/mpih-rshift.c eca25cb1840cef7d60fa2bc6ecb32660cfad14e3a3a8aeeb11ec5a5eb2d702c972331351da75c5c111b7c90075b1922db5c475c246b11d7d6097e50538b230f8 @@ -1,34 +1,29 @@ /* mpih-rshift.c - MPI helper functions - * Copyright (C) 1994, 1996, 1998, 1999, - * 2000, 2001 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GNUPG + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GNUPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GNUPG is distributed in the hope that it will be useful, + * This program 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, see . - * - * Note: This code is heavily based on the GNU MP Library. - * Actually it's the same code with only minor changes in the - * way the data is stored; this is to support the abstraction - * of an optional secure memory allocation which may be used - * to avoid revealing of sensitive data due to paging etc. - * The GNU MP Library itself is published under the LGPL; - * however I decided to publish this code under the plain GPL. + * along with this program. If not, see . */ -#include #include #include + +#include "knobs.h" #include "mpi-internal.h" diff -uNr a/mpi/mpih-sub1.c b/mpi/mpih-sub1.c --- a/mpi/mpih-sub1.c 1f021e754f091eac1ab7b46306b00849f7160cfa7cd0cc8a6481020b6d42cb12058cd12ac9e2b1d7f730688fbe2d876374ec9d5bb7a5f9d66a42cc9259cf2539 +++ b/mpi/mpih-sub1.c a23c0420e5786f7ed38842dc31330ec3c7f5544566a434414b7d097f237969d37d3c9390d2cc393d58f011ec991959cb059758b5e66ffcea2002f4597ac049cf @@ -1,33 +1,29 @@ /* mpihelp-add_2.c - MPI helper functions - * Copyright (C) 1994, 1996, 1997, 1998, 2001 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . - * - * Note: This code is heavily based on the GNU MP Library. - * Actually it's the same code with only minor changes in the - * way the data is stored; this is to support the abstraction - * of an optional secure memory allocation which may be used - * to avoid revealing of sensitive data due to paging etc. - * The GNU MP Library itself is published under the LGPL; - * however I decided to publish this code under the plain GPL. + * along with this program. If not, see . */ -#include #include #include + +#include "knobs.h" #include "mpi-internal.h" #include "longlong.h" diff -uNr a/mpi/mpi-inline.c b/mpi/mpi-inline.c --- a/mpi/mpi-inline.c 22b8e75d35abc0449e048a2b18461b17d7ef5a6a00a56fe1a16bd89b526b8f6f19dea196a258d6e3760f84b1124d7d40fa28d1b6c5bc4932be11b9d91c7077ec +++ b/mpi/mpi-inline.c 8a4a177c130b437c9ed2e935a375e693b12a57b12b241660b5f715698b9926d82f68c0c74c450bea2dc60888920bb04f9370bedc8737d1ec375a307eb3d4a0a1 @@ -1,26 +1,30 @@ /* mpi-inline.c - * Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . + * along with this program. If not, see . */ -#include #include #include +#include "knobs.h" + /* put the inline functions as real functions into the lib */ #define G10_MPI_INLINE_DECL diff -uNr a/mpi/mpi-inv.c b/mpi/mpi-inv.c --- a/mpi/mpi-inv.c 66edf48a07bb672b7d9329150436a40ab2f1628f1f289b4c52b2e4bdb987b9105f36c441fb21a141346406a675d34b6265a4a0bc00d3c4de471f461d0acc5765 +++ b/mpi/mpi-inv.c 89b26071ae7d00a43324b0152330b04e9981dc9f81c0482e760c629c4fd056ed3125c7432155e7a44cadb0ff26c3eb6abef3ebacfcac4781f628d315c59f3539 @@ -1,25 +1,29 @@ /* mpi-inv.c - MPI functions - * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . + * along with this program. If not, see . */ -#include #include #include + +#include "knobs.h" #include "mpi-internal.h" diff -uNr a/mpi/mpi-mpow.c b/mpi/mpi-mpow.c --- a/mpi/mpi-mpow.c a87ebb2e2397f5903eaa0066a9adf8f977bf7a67866cd181d0699b6d6a029880d86f349be9cb9e6901d35b052bd871380e18ab19efcf319c8a3662a93691856e +++ b/mpi/mpi-mpow.c 770f4b4229521f5f780d90ead019bb19ac247128a768d6eef565da48fade1634ff195a94e39412973b08c01c55c410db075d2be44e393b8f343568b2b4b85cdd @@ -1,28 +1,33 @@ /* mpi-mpow.c - MPI functions - * Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . + * along with this program. If not, see . */ -#include #include #include +#include + +#include "knobs.h" #include "mpi-internal.h" #include "longlong.h" -#include + static int build_index( MPI *exparray, int k, int i, int t ) diff -uNr a/mpi/mpi-mul.c b/mpi/mpi-mul.c --- a/mpi/mpi-mul.c 8a56adb14bcac8d72e4454562a0455c241756ede576d2cd4e8a42cfdff5abe7c803a5f1523945ee81d5a149b88d969739443d00165fdaab7041bac9be10dc8cf +++ b/mpi/mpi-mul.c e59e2d292e0e80c84bbc7526ffb1d48cf9ce718840c0b6d6ff26e1bee1a331e7eaa4f7002050d195af9d7e915ce49ca6b4b9a43f7d4c0d74e9c6040b6b871bf6 @@ -1,34 +1,29 @@ /* mpi-mul.c - MPI functions - * Copyright (C) 1994, 1996 Free Software Foundation, Inc. - * Copyright (C) 1998, 2001 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . - * - * Note: This code is heavily based on the GNU MP Library. - * Actually it's the same code with only minor changes in the - * way the data is stored; this is to support the abstraction - * of an optional secure memory allocation which may be used - * to avoid revealing of sensitive data due to paging etc. - * The GNU MP Library itself is published under the LGPL; - * however I decided to publish this code under the plain GPL. + * along with this program. If not, see . */ -#include #include #include + +#include "knobs.h" #include "mpi-internal.h" diff -uNr a/mpi/mpi-pow.c b/mpi/mpi-pow.c --- a/mpi/mpi-pow.c 8341923461226ec55de5b29209cc03051587de11885cb49433ff4c0eba2160798b7dc27573b9bc363ee0954a8fc08cbd21af3f655a9c0bc8aa294a74f80eb2c9 +++ b/mpi/mpi-pow.c 054bf70520a4b8936ce1e9a3176884ae01fa796177f57feb9676be0197e3d87f82a7074e19144553d603861b5afe804808a10c0e59e6f649be4435bf6055ba88 @@ -1,37 +1,34 @@ /* mpi-pow.c - MPI functions - * Copyright (C) 1994, 1996, 1998, 2000 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . - * - * Note: This code is heavily based on the GNU MP Library. - * Actually it's the same code with only minor changes in the - * way the data is stored; this is to support the abstraction - * of an optional secure memory allocation which may be used - * to avoid revealing of sensitive data due to paging etc. - * The GNU MP Library itself is published under the LGPL; - * however I decided to publish this code under the plain GPL. + * along with this program. If not, see . */ -#include #include #include #include +#include + +#include "knobs.h" #include "mpi-internal.h" #include "longlong.h" -#include + /**************** diff -uNr a/mpi/mpi-scan.c b/mpi/mpi-scan.c --- a/mpi/mpi-scan.c affa0e93e6625cad75cd10c454b493cbebf061aeca3185e45b6571a26ae10f03947a1ef363c0898609f95cc737053e45a73926b22f14f4ec6a800410915d3ff9 +++ b/mpi/mpi-scan.c a5515e663fe1096bc9e9187508e493a8992770e13039758663f0b5979f49ab422f7f5847b707007a6d53190493f5250c8963c147405defee82bca6037731b869 @@ -1,25 +1,29 @@ /* mpi-scan.c - MPI functions - * Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . + * along with this program. If not, see . */ - -#include + #include #include + +#include "knobs.h" #include "mpi-internal.h" #include "longlong.h" diff -uNr a/mpi/mpiutil.c b/mpi/mpiutil.c --- a/mpi/mpiutil.c 757f8a9ffa7640843abc7a20ee7f0460fae4cb11a2928963c85399b7ea7aba3332f5c1574e86dab4bba8384e5bf3f95161c1d1e15db7b85bb96f369f1e67f6fa +++ b/mpi/mpiutil.c 38480c0221f17670a5009ece9021655c15eae6c5c378ba516cddcdd1c3179a647f1862b1cd92391a57f62313a208faa2fbe2ebdf2584c6570500626cf5b926c1 @@ -1,28 +1,31 @@ /* mpiutil.ac - Utility functions for MPI - * Copyright (C) 1998, 1999 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . + * along with this program. If not, see . */ -#include #include #include #include #include +#include "knobs.h" #include "mpi.h" #include "mpi-internal.h" #include "memory.h" diff -uNr a/mpi/README b/mpi/README --- a/mpi/README 6be57f08ec92d8bb7fba6e14de060ca60d0655b3dad55ccc31b8387b9a305361f208e05589f091f8a0f774d9830e43b015e81e5ddc16ec41c16b00a04a13f69f +++ b/mpi/README 812488321dd4dd4e83cfc49f1ffd543231bfd8099880bf8106d7c5debf7e7fec8b6e17f9b91ebc7cc7c772b06c03c6ffc176438bc3204953bda7842f06ef43ae @@ -6,6 +6,18 @@ SHA512(gnupg-1.4.10.tar.gz) : d037041d2e6882fd3b999500b5a7b42be2c224836afc358e1f8a2465c1b74473d518f185b7c324b2c8dec4ffb70e9e34a03c94d1a54cc55d297f40c9745f6e1b +DEMO: + +1) make +2) cd tests +3) make +4) ./test_mpi +5) output is: + 37A063D056817668C7AA3418F29 +6) q: 'Waaaaaa, it barfed!' + a: You are probably using GCC 5 or LLVM. Stop. + + CHANGES FROM ORIGINAL: 1) Everything pertaining to Automake was nuked, and the earth where it stood - @@ -16,7 +28,7 @@ another project. This will turn up in 'bin'. Among other things, this now means that all KNOBS now reside in a - MANUALLY-controlled 'config.h' found in 'include'. If you are building + MANUALLY-controlled 'knobs.h' found in 'include'. If you are building on some very peculiar unix, please read it and adjust as appropriate. It contains ONLY those knobs which actually pertain to the code. @@ -41,7 +53,7 @@ don't need'em in their source code. 4) Other code has been altered solely to the extent required by items - (1) and (2). + (1), (2), and (3). Cruft which appears in dead #ifdefs may be removed in the future. Don't get comfortable with it being there. @@ -55,3 +67,20 @@ 7) The original code was distributed under GPL 3, which may apply on your planet and is therefore included. (See COPYING.) + +---------- +UPDATE #1: +---------- + +1) Abolished the logging subsystem inherited from GPG. + +2) Abolished the I/O buffering subsystem, from same. + +3) Eliminated all #ifdef blocks pertaining to RiscOS. + +4) config.h is now knobs.h and is considerably shorter + on account of there now being a great many fewer knobs. + +5) Eliminated certain blocks of dead code. + +6) Inserted notice of modifications as specified in GPL-3 diff -uNr a/mpi/secmem.c b/mpi/secmem.c --- a/mpi/secmem.c a0b28117315bd9560be404c97e44252316fd19ff9cbc762bf5d46235034846155d5058e22a73d7010f78cf7442ba6624e2417a719ffcbe2f8a163090706e069c +++ b/mpi/secmem.c 914398e87edaf3b4ed8010ec6795c55f1a46b7c112d8df2a28b9b73c4a786ab7335a662b097522fcf79695b5dbee04c7ad8f2c8e70caeca39c40430b7bc2feb8 @@ -1,24 +1,27 @@ /* secmem.c - memory allocation from a secure heap - * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, - * 2007 Free Software Foundation, Inc. + * Modified by No Such Labs. (C) 2015. See README. * - * This file is part of GnuPG. + * This file was originally part of Gnu Privacy Guard (GPG), ver. 1.4.10, + * SHA256(gnupg-1.4.10.tar.gz): + * 0bfd74660a2f6cedcf7d8256db4a63c996ffebbcdc2cf54397bfb72878c5a85a + * (C) 1994-2005 Free Software Foundation, Inc. * - * GnuPG is free software; you can redistribute it and/or modify + * This program 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 3 of the License, or + * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * - * GnuPG is distributed in the hope that it will be useful, + * This program 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, see . + * along with this program. If not, see . */ -#include +#include "knobs.h" + #include #include #include @@ -92,9 +95,7 @@ { if (!no_warning) { - log_info(_("WARNING: using insecure memory!\n")); - log_info(_("please see http://www.gnupg.org/faq.html" - " for more information\n")); + log_info("WARNING: using insecure memory!\n"); } } @@ -202,11 +203,6 @@ /* It does not make sense to print such a warning, given the fact that * this whole Windows !@#$% and their user base are inherently insecure */ -#elif defined (__riscos__) - /* no virtual memory on RISC OS, so no pages are swapped to disc, - * besides we don't have mmap, so we don't use it! ;-) - * But don't complain, as explained above. - */ #else log_info("Please note that you don't have secure memory on this system\n"); #endif @@ -313,14 +309,11 @@ secmem_init( size_t n ) { if( !n ) { -#ifndef __riscos__ #ifdef USE_CAPABILITIES /* drop all capabilities */ cap_set_proc( cap_from_text("all-eip") ); - #elif !defined(HAVE_DOSISH_SYSTEM) uid_t uid; - disable_secmem=1; uid = getuid(); if( uid != geteuid() ) { @@ -328,7 +321,6 @@ log_fatal("failed to drop setuid\n" ); } #endif -#endif /* !__riscos__ */ } else { if( n < DEFAULT_POOLSIZE ) @@ -351,8 +343,8 @@ if( !pool_okay ) { log_info( - _("operation is not possible without initialized secure memory\n")); - log_info(_("(you may have used the wrong program for this task)\n")); + "operation is not possible without initialized secure memory\n"); + log_info("(you may have used the wrong program for this task)\n"); exit(2); } if( show_warning && !suspend_warning ) { diff -uNr a/mpi/tests/Makefile b/mpi/tests/Makefile --- a/mpi/tests/Makefile false +++ b/mpi/tests/Makefile b063bf6e022989224fa35d648e8fc1cef134c07c8602d502f83a2fdba824707919fc09460552c52e6ee533625e949a4f83e733182050b728ce64e92ef8c26ad8 @@ -0,0 +1,24 @@ +PROGRAM = test_mpi + +CXX = gcc +OBJECTS := $(patsubst %.c,%.o,$(wildcard *.c)) +FLAGS = -g -Wall +INCLUDE = -I ../include +MPI = ../bin/mpi.a +LIBS := $(MPI) + +.SUFFIXES: .o .c + +.c.o: + $(CXX) $(FLAGS) $(INCLUDE) -c $< -o $@ + +all: $(PROGRAM) + +$(PROGRAM): $(OBJECTS) + $(CXX) $(FLAGS) $(INCLUDE) -o $(PROGRAM) $(OBJECTS) $(LIBS) + +clean : + rm -rf nul core *flymake* *.o $(PROGRAM) *~ bin obj + +check-syntax: + $(CXX) -c $(FLAGS) $(INCLUDE) -o nul -Wall -S $(CHK_SOURCES) diff -uNr a/mpi/tests/test_mpi.c b/mpi/tests/test_mpi.c --- a/mpi/tests/test_mpi.c false +++ b/mpi/tests/test_mpi.c 5f400376f8290ae83062c457bedfde1fb7a2c2e31efe956ada2e4dc4eaaf6871428b74be1193d9268ee74cf454bdc3df5c4c4a88e6942d216ddb5a0395f48099 @@ -0,0 +1,39 @@ +#include "mpi.h" +#include + +void err(char *msg) +{ + fprintf(stderr, "%s\n", msg); + exit(1); +} + +void terpri(FILE *fp) +{ + fprintf(fp, "\n"); +} + +int main(int ac, char **av) +{ + MPI a, b, y; + int r; + + r = secmem_init(1000); + if (r==0) err("secmem init"); + + a = mpi_alloc_secure(0); + b = mpi_alloc_secure(0); + y = mpi_alloc_secure(0); + mpi_fromstr(a, "0x1B0B206C488601"); + mpi_fromstr(b, "0x20E92FE28E1929"); + mpi_mul(y, a, b); + mpi_free(a); + mpi_free(b); + + mpi_print(stdout, y, 1); + mpi_free(y); + + terpri(stdout); + secmem_term(); + + return 0; +} diff -uNr a/mpi/udiv-w-sdiv.c b/mpi/udiv-w-sdiv.c --- a/mpi/udiv-w-sdiv.c fb984a326a9bcda1a4cbc05ee279e55cfefcf157393d2f66405760b256395c3a73f1f41ebfc335722022ea04c79f6e02ab3179ecc9a66e037dd7a106572b4924 +++ b/mpi/udiv-w-sdiv.c false @@ -1,132 +0,0 @@ -/* mpihelp_udiv_w_sdiv -- implement udiv_qrnnd on machines with only signed - * division. - * Copyright (C) 1992, 1994, 1996, 1998 Free Software Foundation, Inc. - * Contributed by Peter L. Montgomery. - * - * 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 3 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, see . - */ - -#include -#include -#include -#include "mpi-internal.h" -#include "longlong.h" - - -#if 0 /* not yet ported to MPI */ - -mpi_limb_t -mpihelp_udiv_w_sdiv( mpi_limp_t *rp, - mpi_limp_t *a1, - mpi_limp_t *a0, - mpi_limp_t *d ) -{ - mp_limb_t q, r; - mp_limb_t c0, c1, b1; - - if ((mpi_limb_signed_t) d >= 0) - { - if (a1 < d - a1 - (a0 >> (BITS_PER_MP_LIMB - 1))) - { - /* dividend, divisor, and quotient are nonnegative */ - sdiv_qrnnd (q, r, a1, a0, d); - } - else - { - /* Compute c1*2^32 + c0 = a1*2^32 + a0 - 2^31*d */ - sub_ddmmss (c1, c0, a1, a0, d >> 1, d << (BITS_PER_MP_LIMB - 1)); - /* Divide (c1*2^32 + c0) by d */ - sdiv_qrnnd (q, r, c1, c0, d); - /* Add 2^31 to quotient */ - q += (mp_limb_t) 1 << (BITS_PER_MP_LIMB - 1); - } - } - else - { - b1 = d >> 1; /* d/2, between 2^30 and 2^31 - 1 */ - c1 = a1 >> 1; /* A/2 */ - c0 = (a1 << (BITS_PER_MP_LIMB - 1)) + (a0 >> 1); - - if (a1 < b1) /* A < 2^32*b1, so A/2 < 2^31*b1 */ - { - sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */ - - r = 2*r + (a0 & 1); /* Remainder from A/(2*b1) */ - if ((d & 1) != 0) - { - if (r >= q) - r = r - q; - else if (q - r <= d) - { - r = r - q + d; - q--; - } - else - { - r = r - q + 2*d; - q -= 2; - } - } - } - else if (c1 < b1) /* So 2^31 <= (A/2)/b1 < 2^32 */ - { - c1 = (b1 - 1) - c1; - c0 = ~c0; /* logical NOT */ - - sdiv_qrnnd (q, r, c1, c0, b1); /* (A/2) / (d/2) */ - - q = ~q; /* (A/2)/b1 */ - r = (b1 - 1) - r; - - r = 2*r + (a0 & 1); /* A/(2*b1) */ - - if ((d & 1) != 0) - { - if (r >= q) - r = r - q; - else if (q - r <= d) - { - r = r - q + d; - q--; - } - else - { - r = r - q + 2*d; - q -= 2; - } - } - } - else /* Implies c1 = b1 */ - { /* Hence a1 = d - 1 = 2*b1 - 1 */ - if (a0 >= -d) - { - q = -1; - r = a0 + d; - } - else - { - q = -2; - r = a0 + 2*d; - } - } - } - - *rp = r; - return q; -} - -#endif -