diff options
Diffstat (limited to 'community/tg/openssl-1.1.patch')
-rw-r--r-- | community/tg/openssl-1.1.patch | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/community/tg/openssl-1.1.patch b/community/tg/openssl-1.1.patch new file mode 100644 index 00000000000..fd791563085 --- /dev/null +++ b/community/tg/openssl-1.1.patch @@ -0,0 +1,102 @@ +diff --git a/tgl/mtproto-client.c b/tgl/mtproto-client.c +index 075decc..0f6c3f2 100644 +--- a/tgl/mtproto-client.c ++++ b/tgl/mtproto-client.c +@@ -143,7 +143,9 @@ static int decrypt_buffer[ENCRYPT_BUFFER_INTS]; + + static int encrypt_packet_buffer (struct tgl_state *TLS, struct tgl_dc *DC) { + RSA *key = TLS->rsa_key_loaded[DC->rsa_key_idx]; +- return tgl_pad_rsa_encrypt (TLS, (char *) packet_buffer, (packet_ptr - packet_buffer) * 4, (char *) encrypt_buffer, ENCRYPT_BUFFER_INTS * 4, key->n, key->e); ++ const BIGNUM *n, *e; ++ RSA_get0_key(key, &n, &e, NULL); ++ return tgl_pad_rsa_encrypt (TLS, (char *) packet_buffer, (packet_ptr - packet_buffer) * 4, (char *) encrypt_buffer, ENCRYPT_BUFFER_INTS * 4, n, e); + } + + static int encrypt_packet_buffer_aes_unauth (const char server_nonce[16], const char hidden_client_nonce[32]) { +diff --git a/tgl/mtproto-common.c b/tgl/mtproto-common.c +index f3b6582..b782256 100644 +--- a/tgl/mtproto-common.c ++++ b/tgl/mtproto-common.c +@@ -178,10 +178,12 @@ int tgl_serialize_bignum (BIGNUM *b, char *buffer, int maxlen) { + long long tgl_do_compute_rsa_key_fingerprint (RSA *key) { + static char tempbuff[4096]; + static unsigned char sha[20]; +- assert (key->n && key->e); +- int l1 = tgl_serialize_bignum (key->n, tempbuff, 4096); ++ const BIGNUM *n, *e; ++ RSA_get0_key(key, &n, &e, NULL); ++ assert (n && e); ++ int l1 = tgl_serialize_bignum (n, tempbuff, 4096); + assert (l1 > 0); +- int l2 = tgl_serialize_bignum (key->e, tempbuff + l1, 4096 - l1); ++ int l2 = tgl_serialize_bignum (e, tempbuff + l1, 4096 - l1); + assert (l2 > 0 && l1 + l2 <= 4096); + SHA1 ((unsigned char *)tempbuff, l1 + l2, sha); + return *(long long *)(sha + 12); +@@ -258,21 +260,20 @@ int tgl_pad_rsa_encrypt (struct tgl_state *TLS, char *from, int from_len, char * + assert (size >= chunks * 256); + assert (RAND_pseudo_bytes ((unsigned char *) from + from_len, pad) >= 0); + int i; +- BIGNUM x, y; +- BN_init (&x); +- BN_init (&y); ++ BIGNUM *x = BN_new(); ++ BIGNUM *y = BN_new(); + rsa_encrypted_chunks += chunks; + for (i = 0; i < chunks; i++) { +- BN_bin2bn ((unsigned char *) from, 255, &x); +- assert (BN_mod_exp (&y, &x, E, N, TLS->BN_ctx) == 1); +- unsigned l = 256 - BN_num_bytes (&y); ++ BN_bin2bn ((unsigned char *) from, 255, x); ++ assert (BN_mod_exp (y, x, E, N, TLS->BN_ctx) == 1); ++ unsigned l = 256 - BN_num_bytes (y); + assert (l <= 256); + memset (to, 0, l); +- BN_bn2bin (&y, (unsigned char *) to + l); ++ BN_bn2bin (y, (unsigned char *) to + l); + to += 256; + } +- BN_free (&x); +- BN_free (&y); ++ BN_free (x); ++ BN_free (y); + return chunks * 256; + } + +@@ -285,26 +286,25 @@ int tgl_pad_rsa_decrypt (struct tgl_state *TLS, char *from, int from_len, char * + assert (bits >= 2041 && bits <= 2048); + assert (size >= chunks * 255); + int i; +- BIGNUM x, y; +- BN_init (&x); +- BN_init (&y); ++ BIGNUM *x = BN_new(); ++ BIGNUM *y = BN_new(); + for (i = 0; i < chunks; i++) { + ++rsa_decrypted_chunks; +- BN_bin2bn ((unsigned char *) from, 256, &x); +- assert (BN_mod_exp (&y, &x, D, N, TLS->BN_ctx) == 1); +- int l = BN_num_bytes (&y); ++ BN_bin2bn ((unsigned char *) from, 256, x); ++ assert (BN_mod_exp (y, x, D, N, TLS->BN_ctx) == 1); ++ int l = BN_num_bytes (y); + if (l > 255) { +- BN_free (&x); +- BN_free (&y); ++ BN_free (x); ++ BN_free (y); + return -1; + } + assert (l >= 0 && l <= 255); + memset (to, 0, 255 - l); +- BN_bn2bin (&y, (unsigned char *) to + 255 - l); ++ BN_bn2bin (y, (unsigned char *) to + 255 - l); + to += 255; + } +- BN_free (&x); +- BN_free (&y); ++ BN_free (x); ++ BN_free (y); + return chunks * 255; + } + |