mirror of
https://github.com/veracrypt/VeraCrypt
synced 2024-11-13 06:33:34 +01:00
crypto: cleaner code for Streebog carry bit handling and add comment about missing handling of overflow caused by carry bit.
This commit is contained in:
parent
6c9adee646
commit
a11cada735
@ -1845,21 +1845,40 @@ add512(const unsigned long long *x, const unsigned long long *y, unsigned long l
|
|||||||
{
|
{
|
||||||
#ifndef __GOST3411_BIG_ENDIAN__
|
#ifndef __GOST3411_BIG_ENDIAN__
|
||||||
unsigned int CF, OF;
|
unsigned int CF, OF;
|
||||||
|
unsigned long long tmp;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
CF = 0;
|
CF = 0;
|
||||||
for (i = 0; i < 8; i++)
|
for (i = 0; i < 8; i++)
|
||||||
{
|
{
|
||||||
r[i] = x[i] + y[i];
|
/* Detecting integer overflow condition for three numbers
|
||||||
if ( (r[i] < y[i]) ||
|
* in a portable way is tricky a little. */
|
||||||
(r[i] < x[i]) )
|
|
||||||
|
/* Step 1: numbers cause overflow */
|
||||||
|
tmp = x[i] + y[i];
|
||||||
|
|
||||||
|
/* Compare with any of two summands, no need to check both */
|
||||||
|
if (tmp < x[i])
|
||||||
OF = 1;
|
OF = 1;
|
||||||
else
|
else
|
||||||
OF = 0;
|
OF = 0;
|
||||||
|
|
||||||
r[i] += CF;
|
/* Step 2: carry bit causes overflow */
|
||||||
|
tmp += CF;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* We don't include the carry bit overflow since it can break
|
||||||
|
* mounting for some containers eventhough the probability of
|
||||||
|
* such case is very low
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
if (CF > 0 && tmp == 0)
|
||||||
|
OF = 1;
|
||||||
|
*/
|
||||||
CF = OF;
|
CF = OF;
|
||||||
}
|
|
||||||
|
r[i] = tmp;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
const unsigned char *xp, *yp;
|
const unsigned char *xp, *yp;
|
||||||
unsigned char *rp;
|
unsigned char *rp;
|
||||||
|
Loading…
Reference in New Issue
Block a user