]> wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
Bugfix - carry bit overflow
authorDmitry Belyavskiy <beldmit@gmail.com>
Thu, 15 Mar 2018 08:03:36 +0000 (11:03 +0300)
committerDmitry Belyavskiy <beldmit@gmail.com>
Thu, 15 Mar 2018 08:03:36 +0000 (11:03 +0300)
etalon/carry [new file with mode: 0644]
etalon/dgst.result
gosthash2012.c

diff --git a/etalon/carry b/etalon/carry
new file mode 100644 (file)
index 0000000..a6c1240
--- /dev/null
@@ -0,0 +1 @@
+îîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîîî\16\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\11\16
\ No newline at end of file
index 5c4fe80823960044109f8e5a9e8fed37945b67f1..c1e71de7e6c98a9d7b25ce6b13479490576d1300 100644 (file)
@@ -5,6 +5,7 @@ md_gost12_512(M4)= b0fd29ac1b0df441769ff3fdb8dc564df67721d6ac06fb28ceffb7bbaa794
 md_gost12_512(M5)= 363b449ec81ae40b3a407b125c3b1c2b768b50496bcb5f690b89e9007b06e4084182ed45d4072a67fec9d3421dab013da2aabc1d6528e8e775aec7b3457ac675
 md_gost12_512(M6)= 8781dfc81d2db6a41d1857f3230b3ffe2bda574273ea1947189aaa5468470df1c4b374b1a2b56e59d11d213fea57e3514543b0ced9b20e553ae66425ec909cfd
 md_gost12_512(M7)= 03e12ae816c7f794929b7550781d22efc7bc724fd70e295f3123d157c4d577fdc325943ef2b999cc43205dc323fa930bddc60d44663d76844b779fd36aa89de3
+md_gost12_512(carry)= 8b06f41e59907d9636e892caf5942fcdfb71fa31169a5e70f0edb873664df41c2cce6e06dc6755d15a61cdeb92bd607cc4aaca6732bf3568a23a210dd520fd41
 md_gost12_256(M1)= 9d151eefd8590b89daa6ba6cb74af9275dd051026bb149a452fd84e5e57b5500
 md_gost12_256(M2)= 9dd2fe4e90409e5da87f53976d7405b0c0cac628fc669a741d50063c557e8f50
 md_gost12_256(M3)= 3f539a213e97c802cc229d474c6aa32a825a360b2a933a949fd925208d9ce1bb
@@ -12,3 +13,4 @@ md_gost12_256(M4)= df1fda9ce83191390537358031db2ecaa6aa54cd0eda241dc107105e13636
 md_gost12_256(M5)= f0a557f6a04a90ab1811c1b6e9b078e4163b74037c6cf59f52444a37f48e11d8
 md_gost12_256(M6)= 2f4f651fe88fea46ec6f2223728d8dff3968893558ef00a310c23e7d1923ba0c
 md_gost12_256(M7)= 633b567983d60243837715e56cc52443ffff9824170ad60b613b2dd6fabf2f40
+md_gost12_256(carry)= 81bb632fa31fcc38b4c379a662dbc58b9bed83f50d3a1b2ce7271ab02d25babb 
index f9b8f233aeff3bb9b0ef7d989290e12f9aac6949..ee534c2f9f838f2ef52797c23e88e63f98b9b5ef 100644 (file)
@@ -60,18 +60,33 @@ static INLINE void add512(const union uint512_u *x,
 {
 #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])
+    for (i = 0; i < 8; i++)
+    {
+        /* Detecting integer overflow condition for three numbers
+         * in a portable way is tricky a little. */
+
+        /* Step 1: numbers cause overflow */
+        tmp = x->QWORD[i] + y->QWORD[i];
+
+        /* Compare with any of two summands, no need to check both */
+        if (tmp < x->QWORD[i])
             OF = 1;
         else
             OF = 0;
 
-        r->QWORD[i] += CF;
+        /* Step 2: carry bit causes overflow */
+        tmp += CF;
+
+        if (CF > 0 && tmp == 0)
+            OF = 1;
+
         CF = OF;
+
+        r->QWORD[i] = tmp;
     }
 #else
     const unsigned char *xp, *yp;