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

fixed duplicate symbol with another lib #4093

2 changes: 1 addition & 1 deletion src/Nimiq/Address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Address::Address(const std::vector<uint8_t>& data) {

Address::Address(const PublicKey& publicKey) {
auto hash = std::array<uint8_t, 32>();
blake2b(publicKey.bytes.data(), 32, hash.data(), hash.size());
tc_blake2b(publicKey.bytes.data(), 32, hash.data(), hash.size());
std::copy(hash.begin(), hash.begin() + Address::size, bytes.begin());
}

Expand Down
2 changes: 1 addition & 1 deletion src/interface/TWHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ TWData *_Nonnull TWHashBlake2bPersonal(TWData *_Nonnull data, TWData * _Nonnull
auto dataBytes = TWDataBytes(data);
auto personalBytes = TWDataBytes(personal);
auto personalSize = TWDataSize(personal);
blake2b_Personal(dataBytes, static_cast<uint32_t>(TWDataSize(data)), personalBytes, personalSize, resultBytes.data(), outlen);
tc_blake2b_Personal(dataBytes, static_cast<uint32_t>(TWDataSize(data)), personalBytes, personalSize, resultBytes.data(), outlen);
auto result = TWDataCreateWithBytes(resultBytes.data(), outlen);
return result;
}
Expand Down
40 changes: 20 additions & 20 deletions trezor-crypto/crypto/blake2b.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static void blake2b_init0( blake2b_state *S )
}

/* init xors IV with input parameter block */
int blake2b_init_param( blake2b_state *S, const blake2b_param *P )
static int blake2b_init_param( blake2b_state *S, const blake2b_param *P )
{
const uint8_t *p = ( const uint8_t * )( P );
size_t i = 0;
Expand All @@ -109,8 +109,8 @@ int blake2b_init_param( blake2b_state *S, const blake2b_param *P )
}


/* Sequential blake2b initialization */
ahaladok marked this conversation as resolved.
Show resolved Hide resolved
int blake2b_Init( blake2b_state *S, size_t outlen )
/* Sequential tc_blake2b initialization */
int tc_blake2b_Init( blake2b_state *S, size_t outlen )
{
blake2b_param P[1] = {0};

Expand All @@ -131,7 +131,7 @@ int blake2b_Init( blake2b_state *S, size_t outlen )
return blake2b_init_param( S, P );
}

