diff options
author | Nick Mathewson <nickm@torproject.org> | 2013-02-04 12:50:01 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2013-02-07 14:09:01 -0500 |
commit | 266419d244c1a4795407479693b016c5a8b5da96 (patch) | |
tree | cb5c0b8a9aab066209f81bb8b80cb1e7c3719929 /src/common/crypto_curve25519.c | |
parent | 898f2d7c278442d2c4fbdf0126eaa406d503d088 (diff) | |
download | tor-266419d244c1a4795407479693b016c5a8b5da96.tar.gz tor-266419d244c1a4795407479693b016c5a8b5da96.zip |
Tolerate curve25519 backends where the high bit of the pk isn't ignored
Right now, all our curve25519 backends ignore the high bit of the
public key. But possibly, others could treat the high bit of the
public key as encoding out-of-bounds values, or as something to be
preserved. This could be used to distinguish clients with different
backends, at the cost of killing a circuit.
As a workaround, let's just clear the high bit of each public key
indiscriminately before we use it. Fix for bug 8121, reported by
rransom. Bugfix on 0.2.4.8-alpha.
Diffstat (limited to 'src/common/crypto_curve25519.c')
-rw-r--r-- | src/common/crypto_curve25519.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/common/crypto_curve25519.c b/src/common/crypto_curve25519.c index 425a1a078c..3e4004db2e 100644 --- a/src/common/crypto_curve25519.c +++ b/src/common/crypto_curve25519.c @@ -33,13 +33,20 @@ int curve25519_impl(uint8_t *output, const uint8_t *secret, const uint8_t *basepoint) { + uint8_t bp[CURVE25519_PUBKEY_LEN]; + int r; + memcpy(bp, basepoint, CURVE25519_PUBKEY_LEN); + /* Clear the high bit, in case our backend foolishly looks at it. */ + bp[31] &= 0x7f; #ifdef USE_CURVE25519_DONNA - return curve25519_donna(output, secret, basepoint); + r = curve25519_donna(output, secret, bp); #elif defined(USE_CURVE25519_NACL) - return crypto_scalarmult_curve25519(output, secret, basepoint); + r = crypto_scalarmult_curve25519(output, secret, bp); #else #error "No implementation of curve25519 is available." #endif + memwipe(bp, 0, sizeof(bp)); + return r; } /* ============================== |