Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Groestlcoin #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ CFLAGS += -ansi -Wall $(CFLAGS_DEBUG) $(CFLAGS_OPTIMISE) \
$(CFLAGS_DISABLE_WARNINGS) $(INCLUDE)

OBJECTS = main.o keys.o hash.o base58.o segwit_addr.o result.o combination.o applog.o \
utility.o prefix.o
utility.o prefix.o groestl.o

.PHONY : all clean test

Expand Down
17 changes: 10 additions & 7 deletions base58.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,16 @@ BitcoinResult Bitcoin_EncodeBase58(

BitcoinResult Bitcoin_EncodeBase58Check(
char *output, size_t output_size, size_t *encoded_output_size,
const void *source, size_t source_size
const void *source, size_t source_size,
void (*checksum_fn)(struct BitcoinSHA256 *output, const void *input, size_t size)
)
{
struct BitcoinSHA256 checksum;
size_t buffer_size = source_size + BITCOIN_BASE58CHECK_CHECKSUM_SIZE;
unsigned char *buffer = malloc(buffer_size);
BitcoinResult result = 0;

/* calc checksum bytes */
Bitcoin_DoubleSHA256(&checksum, source, source_size);
(*checksum_fn)(&checksum, source, source_size);

memcpy(buffer, source, source_size);
memcpy(buffer + source_size, &checksum, BITCOIN_BASE58CHECK_CHECKSUM_SIZE);
Expand Down Expand Up @@ -210,7 +210,8 @@ BitcoinResult Bitcoin_DecodeBase58(

BitcoinResult Bitcoin_DecodeBase58Check(
uint8_t *output, size_t output_buffer_size, size_t *decoded_output_size,
const void *input, size_t input_size
const void *input, size_t input_size,
void (*checksum_fn)(struct BitcoinSHA256 *output, const void *input, size_t size)
)
{
struct BitcoinSHA256 hash;
Expand All @@ -225,7 +226,8 @@ BitcoinResult Bitcoin_DecodeBase58Check(
return result;
}

Bitcoin_DoubleSHA256(&hash, output,

(*checksum_fn)(&hash, output,
temp_decoded_output_size - BITCOIN_BASE58CHECK_CHECKSUM_SIZE
);

Expand All @@ -250,7 +252,8 @@ BitcoinResult Bitcoin_FixBase58Check(
const char *input, size_t input_size,
unsigned change_chars,
unsigned remove_chars,
unsigned insert_chars
unsigned insert_chars,
void (*checksum_fn)(struct BitcoinSHA256 *output, const void *input, size_t size)
)
{
/* attempt to 'fix' an invalid base58check string by changing characters
Expand Down Expand Up @@ -310,7 +313,7 @@ BitcoinResult Bitcoin_FixBase58Check(
}

result = Bitcoin_DecodeBase58Check(output, output_buffer_size,
decoded_output_size, fixed_output, input_size
decoded_output_size, fixed_output, input_size, checksum_fn
);

if (result == BITCOIN_SUCCESS) {
Expand Down
13 changes: 10 additions & 3 deletions base58.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <stdint.h> /* uint8_t */

#include "result.h" /* BitcoinResult / BITCOIN_SUCCESS / BITCOIN_ERROR_* */
#include "hash.h"

/** Base58Check defines a four byte suffix to be used as the checksum */
#define BITCOIN_BASE58CHECK_CHECKSUM_SIZE 4
Expand Down Expand Up @@ -55,14 +56,16 @@ BitcoinResult Bitcoin_EncodeBase58(
* to the contents pointed to by 'output_size'.
* @param[in] source Pointer to sequence of bytes to read.
* @param[in] source_size Number of bytes to read.
* @param[in] checksum_fn The hash function to use for the checksum bytes
*
* @return BitcoinResult indicating error state :
* BITCOIN_SUCCESS if success.
* BITCOIN_ERROR_OUTPUT_BUFFER_TOO_SMALL if output buffer too small.
*/
BitcoinResult Bitcoin_EncodeBase58Check(
char *output, size_t output_size, size_t *encoded_output_size,
const void *source, size_t source_size
const void *source, size_t source_size,
void (*checksum_fn)(struct BitcoinSHA256 *output, const void *input, size_t size)
);

/** @brief Convert a Base58 string to its binary representation.
Expand Down Expand Up @@ -101,6 +104,7 @@ BitcoinResult Bitcoin_DecodeBase58(
* maximum specified in output_buffer_size.
* @param[in] source Pointer to Base58Check string to read.
* @param[in] source_size Number of characters to read from 'source'.
* @param[in] checksum_fn The hash function to use for the checksum bytes
*
* @return BitcoinResult indicating error state :
* BITCOIN_SUCCESS if success.
Expand All @@ -109,7 +113,8 @@ BitcoinResult Bitcoin_DecodeBase58(
*/
BitcoinResult Bitcoin_DecodeBase58Check(
uint8_t *output, size_t output_buffer_size, size_t *decoded_output_size,
const void *input, size_t input_size
const void *input, size_t input_size,
void (*checksum_fn)(struct BitcoinSHA256 *output, const void *input, size_t size)
);

/** @brief Convert a Base58Check string to its binary representation, changing
Expand Down Expand Up @@ -143,6 +148,7 @@ BitcoinResult Bitcoin_DecodeBase58Check(
* @param[in] remove_chars Maximum number of characters to remove. Every
* possible combination of inserted characters up to
* this amount will be tested.
* @param[in] checksum_fn The hash function to use for the checksum bytes
*
* @return BitcoinResult indicating error state :
* BITCOIN_SUCCESS if success.
Expand All @@ -155,7 +161,8 @@ BitcoinResult Bitcoin_FixBase58Check(
const char *input, size_t input_size,
unsigned change_chars,
unsigned insert_chars,
unsigned remove_chars
unsigned remove_chars,
void (*checksum_fn)(struct BitcoinSHA256 *output, const void *input, size_t size)
);

#endif
Loading