Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5cf0790

Browse files
committed
Fix errors in fortuna PRNG reseeding logic that could cause a predictable
session key to be selected by pgp_sym_encrypt() in some cases. This onlyaffects non-OpenSSL-using builds. Marko Kreen
1 parent515112f commit5cf0790

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

‎contrib/pgcrypto/fortuna.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727
* SUCH DAMAGE.
2828
*
29-
* $PostgreSQL: pgsql/contrib/pgcrypto/fortuna.c,v 1.5 2005/10/15 02:49:06 momjian Exp $
29+
* $PostgreSQL: pgsql/contrib/pgcrypto/fortuna.c,v 1.6 2006/05/21 20:22:16 tgl Exp $
3030
*/
3131

3232
#include"postgres.h"
@@ -219,21 +219,30 @@ encrypt_counter(FState * st, uint8 *dst)
219219
* microseconds.
220220
*/
221221
staticint
222-
too_often(FState*st)
222+
enough_time_passed(FState*st)
223223
{
224224
intok;
225225
structtimevaltv;
226226
structtimeval*last=&st->last_reseed_time;
227227

228228
gettimeofday(&tv,NULL);
229229

230+
/* check how much time has passed */
230231
ok=0;
231-
if (tv.tv_sec!=last->tv_sec)
232+
if (tv.tv_sec>last->tv_sec+1)
232233
ok=1;
234+
elseif (tv.tv_sec==last->tv_sec+1)
235+
{
236+
if (1000000+tv.tv_usec-last->tv_usec >=RESEED_INTERVAL)
237+
ok=1;
238+
}
233239
elseif (tv.tv_usec-last->tv_usec >=RESEED_INTERVAL)
234240
ok=1;
235241

236-
memcpy(last,&tv,sizeof(tv));
242+
/* reseed will happen, update last_reseed_time */
243+
if (ok)
244+
memcpy(last,&tv,sizeof(tv));
245+
237246
memset(&tv,0,sizeof(tv));
238247

239248
returnok;
@@ -372,7 +381,7 @@ extract_data(FState * st, unsigned count, uint8 *dst)
372381
unsignedblock_nr=0;
373382

374383
/* Can we reseed? */
375-
if (st->pool0_bytes >=POOL0_FILL&&!too_often(st))
384+
if (st->pool0_bytes >=POOL0_FILL&&enough_time_passed(st))
376385
reseed(st);
377386

378387
/* Is counter initialized? */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp