Bitcoin/address validation: Difference between revisions
Content added Content deleted
(→{{header|Python}}: More valid bc's) |
m (→{{header|C}}: use simple function from library) |
||
Line 28: | Line 28: | ||
#include <string.h> |
#include <string.h> |
||
#include <openssl/sha.h> |
#include <openssl/sha.h> |
||
void sha256(unsigned char* str, int len, unsigned char *d) { |
|||
SHA256_CTX ctx; |
|||
SHA256_Init(&ctx); |
|||
SHA256_Update(&ctx, str, len); |
|||
SHA256_Final(d, &ctx); |
|||
} |
|||
char *coin_err; |
char *coin_err; |
||
Line 48: | Line 41: | ||
memset(out, 0, 25); |
memset(out, 0, 25); |
||
for (i = 0; s[i]; i++) { |
for (i = 0; s[i]; i++) { |
||
if (!(p = strchr(tmpl, s[i]))) |
if (!(p = strchr(tmpl, s[i]))) |
||
bail("bad char"); |
bail("bad char"); |
||
Line 70: | Line 63: | ||
if (!unbase58(s, dec)) return 0; |
if (!unbase58(s, dec)) return 0; |
||
SHA256(SHA256(dec, 21, d1), SHA256_DIGEST_LENGTH, d2); |
|||
sha256(d1, SHA256_DIGEST_LENGTH, d2); |
|||
if (memcmp(dec + 21, d2, 4)) |
if (memcmp(dec + 21, d2, 4)) |