Add functions for getting BigNum parameters of DhHandshake.

GitOrigin-RevId: 7ad8d822f5d4c696769b5585b6fc6533ba56d0e0
This commit is contained in:
levlam 2018-08-08 22:57:37 +03:00
parent 7e1d116d70
commit c44361fb60
2 changed files with 28 additions and 2 deletions

View File

@ -318,11 +318,30 @@ Status DhHandshake::run_checks(DhCallback *callback) {
return dh_check(prime_str_, prime_, g_int_, g_a_, g_b_, ctx_, callback); return dh_check(prime_str_, prime_, g_int_, g_a_, g_b_, ctx_, callback);
} }
std::pair<int64, string> DhHandshake::gen_key() { BigNum DhHandshake::get_g() const {
CHECK(has_config_);
return g_;
}
BigNum DhHandshake::get_p() const {
CHECK(has_config_);
return prime_;
}
BigNum DhHandshake::get_b() const {
CHECK(has_config_);
return b_;
}
BigNum DhHandshake::get_g_ab() {
CHECK(has_g_a_ && has_config_); CHECK(has_g_a_ && has_config_);
BigNum g_ab; BigNum g_ab;
BigNum::mod_exp(g_ab, g_a_, b_, prime_, ctx_); BigNum::mod_exp(g_ab, g_a_, b_, prime_, ctx_);
string key = g_ab.to_binary(2048 / 8); return g_ab;
}
std::pair<int64, string> DhHandshake::gen_key() {
string key = get_g_ab().to_binary(2048 / 8);
auto key_id = calc_key_id(key); auto key_id = calc_key_id(key);
return std::pair<int64, string>(key_id, std::move(key)); return std::pair<int64, string>(key_id, std::move(key));
} }

View File

@ -55,6 +55,7 @@ class DhCallback {
virtual void add_good_prime(Slice prime_str) const = 0; virtual void add_good_prime(Slice prime_str) const = 0;
virtual void add_bad_prime(Slice prime_str) const = 0; virtual void add_bad_prime(Slice prime_str) const = 0;
}; };
class DhHandshake { class DhHandshake {
public: public:
void set_config(int32 g_int, Slice prime_str); void set_config(int32 g_int, Slice prime_str);
@ -72,6 +73,11 @@ class DhHandshake {
string get_g_b_hash() const; string get_g_b_hash() const;
Status run_checks(DhCallback *callback) TD_WARN_UNUSED_RESULT; Status run_checks(DhCallback *callback) TD_WARN_UNUSED_RESULT;
BigNum get_g() const;
BigNum get_p() const;
BigNum get_b() const;
BigNum get_g_ab();
std::pair<int64, string> gen_key(); std::pair<int64, string> gen_key();
static int64 calc_key_id(const string &auth_key); static int64 calc_key_id(const string &auth_key);
@ -157,4 +163,5 @@ int64 dh_auth_key_id(const string &auth_key);
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);
void KDF2(Slice auth_key, const UInt128 &msg_key, int X, UInt256 *aes_key, UInt256 *aes_iv); void KDF2(Slice auth_key, const UInt128 &msg_key, int X, UInt256 *aes_key, UInt256 *aes_iv);
} // namespace td } // namespace td