mirror of
https://github.com/urbit/shrub.git
synced 2024-11-30 22:15:47 +03:00
jets: switch openssl to the loom allocator.
This: - uses OPENSSL_malloc() in libaes_siv - fixes a case where our jet code was not freeing ssl objects. - sets the openssl allocator to the loom allocator.
This commit is contained in:
parent
d1c4afca85
commit
b25023805f
@ -247,12 +247,12 @@ void AES_SIV_CTX_free(AES_SIV_CTX *ctx) {
|
||||
CMAC_CTX_free(ctx->cmac_ctx);
|
||||
}
|
||||
OPENSSL_cleanse(&ctx->d, sizeof ctx->d);
|
||||
free(ctx);
|
||||
OPENSSL_free(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
AES_SIV_CTX *AES_SIV_CTX_new(void) {
|
||||
AES_SIV_CTX *ctx = malloc(sizeof(struct AES_SIV_CTX_st));
|
||||
AES_SIV_CTX *ctx = OPENSSL_malloc(sizeof(struct AES_SIV_CTX_st));
|
||||
if (UNLIKELY(ctx == NULL)) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -351,6 +351,15 @@
|
||||
void*
|
||||
u3a_malloc(size_t len_i);
|
||||
|
||||
/* u3a_malloc_ssl(): openssl-shaped malloc
|
||||
*/
|
||||
void*
|
||||
u3a_malloc_ssl(size_t len_i
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
, const char* file, int line
|
||||
#endif
|
||||
);
|
||||
|
||||
/* u3a_calloc(): aligned storage measured in bytes.
|
||||
*/
|
||||
void*
|
||||
@ -366,6 +375,15 @@
|
||||
void*
|
||||
u3a_realloc2(void* lag_v, size_t old_i, size_t new_i);
|
||||
|
||||
/* u3a_realloc_ssl(): openssl-shaped realloc.
|
||||
*/
|
||||
void*
|
||||
u3a_realloc_ssl(void* lag_v, size_t len_i
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
, const char* file, int line
|
||||
#endif
|
||||
);
|
||||
|
||||
/* u3a_free(): free for aligned malloc.
|
||||
*/
|
||||
void
|
||||
@ -376,6 +394,15 @@
|
||||
void
|
||||
u3a_free2(void* tox_v, size_t siz_i);
|
||||
|
||||
/* u3a_free_ssl(): openssl-shaped free.
|
||||
*/
|
||||
void
|
||||
u3a_free_ssl(void* tox_v
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
, const char* file, int line
|
||||
#endif
|
||||
);
|
||||
|
||||
/* Reference and arena control.
|
||||
*/
|
||||
/* u3a_gain(): gain a reference count in normal space.
|
||||
|
@ -7,7 +7,6 @@
|
||||
|
||||
#include "aes_siv.h"
|
||||
|
||||
|
||||
/* functions
|
||||
*/
|
||||
static void u3r_bytes_reverse(c3_w a_w,
|
||||
@ -33,9 +32,13 @@ static u3_noun _siv_en(c3_y* key_y,
|
||||
u3_atom txt)
|
||||
{
|
||||
AES_SIV_CTX* ctx = AES_SIV_CTX_new();
|
||||
if ( 0 == ctx ) {
|
||||
return u3_none;
|
||||
}
|
||||
|
||||
if ( 0 == AES_SIV_Init(ctx, key_y, keysize) ) {
|
||||
AES_SIV_CTX_free(ctx);
|
||||
return u3m_bail(c3__exit);
|
||||
return u3_none;
|
||||
}
|
||||
|
||||
while (u3_nul != ads) {
|
||||
@ -48,7 +51,7 @@ static u3_noun _siv_en(c3_y* key_y,
|
||||
|
||||
if ( 0 == ret ) {
|
||||
AES_SIV_CTX_free(ctx);
|
||||
return u3m_bail(c3__exit);
|
||||
return u3_none;
|
||||
}
|
||||
|
||||
ads = u3t(ads);
|
||||
@ -67,7 +70,7 @@ static u3_noun _siv_en(c3_y* key_y,
|
||||
u3a_free(out_y);
|
||||
u3a_free(txt_y);
|
||||
AES_SIV_CTX_free(ctx);
|
||||
return u3m_bail(c3__exit);
|
||||
return u3_none;
|
||||
}
|
||||
|
||||
u3a_free(txt_y);
|
||||
@ -97,9 +100,13 @@ static u3_noun _siv_de(c3_y* key_y,
|
||||
u3_atom txt)
|
||||
{
|
||||
AES_SIV_CTX* ctx = AES_SIV_CTX_new();
|
||||
if ( 0 == ctx ) {
|
||||
return u3_none;
|
||||
}
|
||||
|
||||
if ( 0 == AES_SIV_Init(ctx, key_y, keysize) ) {
|
||||
AES_SIV_CTX_free(ctx);
|
||||
return u3m_bail(c3__exit);
|
||||
return u3_none;
|
||||
}
|
||||
|
||||
while (u3_nul != ads) {
|
||||
@ -112,7 +119,7 @@ static u3_noun _siv_de(c3_y* key_y,
|
||||
|
||||
if ( 0 == ret ) {
|
||||
AES_SIV_CTX_free(ctx);
|
||||
return u3m_bail(c3__exit);
|
||||
return u3_none;
|
||||
}
|
||||
|
||||
ads = u3t(ads);
|
||||
@ -133,8 +140,10 @@ static u3_noun _siv_de(c3_y* key_y,
|
||||
u3a_free(txt_y);
|
||||
AES_SIV_CTX_free(ctx);
|
||||
|
||||
// Dcryption failed or signature bad.
|
||||
return 0;
|
||||
// Either decryption failed or signature bad or there was a memory
|
||||
// error. Some of these are deterministic and some are not. return u3_none
|
||||
// to fallback to the Nock implementation.
|
||||
return u3_none;
|
||||
}
|
||||
|
||||
u3a_free(txt_y);
|
||||
|
@ -17,15 +17,7 @@
|
||||
u3r_bytes(0, wid, (void*)dat_y, dat);
|
||||
|
||||
const EVP_MD* rip_u = EVP_ripemd160(); // ripem algorithm
|
||||
static EVP_MD_CTX* con_u = NULL; // context
|
||||
|
||||
/* build library context object
|
||||
we do this once (and only once)
|
||||
*/
|
||||
|
||||
if (NULL == con_u) {
|
||||
con_u = EVP_MD_CTX_create();
|
||||
}
|
||||
EVP_MD_CTX* con_u = EVP_MD_CTX_create();
|
||||
|
||||
/* perform signature
|
||||
*/
|
||||
@ -37,6 +29,7 @@
|
||||
ret_w = EVP_DigestInit_ex(con_u, rip_u, NULL);
|
||||
if ( 1 != ret_w ) {
|
||||
u3a_free(dat_y);
|
||||
EVP_MD_CTX_destroy(con_u);
|
||||
u3l_log("\rripe jet: crypto library fail 1\n");
|
||||
return u3m_bail(c3__exit);
|
||||
}
|
||||
@ -44,16 +37,20 @@
|
||||
ret_w = EVP_DigestUpdate(con_u, (void*)dat_y, wid);
|
||||
u3a_free(dat_y);
|
||||
if (1 != ret_w) {
|
||||
EVP_MD_CTX_destroy(con_u);
|
||||
u3l_log("\rripe jet: crypto library fail 2\n");
|
||||
return u3m_bail(c3__exit);
|
||||
}
|
||||
|
||||
ret_w = EVP_DigestFinal_ex(con_u, sib_y, &sil_w);
|
||||
if ( 1 != ret_w ) {
|
||||
EVP_MD_CTX_destroy(con_u);
|
||||
u3l_log("\rripe jet: crypto library fail 3\n");
|
||||
return u3m_bail(c3__exit);
|
||||
}
|
||||
|
||||
EVP_MD_CTX_destroy(con_u);
|
||||
|
||||
/* endian conversion;
|
||||
turn into noun for return
|
||||
*/
|
||||
|
@ -700,6 +700,18 @@ u3a_malloc(size_t len_i)
|
||||
return out_w;
|
||||
}
|
||||
|
||||
/* u3a_malloc_ssl(): openssl-shaped malloc
|
||||
*/
|
||||
void*
|
||||
u3a_malloc_ssl(size_t len_i
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
, const char* file, int line
|
||||
#endif
|
||||
)
|
||||
{
|
||||
return u3a_malloc(len_i);
|
||||
}
|
||||
|
||||
/* u3a_cellblock(): allocate a block of cells on the hat.
|
||||
*/
|
||||
static c3_o
|
||||
@ -883,6 +895,18 @@ u3a_realloc2(void* lag_v, size_t old_i, size_t new_i)
|
||||
return u3a_realloc(lag_v, new_i);
|
||||
}
|
||||
|
||||
/* u3a_realloc_ssl(): openssl-shaped realloc.
|
||||
*/
|
||||
void*
|
||||
u3a_realloc_ssl(void* lag_v, size_t len_i
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
, const char* file, int line
|
||||
#endif
|
||||
)
|
||||
{
|
||||
return u3a_realloc(lag_v, len_i);
|
||||
}
|
||||
|
||||
/* u3a_free(): free for aligned malloc.
|
||||
*/
|
||||
void
|
||||
@ -907,6 +931,18 @@ u3a_free2(void* tox_v, size_t siz_i)
|
||||
return u3a_free(tox_v);
|
||||
}
|
||||
|
||||
/* u3a_free_ssl(): openssl-shaped free.
|
||||
*/
|
||||
void
|
||||
u3a_free_ssl(void* tox_v
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
, const char* file, int line
|
||||
#endif
|
||||
)
|
||||
{
|
||||
return u3a_free(tox_v);
|
||||
}
|
||||
|
||||
/* _me_wash_north(): clean up mug slots after copy.
|
||||
*/
|
||||
static void _me_wash_north(u3_noun dog);
|
||||
|
@ -7,6 +7,7 @@
|
||||
#include <ctype.h>
|
||||
#include <sigsegv.h>
|
||||
#include <curl/curl.h>
|
||||
#include <openssl/crypto.h>
|
||||
|
||||
#include "all.h"
|
||||
|
||||
@ -1633,6 +1634,11 @@ u3m_boot(c3_c* dir_c)
|
||||
*/
|
||||
u3m_init();
|
||||
|
||||
/* In the worker, set the openssl memory allocation functions to always
|
||||
** work on the loom.
|
||||
*/
|
||||
CRYPTO_set_mem_functions(u3a_malloc_ssl, u3a_realloc_ssl, u3a_free_ssl);
|
||||
|
||||
/* Activate the storage system.
|
||||
*/
|
||||
nuu_o = u3e_live(c3n, dir_c);
|
||||
|
Loading…
Reference in New Issue
Block a user