From 379110a8a27316dcf4479895582018be675be573 Mon Sep 17 00:00:00 2001 From: seelabs Date: Sat, 26 Sep 2015 20:15:20 -0400 Subject: [PATCH] Improve treatment of signature components --- src/ripple/crypto/impl/ECDSACanonical.cpp | 2 +- src/ripple/crypto/impl/RFC1751.cpp | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/ripple/crypto/impl/ECDSACanonical.cpp b/src/ripple/crypto/impl/ECDSACanonical.cpp index 66ad596ab..6cdd0e2d7 100644 --- a/src/ripple/crypto/impl/ECDSACanonical.cpp +++ b/src/ripple/crypto/impl/ECDSACanonical.cpp @@ -98,7 +98,7 @@ public: : m_skip (0) { // The format is: <02> - if ((sig[0] != 0x02) || (size < 3)) + if ((size < 3) || (sig[0] != 0x02)) return; std::size_t const len (sig[1]); diff --git a/src/ripple/crypto/impl/RFC1751.cpp b/src/ripple/crypto/impl/RFC1751.cpp index 9f9a8720a..009083c0c 100644 --- a/src/ripple/crypto/impl/RFC1751.cpp +++ b/src/ripple/crypto/impl/RFC1751.cpp @@ -271,12 +271,13 @@ unsigned long RFC1751::extract (char const* s, int start, int length) assert (length >= 0); assert (start + length <= 66); + int const shiftR = 24 - (length + (start % 8)); cl = s[start / 8]; // get components - cc = s[start / 8 + 1]; - cr = s[start / 8 + 2]; + cc = (shiftR < 16) ? s[start / 8 + 1] : 0; + cr = (shiftR < 8) ? s[start / 8 + 2] : 0; x = ((long) (cl << 8 | cc) << 8 | cr) ; // Put bits together - x = x >> (24 - (length + (start % 8))); // Right justify number + x = x >> shiftR; // Right justify number x = ( x & (0xffff >> (16 - length) ) ); // Trim extra bits. return x;