28 lines
696 B
Go
28 lines
696 B
Go
package faketls
|
|
|
|
import (
|
|
crand "crypto/rand"
|
|
|
|
"golang.org/x/crypto/curve25519"
|
|
)
|
|
|
|
// GenX25519PublicKey returns a valid X25519 public key (32 bytes) for the ClientHello key_share extension.
|
|
// Some MTProxy builds validate the point; a random quadratic residue mod P (older telethon-faketls trick) is rejected.
|
|
func GenX25519PublicKey() ([]byte, error) {
|
|
var priv, pub [32]byte
|
|
if _, err := crand.Read(priv[:]); err != nil {
|
|
return nil, err
|
|
}
|
|
curve25519.ScalarBaseMult(&pub, &priv)
|
|
return pub[:], nil
|
|
}
|
|
|
|
// Rand32 returns 32 random bytes (session id).
|
|
func Rand32() ([]byte, error) {
|
|
b := make([]byte, 32)
|
|
if _, err := crand.Read(b); err != nil {
|
|
return nil, err
|
|
}
|
|
return b, nil
|
|
}
|