package srpimport ()// computeXV computes following numbers//// `x = PH2(password, salt1, salt2)`// `v = pow(g, x) mod p`//// TDLib uses terms `clientSalt` for `salt1` and `serverSalt` for `salt2`.func ( SRP) (, , []byte, , *big.Int) (, *big.Int) {// `x = PH2(password, salt1, salt2)` = new(big.Int).SetBytes(.secondary(, , ))// `v = pow(g, x) mod p` = new(big.Int).Exp(, , )return , }// NewHash computes new user password hash using parameters from server.//// See https://core.telegram.org/api/srp#setting-a-new-2fa-password.//// TDLib implementation:// See https://github.com/tdlib/td/blob/fa8feefed70d64271945e9d5fd010b957d93c8cd/td/telegram/PasswordManager.cpp#L57.//// TDesktop implementation:// See https://github.com/telegramdesktop/tdesktop/blob/v3.4.8/Telegram/SourceFiles/core/core_cloud_password.cpp#L68.func ( SRP) ( []byte, Input) (, []byte, error) {// Generate a new new_password_hash using the KDF algorithm specified in the new_settings, // just append 32 sufficiently random bytes to the salt1, first. Proceed as for checking passwords with SRP, // just stop at the generation of the v parameter, and use it as new_password_hash: := new(big.Int).SetBytes(.P)if := checkInput(.G, ); != nil {returnnil, nil, errors.Wrap(, "validate algo") }// Make a copy. := append([]byte(nil), .Salt1...) = append(, make([]byte, 32)...)// ... append 32 sufficiently random bytes to the salt1 ...if , := io.ReadFull(.random, [len()-32:]); != nil {returnnil, nil, } , := .computeXV(, , .Salt2, big.NewInt(int64(.G)), )// As usual in big endian form, padded to 2048 bits. , := .pad256FromBig()return [:], , nil}
The pages are generated with Goldsv0.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.