int blake2b_InitPersonal( blake2b_state *S, size_t outlen, const void *personal, size_t personal_len)
int tc_blake2b_InitPersonal( blake2b_state *S, size_t outlen, const void *personal, size_t personal_len)
{
blake2b_param P[1] = {0};

Expand All @@ -153,7 +153,7 @@ int blake2b_InitPersonal( blake2b_state *S, size_t outlen, const void *personal,
return blake2b_init_param( S, P );
}

int blake2b_InitKey( blake2b_state *S, size_t outlen, const void *key, size_t keylen )
int tc_blake2b_InitKey( blake2b_state *S, size_t outlen, const void *key, size_t keylen )
{
blake2b_param P[1] = {0};

Expand All @@ -180,7 +180,7 @@ int blake2b_InitKey( blake2b_state *S, size_t outlen, const void *key, size_t ke
uint8_t block[BLAKE2B_BLOCKBYTES] = {0};
memzero( block, BLAKE2B_BLOCKBYTES );
memcpy( block, key, keylen );
blake2b_Update( S, block, BLAKE2B_BLOCKBYTES );
tc_blake2b_Update( S, block, BLAKE2B_BLOCKBYTES );
memzero( block, BLAKE2B_BLOCKBYTES ); /* Burn the key from stack */
}
return 0;
Expand Down Expand Up @@ -254,7 +254,7 @@ static void blake2b_compress( blake2b_state *S, const uint8_t block[BLAKE2B_BLOC
#undef G
#undef ROUND

int blake2b_Update( blake2b_state *S, const void *pin, size_t inlen )
int tc_blake2b_Update( blake2b_state *S, const void *pin, size_t inlen )
{
const unsigned char * in = (const unsigned char *)pin;
if( inlen > 0 )
Expand All @@ -281,7 +281,7 @@ int blake2b_Update( blake2b_state *S, const void *pin, size_t inlen )
return 0;
}

int blake2b_Final( blake2b_state *S, void *out, size_t outlen )
int tc_blake2b_Final( blake2b_state *S, void *out, size_t outlen )
{
uint8_t buffer[BLAKE2B_OUTBYTES] = {0};
size_t i = 0;
Expand All @@ -305,30 +305,30 @@ int blake2b_Final( blake2b_state *S, void *out, size_t outlen )
return 0;
}

int blake2b(const uint8_t *msg, uint32_t msg_len, void *out, size_t outlen)
int tc_blake2b(const uint8_t *msg, uint32_t msg_len, void *out, size_t outlen)
{
BLAKE2B_CTX ctx;
if (0 != blake2b_Init(&ctx, outlen)) return -1;
if (0 != blake2b_Update(&ctx, msg, msg_len)) return -1;
if (0 != blake2b_Final(&ctx, out, outlen)) return -1;
if (0 != tc_blake2b_Init(&ctx, outlen)) return -1;
if (0 != tc_blake2b_Update(&ctx, msg, msg_len)) return -1;
if (0 != tc_blake2b_Final(&ctx, out, outlen)) return -1;
return 0;
}

// [wallet-core]
int blake2b_Personal(const uint8_t *msg, uint32_t msg_len, const void *personal, size_t personal_len, void *out, size_t outlen)
int tc_blake2b_Personal(const uint8_t *msg, uint32_t msg_len, const void *personal, size_t personal_len, void *out, size_t outlen)
{
BLAKE2B_CTX ctx;
if (0 != blake2b_InitPersonal(&ctx, outlen, personal, personal_len)) return -1;
if (0 != blake2b_Update(&ctx, msg, msg_len)) return -1;
if (0 != blake2b_Final(&ctx, out, outlen)) return -1;
if (0 != tc_blake2b_InitPersonal(&ctx, outlen, personal, personal_len)) return -1;
if (0 != tc_blake2b_Update(&ctx, msg, msg_len)) return -1;
if (0 != tc_blake2b_Final(&ctx, out, outlen)) return -1;
return 0;
}

int blake2b_Key(const uint8_t *msg, uint32_t msg_len, const void *key, size_t keylen, void *out, size_t outlen)
int tc_blake2b_Key(const uint8_t *msg, uint32_t msg_len, const void *key, size_t keylen, void *out, size_t outlen)
{
BLAKE2B_CTX ctx;
if (0 != blake2b_InitKey(&ctx, outlen, key, keylen)) return -1;
if (0 != blake2b_Update(&ctx, msg, msg_len)) return -1;
if (0 != blake2b_Final(&ctx, out, outlen)) return -1;
if (0 != tc_blake2b_InitKey(&ctx, outlen, key, keylen)) return -1;
if (0 != tc_blake2b_Update(&ctx, msg, msg_len)) return -1;
if (0 != tc_blake2b_Final(&ctx, out, outlen)) return -1;
return 0;
}
8 changes: 4 additions & 4 deletions trezor-crypto/crypto/hasher.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ void hasher_InitParam(Hasher *hasher, HasherType type, const void *param,
groestl512_Init(&hasher->ctx.groestl);
break;
case HASHER_BLAKE2B:
blake2b_Init(&hasher->ctx.blake2b, 32);
tc_blake2b_Init(&hasher->ctx.blake2b, 32);
break;
case HASHER_BLAKE2B_PERSONAL:
blake2b_InitPersonal(&hasher->ctx.blake2b, 32, hasher->param,
tc_blake2b_InitPersonal(&hasher->ctx.blake2b, 32, hasher->param,
hasher->param_size);
break;
}
Expand Down Expand Up @@ -90,7 +90,7 @@ void hasher_Update(Hasher *hasher, const uint8_t *data, size_t length) {
break;
case HASHER_BLAKE2B:
case HASHER_BLAKE2B_PERSONAL:
blake2b_Update(&hasher->ctx.blake2b, data, length);
tc_blake2b_Update(&hasher->ctx.blake2b, data, length);
break;
}
}
Expand Down Expand Up @@ -132,7 +132,7 @@ void hasher_Final(Hasher *hasher, uint8_t hash[HASHER_DIGEST_LENGTH]) {
break;
case HASHER_BLAKE2B:
case HASHER_BLAKE2B_PERSONAL:
blake2b_Final(&hasher->ctx.blake2b, hash, 32);
tc_blake2b_Final(&hasher->ctx.blake2b, hash, 32);
break;
}
}
Expand Down
12 changes: 6 additions & 6 deletions trezor-crypto/crypto/nano.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ size_t nano_get_address(

uint8_t checksum[NANO_CHECKSUM_LEN];
blake2b_state hash;
blake2b_Init(&hash, NANO_CHECKSUM_LEN);
blake2b_Update(&hash, public_key, sizeof(ed25519_public_key));
blake2b_Final(&hash, checksum, NANO_CHECKSUM_LEN);
tc_blake2b_Init(&hash, NANO_CHECKSUM_LEN);
tc_blake2b_Update(&hash, public_key, sizeof(ed25519_public_key));
tc_blake2b_Final(&hash, checksum, NANO_CHECKSUM_LEN);

for (int i = 0; i < NANO_CHECKSUM_LEN; i++) {
raw.data.checksum[NANO_CHECKSUM_LEN - (i + 1)] = checksum[i];
Expand Down Expand Up @@ -132,9 +132,9 @@ bool nano_validate_address(
// Validate the checksum
uint8_t checksum[NANO_CHECKSUM_LEN];
blake2b_state hash;
blake2b_Init(&hash, NANO_CHECKSUM_LEN);
blake2b_Update(&hash, raw.data.public_key, sizeof(ed25519_public_key));
blake2b_Final(&hash, checksum, NANO_CHECKSUM_LEN);
tc_blake2b_Init(&hash, NANO_CHECKSUM_LEN);
tc_blake2b_Update(&hash, raw.data.public_key, sizeof(ed25519_public_key));
tc_blake2b_Final(&hash, checksum, NANO_CHECKSUM_LEN);

for (int i = 0; i < NANO_CHECKSUM_LEN; i++) {
if (raw.data.checksum[NANO_CHECKSUM_LEN - (i + 1)] != checksum[i]) {
Expand Down
22 changes: 11 additions & 11 deletions trezor-crypto/crypto/tests/test_check.c
Original file line number Diff line number Diff line change
Expand Up @@ -4837,21 +4837,21 @@ START_TEST(test_blake2b) {
uint8_t digest[BLAKE2B_DIGEST_LENGTH];
for (size_t i = 0; i < (sizeof(tests) / sizeof(*tests)); i++) {
size_t msg_len = strlen(tests[i].msg) / 2;
blake2b_Key(fromhex(tests[i].msg), msg_len, key, sizeof(key), digest,
tc_blake2b_Key(fromhex(tests[i].msg), msg_len, key, sizeof(key), digest,
sizeof(digest));
ck_assert_mem_eq(digest, fromhex(tests[i].hash), sizeof(digest));

// Test progressive hashing.
size_t part_len = msg_len / 2;
BLAKE2B_CTX ctx;
ck_assert_int_eq(blake2b_InitKey(&ctx, sizeof(digest), key, sizeof(key)),
ck_assert_int_eq(tc_blake2b_InitKey(&ctx, sizeof(digest), key, sizeof(key)),
0);
ck_assert_int_eq(blake2b_Update(&ctx, fromhex(tests[i].msg), part_len), 0);
ck_assert_int_eq(blake2b_Update(&ctx, NULL, 0), 0);
ck_assert_int_eq(blake2b_Update(&ctx, fromhex(tests[i].msg) + part_len,
ck_assert_int_eq(tc_blake2b_Update(&ctx, fromhex(tests[i].msg), part_len), 0);
ck_assert_int_eq(tc_blake2b_Update(&ctx, NULL, 0), 0);
ck_assert_int_eq(tc_blake2b_Update(&ctx, fromhex(tests[i].msg) + part_len,
msg_len - part_len),
0);
ck_assert_int_eq(blake2b_Final(&ctx, digest, sizeof(digest)), 0);
ck_assert_int_eq(tc_blake2b_Final(&ctx, digest, sizeof(digest)), 0);
ck_assert_mem_eq(digest, fromhex(tests[i].hash), BLAKE2B_DIGEST_LENGTH);
}
}
Expand Down Expand Up @@ -4897,15 +4897,15 @@ START_TEST(test_blake2bp) {
size_t part_len = msg_len / 2;
BLAKE2B_CTX ctx;
ck_assert_int_eq(
blake2b_InitPersonal(&ctx, sizeof(digest), tests[i].personal,
tc_blake2b_InitPersonal(&ctx, sizeof(digest), tests[i].personal,
strlen(tests[i].personal)),
0);
ck_assert_int_eq(blake2b_Update(&ctx, fromhex(tests[i].msg), part_len), 0);
ck_assert_int_eq(blake2b_Update(&ctx, NULL, 0), 0);
ck_assert_int_eq(blake2b_Update(&ctx, fromhex(tests[i].msg) + part_len,
ck_assert_int_eq(tc_blake2b_Update(&ctx, fromhex(tests[i].msg), part_len), 0);
ck_assert_int_eq(tc_blake2b_Update(&ctx, NULL, 0), 0);
ck_assert_int_eq(tc_blake2b_Update(&ctx, fromhex(tests[i].msg) + part_len,
msg_len - part_len),
0);
ck_assert_int_eq(blake2b_Final(&ctx, digest, sizeof(digest)), 0);
ck_assert_int_eq(tc_blake2b_Final(&ctx, digest, sizeof(digest)), 0);
ck_assert_mem_eq(digest, fromhex(tests[i].hash), sizeof(digest));
}
}
Expand Down
16 changes: 8 additions & 8 deletions trezor-crypto/include/TrezorCrypto/blake2b.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ typedef struct __blake2b_state
#define BLAKE2B_DIGEST_LENGTH BLAKE2B_OUTBYTES
#define BLAKE2B_KEY_LENGTH BLAKE2B_KEYBYTES

int blake2b_Init(blake2b_state *S, size_t outlen);
int blake2b_InitKey(blake2b_state *S, size_t outlen, const void *key, size_t keylen);
int blake2b_InitPersonal(blake2b_state *S, size_t outlen, const void *personal, size_t personal_len);
int blake2b_Update(blake2b_state *S, const void *pin, size_t inlen);
int blake2b_Final(blake2b_state *S, void *out, size_t outlen);
int tc_blake2b_Init(blake2b_state *S, size_t outlen);
int tc_blake2b_InitKey(blake2b_state *S, size_t outlen, const void *key, size_t keylen);
int tc_blake2b_InitPersonal(blake2b_state *S, size_t outlen, const void *personal, size_t personal_len);
int tc_blake2b_Update(blake2b_state *S, const void *pin, size_t inlen);
int tc_blake2b_Final(blake2b_state *S, void *out, size_t outlen);

int blake2b(const uint8_t *msg, uint32_t msg_len, void *out, size_t outlen);
int tc_blake2b(const uint8_t *msg, uint32_t msg_len, void *out, size_t outlen);
// [wallet-core]
int blake2b_Personal(const uint8_t *msg, uint32_t msg_len, const void *personal, size_t personal_len, void *out, size_t outlen);
int blake2b_Key(const uint8_t *msg, uint32_t msg_len, const void *key, size_t keylen, void *out, size_t outlen);
int tc_blake2b_Personal(const uint8_t *msg, uint32_t msg_len, const void *personal, size_t personal_len, void *out, size_t outlen);
int tc_blake2b_Key(const uint8_t *msg, uint32_t msg_len, const void *key, size_t keylen, void *out, size_t outlen);

#ifdef __cplusplus
} /* extern "C" */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
#include <TrezorCrypto/blake2b.h>

#define ed25519_hash_context BLAKE2B_CTX
#define ed25519_hash_init(ctx) blake2b_Init(ctx, 64)
#define ed25519_hash_update(ctx, in, inlen) blake2b_Update((ctx), (in), (inlen))
#define ed25519_hash_final(ctx, hash) blake2b_Final((ctx), (hash), 64)
#define ed25519_hash(hash, in, inlen) blake2b((in), (inlen), (hash), 64)
#define ed25519_hash_init(ctx) tc_blake2b_Init(ctx, 64)
#define ed25519_hash_update(ctx, in, inlen) tc_blake2b_Update((ctx), (in), (inlen))
#define ed25519_hash_final(ctx, hash) tc_blake2b_Final((ctx), (hash), 64)
#define ed25519_hash(hash, in, inlen) tc_blake2b((in), (inlen), (hash), 64)

#endif // ED25519_HASH_CUSTOM
Loading