diff options
author | Werner Koch <wk@gnupg.org> | 1998-06-15 17:41:04 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 1998-06-15 17:41:04 +0200 |
commit | 6e1ca6b80fb50ff5e1c065b7ac12635487b4a6d2 (patch) | |
tree | 7c4a888893a91b59753b3d89e59832f8c24ba039 /g10/misc.c | |
parent | gnupg extension are now working (diff) | |
download | gnupg2-6e1ca6b80fb50ff5e1c065b7ac12635487b4a6d2.tar.xz gnupg2-6e1ca6b80fb50ff5e1c065b7ac12635487b4a6d2.zip |
extensions are now working and fixed a lot of bugs
Diffstat (limited to 'g10/misc.c')
-rw-r--r-- | g10/misc.c | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/g10/misc.c b/g10/misc.c index 782b5cd10..d1bacf694 100644 --- a/g10/misc.c +++ b/g10/misc.c @@ -28,7 +28,15 @@ #endif #include "util.h" #include "main.h" +#include "options.h" +volatile int +pull_in_libs(void) +{ + g10m_revision_string(0); + g10c_revision_string(0); + g10u_revision_string(0); +} #if defined(__linux__) && defined(__alpha__) @@ -63,7 +71,22 @@ checksum_u16( unsigned n ) u16 a; a = (n >> 8) & 0xff; - a |= n & 0xff; + if( opt.emulate_bugs & 1 ) { + a |= n & 0xff; + log_debug("csum_u16 emulated for n=%u\n", n); + } + else + a += n & 0xff; + return a; +} + +static u16 +checksum_u16_nobug( unsigned n ) +{ + u16 a; + + a = (n >> 8) & 0xff; + a += n & 0xff; return a; } @@ -83,12 +106,43 @@ checksum_mpi( MPI a ) u16 csum; byte *buffer; unsigned nbytes; + unsigned nbits; buffer = mpi_get_buffer( a, &nbytes, NULL ); - csum = checksum_u16( mpi_get_nbits(a) ); + /* some versions of gpg encode wrong values for the length of an mpi + * so that mpi_get_nbits() which counts the mpi yields another (shorter) + * value than the one store with the mpi. mpi_get_nbit_info() returns + * this stored value if it is still available. + */ + + if( opt.emulate_bugs & 1 ) + nbits = 0; + else + nbits = mpi_get_nbit_info(a); + if( !nbits ) + nbits = mpi_get_nbits(a); + csum = checksum_u16( nbits ); csum += checksum( buffer, nbytes ); m_free( buffer ); return csum; } +/**************** + * This is the correct function + */ +u16 +checksum_mpi_counted_nbits( MPI a ) +{ + u16 csum; + byte *buffer; + unsigned nbytes; + unsigned nbits; + + buffer = mpi_get_buffer( a, &nbytes, NULL ); + nbits = mpi_get_nbits(a); + csum = checksum_u16_nobug( nbits ); + csum += checksum( buffer, nbytes ); + m_free( buffer ); + return csum; +} |