You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

112 lines
3.7 KiB

diff -uNr tg/tgl/mtproto-client.c tg.mod/tgl/mtproto-client.c
--- tg/tgl/mtproto-client.c 2019-01-29 01:55:55.570050827 +0200
+++ tg.mod/tgl/mtproto-client.c 2019-01-29 01:56:24.363507963 +0200
@@ -143,7 +143,12 @@
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);
+
+ BIGNUM *key_e=NULL, *key_n=NULL, *key_d=NULL;
+ RSA_get0_key(key, (const BIGNUM **) &key_n,
+ (const BIGNUM **) &key_e, (const BIGNUM **) &key_d);
+
+ 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);
}
static int encrypt_packet_buffer_aes_unauth (const char server_nonce[16], const char hidden_client_nonce[32]) {
diff -uNr tg/tgl/mtproto-common.c tg.mod/tgl/mtproto-common.c
--- tg/tgl/mtproto-common.c 2019-01-29 01:55:55.570050827 +0200
+++ tg.mod/tgl/mtproto-common.c 2019-01-29 01:56:29.480196634 +0200
@@ -177,11 +177,16 @@
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);
+ static unsigned char sha[20];
+
+ BIGNUM *key_e=NULL, *key_n=NULL, *key_d=NULL;
+ RSA_get0_key(key, (const BIGNUM **) &key_n,
+ (const BIGNUM **) &key_e, (const BIGNUM **) &key_d);
+
+ assert (key_n && key_e);
+ int l1 = tgl_serialize_bignum (key_n, tempbuff, 4096);
assert (l1 > 0);
- int l2 = tgl_serialize_bignum (key->e, tempbuff + l1, 4096 - l1);
+ int l2 = tgl_serialize_bignum (key_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 +263,22 @@
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, *y;
+ x = BN_new();
+ 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 +291,27 @@
assert (bits >= 2041 && bits <= 2048);
assert (size >= chunks * 255);
int i;
- BIGNUM x, y;
- BN_init (&x);
- BN_init (&y);
+ BIGNUM *x, *y;
+ x = BN_new();
+ 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;
}