mirror of
https://github.com/eosswedenorg/libantelope
synced 2026-06-16 03:34:56 +02:00
Hash: Define init/update/final functions for sha256 and ripemd160
This commit is contained in:
parent
891d2e970d
commit
610c32c171
2 changed files with 62 additions and 0 deletions
|
|
@ -25,6 +25,7 @@
|
|||
#define LIBANTELOPE_HASH_H
|
||||
|
||||
#include <cstddef>
|
||||
#include <libantelope/internal/hash.hpp>
|
||||
|
||||
namespace libantelope {
|
||||
|
||||
|
|
@ -34,6 +35,26 @@ namespace libantelope {
|
|||
typedef unsigned char ripemd160_t[20];
|
||||
typedef unsigned char sha256_t[32];
|
||||
|
||||
typedef internal::sha256_state sha256_ctx_t;
|
||||
typedef internal::ripemd160_state ripemd160_ctx_t;
|
||||
|
||||
/**
|
||||
* Initialize a sha256_ctx_t structure
|
||||
*/
|
||||
int sha256_init(sha256_ctx_t* ctx);
|
||||
|
||||
/**
|
||||
* Update the sha256 hash value with the contents in `data` up to `len` bytes.
|
||||
* This can be called repeatedly to hash chunks of data.
|
||||
*/
|
||||
int sha256_update(sha256_ctx_t* ctx, const void *data, std::size_t len);
|
||||
|
||||
/**
|
||||
* Place the message digest in out variable.
|
||||
* The ctx's internal state is reset after this operation.
|
||||
*/
|
||||
int sha256_final(sha256_ctx_t* ctx, sha256_t* out);
|
||||
|
||||
/**
|
||||
* sha256 hashing function.
|
||||
* Hashes the content in `data` up to `len` bytes. The result is stored in `out`.
|
||||
|
|
@ -48,6 +69,23 @@ sha256_t* sha256(const unsigned char *data, std::size_t len, sha256_t* out);
|
|||
*/
|
||||
sha256_t* sha256d(const unsigned char *data, std::size_t len, sha256_t* out);
|
||||
|
||||
/**
|
||||
* Initialize a ripmemd160_ctx_t structure
|
||||
*/
|
||||
int ripemd160_init(ripemd160_ctx_t* ctx);
|
||||
|
||||
/**
|
||||
* Update the RipeMD160 hash value with the contents in `data` up to `len` bytes.
|
||||
* This can be called repeatedly to hash chunks of data.
|
||||
*/
|
||||
int ripemd160_update(ripemd160_ctx_t* ctx, const void *data, std::size_t len);
|
||||
|
||||
/**
|
||||
* Places the RipeMD160 message digest in out variable.
|
||||
* The ctx's internal state is reset after this operation.
|
||||
*/
|
||||
int ripemd160_final(ripemd160_ctx_t* ctx, ripemd160_t* out);
|
||||
|
||||
/**
|
||||
* RipeMD160 hashing function.
|
||||
* Hashes the content in `data` up to `len` bytes. The result is stored in `out`.
|
||||
|
|
|
|||
|
|
@ -27,6 +27,18 @@
|
|||
|
||||
namespace libantelope {
|
||||
|
||||
int sha256_init(struct sha256_ctx* ctx) {
|
||||
return SHA256_Init((SHA256_CTX*)ctx);
|
||||
}
|
||||
|
||||
int sha256_update(sha256_ctx_t* ctx, const void *data, std::size_t len) {
|
||||
return SHA256_Update((SHA256_CTX*)ctx, data, len);
|
||||
}
|
||||
|
||||
int sha256_final(sha256_ctx_t* ctx, sha256_t* out) {
|
||||
return SHA256_Final((unsigned char*) out, (SHA256_CTX*)ctx);
|
||||
}
|
||||
|
||||
sha256_t* sha256(const unsigned char *data, std::size_t len, sha256_t* out) {
|
||||
return (sha256_t *) SHA256(data, len, (unsigned char*) out);
|
||||
}
|
||||
|
|
@ -36,6 +48,18 @@ sha256_t* sha256d(const unsigned char *data, std::size_t len, sha256_t* out) {
|
|||
return (sha256_t *) SHA256((unsigned char*) out, 32, (unsigned char*) out);
|
||||
}
|
||||
|
||||
int ripemd160_init(ripemd160_ctx_t* ctx) {
|
||||
return RIPEMD160_Init((RIPEMD160_CTX*)ctx);
|
||||
}
|
||||
|
||||
int ripemd160_update(ripemd160_ctx_t* ctx, const void *data, std::size_t len) {
|
||||
return RIPEMD160_Update((RIPEMD160_CTX*)ctx, data, len);
|
||||
}
|
||||
|
||||
int ripemd160_final(ripemd160_ctx_t* ctx, ripemd160_t* out) {
|
||||
return RIPEMD160_Final((unsigned char*) out, (RIPEMD160_CTX*)ctx);
|
||||
}
|
||||
|
||||
ripemd160_t* ripemd160(const unsigned char *data, std::size_t len, ripemd160_t* out) {
|
||||
return (ripemd160_t *) RIPEMD160(data, len, (unsigned char*) out);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue