Remove legacy DH functions.
GitOrigin-RevId: 13efa3ef84b99095170df7f5c994482eb9606fe2
This commit is contained in:
parent
0c7e2ce37b
commit
af4c366fdd
@ -171,8 +171,6 @@ Status AuthKeyHandshake::on_server_dh_params(Slice message, Callback *connection
|
|||||||
return Status::Error("SHA1 mismatch");
|
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) {
|
if (dh_inner_data.nonce_ != nonce) {
|
||||||
return Status::Error("Nonce mismatch");
|
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();
|
server_time_diff = dh_inner_data.server_time_ - Time::now();
|
||||||
|
|
||||||
string g_b;
|
DhHandshake handshake;
|
||||||
string auth_key_str;
|
handshake.set_config(dh_inner_data.g_, dh_inner_data.dh_prime_);
|
||||||
TRY_STATUS(
|
handshake.set_g_a(dh_inner_data.g_a_);
|
||||||
dh_handshake(dh_inner_data.g_, dh_inner_data.dh_prime_, dh_inner_data.g_a_, &g_b, &auth_key_str, dh_callback));
|
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);
|
mtproto_api::client_DH_inner_data data(nonce, server_nonce, 0, g_b);
|
||||||
size_t data_size = 4 + tl_calc_length(data);
|
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);
|
mtproto_api::set_client_DH_params set_client_dh_params(nonce, server_nonce, encrypted_data);
|
||||||
send(connection, create_storer(set_client_dh_params));
|
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) {
|
if (mode_ == Mode::Temp) {
|
||||||
auth_key.set_expire_at(expire_at_);
|
auth_key.set_expire_at(expire_at_);
|
||||||
}
|
}
|
||||||
@ -231,6 +231,7 @@ Status AuthKeyHandshake::on_dh_gen_response(Slice message, Callback *connection)
|
|||||||
}
|
}
|
||||||
return Status::OK();
|
return Status::OK();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AuthKeyHandshake::send(Callback *connection, const Storer &storer) {
|
void AuthKeyHandshake::send(Callback *connection, const Storer &storer) {
|
||||||
auto size = storer.size();
|
auto size = storer.size();
|
||||||
auto writer = BufferWriter{size, 0, 0};
|
auto writer = BufferWriter{size, 0, 0};
|
||||||
@ -239,6 +240,7 @@ void AuthKeyHandshake::send(Callback *connection, const Storer &storer) {
|
|||||||
last_query_ = writer.as_buffer_slice();
|
last_query_ = writer.as_buffer_slice();
|
||||||
return do_send(connection, create_storer(last_query_.as_slice()));
|
return do_send(connection, create_storer(last_query_.as_slice()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AuthKeyHandshake::do_send(Callback *connection, const Storer &storer) {
|
void AuthKeyHandshake::do_send(Callback *connection, const Storer &storer) {
|
||||||
return connection->send_no_crypto(storer);
|
return connection->send_no_crypto(storer);
|
||||||
}
|
}
|
||||||
|
@ -241,12 +241,6 @@ Status DhHandshake::dh_check(const BigNum &prime, const BigNum &g_a, const BigNu
|
|||||||
return Status::OK();
|
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<int64>(auth_key_sha1.raw + 12);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DhHandshake::set_config(int32 g_int, Slice prime_str) {
|
void DhHandshake::set_config(int32 g_int, Slice prime_str) {
|
||||||
has_config_ = true;
|
has_config_ = true;
|
||||||
prime_ = BigNum::from_binary(prime_str);
|
prime_ = BigNum::from_binary(prime_str);
|
||||||
@ -350,17 +344,6 @@ int64 DhHandshake::calc_key_id(const string &auth_key) {
|
|||||||
return as<int64>(auth_key_sha1.raw + 12);
|
return as<int64>(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 ***/
|
/*** KDF ***/
|
||||||
void KDF(const string &auth_key, const UInt128 &msg_key, int X, UInt256 *aes_key, UInt256 *aes_iv) {
|
void KDF(const string &auth_key, const UInt128 &msg_key, int X, UInt256 *aes_key, UInt256 *aes_iv) {
|
||||||
CHECK(auth_key.size() == 2048 / 8);
|
CHECK(auth_key.size() == 2048 / 8);
|
||||||
|
@ -158,11 +158,6 @@ class DhHandshake {
|
|||||||
BigNumContext ctx_;
|
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 ***/
|
/*** KDF ***/
|
||||||
void KDF(const string &auth_key, const UInt128 &msg_key, int X, UInt256 *aes_key, UInt256 *aes_iv);
|
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);
|
void tmp_KDF(const UInt128 &server_nonce, const UInt256 &new_nonce, UInt256 *tmp_aes_key, UInt256 *tmp_aes_iv);
|
||||||
|
Reference in New Issue
Block a user