From af4c366fdd259da073b2896ec92b102366c5da57 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 11 Aug 2018 13:29:06 +0300 Subject: [PATCH] Remove legacy DH functions. GitOrigin-RevId: 13efa3ef84b99095170df7f5c994482eb9606fe2 --- td/mtproto/Handshake.cpp | 16 +++++++++------- td/mtproto/crypto.cpp | 17 ----------------- td/mtproto/crypto.h | 5 ----- 3 files changed, 9 insertions(+), 29 deletions(-) diff --git a/td/mtproto/Handshake.cpp b/td/mtproto/Handshake.cpp index e7a5aeb03..f9062045c 100644 --- a/td/mtproto/Handshake.cpp +++ b/td/mtproto/Handshake.cpp @@ -171,8 +171,6 @@ Status AuthKeyHandshake::on_server_dh_params(Slice message, Callback *connection return Status::Error("SHA1 mismatch"); } - // server_DH_inner_data#b5890dba nonce:int128 server_nonce:int128 g:int dh_prime:string g_a:string server_time:int = - // Server_DH_inner_data; if (dh_inner_data.nonce_ != nonce) { return Status::Error("Nonce mismatch"); } @@ -182,10 +180,12 @@ Status AuthKeyHandshake::on_server_dh_params(Slice message, Callback *connection server_time_diff = dh_inner_data.server_time_ - Time::now(); - string g_b; - string auth_key_str; - TRY_STATUS( - dh_handshake(dh_inner_data.g_, dh_inner_data.dh_prime_, dh_inner_data.g_a_, &g_b, &auth_key_str, dh_callback)); + DhHandshake handshake; + handshake.set_config(dh_inner_data.g_, dh_inner_data.dh_prime_); + handshake.set_g_a(dh_inner_data.g_a_); + TRY_STATUS(handshake.run_checks(false, dh_callback)); + string g_b = handshake.get_g_b(); + auto auth_key_params = handshake.gen_key(); mtproto_api::client_DH_inner_data data(nonce, server_nonce, 0, g_b); size_t data_size = 4 + tl_calc_length(data); @@ -205,7 +205,7 @@ Status AuthKeyHandshake::on_server_dh_params(Slice message, Callback *connection mtproto_api::set_client_DH_params set_client_dh_params(nonce, server_nonce, encrypted_data); send(connection, create_storer(set_client_dh_params)); - auth_key = AuthKey(dh_auth_key_id(auth_key_str), std::move(auth_key_str)); + auth_key = AuthKey(auth_key_params.first, std::move(auth_key_params.second)); if (mode_ == Mode::Temp) { auth_key.set_expire_at(expire_at_); } @@ -231,6 +231,7 @@ Status AuthKeyHandshake::on_dh_gen_response(Slice message, Callback *connection) } return Status::OK(); } + void AuthKeyHandshake::send(Callback *connection, const Storer &storer) { auto size = storer.size(); auto writer = BufferWriter{size, 0, 0}; @@ -239,6 +240,7 @@ void AuthKeyHandshake::send(Callback *connection, const Storer &storer) { last_query_ = writer.as_buffer_slice(); return do_send(connection, create_storer(last_query_.as_slice())); } + void AuthKeyHandshake::do_send(Callback *connection, const Storer &storer) { return connection->send_no_crypto(storer); } diff --git a/td/mtproto/crypto.cpp b/td/mtproto/crypto.cpp index 59e287993..0b0846d12 100644 --- a/td/mtproto/crypto.cpp +++ b/td/mtproto/crypto.cpp @@ -241,12 +241,6 @@ Status DhHandshake::dh_check(const BigNum &prime, const BigNum &g_a, const BigNu return Status::OK(); } -int64 dh_auth_key_id(const string &auth_key) { - UInt<160> auth_key_sha1; - sha1(auth_key, auth_key_sha1.raw); - return as(auth_key_sha1.raw + 12); -} - void DhHandshake::set_config(int32 g_int, Slice prime_str) { has_config_ = true; prime_ = BigNum::from_binary(prime_str); @@ -350,17 +344,6 @@ int64 DhHandshake::calc_key_id(const string &auth_key) { return as(auth_key_sha1.raw + 12); } -Status dh_handshake(int g_int, Slice prime_str, Slice g_a_str, string *g_b_str, string *g_ab_str, - DhCallback *callback) { - DhHandshake handshake; - handshake.set_config(g_int, prime_str); - handshake.set_g_a(g_a_str); - TRY_STATUS(handshake.run_checks(false, callback)); - *g_b_str = handshake.get_g_b(); - *g_ab_str = handshake.gen_key().second; - return Status::OK(); -} - /*** KDF ***/ void KDF(const string &auth_key, const UInt128 &msg_key, int X, UInt256 *aes_key, UInt256 *aes_iv) { CHECK(auth_key.size() == 2048 / 8); diff --git a/td/mtproto/crypto.h b/td/mtproto/crypto.h index 39e4cca70..2358dd6c9 100644 --- a/td/mtproto/crypto.h +++ b/td/mtproto/crypto.h @@ -158,11 +158,6 @@ class DhHandshake { BigNumContext ctx_; }; -// TODO: remove this legacy functions -Status dh_handshake(int g_int, Slice prime_str, Slice g_a_str, string *g_b_str, string *g_ab_str, - DhCallback *callback) TD_WARN_UNUSED_RESULT; -int64 dh_auth_key_id(const string &auth_key); - /*** KDF ***/ void KDF(const string &auth_key, const UInt128 &msg_key, int X, UInt256 *aes_key, UInt256 *aes_iv); void tmp_KDF(const UInt128 &server_nonce, const UInt256 &new_nonce, UInt256 *tmp_aes_key, UInt256 *tmp_aes_iv);