move gotd fork into repo. (#111)
- update to latest telegram layer - remove some references to fields in tg.Entities that don't exist in the schema - originally added here: https://github.com/beeper/td/commit/820929062a2ba0104397bc01235ab58a9cff780e - referenced here - https://github.com/mautrix/telegramgo/commit/124f0967ed195b5a380c9bd02e170ada9710dde3 - https://github.com/mautrix/telegramgo/commit/4205047aab2e0639217148b5d125bfaab668bd8e
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
// Package srp contains implementation of Secure Remote Password protocol.
|
||||
package srp
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"io"
|
||||
"math/big"
|
||||
|
||||
"github.com/go-faster/xor"
|
||||
|
||||
"go.mau.fi/mautrix-telegram/pkg/gotd/crypto"
|
||||
)
|
||||
|
||||
// SRP is client implementation of Secure Remote Password protocol.
|
||||
//
|
||||
// See https://core.telegram.org/api/srp.
|
||||
type SRP struct {
|
||||
random io.Reader
|
||||
}
|
||||
|
||||
// NewSRP creates new SRP instance.
|
||||
func NewSRP(random io.Reader) SRP {
|
||||
return SRP{random: random}
|
||||
}
|
||||
|
||||
// Input is hashing algorithm parameters from server.
|
||||
//
|
||||
// Copy of tg.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow
|
||||
type Input struct {
|
||||
// One of two salts used by the derivation function (see SRP 2FA login)
|
||||
Salt1 []byte
|
||||
// One of two salts used by the derivation function (see SRP 2FA login)
|
||||
Salt2 []byte
|
||||
// Base (see SRP 2FA login)
|
||||
G int
|
||||
// 2048-bit modulus (see SRP 2FA login)
|
||||
P []byte
|
||||
}
|
||||
|
||||
// Answer is result of SRP algorithm.
|
||||
type Answer struct {
|
||||
// A parameter (see SRP)
|
||||
A []byte
|
||||
// M1 parameter (see SRP)
|
||||
M1 []byte
|
||||
}
|
||||
|
||||
func xor32(a, b [sha256.Size]byte) (res [sha256.Size]byte) {
|
||||
xor.Bytes(res[:], a[:], b[:])
|
||||
return res
|
||||
}
|
||||
|
||||
func (s SRP) bigFromBytes(b []byte) *big.Int {
|
||||
return new(big.Int).SetBytes(b)
|
||||
}
|
||||
|
||||
func (s SRP) bigExp(x, y, m *big.Int) *big.Int {
|
||||
return new(big.Int).Exp(x, y, m)
|
||||
}
|
||||
|
||||
func checkInput(g int, p *big.Int) error {
|
||||
return crypto.CheckDH(g, p)
|
||||
}
|
||||
Reference in New Issue
Block a user