From 4326ba3c386db0efea19fbe441953b897865a86a Mon Sep 17 00:00:00 2001 From: XMRig Date: Mon, 4 May 2020 18:09:34 +0700 Subject: [PATCH] Add prefixes to argon2 to avoid potential conflicts with other implementations. --- .../argon2/arch/x86_64/lib/argon2-arch.c | 10 +- .../argon2/arch/x86_64/lib/argon2-avx2.c | 19 +--- .../argon2/arch/x86_64/lib/argon2-avx2.h | 6 +- .../argon2/arch/x86_64/lib/argon2-avx512f.c | 19 +--- .../argon2/arch/x86_64/lib/argon2-avx512f.h | 6 +- .../argon2/arch/x86_64/lib/argon2-sse2.c | 16 +-- .../argon2/arch/x86_64/lib/argon2-sse2.h | 6 +- .../argon2/arch/x86_64/lib/argon2-ssse3.c | 16 +-- .../argon2/arch/x86_64/lib/argon2-ssse3.h | 6 +- .../arch/x86_64/lib/argon2-template-128.h | 3 +- .../argon2/arch/x86_64/lib/argon2-xop.c | 16 +-- .../argon2/arch/x86_64/lib/argon2-xop.h | 6 +- src/3rdparty/argon2/lib/argon2-template-64.h | 3 +- src/3rdparty/argon2/lib/argon2.c | 16 +-- src/3rdparty/argon2/lib/blake2/blake2.c | 44 ++++---- src/3rdparty/argon2/lib/blake2/blake2.h | 8 +- src/3rdparty/argon2/lib/core.c | 105 ++++++++---------- src/3rdparty/argon2/lib/core.h | 30 ++--- src/3rdparty/argon2/lib/encoding.c | 4 +- src/3rdparty/argon2/lib/impl-select.c | 2 +- 20 files changed, 134 insertions(+), 207 deletions(-) diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-arch.c b/src/3rdparty/argon2/arch/x86_64/lib/argon2-arch.c index 4486e395..48d2a77e 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-arch.c +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-arch.c @@ -27,11 +27,11 @@ void argon2_get_impl_list(argon2_impl_list *list) { static const argon2_impl IMPLS[] = { { "x86_64", NULL, fill_segment_default }, - { "SSE2", check_sse2, fill_segment_sse2 }, - { "SSSE3", check_ssse3, fill_segment_ssse3 }, - { "XOP", check_xop, fill_segment_xop }, - { "AVX2", check_avx2, fill_segment_avx2 }, - { "AVX-512F", check_avx512f, fill_segment_avx512f }, + { "SSE2", xmrig_ar2_check_sse2, xmrig_ar2_fill_segment_sse2 }, + { "SSSE3", xmrig_ar2_check_ssse3, xmrig_ar2_fill_segment_ssse3 }, + { "XOP", xmrig_ar2_check_xop, xmrig_ar2_fill_segment_xop }, + { "AVX2", xmrig_ar2_check_avx2, xmrig_ar2_fill_segment_avx2 }, + { "AVX-512F", xmrig_ar2_check_avx512f, xmrig_ar2_fill_segment_avx512f }, }; cpu_flags_get(); diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx2.c b/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx2.c index 09ef421a..976fd471 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx2.c +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx2.c @@ -225,8 +225,7 @@ static void next_addresses(block *address_block, block *input_block) fill_block(zero2_block, address_block, address_block, 0); } -void fill_segment_avx2(const argon2_instance_t *instance, - argon2_position_t position) +void xmrig_ar2_fill_segment_avx2(const argon2_instance_t *instance, argon2_position_t position) { block *ref_block = NULL, *curr_block = NULL; block address_block, input_block; @@ -310,8 +309,7 @@ void fill_segment_avx2(const argon2_instance_t *instance, * lane. */ position.index = i; - ref_index = index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF, - ref_lane == position.lane); + ref_index = xmrig_ar2_index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF, ref_lane == position.lane); /* 2 Creating a new block */ ref_block = @@ -327,21 +325,14 @@ void fill_segment_avx2(const argon2_instance_t *instance, } } -int check_avx2(void) +int xmrig_ar2_check_avx2(void) { return cpu_flags_have_avx2(); } #else -void fill_segment_avx2(const argon2_instance_t *instance, - argon2_position_t position) -{ -} - -int check_avx2(void) -{ - return 0; -} +void xmrig_ar2_fill_segment_avx2(const argon2_instance_t *instance, argon2_position_t position) {} +int xmrig_ar2_check_avx2(void) { return 0; } #endif diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx2.h b/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx2.h index 8abdb8a5..2c34269a 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx2.h +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx2.h @@ -3,9 +3,7 @@ #include "core.h" -void fill_segment_avx2(const argon2_instance_t *instance, - argon2_position_t position); - -int check_avx2(void); +void xmrig_ar2_fill_segment_avx2(const argon2_instance_t *instance, argon2_position_t position); +int xmrig_ar2_check_avx2(void); #endif // ARGON2_AVX2_H diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx512f.c b/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx512f.c index 79fd2dda..994f3502 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx512f.c +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx512f.c @@ -210,8 +210,7 @@ static void next_addresses(block *address_block, block *input_block) fill_block(zero2_block, address_block, address_block, 0); } -void fill_segment_avx512f(const argon2_instance_t *instance, - argon2_position_t position) +void xmrig_ar2_fill_segment_avx512f(const argon2_instance_t *instance, argon2_position_t position) { block *ref_block = NULL, *curr_block = NULL; block address_block, input_block; @@ -295,8 +294,7 @@ void fill_segment_avx512f(const argon2_instance_t *instance, * lane. */ position.index = i; - ref_index = index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF, - ref_lane == position.lane); + ref_index = xmrig_ar2_index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF, ref_lane == position.lane); /* 2 Creating a new block */ ref_block = @@ -312,21 +310,14 @@ void fill_segment_avx512f(const argon2_instance_t *instance, } } -int check_avx512f(void) +int xmrig_ar2_check_avx512f(void) { return cpu_flags_have_avx512f(); } #else -void fill_segment_avx512f(const argon2_instance_t *instance, - argon2_position_t position) -{ -} - -int check_avx512f(void) -{ - return 0; -} +void xmrig_ar2_fill_segment_avx512f(const argon2_instance_t *instance, argon2_position_t position) {} +int xmrig_ar2_check_avx512f(void) { return 0; } #endif diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx512f.h b/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx512f.h index ba431114..882bb7fd 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx512f.h +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-avx512f.h @@ -3,9 +3,7 @@ #include "core.h" -void fill_segment_avx512f(const argon2_instance_t *instance, - argon2_position_t position); - -int check_avx512f(void); +void xmrig_ar2_fill_segment_avx512f(const argon2_instance_t *instance, argon2_position_t position); +int xmrig_ar2_check_avx512f(void); #endif // ARGON2_AVX512F_H diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-sse2.c b/src/3rdparty/argon2/arch/x86_64/lib/argon2-sse2.c index 5eccdf07..1e992b54 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-sse2.c +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-sse2.c @@ -102,27 +102,19 @@ static __m128i f(__m128i x, __m128i y) #include "argon2-template-128.h" -void fill_segment_sse2(const argon2_instance_t *instance, - argon2_position_t position) +void xmrig_ar2_fill_segment_sse2(const argon2_instance_t *instance, argon2_position_t position) { fill_segment_128(instance, position); } -int check_sse2(void) +int xmrig_ar2_check_sse2(void) { return cpu_flags_have_sse2(); } #else -void fill_segment_sse2(const argon2_instance_t *instance, - argon2_position_t position) -{ -} - -int check_sse2(void) -{ - return 0; -} +void xmrig_ar2_fill_segment_sse2(const argon2_instance_t *instance, argon2_position_t position) {} +int xmrig_ar2_check_sse2(void) { return 0; } #endif diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-sse2.h b/src/3rdparty/argon2/arch/x86_64/lib/argon2-sse2.h index 024d503d..9f92fbc6 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-sse2.h +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-sse2.h @@ -3,9 +3,7 @@ #include "core.h" -void fill_segment_sse2(const argon2_instance_t *instance, - argon2_position_t position); - -int check_sse2(void); +void xmrig_ar2_fill_segment_sse2(const argon2_instance_t *instance, argon2_position_t position); +int xmrig_ar2_check_sse2(void); #endif // ARGON2_SSE2_H diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-ssse3.c b/src/3rdparty/argon2/arch/x86_64/lib/argon2-ssse3.c index 86e9b3c9..b848e3eb 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-ssse3.c +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-ssse3.c @@ -114,27 +114,19 @@ static __m128i f(__m128i x, __m128i y) #include "argon2-template-128.h" -void fill_segment_ssse3(const argon2_instance_t *instance, - argon2_position_t position) +void xmrig_ar2_fill_segment_ssse3(const argon2_instance_t *instance, argon2_position_t position) { fill_segment_128(instance, position); } -int check_ssse3(void) +int xmrig_ar2_check_ssse3(void) { return cpu_flags_have_ssse3(); } #else -void fill_segment_ssse3(const argon2_instance_t *instance, - argon2_position_t position) -{ -} - -int check_ssse3(void) -{ - return 0; -} +void xmrig_ar2_fill_segment_ssse3(const argon2_instance_t *instance, argon2_position_t position) {} +int xmrig_ar2_check_ssse3(void) { return 0; } #endif diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-ssse3.h b/src/3rdparty/argon2/arch/x86_64/lib/argon2-ssse3.h index 139fdacc..7d0346c7 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-ssse3.h +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-ssse3.h @@ -3,9 +3,7 @@ #include "core.h" -void fill_segment_ssse3(const argon2_instance_t *instance, - argon2_position_t position); - -int check_ssse3(void); +void xmrig_ar2_fill_segment_ssse3(const argon2_instance_t *instance, argon2_position_t position); +int xmrig_ar2_check_ssse3(void); #endif // ARGON2_SSSE3_H diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-template-128.h b/src/3rdparty/argon2/arch/x86_64/lib/argon2-template-128.h index 4fb04c1f..e55bbb92 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-template-128.h +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-template-128.h @@ -150,8 +150,7 @@ static void fill_segment_128(const argon2_instance_t *instance, * lane. */ position.index = i; - ref_index = index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF, - ref_lane == position.lane); + ref_index = xmrig_ar2_index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF, ref_lane == position.lane); /* 2 Creating a new block */ ref_block = diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-xop.c b/src/3rdparty/argon2/arch/x86_64/lib/argon2-xop.c index 0e877bce..2e8b965b 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-xop.c +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-xop.c @@ -102,27 +102,19 @@ static __m128i f(__m128i x, __m128i y) #include "argon2-template-128.h" -void fill_segment_xop(const argon2_instance_t *instance, - argon2_position_t position) +void xmrig_ar2_fill_segment_xop(const argon2_instance_t *instance, argon2_position_t position) { fill_segment_128(instance, position); } -int check_xop(void) +int xmrig_ar2_check_xop(void) { return cpu_flags_have_xop(); } #else -void fill_segment_xop(const argon2_instance_t *instance, - argon2_position_t position) -{ -} - -int check_xop(void) -{ - return 0; -} +void xmrig_ar2_fill_segment_xop(const argon2_instance_t *instance, argon2_position_t position) {} +int xmrig_ar2_check_xop(void) { return 0; } #endif diff --git a/src/3rdparty/argon2/arch/x86_64/lib/argon2-xop.h b/src/3rdparty/argon2/arch/x86_64/lib/argon2-xop.h index 1474a11c..631f239c 100644 --- a/src/3rdparty/argon2/arch/x86_64/lib/argon2-xop.h +++ b/src/3rdparty/argon2/arch/x86_64/lib/argon2-xop.h @@ -3,9 +3,7 @@ #include "core.h" -void fill_segment_xop(const argon2_instance_t *instance, - argon2_position_t position); - -int check_xop(void); +void xmrig_ar2_fill_segment_xop(const argon2_instance_t *instance, argon2_position_t position); +int xmrig_ar2_check_xop(void); #endif // ARGON2_XOP_H diff --git a/src/3rdparty/argon2/lib/argon2-template-64.h b/src/3rdparty/argon2/lib/argon2-template-64.h index 16ddbd35..c7541c07 100644 --- a/src/3rdparty/argon2/lib/argon2-template-64.h +++ b/src/3rdparty/argon2/lib/argon2-template-64.h @@ -174,8 +174,7 @@ static void fill_segment_64(const argon2_instance_t *instance, * lane. */ position.index = i; - ref_index = index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF, - ref_lane == position.lane); + ref_index = xmrig_ar2_index_alpha(instance, &position, pseudo_rand & 0xFFFFFFFF, ref_lane == position.lane); /* 2 Creating a new block */ ref_block = diff --git a/src/3rdparty/argon2/lib/argon2.c b/src/3rdparty/argon2/lib/argon2.c index b2eafd2f..ab45229c 100644 --- a/src/3rdparty/argon2/lib/argon2.c +++ b/src/3rdparty/argon2/lib/argon2.c @@ -57,7 +57,7 @@ size_t argon2_memory_size(uint32_t m_cost, uint32_t parallelism) { int argon2_ctx_mem(argon2_context *context, argon2_type type, void *memory, size_t memory_size) { /* 1. Validate all inputs */ - int result = validate_inputs(context); + int result = xmrig_ar2_validate_inputs(context); uint32_t memory_blocks, segment_length; argon2_instance_t instance; @@ -98,20 +98,20 @@ int argon2_ctx_mem(argon2_context *context, argon2_type type, void *memory, /* 3. Initialization: Hashing inputs, allocating memory, filling first * blocks */ - result = initialize(&instance, context); + result = xmrig_ar2_initialize(&instance, context); if (ARGON2_OK != result) { return result; } /* 4. Filling memory */ - result = fill_memory_blocks(&instance); + result = xmrig_ar2_fill_memory_blocks(&instance); if (ARGON2_OK != result) { return result; } /* 5. Finalization */ - finalize(context, &instance); + xmrig_ar2_finalize(context, &instance); return ARGON2_OK; } @@ -174,7 +174,7 @@ int argon2_hash(const uint32_t t_cost, const uint32_t m_cost, result = argon2_ctx(&context, type); if (result != ARGON2_OK) { - clear_internal_memory(out, hashlen); + xmrig_ar2_clear_internal_memory(out, hashlen); free(out); return result; } @@ -187,13 +187,13 @@ int argon2_hash(const uint32_t t_cost, const uint32_t m_cost, /* if encoding requested, write it */ if (encoded && encodedlen) { if (encode_string(encoded, encodedlen, &context, type) != ARGON2_OK) { - clear_internal_memory(out, hashlen); /* wipe buffers if error */ - clear_internal_memory(encoded, encodedlen); + xmrig_ar2_clear_internal_memory(out, hashlen); /* wipe buffers if error */ + xmrig_ar2_clear_internal_memory(encoded, encodedlen); free(out); return ARGON2_ENCODING_FAIL; } } - clear_internal_memory(out, hashlen); + xmrig_ar2_clear_internal_memory(out, hashlen); free(out); return ARGON2_OK; diff --git a/src/3rdparty/argon2/lib/blake2/blake2.c b/src/3rdparty/argon2/lib/blake2/blake2.c index d32028ed..76de85a5 100644 --- a/src/3rdparty/argon2/lib/blake2/blake2.c +++ b/src/3rdparty/argon2/lib/blake2/blake2.c @@ -128,14 +128,14 @@ static void blake2b_init_state(blake2b_state *S) S->buflen = 0; } -void blake2b_init(blake2b_state *S, size_t outlen) +void xmrig_ar2_blake2b_init(blake2b_state *S, size_t outlen) { blake2b_init_state(S); /* XOR initial state with param block: */ S->h[0] ^= (uint64_t)outlen | (UINT64_C(1) << 16) | (UINT64_C(1) << 24); } -void blake2b_update(blake2b_state *S, const void *in, size_t inlen) +void xmrig_ar2_blake2b_update(blake2b_state *S, const void *in, size_t inlen) { const uint8_t *pin = (const uint8_t *)in; @@ -160,7 +160,7 @@ void blake2b_update(blake2b_state *S, const void *in, size_t inlen) S->buflen += inlen; } -void blake2b_final(blake2b_state *S, void *out, size_t outlen) +void xmrig_ar2_blake2b_final(blake2b_state *S, void *out, size_t outlen) { uint8_t buffer[BLAKE2B_OUTBYTES] = {0}; unsigned int i; @@ -174,12 +174,12 @@ void blake2b_final(blake2b_state *S, void *out, size_t outlen) } memcpy(out, buffer, outlen); - clear_internal_memory(buffer, sizeof(buffer)); - clear_internal_memory(S->buf, sizeof(S->buf)); - clear_internal_memory(S->h, sizeof(S->h)); + xmrig_ar2_clear_internal_memory(buffer, sizeof(buffer)); + xmrig_ar2_clear_internal_memory(S->buf, sizeof(S->buf)); + xmrig_ar2_clear_internal_memory(S->h, sizeof(S->h)); } -void blake2b_long(void *out, size_t outlen, const void *in, size_t inlen) +void xmrig_ar2_blake2b_long(void *out, size_t outlen, const void *in, size_t inlen) { uint8_t *pout = (uint8_t *)out; blake2b_state blake_state; @@ -187,39 +187,39 @@ void blake2b_long(void *out, size_t outlen, const void *in, size_t inlen) store32(outlen_bytes, (uint32_t)outlen); if (outlen <= BLAKE2B_OUTBYTES) { - blake2b_init(&blake_state, outlen); - blake2b_update(&blake_state, outlen_bytes, sizeof(outlen_bytes)); - blake2b_update(&blake_state, in, inlen); - blake2b_final(&blake_state, pout, outlen); + xmrig_ar2_blake2b_init(&blake_state, outlen); + xmrig_ar2_blake2b_update(&blake_state, outlen_bytes, sizeof(outlen_bytes)); + xmrig_ar2_blake2b_update(&blake_state, in, inlen); + xmrig_ar2_blake2b_final(&blake_state, pout, outlen); } else { uint32_t toproduce; uint8_t out_buffer[BLAKE2B_OUTBYTES]; - blake2b_init(&blake_state, BLAKE2B_OUTBYTES); - blake2b_update(&blake_state, outlen_bytes, sizeof(outlen_bytes)); - blake2b_update(&blake_state, in, inlen); - blake2b_final(&blake_state, out_buffer, BLAKE2B_OUTBYTES); + xmrig_ar2_blake2b_init(&blake_state, BLAKE2B_OUTBYTES); + xmrig_ar2_blake2b_update(&blake_state, outlen_bytes, sizeof(outlen_bytes)); + xmrig_ar2_blake2b_update(&blake_state, in, inlen); + xmrig_ar2_blake2b_final(&blake_state, out_buffer, BLAKE2B_OUTBYTES); memcpy(pout, out_buffer, BLAKE2B_OUTBYTES / 2); pout += BLAKE2B_OUTBYTES / 2; toproduce = (uint32_t)outlen - BLAKE2B_OUTBYTES / 2; while (toproduce > BLAKE2B_OUTBYTES) { - blake2b_init(&blake_state, BLAKE2B_OUTBYTES); - blake2b_update(&blake_state, out_buffer, BLAKE2B_OUTBYTES); - blake2b_final(&blake_state, out_buffer, BLAKE2B_OUTBYTES); + xmrig_ar2_blake2b_init(&blake_state, BLAKE2B_OUTBYTES); + xmrig_ar2_blake2b_update(&blake_state, out_buffer, BLAKE2B_OUTBYTES); + xmrig_ar2_blake2b_final(&blake_state, out_buffer, BLAKE2B_OUTBYTES); memcpy(pout, out_buffer, BLAKE2B_OUTBYTES / 2); pout += BLAKE2B_OUTBYTES / 2; toproduce -= BLAKE2B_OUTBYTES / 2; } - blake2b_init(&blake_state, toproduce); - blake2b_update(&blake_state, out_buffer, BLAKE2B_OUTBYTES); - blake2b_final(&blake_state, out_buffer, toproduce); + xmrig_ar2_blake2b_init(&blake_state, toproduce); + xmrig_ar2_blake2b_update(&blake_state, out_buffer, BLAKE2B_OUTBYTES); + xmrig_ar2_blake2b_final(&blake_state, out_buffer, toproduce); memcpy(pout, out_buffer, toproduce); - clear_internal_memory(out_buffer, sizeof(out_buffer)); + xmrig_ar2_clear_internal_memory(out_buffer, sizeof(out_buffer)); } } diff --git a/src/3rdparty/argon2/lib/blake2/blake2.h b/src/3rdparty/argon2/lib/blake2/blake2.h index 7deeaa1f..33f19eec 100644 --- a/src/3rdparty/argon2/lib/blake2/blake2.h +++ b/src/3rdparty/argon2/lib/blake2/blake2.h @@ -20,11 +20,11 @@ typedef struct __blake2b_state { } blake2b_state; /* Streaming API */ -void blake2b_init(blake2b_state *S, size_t outlen); -void blake2b_update(blake2b_state *S, const void *in, size_t inlen); -void blake2b_final(blake2b_state *S, void *out, size_t outlen); +void xmrig_ar2_blake2b_init(blake2b_state *S, size_t outlen); +void xmrig_ar2_blake2b_update(blake2b_state *S, const void *in, size_t inlen); +void xmrig_ar2_blake2b_final(blake2b_state *S, void *out, size_t outlen); -void blake2b_long(void *out, size_t outlen, const void *in, size_t inlen); +void xmrig_ar2_blake2b_long(void *out, size_t outlen, const void *in, size_t inlen); #endif // ARGON2_BLAKE2_H diff --git a/src/3rdparty/argon2/lib/core.c b/src/3rdparty/argon2/lib/core.c index e3ec883b..8c5d1c0e 100644 --- a/src/3rdparty/argon2/lib/core.c +++ b/src/3rdparty/argon2/lib/core.c @@ -77,8 +77,7 @@ static void store_block(void *output, const block *src) { /***************Memory functions*****************/ -int allocate_memory(const argon2_context *context, - argon2_instance_t *instance) { +int xmrig_ar2_allocate_memory(const argon2_context *context, argon2_instance_t *instance) { size_t blocks = instance->memory_blocks; size_t memory_size = blocks * ARGON2_BLOCK_SIZE; @@ -107,11 +106,10 @@ int allocate_memory(const argon2_context *context, return ARGON2_OK; } -void free_memory(const argon2_context *context, - const argon2_instance_t *instance) { +void xmrig_ar2_free_memory(const argon2_context *context, const argon2_instance_t *instance) { size_t memory_size = instance->memory_blocks * ARGON2_BLOCK_SIZE; - clear_internal_memory(instance->memory, memory_size); + xmrig_ar2_clear_internal_memory(instance->memory, memory_size); if (instance->keep_memory) { /* user-supplied memory -- do not free */ @@ -125,7 +123,7 @@ void free_memory(const argon2_context *context, } } -void NOT_OPTIMIZED secure_wipe_memory(void *v, size_t n) { +void NOT_OPTIMIZED xmrig_ar2_secure_wipe_memory(void *v, size_t n) { #if defined(_MSC_VER) && VC_GE_2005(_MSC_VER) SecureZeroMemory(v, n); #elif defined memset_s @@ -140,13 +138,13 @@ void NOT_OPTIMIZED secure_wipe_memory(void *v, size_t n) { /* Memory clear flag defaults to true. */ int FLAG_clear_internal_memory = 0; -void clear_internal_memory(void *v, size_t n) { +void xmrig_ar2_clear_internal_memory(void *v, size_t n) { if (FLAG_clear_internal_memory && v) { - secure_wipe_memory(v, n); + xmrig_ar2_secure_wipe_memory(v, n); } } -void finalize(const argon2_context *context, argon2_instance_t *instance) { +void xmrig_ar2_finalize(const argon2_context *context, argon2_instance_t *instance) { if (context != NULL && instance != NULL && context->out != NULL) { block blockhash; uint32_t l; @@ -164,24 +162,21 @@ void finalize(const argon2_context *context, argon2_instance_t *instance) { { uint8_t blockhash_bytes[ARGON2_BLOCK_SIZE]; store_block(blockhash_bytes, &blockhash); - blake2b_long(context->out, context->outlen, blockhash_bytes, - ARGON2_BLOCK_SIZE); + xmrig_ar2_blake2b_long(context->out, context->outlen, blockhash_bytes, ARGON2_BLOCK_SIZE); /* clear blockhash and blockhash_bytes */ - clear_internal_memory(blockhash.v, ARGON2_BLOCK_SIZE); - clear_internal_memory(blockhash_bytes, ARGON2_BLOCK_SIZE); + xmrig_ar2_clear_internal_memory(blockhash.v, ARGON2_BLOCK_SIZE); + xmrig_ar2_clear_internal_memory(blockhash_bytes, ARGON2_BLOCK_SIZE); } if (instance->print_internals) { print_tag(context->out, context->outlen); } - free_memory(context, instance); + xmrig_ar2_free_memory(context, instance); } } -uint32_t index_alpha(const argon2_instance_t *instance, - const argon2_position_t *position, uint32_t pseudo_rand, - int same_lane) { +uint32_t xmrig_ar2_index_alpha(const argon2_instance_t *instance, const argon2_position_t *position, uint32_t pseudo_rand, int same_lane) { /* * Pass 0: * This lane : all already finished segments plus already constructed @@ -257,7 +252,7 @@ static int fill_memory_blocks_st(argon2_instance_t *instance) { for (s = 0; s < ARGON2_SYNC_POINTS; ++s) { for (l = 0; l < instance->lanes; ++l) { argon2_position_t position = { r, l, (uint8_t)s, 0 }; - fill_segment(instance, position); + xmrig_ar2_fill_segment(instance, position); } } @@ -268,7 +263,7 @@ static int fill_memory_blocks_st(argon2_instance_t *instance) { return ARGON2_OK; } -int fill_memory_blocks(argon2_instance_t *instance) { +int xmrig_ar2_fill_memory_blocks(argon2_instance_t *instance) { if (instance == NULL || instance->lanes == 0) { return ARGON2_INCORRECT_PARAMETER; } @@ -276,7 +271,7 @@ int fill_memory_blocks(argon2_instance_t *instance) { return fill_memory_blocks_st(instance); } -int validate_inputs(const argon2_context *context) { +int xmrig_ar2_validate_inputs(const argon2_context *context) { if (NULL == context) { return ARGON2_INCORRECT_PARAMETER; } @@ -403,7 +398,7 @@ int validate_inputs(const argon2_context *context) { return ARGON2_OK; } -void fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance) { +void xmrig_ar2_fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance) { uint32_t l; /* Make the first and second block in each lane as G(H0||0||i) or G(H0||1||i) */ @@ -412,21 +407,17 @@ void fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance) { store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, 0); store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH + 4, l); - blake2b_long(blockhash_bytes, ARGON2_BLOCK_SIZE, blockhash, - ARGON2_PREHASH_SEED_LENGTH); - load_block(&instance->memory[l * instance->lane_length + 0], - blockhash_bytes); + xmrig_ar2_blake2b_long(blockhash_bytes, ARGON2_BLOCK_SIZE, blockhash, ARGON2_PREHASH_SEED_LENGTH); + load_block(&instance->memory[l * instance->lane_length + 0], blockhash_bytes); store32(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, 1); - blake2b_long(blockhash_bytes, ARGON2_BLOCK_SIZE, blockhash, - ARGON2_PREHASH_SEED_LENGTH); - load_block(&instance->memory[l * instance->lane_length + 1], - blockhash_bytes); + xmrig_ar2_blake2b_long(blockhash_bytes, ARGON2_BLOCK_SIZE, blockhash, ARGON2_PREHASH_SEED_LENGTH); + load_block(&instance->memory[l * instance->lane_length + 1], blockhash_bytes); } - clear_internal_memory(blockhash_bytes, ARGON2_BLOCK_SIZE); + xmrig_ar2_clear_internal_memory(blockhash_bytes, ARGON2_BLOCK_SIZE); } -void initial_hash(uint8_t *blockhash, argon2_context *context, +void xmrig_ar2_initial_hash(uint8_t *blockhash, argon2_context *context, argon2_type type) { blake2b_state BlakeHash; uint8_t value[sizeof(uint32_t)]; @@ -435,72 +426,70 @@ void initial_hash(uint8_t *blockhash, argon2_context *context, return; } - blake2b_init(&BlakeHash, ARGON2_PREHASH_DIGEST_LENGTH); + xmrig_ar2_blake2b_init(&BlakeHash, ARGON2_PREHASH_DIGEST_LENGTH); store32(&value, context->lanes); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); store32(&value, context->outlen); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); store32(&value, context->m_cost); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); store32(&value, context->t_cost); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); store32(&value, context->version); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); store32(&value, (uint32_t)type); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); store32(&value, context->pwdlen); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); if (context->pwd != NULL) { - blake2b_update(&BlakeHash, (const uint8_t *)context->pwd, + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)context->pwd, context->pwdlen); if (context->flags & ARGON2_FLAG_CLEAR_PASSWORD) { - secure_wipe_memory(context->pwd, context->pwdlen); + xmrig_ar2_secure_wipe_memory(context->pwd, context->pwdlen); context->pwdlen = 0; } } store32(&value, context->saltlen); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); if (context->salt != NULL) { - blake2b_update(&BlakeHash, (const uint8_t *)context->salt, + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)context->salt, context->saltlen); } store32(&value, context->secretlen); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); if (context->secret != NULL) { - blake2b_update(&BlakeHash, (const uint8_t *)context->secret, - context->secretlen); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)context->secret, context->secretlen); if (context->flags & ARGON2_FLAG_CLEAR_SECRET) { - secure_wipe_memory(context->secret, context->secretlen); + xmrig_ar2_secure_wipe_memory(context->secret, context->secretlen); context->secretlen = 0; } } store32(&value, context->adlen); - blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)&value, sizeof(value)); if (context->ad != NULL) { - blake2b_update(&BlakeHash, (const uint8_t *)context->ad, - context->adlen); + xmrig_ar2_blake2b_update(&BlakeHash, (const uint8_t *)context->ad, context->adlen); } - blake2b_final(&BlakeHash, blockhash, ARGON2_PREHASH_DIGEST_LENGTH); + xmrig_ar2_blake2b_final(&BlakeHash, blockhash, ARGON2_PREHASH_DIGEST_LENGTH); } -int initialize(argon2_instance_t *instance, argon2_context *context) { +int xmrig_ar2_initialize(argon2_instance_t *instance, argon2_context *context) { uint8_t blockhash[ARGON2_PREHASH_SEED_LENGTH]; int result = ARGON2_OK; @@ -510,7 +499,7 @@ int initialize(argon2_instance_t *instance, argon2_context *context) { /* 1. Memory allocation */ - result = allocate_memory(context, instance); + result = xmrig_ar2_allocate_memory(context, instance); if (result != ARGON2_OK) { return result; } @@ -519,11 +508,9 @@ int initialize(argon2_instance_t *instance, argon2_context *context) { /* H_0 + 8 extra bytes to produce the first blocks */ /* uint8_t blockhash[ARGON2_PREHASH_SEED_LENGTH]; */ /* Hashing all inputs */ - initial_hash(blockhash, context, instance->type); + xmrig_ar2_initial_hash(blockhash, context, instance->type); /* Zeroing 8 extra bytes */ - clear_internal_memory(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, - ARGON2_PREHASH_SEED_LENGTH - - ARGON2_PREHASH_DIGEST_LENGTH); + xmrig_ar2_clear_internal_memory(blockhash + ARGON2_PREHASH_DIGEST_LENGTH, ARGON2_PREHASH_SEED_LENGTH - ARGON2_PREHASH_DIGEST_LENGTH); if (instance->print_internals) { initial_kat(blockhash, context, instance->type); @@ -531,9 +518,9 @@ int initialize(argon2_instance_t *instance, argon2_context *context) { /* 3. Creating first blocks, we always have at least two blocks in a slice */ - fill_first_blocks(blockhash, instance); + xmrig_ar2_fill_first_blocks(blockhash, instance); /* Clearing the hash */ - clear_internal_memory(blockhash, ARGON2_PREHASH_SEED_LENGTH); + xmrig_ar2_clear_internal_memory(blockhash, ARGON2_PREHASH_SEED_LENGTH); return ARGON2_OK; } diff --git a/src/3rdparty/argon2/lib/core.h b/src/3rdparty/argon2/lib/core.h index 8a3227a9..1fc75bcc 100644 --- a/src/3rdparty/argon2/lib/core.h +++ b/src/3rdparty/argon2/lib/core.h @@ -110,8 +110,7 @@ typedef struct Argon2_thread_data { * @param instance the Argon2 instance * @return ARGON2_OK if memory is allocated successfully */ -int allocate_memory(const argon2_context *context, - argon2_instance_t *instance); +int xmrig_ar2_allocate_memory(const argon2_context *context, argon2_instance_t *instance); /* * Frees memory at the given pointer, uses the appropriate deallocator as @@ -119,22 +118,21 @@ int allocate_memory(const argon2_context *context, * @param context argon2_context which specifies the deallocator * @param instance the Argon2 instance */ -void free_memory(const argon2_context *context, - const argon2_instance_t *instance); +void xmrig_ar2_free_memory(const argon2_context *context, const argon2_instance_t *instance); /* Function that securely cleans the memory. This ignores any flags set * regarding clearing memory. Usually one just calls clear_internal_memory. * @param mem Pointer to the memory * @param s Memory size in bytes */ -void secure_wipe_memory(void *v, size_t n); +void xmrig_ar2_secure_wipe_memory(void *v, size_t n); /* Function that securely clears the memory if FLAG_clear_internal_memory is * set. If the flag isn't set, this function does nothing. * @param mem Pointer to the memory * @param s Memory size in bytes */ -ARGON2_PUBLIC void clear_internal_memory(void *v, size_t n); +ARGON2_PUBLIC void xmrig_ar2_clear_internal_memory(void *v, size_t n); /* * Computes absolute position of reference block in the lane following a skewed @@ -146,9 +144,7 @@ ARGON2_PUBLIC void clear_internal_memory(void *v, size_t n); * If so we can reference the current segment * @pre All pointers must be valid */ -uint32_t index_alpha(const argon2_instance_t *instance, - const argon2_position_t *position, uint32_t pseudo_rand, - int same_lane); +uint32_t xmrig_ar2_index_alpha(const argon2_instance_t *instance, const argon2_position_t *position, uint32_t pseudo_rand, int same_lane); /* * Function that validates all inputs against predefined restrictions and return @@ -157,7 +153,7 @@ uint32_t index_alpha(const argon2_instance_t *instance, * @return ARGON2_OK if everything is all right, otherwise one of error codes * (all defined in */ -int validate_inputs(const argon2_context *context); +int xmrig_ar2_validate_inputs(const argon2_context *context); /* * Hashes all the inputs into @a blockhash[PREHASH_DIGEST_LENGTH], clears @@ -169,8 +165,7 @@ int validate_inputs(const argon2_context *context); * @pre @a blockhash must have at least @a PREHASH_DIGEST_LENGTH bytes * allocated */ -void initial_hash(uint8_t *blockhash, argon2_context *context, - argon2_type type); +void xmrig_ar2_initial_hash(uint8_t *blockhash, argon2_context *context, argon2_type type); /* * Function creates first 2 blocks per lane @@ -178,7 +173,7 @@ void initial_hash(uint8_t *blockhash, argon2_context *context, * @param blockhash Pointer to the pre-hashing digest * @pre blockhash must point to @a PREHASH_SEED_LENGTH allocated values */ -void fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance); +void xmrig_ar2_fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance); /* * Function allocates memory, hashes the inputs with Blake, and creates first @@ -190,7 +185,7 @@ void fill_first_blocks(uint8_t *blockhash, const argon2_instance_t *instance); * @return Zero if successful, -1 if memory failed to allocate. @context->state * will be modified if successful. */ -int initialize(argon2_instance_t *instance, argon2_context *context); +int xmrig_ar2_initialize(argon2_instance_t *instance, argon2_context *context); /* * XORing the last block of each lane, hashing it, making the tag. Deallocates @@ -203,7 +198,7 @@ int initialize(argon2_instance_t *instance, argon2_context *context); * @pre if context->free_cbk is not NULL, it should point to a function that * deallocates memory */ -void finalize(const argon2_context *context, argon2_instance_t *instance); +void xmrig_ar2_finalize(const argon2_context *context, argon2_instance_t *instance); /* * Function that fills the segment using previous segments also from other @@ -212,8 +207,7 @@ void finalize(const argon2_context *context, argon2_instance_t *instance); * @param position Current position * @pre all block pointers must be valid */ -void fill_segment(const argon2_instance_t *instance, - argon2_position_t position); +void xmrig_ar2_fill_segment(const argon2_instance_t *instance, argon2_position_t position); /* * Function that fills the entire memory t_cost times based on the first two @@ -221,6 +215,6 @@ void fill_segment(const argon2_instance_t *instance, * @param instance Pointer to the current instance * @return ARGON2_OK if successful, @context->state */ -int fill_memory_blocks(argon2_instance_t *instance); +int xmrig_ar2_fill_memory_blocks(argon2_instance_t *instance); #endif diff --git a/src/3rdparty/argon2/lib/encoding.c b/src/3rdparty/argon2/lib/encoding.c index af56e447..6190ae8f 100644 --- a/src/3rdparty/argon2/lib/encoding.c +++ b/src/3rdparty/argon2/lib/encoding.c @@ -323,7 +323,7 @@ int decode_string(argon2_context *ctx, const char *str, argon2_type type) { ctx->flags = ARGON2_DEFAULT_FLAGS; /* On return, must have valid context */ - validation_result = validate_inputs(ctx); + validation_result = xmrig_ar2_validate_inputs(ctx); if (validation_result != ARGON2_OK) { return validation_result; } @@ -371,7 +371,7 @@ int encode_string(char *dst, size_t dst_len, argon2_context *ctx, } while ((void)0, 0) const char* type_string = argon2_type2string(type, 0); - int validation_result = validate_inputs(ctx); + int validation_result = xmrig_ar2_validate_inputs(ctx); if (!type_string) { return ARGON2_ENCODING_FAIL; diff --git a/src/3rdparty/argon2/lib/impl-select.c b/src/3rdparty/argon2/lib/impl-select.c index 965b639e..aa5d9911 100644 --- a/src/3rdparty/argon2/lib/impl-select.c +++ b/src/3rdparty/argon2/lib/impl-select.c @@ -83,7 +83,7 @@ void argon2_select_impl() } } -void fill_segment(const argon2_instance_t *instance, argon2_position_t position) +void xmrig_ar2_fill_segment(const argon2_instance_t *instance, argon2_position_t position) { selected_argon_impl.fill_segment(instance, position); }