mirror of
https://github.com/ton-blockchain/ton
synced 2025-03-09 15:40:10 +00:00
Various changes in TVM, github builds and tests (#793)
* Bugfixes in TVM and node * Upgrade to C++17 * Improve GitHub builds * Fix existing tests and partially integrate them into builds --------- Co-authored-by: neodiX42 <namlem@gmail.com> Co-authored-by: EmelyanenkoK <emelyanenko.kirill@gmail.com>
This commit is contained in:
parent
89700cb2aa
commit
5847897b37
122 changed files with 2889 additions and 4100 deletions
|
@ -159,7 +159,11 @@ bool BigNum::is_bit_set(int num) const {
|
|||
}
|
||||
|
||||
bool BigNum::is_prime(BigNumContext &context) const {
|
||||
#if OPENSSL_VERSION_MAJOR >= 3
|
||||
int result = BN_check_prime(impl_->big_num, context.impl_->big_num_context, nullptr);
|
||||
#else
|
||||
int result = BN_is_prime_ex(impl_->big_num, BN_prime_checks, context.impl_->big_num_context, nullptr);
|
||||
#endif
|
||||
LOG_IF(FATAL, result == -1);
|
||||
return result == 1;
|
||||
}
|
||||
|
|
|
@ -106,6 +106,7 @@ class UdpReader {
|
|||
}
|
||||
if (status.is_error() && !UdpSocketFd::is_critical_read_error(status)) {
|
||||
queue.push(UdpMessage{{}, {}, std::move(status)});
|
||||
return td::Status::OK();
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@
|
|||
#include "td/utils/logging.h"
|
||||
#include "td/utils/misc.h"
|
||||
#include "td/utils/port/RwMutex.h"
|
||||
#include "td/utils/port/thread_local.h"
|
||||
#include "td/utils/Random.h"
|
||||
#include "td/utils/ScopeGuard.h"
|
||||
#include "td/utils/SharedSlice.h"
|
||||
|
@ -598,16 +597,23 @@ void aes_ige_decrypt(Slice aes_key, MutableSlice aes_iv, Slice from, MutableSlic
|
|||
static void aes_cbc_xcrypt(Slice aes_key, MutableSlice aes_iv, Slice from, MutableSlice to, bool encrypt_flag) {
|
||||
CHECK(aes_key.size() == 32);
|
||||
CHECK(aes_iv.size() == 16);
|
||||
AES_KEY key;
|
||||
int err;
|
||||
if (encrypt_flag) {
|
||||
err = AES_set_encrypt_key(aes_key.ubegin(), 256, &key);
|
||||
} else {
|
||||
err = AES_set_decrypt_key(aes_key.ubegin(), 256, &key);
|
||||
}
|
||||
LOG_IF(FATAL, err != 0);
|
||||
CHECK(from.size() <= to.size());
|
||||
AES_cbc_encrypt(from.ubegin(), to.ubegin(), from.size(), &key, aes_iv.ubegin(), encrypt_flag);
|
||||
CHECK(from.size() % 16 == 0);
|
||||
int out_len = 0;
|
||||
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
|
||||
CHECK(ctx);
|
||||
if (encrypt_flag) {
|
||||
CHECK(EVP_EncryptInit_ex(ctx, EVP_aes_256_cbc(), nullptr, aes_key.ubegin(), aes_iv.ubegin()) == 1);
|
||||
CHECK(EVP_CIPHER_CTX_set_padding(ctx, 0) == 1);
|
||||
CHECK(EVP_EncryptUpdate(ctx, to.ubegin(), &out_len, from.ubegin(), td::narrow_cast<int>(from.size())) == 1);
|
||||
CHECK(EVP_EncryptFinal_ex(ctx, to.ubegin() + out_len, &out_len) == 1);
|
||||
} else {
|
||||
CHECK(EVP_DecryptInit_ex(ctx, EVP_aes_256_cbc(), nullptr, aes_key.ubegin(), aes_iv.ubegin()) == 1);
|
||||
CHECK(EVP_CIPHER_CTX_set_padding(ctx, 0) == 1);
|
||||
CHECK(EVP_DecryptUpdate(ctx, to.ubegin(), &out_len, from.ubegin(), td::narrow_cast<int>(from.size())) == 1);
|
||||
CHECK(EVP_DecryptFinal_ex(ctx, to.ubegin() + out_len, &out_len) == 1);
|
||||
}
|
||||
EVP_CIPHER_CTX_free(ctx);
|
||||
}
|
||||
|
||||
void aes_cbc_encrypt(Slice aes_key, MutableSlice aes_iv, Slice from, MutableSlice to) {
|
||||
|
@ -723,7 +729,18 @@ string sha512(Slice data) {
|
|||
|
||||
class Sha256State::Impl {
|
||||
public:
|
||||
SHA256_CTX ctx_;
|
||||
EVP_MD_CTX *ctx_ = nullptr;
|
||||
|
||||
Impl() {
|
||||
ctx_ = EVP_MD_CTX_new();
|
||||
CHECK(ctx_);
|
||||
}
|
||||
|
||||
~Impl() {
|
||||
if (ctx_) {
|
||||
EVP_MD_CTX_free(ctx_);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Sha256State::Sha256State() = default;
|
||||
|
@ -755,24 +772,23 @@ void Sha256State::init() {
|
|||
impl_ = make_unique<Sha256State::Impl>();
|
||||
}
|
||||
CHECK(!is_inited_);
|
||||
int err = SHA256_Init(&impl_->ctx_);
|
||||
LOG_IF(FATAL, err != 1);
|
||||
CHECK(EVP_DigestInit_ex(impl_->ctx_, EVP_sha256(), nullptr) == 1);
|
||||
is_inited_ = true;
|
||||
}
|
||||
|
||||
void Sha256State::feed(Slice data) {
|
||||
CHECK(impl_);
|
||||
CHECK(is_inited_);
|
||||
int err = SHA256_Update(&impl_->ctx_, data.ubegin(), data.size());
|
||||
LOG_IF(FATAL, err != 1);
|
||||
CHECK(EVP_DigestUpdate(impl_->ctx_, data.ubegin(), data.size()) == 1);
|
||||
}
|
||||
|
||||
void Sha256State::extract(MutableSlice output, bool destroy) {
|
||||
CHECK(output.size() >= 32);
|
||||
CHECK(impl_);
|
||||
CHECK(is_inited_);
|
||||
int err = SHA256_Final(output.ubegin(), &impl_->ctx_);
|
||||
LOG_IF(FATAL, err != 1);
|
||||
unsigned size;
|
||||
CHECK(EVP_DigestFinal_ex(impl_->ctx_, output.ubegin(), &size) == 1);
|
||||
CHECK(size == 32);
|
||||
is_inited_ = false;
|
||||
if (destroy) {
|
||||
impl_.reset();
|
||||
|
|
|
@ -151,7 +151,7 @@ class Sha256State {
|
|||
bool is_inited_ = false;
|
||||
};
|
||||
|
||||
void md5(Slice input, MutableSlice output);
|
||||
[[deprecated("MD5 is not cryptographically secure")]] void md5(Slice input, MutableSlice output);
|
||||
|
||||
void pbkdf2_sha256(Slice password, Slice salt, int iteration_count, MutableSlice dest);
|
||||
void pbkdf2_sha512(Slice password, Slice salt, int iteration_count, MutableSlice dest);
|
||||
|
|
|
@ -20,9 +20,13 @@
|
|||
|
||||
#include "td/utils/port/signals.h"
|
||||
|
||||
#if __GLIBC__
|
||||
#if TD_WINDOWS
|
||||
#include <DbgHelp.h>
|
||||
#else
|
||||
#if TD_DARWIN || __GLIBC__
|
||||
#include <execinfo.h>
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if TD_LINUX || TD_FREEBSD
|
||||
#include <sys/types.h>
|
||||
|
@ -39,13 +43,48 @@ namespace td {
|
|||
namespace {
|
||||
|
||||
void print_backtrace(void) {
|
||||
#if __GLIBC__
|
||||
#if TD_WINDOWS
|
||||
void *stack[100];
|
||||
HANDLE process = GetCurrentProcess();
|
||||
SymInitialize(process, nullptr, 1);
|
||||
unsigned frames = CaptureStackBackTrace(0, 100, stack, nullptr);
|
||||
signal_safe_write("------- Stack Backtrace -------\n", false);
|
||||
for (unsigned i = 0; i < frames; i++) {
|
||||
td::uint8 symbol_buf[sizeof(SYMBOL_INFO) + 256];
|
||||
auto symbol = (SYMBOL_INFO *)symbol_buf;
|
||||
memset(symbol_buf, 0, sizeof(symbol_buf));
|
||||
symbol->MaxNameLen = 255;
|
||||
symbol->SizeOfStruct = sizeof(SYMBOL_INFO);
|
||||
SymFromAddr(process, (DWORD64)(stack[i]), nullptr, symbol);
|
||||
// Don't use sprintf here because it is not signal-safe
|
||||
char buf[256 + 32];
|
||||
char* buf_ptr = buf;
|
||||
if (frames - i - 1 < 10) {
|
||||
strcpy(buf_ptr, " ");
|
||||
buf_ptr += strlen(buf_ptr);
|
||||
}
|
||||
_itoa(frames - i - 1, buf_ptr, 10);
|
||||
buf_ptr += strlen(buf_ptr);
|
||||
strcpy(buf_ptr, ": [");
|
||||
buf_ptr += strlen(buf_ptr);
|
||||
_ui64toa(td::uint64(symbol->Address), buf_ptr, 16);
|
||||
buf_ptr += strlen(buf_ptr);
|
||||
strcpy(buf_ptr, "] ");
|
||||
buf_ptr += strlen(buf_ptr);
|
||||
strcpy(buf_ptr, symbol->Name);
|
||||
buf_ptr += strlen(buf_ptr);
|
||||
strcpy(buf_ptr, "\n");
|
||||
signal_safe_write(td::Slice{buf, strlen(buf)}, false);
|
||||
}
|
||||
#else
|
||||
#if TD_DARWIN || __GLIBC__
|
||||
void *buffer[128];
|
||||
int nptrs = backtrace(buffer, 128);
|
||||
signal_safe_write("------- Stack Backtrace -------\n", false);
|
||||
backtrace_symbols_fd(buffer, nptrs, 2);
|
||||
signal_safe_write("-------------------------------\n", false);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void print_backtrace_gdb(void) {
|
||||
|
@ -129,7 +168,7 @@ void Stacktrace::print_to_stderr(const PrintOptions &options) {
|
|||
}
|
||||
|
||||
void Stacktrace::init() {
|
||||
#if __GLIBC__
|
||||
#if TD_DARWIN || __GLIBC__
|
||||
// backtrace needs to be called once to ensure that next calls are async-signal-safe
|
||||
void *buffer[1];
|
||||
backtrace(buffer, 1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue