Skip to content

Commit

Permalink
Put back blake2 and ripemd hash algo
Browse files Browse the repository at this point in the history
  • Loading branch information
tjoly-ledger committed Mar 27, 2023
1 parent 6aa8695 commit 489a22d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 45 deletions.
6 changes: 0 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
Expand Down
14 changes: 2 additions & 12 deletions src/xrp/xrp_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down
12 changes: 0 additions & 12 deletions tests/include/cx.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include <stddef.h>
#include <stdint.h>

#include <openssl/ripemd.h>

typedef unsigned int cx_curve_t;

#define CX_CURVE_256K1 0x1234
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
28 changes: 13 additions & 15 deletions tests/src/cx.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <cmocka.h>
#include <openssl/sha.h>
#include <openssl/ripemd.h>

#include "cx.h"

Expand All @@ -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,
Expand All @@ -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);
}

0 comments on commit 489a22d

Please sign in to comment.