diff --git a/Makefile b/Makefile index 588a3da3..bd126e9c 100755 --- a/Makefile +++ b/Makefile @@ -44,12 +44,6 @@ else ICONNAME=img/nanox_app_$(COIN).gif endif -# RIPEMD160 addition. -DEFINES += HAVE_RIPEMD160 - -SOURCE_PATH += $(BOLOS_SDK)/lib_cxng/src/cx_ripemd160.c -SOURCE_PATH += $(BOLOS_SDK)/lib_cxng/src/cx_hmac.c -# RIPEMD160 - End ################ # Default rule # diff --git a/src/xrp/xrp_helpers.c b/src/xrp/xrp_helpers.c index 7ea753e2..3a601a7e 100644 --- a/src/xrp/xrp_helpers.c +++ b/src/xrp/xrp_helpers.c @@ -78,17 +78,6 @@ static size_t xrp_encode_base58_address(const base58_buf_t *in, xrp_address_t *o return outlen; } -static void xrp_hash_ripemd160(cx_ripemd160_t *hash, - const uint8_t *in, - size_t in_len, - uint8_t *out, - size_t out_len) { - (void) out_len; - cx_ripemd160_init(hash); - cx_ripemd160_update(hash, in, in_len); - cx_ripemd160_final(hash, out); -} - void xrp_public_key_hash160(xrp_pubkey_t *pubkey, uint8_t *out) { union { cx_sha256_t shasha; @@ -98,7 +87,8 @@ void xrp_public_key_hash160(xrp_pubkey_t *pubkey, uint8_t *out) { cx_sha256_init(&u.shasha); cx_hash(&u.shasha.header, CX_LAST, pubkey->buf, sizeof(pubkey->buf), buffer, 32); - xrp_hash_ripemd160(&u.riprip, buffer, 32, out, 20); + cx_ripemd160_init(&u.riprip); + cx_hash(&u.riprip.header, CX_LAST, buffer, 32, out, 20); } size_t xrp_public_key_to_encoded_base58(xrp_pubkey_t *pubkey, diff --git a/tests/include/cx.h b/tests/include/cx.h index dedb8850..202c1a54 100644 --- a/tests/include/cx.h +++ b/tests/include/cx.h @@ -3,8 +3,6 @@ #include #include -#include - typedef unsigned int cx_curve_t; #define CX_CURVE_256K1 0x1234 @@ -62,9 +60,6 @@ struct cx_sha256_s { typedef struct cx_sha256_s cx_sha256_t; struct cx_ripemd160_s { - - RIPEMD160_CTX ctx; - /** See #cx_hash_header_s */ struct cx_hash_header_s header; /** @internal @@ -104,10 +99,3 @@ struct cx_ecfp_256_public_key_s { unsigned char W[65]; }; typedef struct cx_ecfp_256_public_key_s cx_ecfp_public_key_t; - -void cx_ripemd160_update(cx_ripemd160_t *hash, - const uint8_t *in, - size_t len); - -void cx_ripemd160_final(cx_ripemd160_t *hash, - uint8_t *out); diff --git a/tests/src/cx.c b/tests/src/cx.c index 56fdc8c9..60396b07 100644 --- a/tests/src/cx.c +++ b/tests/src/cx.c @@ -6,6 +6,7 @@ #include #include +#include #include "cx.h" @@ -16,6 +17,13 @@ int cx_sha256_init(cx_sha256_t *hash) { return CX_SHA256; } +int cx_ripemd160_init(cx_ripemd160_t *hash) { + memset(hash, 0, sizeof(cx_ripemd160_t)); + hash->header.algo = CX_RIPEMD160; + + return CX_RIPEMD160; +} + int cx_hash(cx_hash_t *hash, int mode, const uint8_t *in, @@ -30,24 +38,14 @@ int cx_hash(cx_hash_t *hash, SHA256_Init(&sha256); SHA256_Update(&sha256, in, len); SHA256_Final(out, &sha256); + } else if (hash->algo == CX_RIPEMD160) { + RIPEMD160_CTX ripemd160; + RIPEMD160_Init(&ripemd160); + RIPEMD160_Update(&ripemd160, in, len); + RIPEMD160_Final(out, &ripemd160); } else { assert_true(false); } return 0; } - -int cx_ripemd160_init(cx_ripemd160_t *hash) { - RIPEMD160_Init(&hash->ctx); -} - -void cx_ripemd160_update(cx_ripemd160_t *hash, - const uint8_t *in, - size_t len) { - RIPEMD160_Update(&hash->ctx, in, len); -} - -void cx_ripemd160_final(cx_ripemd160_t *hash, - uint8_t *out) { - RIPEMD160_Final(out, &hash->ctx); -}