Fixed signedness, simplified word-shift
This commit is contained in:
parent
d67c18f6c3
commit
5377b45d97
2 changed files with 13 additions and 17 deletions
|
|
@ -1,33 +1,29 @@
|
||||||
#include <boost/endian/conversion.hpp>
|
|
||||||
#include <fc/exception/exception.hpp>
|
#include <fc/exception/exception.hpp>
|
||||||
#include "_digest_common.hpp"
|
#include "_digest_common.hpp"
|
||||||
|
|
||||||
namespace fc { namespace detail {
|
namespace fc { namespace detail {
|
||||||
static void shift_l( const uint32_t* in, uint32_t* out, std::size_t n, int i) {
|
static void shift_l( const uint8_t* in, uint8_t* out, std::size_t n, unsigned int i) {
|
||||||
if (i < n) {
|
if (i < n) {
|
||||||
memcpy( out, in + i, 4*(n-i) );
|
memcpy( out, in + i, n-i );
|
||||||
} else {
|
} else {
|
||||||
i = n;
|
i = n;
|
||||||
}
|
}
|
||||||
memset( out + (n-i), 0, 4 * i );
|
memset( out + (n-i), 0, i );
|
||||||
}
|
}
|
||||||
|
|
||||||
void shift_l( const char* in, char* out, std::size_t n, int i) {
|
void shift_l( const char* in, char* out, std::size_t n, unsigned int i) {
|
||||||
FC_ASSERT( (n & 3) == 0 ); // all hashes are a multiple of 32 bit
|
const uint8_t* in8 = (uint8_t*) in;
|
||||||
n >>= 2;
|
uint8_t* out8 = (uint8_t*) out;
|
||||||
const uint32_t* in32 = (uint32_t*) in;
|
|
||||||
uint32_t* out32 = (uint32_t*) out;
|
|
||||||
|
|
||||||
if (i >= 32) {
|
if (i >= 8) {
|
||||||
shift_l( in32, out32, n, i >> 5 );
|
shift_l( in8, out8, n, i >> 3 );
|
||||||
i &= 0x1f;
|
i &= 7;
|
||||||
in32 = out32;
|
in8 = out8;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t p;
|
std::size_t p;
|
||||||
for( p = 0; p < n-1; ++p )
|
for( p = 0; p < n-1; ++p )
|
||||||
out32[p] = boost::endian::native_to_big(boost::endian::big_to_native(in32[p]) << i
|
out8[p] = (in8[p] << i) | (in8[p+1]>>(8-i));
|
||||||
| (boost::endian::big_to_native(in32[p+1])>>(32-i)));
|
out8[p] = in8[p] << i;
|
||||||
out32[p] = boost::endian::native_to_big(boost::endian::big_to_native(in32[p]) << i);
|
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
|
|
@ -3,5 +3,5 @@
|
||||||
/* Common stuff for cryptographic hashes
|
/* Common stuff for cryptographic hashes
|
||||||
*/
|
*/
|
||||||
namespace fc { namespace detail {
|
namespace fc { namespace detail {
|
||||||
void shift_l( const char* in, char* out, std::size_t n, int i);
|
void shift_l( const char* in, char* out, std::size_t n, unsigned int i);
|
||||||
}}
|
}}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue