GithubHelp home page GithubHelp logo

isabella232 / libbase58 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from bitcoin/libbase58

0.0 0.0 0.0 44 KB

C library for Bitcoin's base58 encoding

License: MIT License

Shell 15.99% C 63.72% Makefile 10.08% M4 10.21%

libbase58's Introduction

Initialisation

Before you can use libbase58 for base58check, you must provide a SHA256 function. The required function signature is:

bool my_sha256(void *digest, const void *data, size_t datasz)

Simply assign your function to b58_sha256_impl:

b58_sha256_impl = my_sha256;

This is only required if base58check is used. Raw base58 does not need SHA256.

Decoding Base58

Simply allocate a buffer to store the binary data in, and set a variable with the buffer size, and call the b58tobin function:

bool b58tobin(void *bin, size_t *binsz, const char *b58, size_t b58sz)

The "canonical" base58 byte length will be assigned to binsz on success, which may be larger than the actual buffer if the input has many leading zeros. Regardless of the canonical byte length, the full binary buffer will be used. If b58sz is zero, it will be initialised with strlen(b58); note that a true zero-length base58 string is not supported here.

Validating Base58Check

After calling b58tobin, you can validate base58check data using the b58check function:

int b58check(const void *bin, size_t binsz, const char *b58, size_t b58sz)

Call it with the same buffers used for b58tobin. If the return value is negative, an error occurred. Otherwise, the return value is the base58check "version" byte from the decoded data.

Encoding Base58

Allocate a string to store the base58 content, create a size_t variable with the size of that allocation, and call:

bool b58enc(char *b58, size_t *b58sz, const void *data, size_t binsz)

Note that you must pass a pointer to the string size variable, not the size itself. When b58enc returns, the variable will be modified to contain the actual number of bytes used (including the null terminator). If encoding fails for any reason, or if the string buffer is not large enough for the result, b58enc will return false. Otherwise, it returns true to indicate success.

Encoding Base58Check

Targeting base58check is done similarly to raw base58 encoding, but you must also provide a version byte:

bool b58check_enc(char *b58c, size_t *b58c_sz, uint8_t ver,
                  const void *data, size_t datasz)

libbase58's People

Contributors

4tar avatar copernick8 avatar e271828- avatar jgriffiths avatar laanwj avatar luke-jr avatar randolf avatar voisine avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.