See ChangeLog: Sun Jan 17 11:04:33 CET 1999 Werner Koch

This commit is contained in:
Werner Koch 1999-01-17 10:06:03 +00:00
parent 38008c1c20
commit befacf7efa
19 changed files with 199 additions and 156 deletions

View File

@ -1,3 +1,13 @@
Sun Jan 17 11:04:33 CET 1999 Werner Koch <wk@isil.d.shuttle.de>
* des.c (is_weak_key): Replace system memcmp due to bugs
in SunOS's memcmp.
(des_get_info): Return error on failed selftest.
* twofish.c (twofish_setkey): Return error on failed selftest or
invalid keylength.
* cast5.c (cast_setkey): Ditto.
* blowfish.c (bf_setkey): Return error on failed selftest.
Tue Jan 12 11:17:18 CET 1999 Werner Koch <wk@isil.d.shuttle.de>
* random.c (random_is_faked): New.

View File

@ -34,10 +34,12 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "util.h"
#include "types.h"
#include "errors.h"
#include "blowfish.h"
#define CIPHER_ALGO_BLOWFISH 4 /* blowfish 128 bit key */
#define CIPHER_ALGO_BLOWFISH160 42 /* blowfish 160 bit key (not in OpenPGP)*/
@ -451,7 +453,7 @@ decrypt_block( BLOWFISH_context *bc, byte *outbuf, byte *inbuf )
}
static void
static const char*
selftest()
{
BLOWFISH_context c;
@ -464,18 +466,19 @@ selftest()
bf_setkey( &c, "abcdefghijklmnopqrstuvwxyz", 26 );
encrypt_block( &c, buffer, plain );
if( memcmp( buffer, "\x32\x4E\xD0\xFE\xF4\x13\xA2\x03", 8 ) )
log_error("wrong blowfish encryption\n");
return "Blowfish selftest failed (1).";
decrypt_block( &c, buffer, buffer );
if( memcmp( buffer, plain, 8 ) )
log_bug("blowfish failed\n");
return "Blowfish selftest failed (2).";
bf_setkey( &c, key3, 8 );
encrypt_block( &c, buffer, plain3 );
if( memcmp( buffer, cipher3, 8 ) )
log_error("wrong blowfish encryption (3)\n");
return "Blowfish selftest failed (3).";
decrypt_block( &c, buffer, buffer );
if( memcmp( buffer, plain3, 8 ) )
log_bug("blowfish failed (3)\n");
return "Blowfish selftest failed (4).";
return NULL;
}
@ -486,11 +489,16 @@ bf_setkey( BLOWFISH_context *c, byte *key, unsigned keylen )
int i, j;
u32 data, datal, datar;
static int initialized;
static const char *selftest_failed;
if( !initialized ) {
initialized = 1;
selftest();
selftest_failed = selftest();
if( selftest_failed )
fprintf(stderr,"%s\n", selftest_failed );
}
if( selftest_failed )
return G10ERR_SELFTEST_FAILED;
for(i=0; i < BLOWFISH_ROUNDS+2; i++ )
c->p[i] = ps[i];

View File

