summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2019-05-09 22:54:28 +0000
committertb <>2019-05-09 22:54:28 +0000
commit6bb847467ffdfdf97e77592e232c1b71d0ef6866 (patch)
tree88b1aec97f456e905c2ea2377674b4788c27d225 /src
parent238baabe10e5f495789f5635ba14bc725ec85c31 (diff)
downloadopenbsd-6bb847467ffdfdf97e77592e232c1b71d0ef6866.tar.gz
openbsd-6bb847467ffdfdf97e77592e232c1b71d0ef6866.tar.bz2
openbsd-6bb847467ffdfdf97e77592e232c1b71d0ef6866.zip
Fix incorrect carry operation in 512 bit addition: in the case
that there is already a carry and Sigma[i-1] == -1, the carry must be kept. From Dmitry Eremin-Solenik. Fixes incorrect Streebog result reported by Guido Vranken.
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/gost/streebog.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/lib/libcrypto/gost/streebog.c b/src/lib/libcrypto/gost/streebog.c
index 902472bd9e..61bce0e32c 100644
--- a/src/lib/libcrypto/gost/streebog.c
+++ b/src/lib/libcrypto/gost/streebog.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: streebog.c,v 1.5 2015/09/10 15:56:25 jsing Exp $ */ 1/* $OpenBSD: streebog.c,v 1.6 2019/05/09 22:54:28 tb Exp $ */
2/* 2/*
3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> 3 * Copyright (c) 2014 Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
4 * Copyright (c) 2005-2006 Cryptocom LTD 4 * Copyright (c) 2005-2006 Cryptocom LTD
@@ -1240,6 +1240,7 @@ static void
1240streebog_single_block(STREEBOG_CTX *ctx, const unsigned char *in, size_t num) 1240streebog_single_block(STREEBOG_CTX *ctx, const unsigned char *in, size_t num)
1241{ 1241{
1242 STREEBOG_LONG64 M[8], l; 1242 STREEBOG_LONG64 M[8], l;
1243 STREEBOG_LONG64 CF;
1243 int i; 1244 int i;
1244 1245
1245 for (i = 0; i < 8; i++) 1246 for (i = 0; i < 8; i++)
@@ -1258,12 +1259,13 @@ streebog_single_block(STREEBOG_CTX *ctx, const unsigned char *in, size_t num)
1258 } 1259 }
1259 } 1260 }
1260 1261
1262 CF = 0;
1261 ctx->Sigma[0] += M[0]; 1263 ctx->Sigma[0] += M[0];
1262 for (i = 1; i < 8; i++) 1264 for (i = 1; i < 8; i++) {
1263 if (ctx->Sigma[i-1] < M[i-1]) 1265 if (ctx->Sigma[i-1] != M[i-1])
1264 ctx->Sigma[i] += M[i] + 1; 1266 CF = (ctx->Sigma[i-1] < M[i-1]);
1265 else 1267 ctx->Sigma[i] += M[i] + CF;
1266 ctx->Sigma[i] += M[i]; 1268 }
1267} 1269}
1268 1270
1269 1271