diff options
author | tb <> | 2018-07-13 08:43:31 +0000 |
---|---|---|
committer | tb <> | 2018-07-13 08:43:31 +0000 |
commit | 2784227e885350759036fb7b1ecc5b560746db18 (patch) | |
tree | 8f7a8b11d06eff91987077719d19e4169878e718 | |
parent | 13d98c37792a5abab14711474be5b9d62863e1a8 (diff) | |
download | openbsd-2784227e885350759036fb7b1ecc5b560746db18.tar.gz openbsd-2784227e885350759036fb7b1ecc5b560746db18.tar.bz2 openbsd-2784227e885350759036fb7b1ecc5b560746db18.zip |
Eliminate the weird condition in the BN_swap_ct() API that at most one bit
be set in condition. This makes the constant time bit-twiddling a bit
trickier, but it's not too bad. Thanks to halex for an extensive rubber
ducking session over a non-spicy spicy tabouleh falafel..
ok jsing, kn
-rw-r--r-- | src/lib/libcrypto/bn/bn_lib.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c index d3ec00413f..3a468a1285 100644 --- a/src/lib/libcrypto/bn/bn_lib.c +++ b/src/lib/libcrypto/bn/bn_lib.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: bn_lib.c,v 1.43 2018/07/11 13:57:53 kn Exp $ */ | 1 | /* $OpenBSD: bn_lib.c,v 1.44 2018/07/13 08:43:31 tb Exp $ */ |
2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) |
3 | * All rights reserved. | 3 | * All rights reserved. |
4 | * | 4 | * |
@@ -894,7 +894,6 @@ BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords) | |||
894 | /* | 894 | /* |
895 | * Constant-time conditional swap of a and b. | 895 | * Constant-time conditional swap of a and b. |
896 | * a and b are swapped if condition is not 0. | 896 | * a and b are swapped if condition is not 0. |
897 | * The code assumes that at most one bit of condition is set. XXX add check? | ||
898 | * nwords is the number of words to swap. | 897 | * nwords is the number of words to swap. |
899 | */ | 898 | */ |
900 | int | 899 | int |
@@ -912,7 +911,8 @@ BN_swap_ct(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords) | |||
912 | return 0; | 911 | return 0; |
913 | } | 912 | } |
914 | 913 | ||
915 | condition = ((condition - 1) >> (BN_BITS2 - 1)) - 1; | 914 | /* Set condition to 0 (if it was zero) or all 1s otherwise. */ |
915 | condition = ((~condition & (condition - 1)) >> (BN_BITS2 - 1)) - 1; | ||
916 | 916 | ||
917 | /* swap top field */ | 917 | /* swap top field */ |
918 | t = (a->top ^ b->top) & condition; | 918 | t = (a->top ^ b->top) & condition; |