FC Updates from BitShares and myself #21
3 changed files with 7 additions and 11 deletions
|
|
@ -22,6 +22,7 @@
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include <openssl/sha.h>
|
||||||
#include <boost/endian/buffers.hpp>
|
#include <boost/endian/buffers.hpp>
|
||||||
#include <fc/fwd.hpp>
|
#include <fc/fwd.hpp>
|
||||||
#include <fc/io/raw_fwd.hpp>
|
#include <fc/io/raw_fwd.hpp>
|
||||||
|
|
@ -39,7 +40,7 @@ class hash160
|
||||||
explicit operator string()const;
|
explicit operator string()const;
|
||||||
|
|
||||||
char* data() const;
|
char* data() const;
|
||||||
size_t data_size() const { return 160/8; }
|
static constexpr size_t data_size() { return 160/8; }
|
||||||
|
|
||||||
static hash160 hash( const char* d, uint32_t dlen );
|
static hash160 hash( const char* d, uint32_t dlen );
|
||||||
static hash160 hash( const string& );
|
static hash160 hash( const string& );
|
||||||
|
|
@ -66,7 +67,7 @@ class hash160
|
||||||
private:
|
private:
|
||||||
class impl;
|
class impl;
|
||||||
fc::fwd<impl,96> my;
|
fc::fwd<impl,96> my;
|
||||||
std::vector<uint8_t> bytes;
|
SHA256_CTX sha_ctx;;
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@
|
||||||
|
|
||||||
#include <fc/crypto/hex.hpp>
|
#include <fc/crypto/hex.hpp>
|
||||||
#include <fc/fwd_impl.hpp>
|
#include <fc/fwd_impl.hpp>
|
||||||
#include <openssl/sha.h>
|
|
||||||
#include <openssl/ripemd.h>
|
#include <openssl/ripemd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <fc/crypto/hash160.hpp>
|
#include <fc/crypto/hash160.hpp>
|
||||||
|
|
@ -55,7 +54,7 @@ class hash160::encoder::impl {
|
||||||
};
|
};
|
||||||
|
|
||||||
hash160::encoder::~encoder() {}
|
hash160::encoder::~encoder() {}
|
||||||
hash160::encoder::encoder() {}
|
hash160::encoder::encoder() { SHA256_Init(&sha_ctx); }
|
||||||
|
|
||||||
hash160 hash160::hash( const char* d, uint32_t dlen ) {
|
hash160 hash160::hash( const char* d, uint32_t dlen ) {
|
||||||
encoder e;
|
encoder e;
|
||||||
|
|
@ -69,15 +68,11 @@ hash160 hash160::hash( const string& s ) {
|
||||||
|
|
||||||
void hash160::encoder::write( const char* d, uint32_t dlen )
|
void hash160::encoder::write( const char* d, uint32_t dlen )
|
||||||
{
|
{
|
||||||
for(uint32_t i = 0; i < dlen; ++i)
|
SHA256_Update( &sha_ctx, d, dlen);
|
||||||
bytes.push_back(d[i]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
hash160 hash160::encoder::result() {
|
hash160 hash160::encoder::result() {
|
||||||
// perform the first hashing function
|
// finalize the first hash
|
||||||
SHA256_CTX sha_ctx;
|
|
||||||
SHA256_Init(&sha_ctx);
|
|
||||||
SHA256_Update( &sha_ctx, bytes.data(), bytes.size());
|
|
||||||
unsigned char sha_hash[SHA256_DIGEST_LENGTH];
|
unsigned char sha_hash[SHA256_DIGEST_LENGTH];
|
||||||
SHA256_Final( sha_hash, &sha_ctx );
|
SHA256_Final( sha_hash, &sha_ctx );
|
||||||
// perform the second hashing function
|
// perform the second hashing function
|
||||||
|
|
|
||||||
|
|
@ -74,7 +74,7 @@ BOOST_AUTO_TEST_CASE(static_variant_depth_test)
|
||||||
for( const auto& line : lines )
|
for( const auto& line : lines )
|
||||||
if( line.find("_svdt_visitor") != std::string::npos ) count++;
|
if( line.find("_svdt_visitor") != std::string::npos ) count++;
|
||||||
BOOST_CHECK_LT( 2, count ); // test.visit(), static_variant::visit, function object, visitor
|
BOOST_CHECK_LT( 2, count ); // test.visit(), static_variant::visit, function object, visitor
|
||||||
BOOST_CHECK_GT( 8, count ); // some is implementation-dependent
|
BOOST_CHECK_GT( 10, count ); // some is implementation-dependent
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue