Source File
check_dh.go
Belonging Package
github.com/gotd/td/internal/crypto
package cryptoimport ()// CheckDH performs DH parameters check described in Telegram docs.//// Client is expected to check whether p is a safe 2048-bit prime (meaning that both p and (p-1)/2 are prime,// and that 2^2047 < p < 2^2048), and that g generates a cyclic subgroup of prime order (p-1)/2, i.e.// is a quadratic residue mod p. Since g is always equal to 2, 3, 4, 5, 6 or 7, this is easily done using quadratic// reciprocity law, yielding a simple condition on p mod 4g — namely, p mod 8 = 7 for g = 2; p mod 3 = 2 for g = 3;// no extra condition for g = 4; p mod 5 = 1 or 4 for g = 5; p mod 24 = 19 or 23 for g = 6; and p mod 7 = 3,// 5 or 6 for g = 7.//// See https://core.telegram.org/mtproto/auth_key#presenting-proof-of-work-server-authentication.//// See https://core.telegram.org/api/srp#checking-the-password-with-srp.//// See https://core.telegram.org/api/end-to-end#sending-a-request.func ( int, *big.Int) error {// The client is expected to check whether p is a safe 2048-bit prime// (meaning that both p and (p-1)/2 are prime, and that 2^2047 < p < 2^2048).// FIXME(tdakkota): we check that 2^2047 <= p < 2^2048// but docs says to check 2^2047 < p < 2^2048.//// TDLib check 2^2047 <= too:// https://github.com/tdlib/td/blob/d161323858a782bc500d188b9ae916982526c262/td/mtproto/DhHandshake.cpp#L23if .BitLen() != RSAKeyBits {return errors.New("p should be 2^2047 < p < 2^2048")}if := CheckGP(, ); != nil {return}return checkPrime()}func ( *big.Int) error {if !Prime() {return errors.New("p is not prime number")}:= big.NewInt(0).Sub(, big.NewInt(1)):= .Quo(, big.NewInt(2))if !Prime() {return errors.New("(p-1)/2 is not prime number")}return nil}
![]() |
The pages are generated with Golds v0.6.7. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |