Ok, I got it to work. I just had to make a 'compressed' version of my routine. Here is the code:
bool bitcoinCompressedPublicKeyToAddress(const uint8_t input[32], // The 33 byte long compressed ECDSA public key; first byte will always be 0x2 or 0x3 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
SHA256::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)
RIPEMD160::computeRIPEMD160(hash1,32,&output[1]); // Compute the RIPEMD160 (20 byte) hash of the SHA256 hash
SHA256::computeSHA256(output,21,hash1); // Compute the SHA256 hash of the RIPEMD16 hash + the one byte header (for a checksum)
SHA256::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;
}