@ -39,9 +39,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "util.h"
#include "types.h"
#include "errors.h"
#include "cast5.h"
@ -455,7 +454,7 @@ decrypt_block( CAST5_context *c, byte *outbuf, byte *inbuf )
static void
static const char*
selftest()
{
CAST5_context c;
@ -468,10 +467,10 @@ selftest()
cast_setkey( &c, key, 16 );
encrypt_block( &c, buffer, plain );
if( memcmp( buffer, cipher, 8 ) )
log_error("wrong cast5-128 encryption\n");
return "1";
decrypt_block( &c, buffer, buffer );
if( memcmp( buffer, plain, 8 ) )
log_bug("cast5-128 failed\n");
return "2";
#if 0 /* full maintenance test */
{
@ -494,10 +493,11 @@ selftest()
encrypt_block( &c, b0+8, b0+8 );
}
if( memcmp( a0, a1, 16 ) || memcmp( b0, b1, 16 ) )
log_bug("cast5-128 maintenance test failed\n");
return "3";
}
#endif
return NULL;
}
@ -553,6 +553,7 @@ static int
cast_setkey( CAST5_context *c, byte *key, unsigned keylen )
{
static int initialized;
static const char* selftest_failed;
int i;
u32 x[4];
u32 z[4];
@ -560,10 +561,16 @@ cast_setkey( CAST5_context *c, byte *key, unsigned keylen )
if( !initialized ) {
initialized = 1;
selftest();
selftest_failed = selftest();
if( selftest_failed )
fprintf(stderr,"CAST5 selftest failed (%s).\n", selftest_failed );
}
if( selftest_failed )
return G10ERR_SELFTEST_FAILED;
if( keylen != 16 )
return G10ERR_WRONG_KEYLEN;
assert(keylen==16);
x[0] = key[0] << 24 | key[1] << 16 | key[2] << 8 | key[3];
x[1] = key[4] << 24 | key[5] << 16 | key[6] << 8 | key[7];
x[2] = key[8] << 24 | key[9] << 16 | key[10] << 8 | key[11];

View File

@ -113,12 +113,30 @@
#include <config.h>
#include <stdio.h>
#include <string.h> /* memcpy, memcmp */
#include <assert.h>
#include "types.h" /* for byte and u32 typedefs */
#include "util.h" /* for log_fatal() */
#include "errors.h"
#include "des.h"
#if defined(__GNUC__) && defined(__GNU_LIBRARY__)
#define working_memcmp memcmp
#else
/*
* According to the SunOS man page, memcmp returns indeterminate sign
* depending on whether characters are signed or not.
*/
int
working_memcmp( const char *a, const char *b, size_t n )
{
for( ; n; n--, a++, b++ )
if( *a != *b )
return (int)(*(byte*)a) - (int)(*(byte*)b);
return 0;
}
#endif
/* Some defines/checks to support standalone modules */
@ -128,19 +146,6 @@
#error CIPHER_ALGO_3DES is defined to a wrong value.
#endif
#ifndef G10ERR_WEAK_KEY
#define G10ERR_WEAK_KEY 43
#elif G10ERR_WEAK_KEY != 43
#error G10ERR_WEAK_KEY is defined to a wrong value.
#endif
#ifndef G10ERR_WRONG_KEYLEN
#define G10ERR_WRONG_KEYLEN 44
#elif G10ERR_WRONG_KEYLEN != 44
#error G10ERR_WRONG_KEYLEN is defined to a wrong value.
#endif
/* Macros used by the info function. */
#define FNCCAST_SETKEY(f) ((int(*)(void*, byte*, unsigned))(f))
@ -167,6 +172,7 @@ typedef struct _tripledes_ctx
}
tripledes_ctx[1];
static const char *selftest_failed;
static void des_key_schedule (const byte *, u32 *);
static int des_setkey (struct _des_ctx *, const byte *);
@ -542,6 +548,9 @@ des_setkey (struct _des_ctx *ctx, const byte * key)
{
int i;
if( selftest_failed )
return G10ERR_SELFTEST_FAILED;
des_key_schedule (key, ctx->encrypt_subkeys);
for(i=0; i<32; i+=2)
@ -706,6 +715,8 @@ tripledes_ecb_crypt (struct _tripledes_ctx *ctx, const byte * from, byte * to, i
/*
* Check whether the 8 byte key is weak.
* Dose not check the parity bits of the key but simple ignore them.
@ -727,7 +738,7 @@ is_weak_key ( const byte *key )
{
middle = (left + right) / 2;
if ( !(cmp_result=memcmp(work, weak_keys[middle], 8)) )
if ( !(cmp_result=working_memcmp(work, weak_keys[middle], 8)) )
return -1;
if ( cmp_result > 0 )
@ -836,6 +847,8 @@ selftest (void)
static int
do_tripledes_setkey ( struct _tripledes_ctx *ctx, byte *key, unsigned keylen )
{
if( selftest_failed )
return G10ERR_SELFTEST_FAILED;
if( keylen != 24 )
return G10ERR_WRONG_KEYLEN;
@ -879,9 +892,12 @@ des_get_info( int algo, size_t *keylen,
if( !did_selftest ) {
const char *s = selftest();
if( s )
log_fatal("selftest failed: %s\n", s );
did_selftest = 1;
if( s ) {
fprintf(stderr,"%s\n", s );
selftest_failed = s;
return NULL;
}
}

View File

@ -19,14 +19,14 @@
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h> /* for assert() */
#include <string.h> /* for memcmp() */
#include "types.h" /* for byte and u32 typedefs */
#include "util.h" /* for log_fatal() */
#include "errors.h"
/* Prototype for the self-test function. */
static void selftest(void);
static const char *selftest(void);
/* Macros used by the info function. */
#define FNCCAST_SETKEY(f) ((int(*)(void*, byte*, unsigned))(f))
@ -456,17 +456,23 @@ twofish_setkey (TWOFISH_context *ctx, const byte *key, const unsigned keylen)
/* Temporary for CALC_S. */
byte tmp;
/* Flag for self-test. */
/* Flags for self-test. */
static int initialized = 0;
static const char *selftest_failed=0;
/* Check key length. */
assert (keylen == 16);
if( keylen != 16 )
return G10ERR_WRONG_KEYLEN;
/* Do self-test if necessary. */
if (!initialized) {
initialized = 1;
selftest ();
selftest_failed = selftest ();
if( selftest_failed )
fprintf(stderr, "%s\n", selftest_failed );
}
if( selftest_failed )
return G10ERR_SELFTEST_FAILED;
/* Compute the S vector. The magic numbers are the entries of the RS
* matrix, preprocessed through poly_to_exp. The numbers in the comments
@ -709,7 +715,7 @@ twofish_decrypt (const TWOFISH_context *ctx, byte *out, const byte *in)
/* Test a single encryption and decryption, as a sanity check. */
static void
static const char*
selftest (void)
{
TWOFISH_context ctx; /* Expanded key. */
@ -736,10 +742,11 @@ selftest (void)
twofish_setkey (&ctx, key, sizeof(key));
twofish_encrypt (&ctx, scratch, plaintext);
if (memcmp (scratch, ciphertext, sizeof (ciphertext)))
log_fatal ("Twofish test encryption failed\n");
return "Twofish test encryption failed.";
twofish_decrypt (&ctx, scratch, scratch);
if (memcmp (scratch, plaintext, sizeof (plaintext)))
log_fatal ("Twofish test decryption failed\n");
return "Twofish test decryption failed.";
return NULL;
}
/* More complete test program. This does a thousand encryptions and

View File

@ -1,3 +1,11 @@
Sun Jan 17 11:04:33 CET 1999 Werner Koch <wk@isil.d.shuttle.de>
* textfilter.c (text_filter): Now uses iobuf_read_line().
(read_line): Removed.
* armor.c (trim_trailing_spaces): Removed and replaced
by trim_trailing_ws from libutil
Sat Jan 16 12:03:27 CET 1999 Werner Koch <wk@isil.d.shuttle.de>
* hkp.c (hkp_ask_import): Use only the short keyid

View File

@ -256,31 +256,6 @@ parse_hash_header( const char *line )
static unsigned
trim_trailing_spaces( byte *line, unsigned len )
{
byte *p, *mark;
unsigned n;
for(mark=NULL, p=line, n=0; n < len; n++, p++ ) {
if( strchr(" \t\r\n", *p ) ) {
if( !mark )
mark = p;
}
else
mark = NULL;
}
if( mark ) {
*mark = 0;
return mark - line;
}
return len;
}
/****************
* Check whether this is a armor line.
* returns: -1 if it is not a armor header or the index number of the
@ -339,7 +314,7 @@ parse_header_line( armor_filter_context_t *afx, byte *line, unsigned len )
if( *line == '\n' || ( len && (*line == '\r' && line[1]=='\n') ) )
return 0; /* empty line */
len = trim_trailing_spaces( line, len );
len = trim_trailing_ws( line, len );
p = strchr( line, ':');
if( !p || !p[1] ) {
log_error(_("invalid armor header: "));
@ -521,8 +496,7 @@ fake_packet( armor_filter_context_t *afx, IOBUF a,
if( !maxlen )
afx->truncated++;
if( !afx->not_dash_escaped )
afx->buffer_len = trim_trailing_spaces( afx->buffer,
afx->buffer_len );
afx->buffer_len = trim_trailing_ws( afx->buffer, afx->buffer_len );
p = afx->buffer;
n = afx->buffer_len;

View File

@ -80,10 +80,11 @@ typedef struct {
typedef struct {
int eof;
size_t idx;
size_t len;
byte buf[256];
byte *buffer; /* malloced buffer */
unsigned buffer_size; /* and size of this buffer */
unsigned buffer_len; /* used length of the buffer */
unsigned buffer_pos; /* read position */
int truncated; /* number of truncated lines */
} text_filter_context_t;

View File

@ -444,6 +444,11 @@ cmp_signatures( PKT_signature *a, PKT_signature *b )
return 0;
}
/****************
* Returns: true if the user ids do not match
*/
int
cmp_user_ids( PKT_user_id *a, PKT_user_id *b )
{

View File

@ -349,8 +349,6 @@ sign_file( STRLIST filenames, int detached, STRLIST locusr,
* data, it is not possible to know the used length
* without a double read of the file - to avoid that
* we simple use partial length packets.
* FIXME: We have to do the double read when opt.rfc1991
* is active.
*/
if( opt.textmode && !outfile )
filesize = 0;

View File

@ -30,72 +30,10 @@
#include "memory.h"
#include "util.h"
#include "filter.h"
#include "i18n.h"
static int
read_line( byte *buf, size_t *r_buflen, IOBUF a )
{
int c;
int rc = 0;
byte *p;
size_t buflen;
int no_lf=0;
size_t n;
buflen = *r_buflen;
assert(buflen >= 20 );
buflen -= 3; /* leave some room for CR,LF and one extra */
for(c=0, n=0; n < buflen && (c=iobuf_get(a)) != -1 && c != '\n'; )
buf[n++] = c;
buf[n] = 0;
if( c == -1 ) {
rc = -1;
if( !n || buf[n-1] != '\n' )
no_lf = 1;
}
else if( c != '\n' ) {
IOBUF b = iobuf_temp();
while( (c=iobuf_get(a)) != -1 && c != '\n' ) {
iobuf_put(b,c);
if( c != ' ' && c != '\t' && c != '\r' )
break;
}
if( c == '\n' ) { /* okay we can skip the rest of the line */
iobuf_close(b);
}
else {
iobuf_unget_and_close_temp(a,b);
no_lf = 1;
}
}
if( !no_lf ) {
/* append CR,LF after removing trailing wspaces */
for(p=buf+n-1; n; n--, p-- ) {
assert( *p != '\n' );
if( *p != ' ' && *p != '\t' && *p != '\r' ) {
p[1] = '\r';
p[2] = '\n';
n += 2;
break;
}
}
if( !n ) {
buf[0] = '\r';
buf[1] = '\n';
n = 2;
}
}
*r_buflen = n;
return rc;
}
#define MAX_LINELEN 20000
/****************
@ -109,33 +47,52 @@ text_filter( void *opaque, int control,
size_t size = *ret_len;
text_filter_context_t *tfx = opaque;
int rc=0;
size_t len, n, nn;
if( control == IOBUFCTRL_UNDERFLOW ) {
assert( size > 30 );
len = 0;
size_t len = 0;
unsigned maxlen;
assert( size > 10 );
size -= 2; /* reserve 2 bytes to append CR,LF */
while( !rc && len < size ) {
if( tfx->idx < tfx->len ) { /* flush the last buffer */
n = tfx->len;
for(nn=tfx->idx; len < size && nn < n ; nn++ )
buf[len++] = tfx->buf[nn];
tfx->idx = nn;
int lf_seen;
while( len < size && tfx->buffer_pos < tfx->buffer_len )
buf[len++] = tfx->buffer[tfx->buffer_pos++];
if( len >= size )
continue;
/* read the next line */
maxlen = MAX_LINELEN;
tfx->buffer_pos = 0;
tfx->buffer_len = iobuf_read_line( a, &tfx->buffer,
&tfx->buffer_size, &maxlen );
if( !maxlen )
tfx->truncated++;
if( !tfx->buffer_len ) {
if( !len )
rc = -1; /* eof */
break;
}
if( tfx->eof ) {
rc = -1;
continue;
lf_seen = tfx->buffer[tfx->buffer_len-1] == '\n';
tfx->buffer_len = trim_trailing_ws( tfx->buffer, tfx->buffer_len );
if( lf_seen ) {
tfx->buffer[tfx->buffer_len++] = '\r';
tfx->buffer[tfx->buffer_len++] = '\n';
}
n = DIM(tfx->buf);
tfx->idx = 0;
if( read_line( tfx->buf, &n, a ) == -1 )
tfx->eof = 1;
tfx->len = n;
}
*ret_len = len;
}
else if( control == IOBUFCTRL_DESC )
*(char**)buf = "text_filter";
else if( control == IOBUFCTRL_FREE ) {
if( tfx->truncated )
log_error(_("can't handle text lines longer than %d characters\n"),
MAX_LINELEN );
m_free( tfx->buffer );
tfx->buffer = NULL;
}
return rc;
}

View File

@ -69,6 +69,7 @@
#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
#ifndef HAVE_STRERROR

View File

@ -161,6 +161,7 @@ STRLIST strlist_last( STRLIST node );
const char *memistr( const char *buf, size_t buflen, const char *sub );
char *mem2str( char *, const void *, size_t);
char *trim_spaces( char *string );
unsigned trim_trailing_ws( byte *line, unsigned len );
int string_count_chr( const char *string, int c );
int set_native_charset( const char *newset );
char *native_to_utf8( const char *string );

View File

@ -35,6 +35,7 @@ g10/hkp.c
g10/seckey-cert.c
g10/sig-check.c
g10/sign.c
g10/textfilter.c
g10/tdbio.c
g10/trustdb.c
g10/verify.c

View File

@ -1,3 +1,7 @@
Sun Jan 17 11:04:33 CET 1999 Werner Koch <wk@isil.d.shuttle.de>
* autogen.sh: Now checks for installed gettext
Sat Jan 16 09:27:30 CET 1999 Werner Koch <wk@isil.d.shuttle.de>
* config.guess (m68k-atari-mint): New.

View File

@ -35,6 +35,18 @@ else
DIE="yes"
fi
if (gettext --version </dev/null 2>/dev/null | awk 'NR==1 { split($4,A,"\."); \
X=10000*A[1]+100*A[2]+A[3]; echo X; if( X >= 1035 ) exit 1; exit 0}')
then
echo "**Error**: You must have "\`gettext\'" installed to compile $PGM."
echo ' (version 0.10.35 or newer is required; get'
echo ' ftp://alpha.gnu.org/gnu/gettext-0.10.35.tar.gz)'
DIE="yes"
fi
if test "$DIE" = "yes"; then
exit 1
fi

View File

@ -1,3 +1,7 @@
Sun Jan 17 11:04:33 CET 1999 Werner Koch <wk@isil.d.shuttle.de>
* strgutil.c (trim_trailing_ws): New.
Sat Jan 16 12:03:27 CET 1999 Werner Koch <wk@isil.d.shuttle.de>
* http.c (connect_server): Fixed stupid bug.

View File

@ -98,6 +98,7 @@ g10_errstr( int err )
X(BAD_URI ,N_("bad URI"))
X(INVALID_URI ,N_("unsupported URI"))
X(NETWORK ,N_("network error"))
X(SELFTEST_FAILED,"selftest failed")
default: p = buf; sprintf(buf, "g10err=%d", err); break;
}
#undef X

View File

@ -191,6 +191,34 @@ trim_spaces( char *str )
}
/****************
* remove trailing white spaces and return the length of the buffer
*/
unsigned
trim_trailing_ws( byte *line, unsigned len )
{
byte *p, *mark;
unsigned n;
for(mark=NULL, p=line, n=0; n < len; n++, p++ ) {
if( strchr(" \t\r\n", *p ) ) {
if( !mark )
mark = p;
}
else
mark = NULL;
}
if( mark ) {
*mark = 0;
return mark - line;
}
return len;
}
int
string_count_chr( const char *string, int c )
{