예제 #1
0
void bitcoinRIPEMD160ToScriptAddress(const uint8_t ripeMD160[20],uint8_t output[25])
{
	uint8_t hash1[32]; // holds the intermediate SHA256 hash computations
	output[0] = 5;	// Store a network byte of 0 (i.e. 'main' network)
	memcpy(&output[1],ripeMD160,20); // copy the 20 byte of the public key address
	computeSHA256(output,21,hash1);	// Compute the SHA256 hash of the RIPEMD16 hash + the one byte header (for a checksum)
	computeSHA256(hash1,32,hash1); // now compute the SHA256 hash of the previously computed SHA256 hash (for a checksum)
	output[21] = hash1[0];	// Store the checksum in the last 4 bytes of the public key hash
	output[22] = hash1[1];
	output[23] = hash1[2];
	output[24] = hash1[3];
}
예제 #2
0
bool bitcoinAsciiToAddress(const char *input,uint8_t output[25]) // convert an ASCII bitcoin address into binary.
{
	bool ret = false;
	uint32_t len = decodeBase58(input,output,25,true);
	if ( len == 25 ) // the output must be *exactly* 25 bytes!
	{
		uint8_t checksum[32];
		computeSHA256(output,21,checksum);
		computeSHA256(checksum,32,checksum);
		if ( output[21] == checksum[0] ||
			 output[22] == checksum[1] ||
			 output[23] == checksum[2] ||
			 output[24] == checksum[3] )
		{
			ret = true; // the cheksum matches!
		}
	}
	return ret;
}
예제 #3
0
bool bitcoinCompressedPublicKeyToAddress(const uint8_t input[33], // The 33 byte long compressed ECDSA public key; first byte will always be 0x4 followed by the 32 byte component
									     uint8_t output[25])		// A bitcoin address (in binary( is always 25 bytes long.
{
	bool ret = false;

	if ( input[0] == 0x02 || input[0] == 0x03 )
	{
		uint8_t hash1[32]; // holds the intermediate SHA256 hash computations
		computeSHA256(input,33,hash1);	// Compute the SHA256 hash of the input public ECSDA signature
		output[0] = 0;	// Store a network byte of 0 (i.e. 'main' network)
		computeRIPEMD160(hash1,32,&output[1]);	// Compute the RIPEMD160 (20 byte) hash of the SHA256 hash
		computeSHA256(output,21,hash1);	// Compute the SHA256 hash of the RIPEMD16 hash + the one byte header (for a checksum)
		computeSHA256(hash1,32,hash1); // now compute the SHA256 hash of the previously computed SHA256 hash (for a checksum)
		output[21] = hash1[0];	// Store the checksum in the last 4 bytes of the public key hash
		output[22] = hash1[1];
		output[23] = hash1[2];
		output[24] = hash1[3];
		ret = true;
	}
	return ret;
}
예제 #4
0
ClientImpl::ClientImpl(ClientConfig config) throw(voltdb::Exception, voltdb::LibEventException) :
        m_nextRequestId(INT64_MIN), m_nextConnectionIndex(0), m_listener(config.m_listener),
        m_invocationBlockedOnBackpressure(false), m_loopBreakRequested(false), m_isDraining(false),
        m_instanceIdIsSet(false), m_outstandingRequests(0), m_username(config.m_username),
        m_maxOutstandingRequests(config.m_maxOutstandingRequests), m_ignoreBackpressure(false),
        m_useClientAffinity(false),m_updateHashinator(false), m_pendingConnectionSize(0) ,
        m_pLogger(0)
{

    pthread_once(&once_initLibevent, initLibevent);
#ifdef DEBUG
    if (!voltdb_clientimpl_debug_init_libevent) {
        event_enable_debug_mode();
        voltdb_clientimpl_debug_init_libevent = true;
    }
#endif
    struct event_config *cfg = event_config_new();
    event_config_set_flag(cfg, EVENT_BASE_FLAG_NO_CACHE_TIME);//, EVENT_BASE_FLAG_NOLOCK);
    m_base = event_base_new_with_config(cfg);
    assert(m_base);
    if (!m_base) {
        throw voltdb::LibEventException();
    }
    m_hashScheme = config.m_hashScheme;
    if (m_hashScheme == HASH_SHA1) {
        SHA1_CTX context;
        SHA1_Init(&context);
        SHA1_Update( &context, reinterpret_cast<const unsigned char*>(config.m_password.data()), config.m_password.size());
        m_passwordHash = (unsigned char *)malloc(20*sizeof(char));
        SHA1_Final ( &context, m_passwordHash);
    } else if (config.m_hashScheme == HASH_SHA256) {
        m_passwordHash = (unsigned char *)malloc(32*sizeof(char));
        computeSHA256(config.m_password.c_str(), config.m_password.size(), m_passwordHash);
    } else {
        throw voltdb::LibEventException();
    }

    if (0 == pipe(m_wakeupPipe)) {
        struct event *ev = event_new(m_base, m_wakeupPipe[0], EV_READ|EV_PERSIST, wakeupPipeCallback, this);
        event_add(ev, NULL);
    } else {
        m_wakeupPipe[1] = -1;
    }
    SHA1_CTX context;
    SHA1_Init(&context);
    SHA1_Update( &context, reinterpret_cast<const unsigned char*>(config.m_password.data()), config.m_password.size());
    SHA1_Final(&context, m_passwordHash);
}