Skip to content

Commit

Permalink
Fix overflow check in add512()
Browse files Browse the repository at this point in the history
The common use-case for add512 function is when a caller wants to store
a result in the same variable as a summand, say, add512(x,y,x).
In this case the overflow check is wrong.

        if ( (r->QWORD[i] < y->QWORD[i]) ||
             (r->QWORD[i] < x->QWORD[i]) )

If x is the same variable as r, the second comparision is
meaningless. This patch fixes it.

Signed-off-by: Kirill K. Smirnov <[email protected]>
  • Loading branch information
KirillSmirnov committed Nov 30, 2017
1 parent 92cda02 commit 336fe0e
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions gost3411-2012-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,20 @@ add512(const union uint512_u *x, const union uint512_u *y, union uint512_u *r)
{
#ifndef __GOST3411_BIG_ENDIAN__
unsigned int CF, OF;
unsigned long long tmp;
unsigned int i;

CF = 0;
for (i = 0; i < 8; i++)
{
r->QWORD[i] = x->QWORD[i] + y->QWORD[i];
if ( (r->QWORD[i] < y->QWORD[i]) ||
(r->QWORD[i] < x->QWORD[i]) )
tmp = x->QWORD[i] + y->QWORD[i];
if ( (tmp < y->QWORD[i]) ||
(tmp < x->QWORD[i]) )
OF = 1;
else
OF = 0;

r->QWORD[i] += CF;
tmp += CF;
CF = OF;
}
#else
Expand Down

0 comments on commit 336fe0e

Please sign in to comment.