FC Updates from BitShares and myself #21
4 changed files with 84 additions and 11 deletions
72
include/fc/container/zeroed_array.hpp
Normal file
72
include/fc/container/zeroed_array.hpp
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
#pragma once
|
||||
/*
|
||||
* Copyright (c) 2019 BitShares Blockchain Foundation, and contributors
|
||||
*
|
||||
* The MIT License
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
#include <fc/io/raw_fwd.hpp>
|
||||
|
||||
namespace fc {
|
||||
|
||||
template< typename T, size_t N >
|
||||
class zero_initialized_array;
|
||||
|
||||
template< size_t N >
|
||||
class zero_initialized_array< unsigned char, N > : public std::array< unsigned char, N > {
|
||||
public:
|
||||
zero_initialized_array() : std::array< unsigned char, N >() { }
|
||||
};
|
||||
|
||||
template<typename T,size_t N>
|
||||
struct get_typename< zero_initialized_array<T,N> >
|
||||
{
|
||||
static const char* name()
|
||||
{
|
||||
static std::string _name = std::string("zero_initialized_array<")
|
||||
+ std::string(fc::get_typename<T>::name())
|
||||
+ "," + fc::to_string(N) + ">";
|
||||
return _name.c_str();
|
||||
}
|
||||
};
|
||||
|
||||
class variant;
|
||||
template<size_t N>
|
||||
void to_variant( const zero_initialized_array<unsigned char,N>& bi, variant& v, uint32_t max_depth = 1 )
|
||||
{
|
||||
to_variant( static_cast<const std::array<unsigned char,N>&>( bi ), v, max_depth );
|
||||
}
|
||||
template<size_t N>
|
||||
void from_variant( const variant& v, zero_initialized_array<unsigned char,N>& bi, uint32_t max_depth = 1 )
|
||||
{
|
||||
from_variant( v, static_cast<std::array<unsigned char,N>&>( bi ), max_depth );
|
||||
}
|
||||
|
||||
namespace raw {
|
||||
template<typename Stream, size_t N>
|
||||
inline void pack( Stream& s, const zero_initialized_array<unsigned char,N>& v, uint32_t _max_depth ) {
|
||||
pack( s, static_cast<const std::array<unsigned char,N>&>( v ), _max_depth );
|
||||
}
|
||||
template<typename Stream, size_t N>
|
||||
inline void unpack( Stream& s, zero_initialized_array<unsigned char,N>& v, uint32_t _max_depth ) { try {
|
||||
unpack( s, static_cast<std::array<unsigned char,N>&>( v ), _max_depth );
|
||||
} FC_RETHROW_EXCEPTIONS( warn, "zero_initialized_array<unsigned char,${length}>", ("length",N) ) }
|
||||
}
|
||||
}
|
||||
|
|
@ -1,4 +1,5 @@
|
|||
#pragma once
|
||||
#include <fc/container/zeroed_array.hpp>
|
||||
#include <fc/crypto/bigint.hpp>
|
||||
#include <fc/crypto/openssl.hpp>
|
||||
#include <fc/crypto/sha256.hpp>
|
||||
|
|
@ -17,15 +18,15 @@ namespace fc {
|
|||
class private_key_impl;
|
||||
}
|
||||
|
||||
typedef fc::sha256 blind_factor_type;
|
||||
typedef std::array<unsigned char,33> commitment_type;
|
||||
typedef std::array<unsigned char,33> public_key_data;
|
||||
typedef fc::sha256 private_key_secret;
|
||||
typedef std::array<unsigned char,65> public_key_point_data; ///< the full non-compressed version of the ECC point
|
||||
typedef std::array<unsigned char,72> signature;
|
||||
typedef std::array<unsigned char,65> compact_signature;
|
||||
typedef std::vector<char> range_proof_type;
|
||||
typedef std::array<unsigned char,78> extended_key_data;
|
||||
typedef fc::sha256 blind_factor_type;
|
||||
typedef zero_initialized_array<unsigned char,33> commitment_type;
|
||||
typedef zero_initialized_array<unsigned char,33> public_key_data;
|
||||
typedef fc::sha256 private_key_secret;
|
||||
typedef zero_initialized_array<unsigned char,65> public_key_point_data; ///< the full non-compressed version of the ECC point
|
||||
typedef zero_initialized_array<unsigned char,72> signature;
|
||||
typedef zero_initialized_array<unsigned char,65> compact_signature;
|
||||
typedef std::vector<char> range_proof_type;
|
||||
typedef zero_initialized_array<unsigned char,78> extended_key_data;
|
||||
|
||||
/**
|
||||
* @class public_key
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@
|
|||
namespace fc { namespace ecc {
|
||||
|
||||
namespace detail {
|
||||
typedef std::array<unsigned char,37> chr37;
|
||||
typedef zero_initialized_array<unsigned char,37> chr37;
|
||||
|
||||
fc::sha256 _left( const fc::sha512& v )
|
||||
{
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ namespace fc { namespace ecc {
|
|||
public_key_data _key;
|
||||
};
|
||||
|
||||
typedef std::array<unsigned char,37> chr37;
|
||||
typedef zero_initialized_array<unsigned char,37> chr37;
|
||||
chr37 _derive_message( const public_key_data& key, int i );
|
||||
fc::sha256 _left( const fc::sha512& v );
|
||||
fc::sha256 _right( const fc::sha512& v );
|
||||
|
|
|
|||
Loading…
Reference in a new issue