Documentation ¶
Overview ¶
Package crypto implements cryptographical primitives for MTproto.
Reference:
Index ¶
- func CheckDHParams(dhPrime, g, gA, gB *big.Int) error
- func DataWithHash(data []byte, randomSource io.Reader) ([]byte, error)
- func DecomposePQ(pq *big.Int, randSource io.Reader) (p, q *big.Int, err error)
- func EncryptHashed(data []byte, key *rsa.PublicKey, randomSource io.Reader) ([]byte, error)
- func GuessDataWithHash(dataWithHash []byte) []byte
- func Keys(authKey AuthKey, msgKey bin.Int128, mode Side) (key, iv bin.Int256)
- func MessageKey(authKey AuthKey, plaintextPadded []byte, mode Side) bin.Int128
- func NewSessionID(reader io.Reader) (int64, error)
- func ParseRSAPublicKeys(data []byte) ([]*rsa.PublicKey, error)
- func RSAFingerprint(key *rsa.PublicKey) int64
- func RandInt128(randSource io.Reader) (bin.Int128, error)
- func RandInt256(randSource io.Reader) (bin.Int256, error)
- func RandInt64(randSource io.Reader) (int64, error)
- func TempAESKeys(newNonce, serverNonce *big.Int) (key, iv []byte)
- type AuthKey
- type EncryptedMessage
- type EncryptedMessageData
- type Side
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckDHParams ¶
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 DataWithHash ¶
DataWithHash prepends data with SHA1(data) and 0..15 random bytes so result length is divisible by 16.
Use GuessDataWithHash(result) to obtain data.
func DecomposePQ ¶
DecomposePQ decomposes pq into prime factors such that p < q.
func EncryptHashed ¶
EncryptHashed encrypts given data with RSA, prefixing with a hash.
func GuessDataWithHash ¶
GuessDataWithHash guesses data from data_with_hash.
func Keys ¶
Keys returns (aes_key, aes_iv) pair for AES-IGE.
Reference: * https://core.telegram.org/mtproto/description#defining-aes-key-and-initialization-vector
Example:
key, iv := crypto.Keys(authKey, messageKey, crypto.Client) cipher, err := aes.NewCipher(key[:]) if err != nil { return nil, err } encryptor := ige.NewIGEEncrypter(cipher, iv[:])
func MessageKey ¶
MessageKey computes message key for provided auth_key and padded payload.
func NewSessionID ¶
NewSessionID generates new random int64 from reader.
Use crypto/rand.Reader if session id should be cryptographically safe.
func ParseRSAPublicKeys ¶
ParseRSAPublicKeys parses data as list of PEM-encdoed public keys.
func RSAFingerprint ¶
RSAFingerprint returns fingerprint of RSA public key as defined in MTProto.
func RandInt128 ¶
RandInt128 generates and returns new random 128-bit integer.
Use crypto/rand.Reader as randSource in production.
func RandInt256 ¶
RandInt256 generates and returns new random 256-bit integer.
Use crypto/rand.Reader as randSource in production.
func TempAESKeys ¶
TempAESKeys returns tmp_aes_key and tmp_aes_iv based on new_nonce and server_nonce as defined in "Creating an Authorization Key".
Types ¶
type EncryptedMessage ¶
EncryptedMessage of protocol.
type EncryptedMessageData ¶
type EncryptedMessageData struct { Salt int64 SessionID int64 MessageID int64 SeqNo int32 MessageDataLen int32 MessageDataWithPadding []byte }
EncryptedMessageData is stored in EncryptedMessage.EncryptedData.