diff --git a/g10/ChangeLog b/g10/ChangeLog index 8ee93128c..5653bf650 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,9 @@ +2004-08-19 Werner Koch + + * seskey.c (encode_session_key): Changed the zero random byte + substituting code to actually do clever things. Thanks to + Matthias Urlichs for noting the implementation problem. + 2004-08-18 Marcus Brinkmann * passphrase.c (agent_get_passphrase): Fix detection of gpg-agent diff --git a/g10/seskey.c b/g10/seskey.c index 664508be0..cc58154ad 100644 --- a/g10/seskey.c +++ b/g10/seskey.c @@ -117,11 +117,14 @@ encode_session_key( DEK *dek, unsigned nbits ) k++; if( !k ) break; /* okay: no zero bytes */ - k += k/128; /* better get some more */ + k += k/128 + 3; /* better get some more */ pp = get_random_bits( k*8, 1, 1); - for(j=0; j < i && k ; j++ ) + for(j=0; j < i && k ;) { if( !p[j] ) p[j] = pp[--k]; + if (p[j]) + j++; + } m_free(pp); } memcpy( frame+n, p, i );