mirror of
https://github.com/ilyakooo0/urbit.git
synced 2025-01-03 12:42:48 +03:00
compiles and starts
This commit is contained in:
parent
58e4915a8d
commit
ecd4b2531a
@ -748,6 +748,10 @@ main(c3_i argc,
|
||||
}
|
||||
}
|
||||
|
||||
// starting u3m configures OpenSSL memory functions, so we must do it
|
||||
// before any OpenSSL allocations
|
||||
u3m_boot_lite();
|
||||
|
||||
// Initialize OpenSSL for client and server
|
||||
//
|
||||
{
|
||||
@ -755,10 +759,6 @@ main(c3_i argc,
|
||||
SSL_load_error_strings();
|
||||
}
|
||||
|
||||
// must come before curl initialization because curl will use
|
||||
// openssl malloc and prevent us from installing our custom allocator
|
||||
u3m_boot_lite();
|
||||
|
||||
// initialize curl
|
||||
//
|
||||
if ( 0 != curl_global_init(CURL_GLOBAL_DEFAULT) ) {
|
||||
|
@ -7,16 +7,15 @@
|
||||
#include "urcrypt.h"
|
||||
#include <ent.h>
|
||||
|
||||
static void* pre_u;
|
||||
static urcrypt_secp_context sec_u;
|
||||
static urcrypt_secp_context* sec_u;
|
||||
|
||||
void u3e_secp_init()
|
||||
{
|
||||
c3_y ent_y[32];
|
||||
ent_getentropy(ent_y, 32);
|
||||
pre_u = malloc(urcrypt_secp_prealloc_size());
|
||||
sec_u = malloc(urcrypt_secp_prealloc_size());
|
||||
|
||||
if ( 0 != urcrypt_secp_init(&sec_u, pre_u, ent_y) ) {
|
||||
if ( 0 != urcrypt_secp_init(sec_u, ent_y) ) {
|
||||
u3l_log("%s\r\n", "u3e_secp_init failed");
|
||||
abort();
|
||||
}
|
||||
@ -24,9 +23,9 @@ void u3e_secp_init()
|
||||
|
||||
void u3e_secp_stop()
|
||||
{
|
||||
urcrypt_secp_destroy(&sec_u);
|
||||
free(pre_u);
|
||||
pre_u = NULL;
|
||||
urcrypt_secp_destroy(sec_u);
|
||||
free(sec_u);
|
||||
sec_u = NULL;
|
||||
}
|
||||
|
||||
/* util funcs
|
||||
@ -192,7 +191,8 @@ _cqe_reco(u3_atom has,
|
||||
u3r_bytes_fit(32, has_y, has) &&
|
||||
u3r_bytes_fit(32, sir_y, sir) &&
|
||||
u3r_bytes_fit(32, sis_y, sis) &&
|
||||
(0 == urcrypt_secp_reco(has_y, (c3_y) siv, sir_y, sis_y, x_y, y_y))) )
|
||||
(0 == urcrypt_secp_reco(sec_u, has_y,
|
||||
(c3_y) siv, sir_y, sis_y, x_y, y_y))) )
|
||||
{
|
||||
return u3_none;
|
||||
}
|
||||
@ -333,9 +333,6 @@ u3we_make(u3_noun cor)
|
||||
return u3m_bail(c3__exit);
|
||||
}
|
||||
else {
|
||||
return u3l_punt("secp-make",
|
||||
_cqe_256k1_veri(cor)
|
||||
? _cqe_make(has, prv)
|
||||
: u3_none);
|
||||
return u3l_punt("secp-make", _cqe_make(has, prv));
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,7 @@
|
||||
|
||||
#include <secp256k1.h>
|
||||
#include <secp256k1_recovery.h>
|
||||
#include <secp256k1_preallocated.h>
|
||||
|
||||
int
|
||||
urcrypt_set_openssl_mem_functions(urcrypt_openssl_malloc_t m,
|
||||
@ -772,7 +773,7 @@ urcrypt_argon2(uint8_t type,
|
||||
uint8_t *salt,
|
||||
size_t out_length,
|
||||
uint8_t *out,
|
||||
urcrypt_argon2_malloc_t malloc_ptr,
|
||||
urcrypt_argon2_alloc_t alloc_ptr,
|
||||
urcrypt_argon2_free_t free_ptr)
|
||||
{
|
||||
if ( !( SZ_32(secret_length) &&
|
||||
@ -824,13 +825,11 @@ urcrypt_argon2(uint8_t type,
|
||||
threads,
|
||||
threads,
|
||||
version, // algorithm version
|
||||
malloc_ptr, // custom memory allocation function
|
||||
alloc_ptr, // custom memory allocation function
|
||||
free_ptr, // custom memory deallocation function
|
||||
ARGON2_DEFAULT_FLAGS // by default only internal memory is cleared
|
||||
};
|
||||
|
||||
_urcrypt_argon2_malloc_ptr = malloc_ptr;
|
||||
_urcrypt_argon2_free_ptr = free_ptr;
|
||||
result = (*f)(&context);
|
||||
|
||||
if ( ARGON2_OK != result ) {
|
||||
@ -870,25 +869,26 @@ urcrypt_blake2(size_t message_length,
|
||||
}
|
||||
}
|
||||
|
||||
#define SECP_FLAGS SECP256K1_CONTEXT_VERIFY | SECP256K1_CONTEXT_SIGN;
|
||||
#define SECP_FLAGS SECP256K1_CONTEXT_VERIFY | SECP256K1_CONTEXT_SIGN
|
||||
|
||||
struct urcrypt_secp_context_struct {
|
||||
secp256k1_context* secp;
|
||||
uint8_t prealloc[];
|
||||
};
|
||||
|
||||
size_t
|
||||
urcrypt_secp_prealloc_size()
|
||||
{
|
||||
return secp256k1_context_preallocated_size(SECP_FLAGS);
|
||||
return sizeof(urcrypt_secp_context) +
|
||||
secp256k1_context_preallocated_size(SECP_FLAGS);
|
||||
}
|
||||
|
||||
int
|
||||
urcrypt_secp_init(urcrypt_secp_context *context,
|
||||
void *prealloc,
|
||||
uint8_t entropy[32])
|
||||
{
|
||||
secp256k1_context* secp =
|
||||
secp256k1_context_preallocated_create(prealloc, SECP_FLAGS);
|
||||
secp256k1_context_preallocated_create(context->prealloc, SECP_FLAGS);
|
||||
if ( 1 == secp256k1_context_randomize(secp, entropy) ) {
|
||||
context->secp = secp;
|
||||
return 0;
|
||||
|
@ -27,14 +27,14 @@ typedef void *(*urcrypt_openssl_realloc_t)(void*, size_t
|
||||
#endif
|
||||
);
|
||||
|
||||
typedef void (*urcrypt_openssl_free_t)(void*,
|
||||
typedef void (*urcrypt_openssl_free_t)(void*
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
, const char*, int
|
||||
#endif
|
||||
);
|
||||
|
||||
typedef int (*urcrypt_argon2_alloc_t)(uint8_t**, size_t);
|
||||
typedef void (*urcrypt_argon2_free)(uint8_t*, size_t);
|
||||
typedef void (*urcrypt_argon2_free_t)(uint8_t*, size_t);
|
||||
|
||||
int urcrypt_set_openssl_mem_functions(urcrypt_openssl_malloc_t,
|
||||
urcrypt_openssl_realloc_t,
|
||||
@ -86,6 +86,8 @@ int urcrypt_aes_ecbb_de(uint8_t key[24], uint8_t block[16], uint8_t out[16]);
|
||||
int urcrypt_aes_ecbc_en(uint8_t key[32], uint8_t block[16], uint8_t out[16]);
|
||||
int urcrypt_aes_ecbc_de(uint8_t key[32], uint8_t block[16], uint8_t out[16]);
|
||||
|
||||
typedef void* (*urcrypt_realloc_t)(void*, size_t);
|
||||
|
||||
// message and length are read/write so
|
||||
// realloc_ptr can be used as realloc to pad message
|
||||
int urcrypt_aes_cbca_en(uint8_t **message_ptr,
|
||||
@ -197,7 +199,7 @@ const char* urcrypt_argon2(uint8_t type, // one of the urcrpyt_argon2_*
|
||||
uint8_t *salt,
|
||||
size_t out_length,
|
||||
uint8_t *out,
|
||||
urcrypt_argon2_malloc_t malloc_ptr,
|
||||
urcrypt_argon2_alloc_t alloc_ptr,
|
||||
urcrypt_argon2_free_t free_ptr);
|
||||
|
||||
int urcrypt_blake2(size_t message_length,
|
||||
@ -212,13 +214,12 @@ int urcrypt_blake2(size_t message_length,
|
||||
*/
|
||||
typedef struct urcrypt_secp_context_struct urcrypt_secp_context;
|
||||
|
||||
// malloc a pointer of this size and pass it to init
|
||||
// size of opaque secp handle, malloc and pass to init
|
||||
size_t urcrypt_secp_prealloc_size(void);
|
||||
// call this once at per context with high quality entropy
|
||||
int urcrypt_secp_init(urcrypt_secp_context *context,
|
||||
void* prealloc,
|
||||
uint8_t entropy[32]);
|
||||
// call just before freeing prealloc'd pointer
|
||||
// call before freeing opaque secp handle
|
||||
void urcrypt_secp_destroy(urcrypt_secp_context *context);
|
||||
|
||||
/* restore initial secp context conditons (not thread-safe). Recommendation:
|
||||
@ -229,7 +230,8 @@ void urcrypt_secp_cleanup(void);
|
||||
// technically usable without the secp context
|
||||
int urcrypt_secp_make(uint8_t hash[32], uint8_t key[32], uint8_t out[32]);
|
||||
|
||||
int urcrypt_secp_reco(uint8_t hash[32],
|
||||
int urcrypt_secp_reco(urcrypt_secp_context* context,
|
||||
uint8_t hash[32],
|
||||
uint8_t key_v, // 0, 1, 2, 3
|
||||
const uint8_t key_r[32],
|
||||
const uint8_t key_s[32],
|
||||
|
Loading…
Reference in New Issue
Block a user