diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/cipher.h | 87 | ||||
-rw-r--r-- | include/errors.h | 52 | ||||
-rw-r--r-- | include/iobuf.h | 120 | ||||
-rw-r--r-- | include/memory.h | 64 | ||||
-rw-r--r-- | include/mpi.h | 147 | ||||
-rw-r--r-- | include/ttyio.h | 29 | ||||
-rw-r--r-- | include/types.h | 76 | ||||
-rw-r--r-- | include/util.h | 100 |
8 files changed, 675 insertions, 0 deletions
diff --git a/include/cipher.h b/include/cipher.h new file mode 100644 index 000000000..ac19c3fc0 --- /dev/null +++ b/include/cipher.h @@ -0,0 +1,87 @@ +/* cipher.h + * Copyright (c) 1997 by Werner Koch (dd9jn) + * + * ATTENTION: This code should not be exported from the United States + * nor should it be used their without a license agreement with PKP. + * The RSA alorithm is protected by U.S. Patent #4,405,829 which + * expires on September 20, 2000! + * + * This file is part of G10. + * + * G10 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * G10 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ +#ifndef G10_CIPHER_H +#define G10_CIPHER_H + +#define DBG_CIPHER cipher_debug_mode + +#include "mpi.h" +#include "../cipher/md5.h" +#include "../cipher/rmd.h" +#include "../cipher/rsa.h" +#include "../cipher/idea.h" +#include "../cipher/blowfish.h" +#include "../cipher/gost.h" +#include "../cipher/elgamal.h" + + +#define CIPHER_ALGO_NONE 0 +#define CIPHER_ALGO_IDEA 1 +#define CIPHER_ALGO_BLOWFISH 42 +#define CIPHER_ALGO_GOST 43 + +#define PUBKEY_ALGO_RSA 1 +#define PUBKEY_ALGO_ELGAMAL 42 + +#define DIGEST_ALGO_MD5 1 +#define DIGEST_ALGO_RMD160 42 + +#define DEFAULT_CIPHER_ALGO CIPHER_ALGO_BLOWFISH +#define DEFAULT_PUBKEY_ALGO PUBKEY_ALGO_RSA +#define DEFAULT_DIGEST_ALGO DIGEST_ALGO_RMD160 + +typedef struct { + int algo; + int keylen; + byte key[20]; /* this is the largest used keylen */ +} DEK; + +typedef struct { + int algo; /* digest algo */ + union { + MD5HANDLE md5; + RMDHANDLE rmd; + } u; +} MD_HANDLE; + + +int cipher_debug_mode; + +/*-- random.c --*/ +void randomize_buffer( byte *buffer, size_t length, int level ); +byte get_random_byte( int level ); + +/*-- smallprime.c --*/ +extern ushort small_prime_numbers[]; + +/*-- primegen.c --*/ +MPI generate_random_prime( unsigned nbits ); + +/*-- seskey.c --*/ +void make_session_key( DEK *dek ); +MPI encode_session_key( DEK *dek, unsigned nbits ); + + +#endif /*G10_CIPHER_H*/ diff --git a/include/errors.h b/include/errors.h new file mode 100644 index 000000000..f2e7570cc --- /dev/null +++ b/include/errors.h @@ -0,0 +1,52 @@ +/* errors.h - erro code + * Copyright (c) 1997 by Werner Koch (dd9jn) + * + * This file is part of G10. + * + * G10 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * G10 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ +#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_BAD_RING 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 + +#endif /*G10_ERRORS_H*/ diff --git a/include/iobuf.h b/include/iobuf.h new file mode 100644 index 000000000..328cd8da5 --- /dev/null +++ b/include/iobuf.h @@ -0,0 +1,120 @@ +/* iobuf.h - I/O buffer + * Copyright (c) 1997 by Werner Koch (dd9jn) + * + * This file is part of G10. + * + * G10 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * G10 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#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_USER 16 + +typedef struct iobuf_struct *IOBUF; + +struct iobuf_struct { + int usage; /* 1 input , 2 output, 3 temp */ + unsigned long nlimit; + unsigned long nbytes; + 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; + struct { + size_t size; + size_t len; + char *buf; + } recorder; + int filter_eof; + int (*filter)( void *opaque, int control, + IOBUF chain, byte *buf, size_t *len); + void *filter_ov; /* value for opaque */ + IOBUF chain; /* next iobuf used for i/o if any (passed to filter) */ + int no, subno; + const char *desc; +}; + +int iobuf_debug_mode; + +IOBUF iobuf_alloc(int usage, size_t bufsize); +IOBUF iobuf_temp(void); +IOBUF iobuf_open( const char *fname ); +IOBUF iobuf_create( const char *fname ); +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_pop_filter( IOBUF a, int (*f)(void *opaque, int control, + IOBUF chain, byte *buf, size_t *len), void *ov ); +int iobuf_flush(IOBUF a); +void iobuf_clear_eof(IOBUF a); + +void iobuf_set_limit( IOBUF a, unsigned long nlimit ); + +int iobuf_readbyte(IOBUF a); +int iobuf_writebyte(IOBUF a, unsigned c); +int iobuf_write(IOBUF a, byte *buf, unsigned buflen ); + +int iobuf_write_temp( IOBUF a, IOBUF temp ); +size_t iobuf_temp_to_buffer( IOBUF a, byte *buffer, size_t buflen ); + +void iobuf_start_recorder( IOBUF a ); +void iobuf_push_recorder( IOBUF a, int c ); +char *iobuf_stop_recorder( IOBUF a, size_t *n ); + +u32 iobuf_get_filelength( IOBUF a ); + +void iobuf_set_block_mode( IOBUF a, size_t n ); +int iobuf_in_block_mode( IOBUF a ); + +/* 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)->recorder.buf || (a)->nlimit \ + || (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_length(a) ( (a)->d.len ) +#define iobuf_is_temp(a) ( (a)->usage == 3 ) + +#endif /*G10_IOBUF_H*/ diff --git a/include/memory.h b/include/memory.h new file mode 100644 index 000000000..aa8bb706d --- /dev/null +++ b/include/memory.h @@ -0,0 +1,64 @@ +/* memory.h - memory allocation + * Copyright (c) 1997 by Werner Koch (dd9jn) + * + * This file is part of G10. + * + * G10 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * G10 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef G10_MEMORY_H +#define G10_MEMORY_H + +#ifdef M_DEBUG +#ifndef STR + #define STR(v) #v +#endif +#define M_DBGINFO(a) __FUNCTION__ "["__FILE__ ":" STR(a) "]" +#define m_alloc(n) m_debug_alloc((n), M_DBGINFO( __LINE__ ) ) +#define m_alloc_clear(n) m_debug_alloc_clear((n), M_DBGINFO(__LINE__) ) +#define m_alloc_secure(n) m_debug_alloc((n), M_DBGINFO(__LINE__) ) +#define m_alloc_secure_clear(n) m_debug_alloc((n), M_DBGINFO(__LINE__) ) +#define m_realloc(n,m) m_debug_realloc((n),(m), M_DBGINFO(__LINE__) ) +#define m_free(n) m_debug_free((n), M_DBGINFO(__LINE__) ) +#define m_check(n) m_debug_check((n), M_DBGINFO(__LINE__) ) + +void *m_debug_alloc( size_t n, const char *info ); +void *m_debug_alloc_clear( size_t n, const char *info ); +void *m_debug_alloc_secure( size_t n, const char *info ); +void *m_debug_alloc_secure_clear( size_t n, const char *info ); +void *m_debug_realloc( void *a, size_t n, const char *info ); +void m_debug_free( void *p, const char *info ); +void m_debug_check( const void *a, const char *info ); + +#else +void *m_alloc( size_t n ); +void *m_alloc_clear( size_t n ); +void *m_alloc_secure( size_t n ); +void *m_alloc_secure_clear( size_t n ); +void *m_realloc( void *a, size_t n ); +void m_free( void *p ); +void m_check( const void *a ); +#endif + + +size_t m_size( const void *a ); +int m_is_secure( const void *p ); + +#define DBG_MEMORY memory_debug_mode +#define DBG_MEMSTAT memory_stat_debug_mode +int memory_debug_mode; +int memory_stat_debug_mode; + +#endif /*G10_MEMORY_H*/ diff --git a/include/mpi.h b/include/mpi.h new file mode 100644 index 000000000..4470c609a --- /dev/null +++ b/include/mpi.h @@ -0,0 +1,147 @@ +/* mpi.h - Multi Precision Integers + * Copyright (c) 1997 by Werner Koch (dd9jn) + * + * This file is part of G10. + * + * G10 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * G10 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef G10_MPI_H +#define G10_MPI_H + +#include <stdio.h> +#include "iobuf.h" +#include "types.h" +#include "memory.h" + + +#define DBG_MPI mpi_debug_mode +int mpi_debug_mode; + +#if defined(__i386__) + #define BITS_PER_MPI_LIMB 32 + #define BYTES_PER_MPI_LIMB 4 + #define BYTES_PER_MPI_LIMB2 8 + typedef unsigned long int mpi_limb_t; + typedef signed long int mpi_limb_signed_t; +#else + #error add definions for this machine here +#endif + +typedef struct { + int alloced; /* array size (# of allocated limbs) */ + int nlimbs; /* number of valid limbs */ + int sign; /* indicates a negative number */ + int secure; /* array mut be allocated in secure memory space */ + mpi_limb_t *d; /* array with the limbs */ +} *MPI; + +#define MPI_NULL NULL + +#define mpi_get_nlimbs(a) ((a)->nlimbs) + +/*-- mpiutil.c --*/ + +#ifdef M_DEBUG + #define mpi_alloc(n) mpi_debug_alloc((n), M_DBGINFO( __LINE__ ) ) + #define mpi_alloc_secure(n) mpi_debug_alloc_secure((n), M_DBGINFO( __LINE__ ) ) + #define mpi_free(a) mpi_debug_free((a), M_DBGINFO(__LINE__) ) + #define mpi_resize(a,b) mpi_debug_resize((a),(b), M_DBGINFO(__LINE__) ) + #define mpi_copy(a) mpi_debug_copy((a), M_DBGINFO(__LINE__) ) + MPI mpi_debug_alloc( unsigned nlimbs, const char *info ); + MPI mpi_debug_alloc_secure( unsigned nlimbs, const char *info ); + void mpi_debug_free( MPI a, const char *info ); + void mpi_debug_resize( MPI a, unsigned nlimbs, const char *info ); + MPI mpi_debug_copy( MPI a, const char *info ); +#else + MPI mpi_alloc( unsigned nlimbs ); + MPI mpi_alloc_secure( unsigned nlimbs ); + void mpi_free( MPI a ); + void mpi_resize( MPI a, unsigned nlimbs ); + MPI mpi_copy( MPI a ); +#endif +void mpi_clear( MPI a ); +void mpi_set( MPI w, MPI u); +void mpi_set_ui( MPI w, ulong u); +MPI mpi_alloc_set_ui( unsigned long u); +void mpi_m_check( MPI a ); +void mpi_swap( MPI a, MPI b); + +/*-- mpicoder.c --*/ +int mpi_encode( IOBUF out, MPI a ); +int mpi_encode_csum( IOBUF out, MPI a, u16 *csum ); +int mpi_write( IOBUF out, byte *a); +int mpi_write_csum( IOBUF out, byte *a, u16 *csum); +#ifdef M_DEBUG + #define mpi_decode(a,b) mpi_debug_decode((a),(b), M_DBGINFO( __LINE__ ) ) + #define mpi_decode_buffer(a) mpi_debug_decode_buffer((a), M_DBGINFO( __LINE__ ) ) + MPI mpi_debug_decode(IOBUF inp, unsigned *nread, const char *info); + MPI mpi_debug_decode_buffer(byte *buffer, const char *info ); +#else + MPI mpi_decode(IOBUF inp, unsigned *nread); + MPI mpi_decode_buffer(byte *buffer ); +#endif +byte *mpi_read(IOBUF inp, unsigned *ret_nread); +int mpi_fromstr(MPI val, const char *str); +int mpi_print( FILE *fp, MPI a, int mode ); +u32 mpi_get_keyid( MPI a, u32 *keyid ); + +/*-- mpi-add.c --*/ +void mpi_add_ui(MPI w, MPI u, ulong v ); +void mpi_add(MPI w, MPI u, MPI v); +void mpi_sub_ui(MPI w, MPI u, ulong v ); +void mpi_sub( MPI w, MPI u, MPI v); + +/*-- mpi-mul.c --*/ +void mpi_mul_ui(MPI w, MPI u, ulong v ); +void mpi_mul_2exp( MPI w, MPI u, ulong cnt); +void mpi_mul( MPI w, MPI u, MPI v); + +/*-- mpi-div.c --*/ +ulong mpi_fdiv_r_ui( MPI rem, MPI dividend, ulong divisor ); +void mpi_fdiv_r( MPI rem, MPI dividend, MPI divisor ); +void mpi_fdiv_q( MPI quot, MPI dividend, MPI divisor ); +void mpi_fdiv_qr( MPI quot, MPI rem, MPI dividend, MPI divisor ); +void mpi_tdiv_r( MPI rem, MPI num, MPI den); +void mpi_tdiv_qr( MPI quot, MPI rem, MPI num, MPI den); +int mpi_divisible_ui(MPI dividend, ulong divisor ); + +/*-- mpi-gcd.c --*/ +int mpi_gcd( MPI g, MPI a, MPI b ); + +/*-- mpi-pow.c --*/ +void mpi_pow( MPI w, MPI u, MPI v); +void mpi_powm( MPI res, MPI base, MPI exp, MPI mod); + +/*-- mpi-cmp.c --*/ +int mpi_cmp_ui( MPI u, ulong v ); +int mpi_cmp( MPI u, MPI v ); + +/*-- mpi-scan.c --*/ +int mpi_getbyte( MPI a, unsigned index ); +void mpi_putbyte( MPI a, unsigned index, int value ); + +/*-- mpi-bit.c --*/ +unsigned mpi_get_nbits( MPI a ); +int mpi_test_bit( MPI a, unsigned n ); +void mpi_set_bit( MPI a, unsigned n ); +void mpi_clear_bit( MPI a, unsigned n ); +void mpi_set_bytes( MPI a, unsigned nbits, byte (*fnc)(int), int opaque ); + +/*-- mpi-inv.c --*/ +int mpi_inv_mod( MPI x, MPI u, MPI v ); + + +#endif /*G10_MPI_H*/ diff --git a/include/ttyio.h b/include/ttyio.h new file mode 100644 index 000000000..80f66d842 --- /dev/null +++ b/include/ttyio.h @@ -0,0 +1,29 @@ +/* ttyio.h + * Copyright (c) 1997 by Werner Koch (dd9jn) + * + * This file is part of G10. + * + * G10 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * G10 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ +#ifndef G10_TTYIO_H +#define G10_TTYIO_H + +void tty_printf( const char *fmt, ... ); +char *tty_get( const char *prompt ); +char *tty_get_hidden( const char *prompt ); +void tty_kill_prompt(void); + + +#endif /*G10_TTYIO_H*/ diff --git a/include/types.h b/include/types.h new file mode 100644 index 000000000..7db849f41 --- /dev/null +++ b/include/types.h @@ -0,0 +1,76 @@ +/* types.h - some common typedefs + * Copyright (c) 1997 by Werner Koch (dd9jn) + * + * This file is part of G10. + * + * G10 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * G10 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef G10_TYPES_H +#define G10_TYPES_H + +#ifdef __linux__ + #include <linux/types.h> + #define HAVE_ULONG_TYPEDEF + #define HAVE_USHORT_TYPEDEF +#endif + + +/* Common code */ +#ifndef HAVE_ULONG_TYPEDEF + #define HAVE_ULONG_TYPEDEF + typedef unsigned long ulong; +#endif +#ifndef HAVE_USHORT_TYPEDEF + #define HAVE_USHORT_TYPEDEF + typedef unsigned short ushort; +#endif + + +typedef struct string_list { + struct string_list *next; + char d[1]; +} *STRLIST; + + + +/**************************************** + ******** machine dependent stuff ******* + ****************************************/ + +#if defined(__hpux) + #define HAVE_BIG_ENDIAN 1 +#else + #define HAVE_LITTLE_ENDIAN 1 +#endif + + +/*** some defaults ***/ +#ifndef HAVE_BYTE_TYPEDEF + #define HAVE_BYTE_TYPEDEF + typedef unsigned char byte; +#endif +#ifndef HAVE_U16_TYPEDEF + #define HAVE_U16_TYPEDEF + typedef unsigned short u16; +#endif +#ifndef HAVE_U32_TYPEDEF + #define HAVE_U32_TYPEDEF + typedef unsigned long u32; +#endif + + + +#endif /*G10_TYPES_H*/ diff --git a/include/util.h b/include/util.h new file mode 100644 index 000000000..6740e5edd --- /dev/null +++ b/include/util.h @@ -0,0 +1,100 @@ +/* util.h + * Copyright (c) 1997 by Werner Koch (dd9jn) + * + * This file is part of G10. + * + * G10 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * G10 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ +#ifndef G10_UTIL_H +#define G10_UTIL_H + +#include "errors.h" +#include "types.h" +#include "mpi.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 index; + int inarg; + int stopped; + const char *last; + } 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 printstr( int level, const char *fmt, ... ); +void log_bug( const char *fmt, ... ); +void log_fatal( const char *fmt, ... ); +void log_error( const char *fmt, ... ); +void log_info( const char *fmt, ... ); +void log_debug( const char *fmt, ... ); +void log_hexdump( const char *text, char *buf, size_t len ); +void log_mpidump( const char *text, MPI a ); + +/*-- errors.c --*/ +const char * g10_errstr( int no ); + +/*-- argparse.c --*/ +int arg_parse( ARGPARSE_ARGS *arg, ARGPARSE_OPTS *opts); +void usage( int level ); +const char *default_strusage( int level ); + + +/*-- (main program) --*/ +const char *strusage( int level ); + + +/*-- fileutil.c --*/ + +/*-- miscutil.c --*/ +u32 make_timestamp(void); + +/*-- strgutil.c --*/ +void free_strlist( STRLIST sl ); +#define FREE_STRLIST(a) do { free_strlist((a)); (a) = NULL ; } while(0) +char *memistr( char *buf, size_t buflen, const char *sub ); +#define stricmp(a,b) strcasecmp((a),(b)) + + +/******** some macros ************/ +#ifndef STR + #define STR(v) #v +#endif +#define STR2(v) STR(v) +#define DIM(v) (sizeof(v)/sizeof((v)[0])) +#define DIMof(type,member) DIM(((type *)0)->member) + +#endif /*G10_UTIL_H*/ |