Merge commit 'aae086cc650e42eec1eea8db28cd01fa868d7f90'
This commit is contained in:
@ -6,36 +6,46 @@ function(target_link_toxcore target)
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
function(target_link_sodium target)
|
||||
if(TARGET unofficial-sodium::sodium)
|
||||
target_link_libraries(${target} PRIVATE unofficial-sodium::sodium)
|
||||
else()
|
||||
target_link_libraries(${target} PRIVATE ${LIBSODIUM_LIBRARIES})
|
||||
target_link_directories(${target} PRIVATE ${LIBSODIUM_LIBRARY_DIRS})
|
||||
target_include_directories(${target} SYSTEM PRIVATE ${LIBSODIUM_INCLUDE_DIRS})
|
||||
target_compile_options(${target} PRIVATE ${LIBSODIUM_CFLAGS_OTHER})
|
||||
endif()
|
||||
endfunction()
|
||||
|
||||
add_executable(save-generator save-generator.c)
|
||||
target_link_libraries(save-generator PRIVATE misc_tools)
|
||||
target_link_toxcore(save-generator)
|
||||
|
||||
add_executable(strkey strkey.c)
|
||||
target_link_libraries(strkey PRIVATE ${LIBSODIUM_LIBRARIES})
|
||||
target_link_toxcore(strkey)
|
||||
target_link_sodium(strkey)
|
||||
|
||||
add_executable(create_bootstrap_keys create_bootstrap_keys.c)
|
||||
target_link_libraries(create_bootstrap_keys PRIVATE ${LIBSODIUM_LIBRARIES})
|
||||
target_link_toxcore(create_bootstrap_keys)
|
||||
target_link_sodium(create_bootstrap_keys)
|
||||
|
||||
add_executable(create_minimal_savedata create_minimal_savedata.c)
|
||||
target_link_libraries(create_minimal_savedata PRIVATE ${LIBSODIUM_LIBRARIES})
|
||||
target_link_sodium(create_minimal_savedata)
|
||||
|
||||
add_executable(create_savedata create_savedata.c)
|
||||
target_link_libraries(create_savedata PRIVATE ${LIBSODIUM_LIBRARIES})
|
||||
target_link_sodium(create_savedata)
|
||||
target_link_toxcore(create_savedata)
|
||||
|
||||
add_executable(sign sign.c)
|
||||
target_link_libraries(sign PRIVATE ${LIBSODIUM_LIBRARIES} misc_tools)
|
||||
target_link_sodium(sign)
|
||||
|
||||
add_executable(cracker_simple cracker_simple.c)
|
||||
target_link_libraries(cracker_simple ${LIBSODIUM_LIBRARIES} misc_tools)
|
||||
target_link_sodium(cracker_simple)
|
||||
|
||||
# MSVC doesn't support OpenMP
|
||||
if(NOT MSVC)
|
||||
find_package(OpenMP)
|
||||
if(OpenMP_C_FOUND)
|
||||
add_executable(cracker cracker.c)
|
||||
target_link_libraries(cracker PRIVATE OpenMP::OpenMP_C ${LIBSODIUM_LIBRARIES})
|
||||
endif()
|
||||
find_package(OpenMP)
|
||||
if(OpenMP_C_FOUND)
|
||||
add_executable(cracker cracker.c)
|
||||
target_link_libraries(cracker PRIVATE OpenMP::OpenMP_C)
|
||||
target_link_sodium(cracker)
|
||||
else()
|
||||
add_executable(cracker cracker.c)
|
||||
target_link_sodium(cracker)
|
||||
endif()
|
||||
|
13
external/toxcore/c-toxcore/other/fun/cracker.c
vendored
13
external/toxcore/c-toxcore/other/fun/cracker.c
vendored
@ -33,6 +33,7 @@
|
||||
#include <omp.h>
|
||||
#define NUM_THREADS() ((unsigned) omp_get_max_threads())
|
||||
#else
|
||||
#pragma message("Being built without OpenMP support -- the program will utilize a single thread only.")
|
||||
#define NUM_THREADS() (1U)
|
||||
#endif
|
||||
|
||||
@ -112,8 +113,9 @@ static size_t match_hex_prefix(const uint8_t *key, const uint8_t *prefix, size_t
|
||||
static void cracker_core(uint64_t range_start, uint64_t range_end, uint64_t range_offs, uint64_t priv_key_shadow[4],
|
||||
uint32_t *longest_match, uint8_t hex_prefix[MAX_CRACK_BYTES], size_t prefix_chars_len)
|
||||
{
|
||||
#if defined(_OPENMP)
|
||||
#pragma omp parallel for firstprivate(priv_key_shadow) shared(longest_match, range_start, range_end, range_offs, hex_prefix, prefix_chars_len) schedule(static) default(none)
|
||||
|
||||
#endif
|
||||
for (uint64_t batch = range_start; batch < range_end; ++batch) {
|
||||
uint8_t *priv_key = (uint8_t *) priv_key_shadow;
|
||||
/*
|
||||
@ -134,14 +136,19 @@ static void cracker_core(uint64_t range_start, uint64_t range_end, uint64_t rang
|
||||
|
||||
// Global compare and update
|
||||
uint32_t l_longest_match;
|
||||
#if defined(_OPENMP)
|
||||
#pragma omp atomic read
|
||||
#endif
|
||||
l_longest_match = *longest_match;
|
||||
|
||||
if (matching > l_longest_match) {
|
||||
#if defined(_OPENMP)
|
||||
#pragma omp atomic write
|
||||
#endif
|
||||
*longest_match = matching;
|
||||
|
||||
#if defined(_OPENMP)
|
||||
#pragma omp critical
|
||||
#endif
|
||||
{
|
||||
printf("%u chars matching: \n", matching);
|
||||
printf("Public key: ");
|
||||
@ -198,7 +205,6 @@ int main(int argc, char *argv[])
|
||||
randombytes(priv_key, KEY_LEN);
|
||||
uint32_t longest_match = 0;
|
||||
|
||||
|
||||
// Finishes a batch every ~10s on my PC
|
||||
const uint64_t batch_size = (UINT64_C(1) << 18) * NUM_THREADS();
|
||||
|
||||
@ -220,7 +226,6 @@ int main(int argc, char *argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
for (uint64_t tries = 0; tries < rem_start; tries += batch_size) {
|
||||
cracker_core(tries, tries + batch_size, 0, priv_key_shadow, &longest_match, hex_prefix, prefix_chars_len);
|
||||
|
||||
|
@ -13,11 +13,8 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
/* Sodium includes*/
|
||||
#include <sodium/crypto_scalarmult_curve25519.h>
|
||||
#include <sodium/randombytes.h>
|
||||
#include <sodium.h>
|
||||
|
||||
#include "../../testing/misc_tools.h"
|
||||
#include "../../toxcore/ccompat.h"
|
||||
|
||||
// Secret key and public key length
|
||||
@ -30,7 +27,6 @@ static void print_key(const uint8_t *client_id)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if (argc < 2) {
|
||||
@ -41,7 +37,13 @@ int main(int argc, char *argv[])
|
||||
long long unsigned int num_tries = 0;
|
||||
|
||||
size_t len = strlen(argv[1]) / 2;
|
||||
unsigned char *key = hex_string_to_bin(argv[1]);
|
||||
unsigned char *key = (unsigned char *)malloc(len);
|
||||
const char *hex_end = nullptr;
|
||||
if (sodium_hex2bin(key, len, argv[1], strlen(argv[1]), nullptr, nullptr, &hex_end) != 0
|
||||
|| hex_end != argv[1] + strlen(argv[1])) {
|
||||
printf("Invalid key provided\n");
|
||||
return 1;
|
||||
}
|
||||
uint8_t pub_key[KEY_LEN], priv_key[KEY_LEN], c_key[KEY_LEN];
|
||||
|
||||
if (len > KEY_LEN) {
|
||||
|
22
external/toxcore/c-toxcore/other/fun/sign.c
vendored
22
external/toxcore/c-toxcore/other/fun/sign.c
vendored
@ -18,7 +18,6 @@
|
||||
#include <sodium.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "../../testing/misc_tools.h" // hex_string_to_bin
|
||||
#include "../../toxcore/ccompat.h"
|
||||
|
||||
static int load_file(const char *filename, unsigned char **result)
|
||||
@ -70,7 +69,12 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (argc == 5 && argv[1][0] == 's') {
|
||||
unsigned char *secret_key = hex_string_to_bin(argv[2]);
|
||||
const char *hex_end = nullptr;
|
||||
if (sodium_hex2bin(sk, sizeof(sk), argv[2], strlen(argv[2]), nullptr, nullptr, &hex_end) != 0
|
||||
|| hex_end != argv[2] + strlen(argv[2])) {
|
||||
printf("Invalid secret key provided.\n");
|
||||
goto fail;
|
||||
}
|
||||
unsigned char *data = nullptr;
|
||||
int size = load_file(argv[3], &data);
|
||||
|
||||
@ -80,9 +84,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
unsigned long long smlen;
|
||||
unsigned char *sm = (unsigned char *)malloc(size + crypto_sign_ed25519_BYTES * 2);
|
||||
crypto_sign_ed25519(sm, &smlen, data, size, secret_key);
|
||||
crypto_sign_ed25519(sm, &smlen, data, size, sk);
|
||||
free(data);
|
||||
free(secret_key);
|
||||
|
||||
if (smlen - size != crypto_sign_ed25519_BYTES) {
|
||||
free(sm);
|
||||
@ -110,8 +113,13 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (argc == 4 && argv[1][0] == 'c') {
|
||||
unsigned char *public_key = hex_string_to_bin(argv[2]);
|
||||
unsigned char *data;
|
||||
const char *hex_end = nullptr;
|
||||
if (sodium_hex2bin(pk, sizeof(pk), argv[2], strlen(argv[2]), nullptr, nullptr, &hex_end) != 0
|
||||
|| hex_end != argv[2] + strlen(argv[2])) {
|
||||
printf("Invalid public key provided.\n");
|
||||
goto fail;
|
||||
}
|
||||
unsigned char *data = nullptr;
|
||||
int size = load_file(argv[3], &data);
|
||||
|
||||
if (size < 0) {
|
||||
@ -127,7 +135,7 @@ int main(int argc, char *argv[])
|
||||
unsigned char *m = (unsigned char *)malloc(size);
|
||||
unsigned long long mlen;
|
||||
|
||||
if (crypto_sign_ed25519_open(m, &mlen, signe, size, public_key) == -1) {
|
||||
if (crypto_sign_ed25519_open(m, &mlen, signe, size, pk) == -1) {
|
||||
printf("Failed checking sig.\n");
|
||||
free(m);
|
||||
free(signe);
|
||||
|
Reference in New Issue
Block a user