implemented client-server connection, but found out RSA is broken

This commit is contained in:
2025-11-01 19:51:43 +05:00
parent 5cc1484e80
commit 8179609d47
21 changed files with 441 additions and 123 deletions

View File

@@ -4,15 +4,13 @@
// write data from src to array and increment array data pointer
static inline void __Array_writeNext(Array(u8)* dst, u8* src, size_t size){
memcpy(dst->data, src, size);
dst->data = (u8*)dst->data + size;
dst->size -= size;
*dst = Array_sliceAfter(*dst, size);
}
// read data from array to dst and increment array data pointer
static inline void __Array_readNext(u8* dst, Array(u8)* src, size_t size){
memcpy(dst, src->data, size);
src->data = (u8*)src->data + size;
src->size -= size;
*src = Array_sliceAfter(*src, size);
}

View File

@@ -31,7 +31,7 @@ Result(void) RSA_generateKeyPair(u32 key_size,
Return RESULT_VOID;
}
Result(void) RSA_generateKeyPairFromTime(u32 key_size,
Result(void) RSA_generateKeyPairFromSystemRandom(u32 key_size,
br_rsa_private_key* sk, br_rsa_public_key* pk)
{
Deferral(8);
@@ -122,7 +122,7 @@ Result(void) RSA_parsePublicKey_base64(const str src, br_rsa_public_key* pk){
pk->elen = 4;
pk->nlen = key_buffer_size - 4;
pk->e = pk->n + pk->nlen;
u32 offset = str_seekChar(src, ':', 14) + 1;
u32 offset = str_seekChar(src, ':', 10) + 1;
if(offset == 0){
Return RESULT_ERROR("missing ':' before key data", false);
}
@@ -155,7 +155,7 @@ Result(void) RSA_parsePrivateKey_base64(const str src, br_rsa_private_key* sk){
sk->dp = sk->q + field_len;
sk->dq = sk->dp + field_len;
sk->iq = sk->dq + field_len;
u32 offset = str_seekChar(src, ':', 14) + 1;
u32 offset = str_seekChar(src, ':', 10) + 1;
if(offset == 0){
Return RESULT_ERROR("missing ':' before key data", false);
}

View File

@@ -12,7 +12,7 @@
#define RSA_DEFAULT_KEY_SIZE 3072
/// @brief generate random key pair based on system time
/// @brief generate random key pair
/// @param key_size size of public key in bits (2048/3072/4096)
/// @param sk key for decryption
/// @param pk key for encryption
@@ -21,7 +21,8 @@ Result(void) RSA_generateKeyPair(u32 key_size,
br_rsa_private_key* sk, br_rsa_public_key* pk,
const br_prng_class** rng_vtable_ptr);
Result(void) RSA_generateKeyPairFromTime(u32 key_size,
/// @brief generate random key pair using system crypto-rng provider
Result(void) RSA_generateKeyPairFromSystemRandom(u32 key_size,
br_rsa_private_key* sk, br_rsa_public_key* pk);
Result(void) RSA_generateKeyPairFromPassword(u32 key_size,