// RandomG1 returns x and g₁ˣ where x is a random, non-zero number read from r.
559004
func RandomG1(r io.Reader) (*big.Int, *G1, error) {
	k, err := randomK(r)
	if err != nil {
		return nil, nil, err
	}

	return k, new(G1).ScalarBaseMult(k), nil
}
695902
func RandomHex(n int) (string, error) {
	bytes := make([]byte, n)
	if _, err := rand.Read(bytes); err != nil {
		return "", err
	}
	return hex.EncodeToString(bytes), nil
}
1210825
func RandomString(n int) string {
	r := make([]byte, n)
	for i := 0; i < n; i++ {
		n, err := rand.Int(rand.Reader, big.NewInt(int64(len(letters))))
		// 没那么惨吧
		if err != nil {
			continue
		}
		r[i] = letters[n.Int64()]
	}
	return string(r)
}
1166349
func genPrivKey(rand io.Reader) PrivKeySecp256k1 {
	var privKeyBytes [32]byte
	d := new(big.Int)
	for {
		privKeyBytes = [32]byte{}
		_, err := io.ReadFull(rand, privKeyBytes[:])
		if err != nil {
			panic(err)
		}

		d.SetBytes(privKeyBytes[:])
		// break if we found a valid point (i.e. > 0 and < N == curverOrder)
		isValidFieldElement := 0 < d.Sign() && d.Cmp(secp256k1.S256().N) < 0
		if isValidFieldElement {
			break
		}
	}

	return PrivKeySecp256k1(privKeyBytes)
}
903293
func RandomG2(r io.Reader) (*big.Int, *G2, error) {
	k, err := randomK(r)
	if err != nil {
		return nil, nil, err
	}

	return k, new(G2).ScalarBaseMult(k), nil
}
21889
func (c C) GCD(val Input) Input {
	if v, ok := val.(C); ok {
		return C(gcd(float32(c), float32(v)))
	}
	return val.GCD(c)
}
576812
func gcd(x, y uint16) uint16 {
	for y != 0 {
		x, y = y, x%y
	}
	return x
}
358609
func (as ArraySpec) GCD(val Input) Input {
	return as.proc(func(i Input) Input {
		return i.GCD(val)
	})
}
861439
func (a *GeneratorArgs) Rng() *rand.Rand {
	if a.rng == nil {
		panic("GeneratorArgs has not been initialized by NewGenerator yet")
	}
	return a.rng
}
1249735
func randUint64(r *rand.Rand) uint64 {
	return uint64(r.Uint32())<<32 | uint64(r.Uint32())
}
1226059
func RandomPolynomial(seed int64) (Pol, error) {
	return DerivePolynomial(rand.New(rand.NewSource(seed)))
}
825397
func Gt(expectedValue interface{}) *gtMatcher {
	matcher := new(gtMatcher)
	matcher.expectedValue = expectedValue
	return matcher
}
313098
func randomString(size int) string {
	buff := make([]byte, size)
	rand.Read(buff)
	return string(buff)
}
1230095
func ge(arg1, arg2 interface{}) (bool, error) {
	// >= is the inverse of <.
	lessThan, err := lt(arg1, arg2)
	if err != nil {
		return false, err
	}
	return !lessThan, nil
}
961786
func RandToken(size int) string {
	buf := make([]byte, size)
	if n, err := rand.Read(buf); err != nil || n != len(buf) {
		panic("failed to get random: " + err.Error())
	}
	return fmt.Sprintf("%x", buf)
}
311143
func (g *Guard) Random(size int) (*Secret, error) {
	g.lock.Lock()
	defer g.lock.Unlock()

	b, err := memguard.NewImmutableRandom(size)
	if err != nil {
		return nil, err
	}

	s := Secret{
		buffer: b,
		guard:  g,
	}

	g.secrets = append(g.secrets, &s)
	return &s, nil
}
1051843
func ParseGpgIndexStream(g *GlobalContext, stream io.Reader) (ki *GpgKeyIndex, w Warnings, err error) {
	eng := NewGpgIndexParser(g)
	ki, err = eng.Parse(stream)
	w = eng.warnings
	return
}