handshake

package
v2.0.0-rc.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Registry = NewRegistry()

Functions

func CheckDH

func CheckDH(g, p *big.Int) error

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 CheckDHParams

func CheckDHParams(dhPrime, g, gA, gB *big.Int) error

CheckDHParams checks that g_a, g_b and g params meet key exchange conditions.

https://core.telegram.org/mtproto/auth_key#dh-key-exchange-complete

func CheckGP

func CheckGP(g, p *big.Int) error

CheckGP checks whether g generates a cyclic subgroup of prime order (p-1)/2, i.e. is a quadratic residue mod p. Also check that g is 2, 3, 4, 5, 6 or 7.

This function is needed by some Telegram algorithms(Key generation, SRP 2FA).

See https://core.telegram.org/mtproto/auth_key.

See https://core.telegram.org/api/srp.

func DataWithHash

func DataWithHash(data []byte, rand io.Reader) []byte

func DecodeRSAPad

func DecodeRSAPad(data []byte, key *rsa.PrivateKey) ([]byte, error)

DecodeRSAPad implements server-side decoder of RSAPad.

func DecomposePQ

func DecomposePQ(pq uint64, rand io.Reader) (p, q uint64)

DecomposePQ decomposes pq into prime factors such that p < q.

func FillBytes

func FillBytes(b *big.Int, to []byte) bool

FillBytes is safe version of (*big.Int).FillBytes. Returns false if to length is not exact equal to big.Int's. Otherwise fills to using b and returns true.

func GuessDataWithHash

func GuessDataWithHash(dataWithHash []byte) []byte

guessDataWithHash guesses data from data_with_hash.

func InRange

func InRange(x, min, max *big.Int) bool

InRange checks whether x is in (min, max) range, i.e. min < x < max.

func MakeGAB

func MakeGAB(rand io.Reader, g, gA, dh *big.Int) (gB, b *big.Int, err error)

func NewRegistry

func NewRegistry() *tl.ObjectRegistry

func Perform

func Perform(ctx context.Context, conn mode.Mode, keys []*rsa.PublicKey, dc int, expiration time.Duration) ([256]byte, uint64, error)

`expiration` param defines how long session will be stored on server side. This value guarantees *at most** this duration, but not exactly. or even more. According to the documentation, "The server is free to discard its copy earlier". Zero value means permanent session, so if keys will leak, someone might use them to use authorized session.

func Prime

func Prime(p *big.Int) bool

Prime checks that given number is prime.

func RSAPad

func RSAPad(data []byte, key *rsa.PublicKey, randomSource io.Reader) ([]byte, error)

RSAPad encrypts given data with RSA, prefixing with a hash.

See https://core.telegram.org/mtproto/auth_key#presenting-proof-of-work-server-authentication.

func ServerSalt

func ServerSalt(newNonce Int256, serverNonce Int128) (salt uint64)

Types

type ClientDHInnerData

type ClientDHInnerData struct {
	Nonce       Int128
	ServerNonce Int128
	Retry       int64
	GB          []byte
}

func (*ClientDHInnerData) CRC

func (*ClientDHInnerData) CRC() uint32

type DHGenFail

type DHGenFail struct {
	Nonce        Int128
	ServerNonce  Int128
	NewNonceHash Int128
}

func (*DHGenFail) CRC

func (*DHGenFail) CRC() uint32

type DHGenOk

type DHGenOk struct {
	Nonce        Int128
	ServerNonce  Int128
	NewNonceHash Int128
}

func (*DHGenOk) CRC

func (*DHGenOk) CRC() uint32

type DHGenRetry

type DHGenRetry struct {
	Nonce        Int128
	ServerNonce  Int128
	NewNonceHash Int128
}

func (*DHGenRetry) CRC

func (*DHGenRetry) CRC() uint32

type Int128

type Int128 = [16]byte

type Int256

type Int256 = [32]byte

func TempAESKeys

func TempAESKeys(newNonce Int256, serverNonce Int128) (key, iv Int256)

tempAESKeys returns tmp_aes_key and tmp_aes_iv based on new_nonce and server_nonce as defined in "Creating an Authorization Key".

See https://core.telegram.org/mtproto/auth_key#6-server-responds-with

tmp_aes_key := SHA1(new_nonce + server_nonce) + substr (SHA1(server_nonce + new_nonce), 0, 12);

type PQInnerData

type PQInnerData interface {
	tl.Object
	// contains filtered or unexported methods
}

type PQInnerDataDC

type PQInnerDataDC struct {
	Pq          []byte
	P           []byte
	Q           []byte
	Nonce       Int128
	ServerNonce Int128
	NewNonce    Int256
	DC          int32
}

func (*PQInnerDataDC) CRC

func (*PQInnerDataDC) CRC() uint32

type PQInnerDataObj

type PQInnerDataObj struct {
	Pq          []byte
	P           []byte
	Q           []byte
	Nonce       Int128
	ServerNonce Int128
	NewNonce    Int256
}

func (*PQInnerDataObj) CRC

func (*PQInnerDataObj) CRC() uint32

type PQInnerDataTempDC

type PQInnerDataTempDC struct {
	Pq          []byte
	P           []byte
	Q           []byte
	Nonce       Int128
	ServerNonce Int128
	NewNonce    Int256
	DC          int32
	ExpiresIn   int32
}

func (*PQInnerDataTempDC) CRC

func (*PQInnerDataTempDC) CRC() uint32

type ReqDHParamsParams

type ReqDHParamsParams struct {
	Nonce                Int128
	ServerNonce          Int128
	P                    []byte
	Q                    []byte
	PublicKeyFingerprint uint64
	EncryptedData        []byte
}

func (*ReqDHParamsParams) CRC

func (*ReqDHParamsParams) CRC() uint32

type ReqPQMultiParams

type ReqPQMultiParams struct {
	Nonce Int128
}

func (*ReqPQMultiParams) CRC

func (*ReqPQMultiParams) CRC() uint32

type ResPQ

type ResPQ struct {
	Nonce        Int128
	ServerNonce  Int128
	Pq           []byte
	Fingerprints []uint64
}

func (*ResPQ) CRC

func (*ResPQ) CRC() uint32

type ServerDHInnerData

type ServerDHInnerData struct {
	Nonce       Int128
	ServerNonce Int128
	G           int32
	DhPrime     []byte
	GA          []byte
	ServerTime  int32
}

func (*ServerDHInnerData) CRC

func (*ServerDHInnerData) CRC() uint32

type ServerDHParamsOk

type ServerDHParamsOk struct {
	Nonce           Int128
	ServerNonce     Int128
	EncryptedAnswer []byte
}

func (*ServerDHParamsOk) CRC

func (*ServerDHParamsOk) CRC() uint32

type SetClientDHParamsAnswer

type SetClientDHParamsAnswer interface {
	tl.Object
	// contains filtered or unexported methods
}

type SetClientDHParamsParams

type SetClientDHParamsParams struct {
	Nonce         Int128
	ServerNonce   Int128
	EncryptedData []byte
}

func (*SetClientDHParamsParams) CRC

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL