Example #1
0
func main() {
	// Generate pseudorandom bytes using Dual_EC_DRBG on NIST Curve-256.
	// NB: Never, ever use this generator. It is ridiculously slow, demonstrates bias
	// and for the provided values of Q is backdoored by the NSA.

	// The seed s is the value of S *after* seeding the OpenSSL implementation.
	// Any integer on the order of 2^256 will suffice.
	// @TODO: Have compatible seeding routines with OpenSSL.
	s := ec.NewBigInt("14611F02F7F34E6121433EFB0D71ECAC38F28BE4274B3DD784D2C1D4BE78DF89", 16)

	curve := ec.NewP256Curve()
	g := pnc.NewDualECDRBG(
		curve,
		ec.NewBigInt(dual_ec_drbg_curve_p256_qx, 16),
		ec.NewBigInt(dual_ec_drbg_curve_p256_qy, 16),
		s)

	for i := 0; i < 10; i++ {
		fmt.Printf("%x", g.Bytes(600))
	}
	fmt.Println()
}
Example #2
0
File: mul.go Project: 46bit/pnc
func main() {
	curve := ec.NewP256Curve()

	p := curve.G.Copy()

	t := big.NewInt(0)
	t.SetString("05ABA71EB402603B7D24D9F921E49433A69AB3DB2D5A9910FF040FA906207587", 16)

	// ----------------

	fmt.Println("Before:")
	p.Print()

	r := curve.ScalarMultiply(t, p)

	fmt.Println("After:")
	r.Print()

	fmt.Printf("Expected:\n- x = %X\n- y = %X\n- on curve: %t\n",
		ec.NewBigInt("7FDA41915769256A2D8F968BC9897849FC44C5CA64CF03E576EAF95E5FF9A799", 16),
		ec.NewBigInt("D7E013E76E4CEDCEB49F8C267164954F0D57C3FD077B0A81DF4DDA5AF4D5868D", 16),
		true)
}
Example #3
0
File: curve.go Project: 46bit/pnc
func main() {
	curve := ec.NewPrimeCurve(
		ec.NewBigInt(curve_p256_p, 10),
		ec.NewBigInt(curve_p256_a, 10),
		ec.NewBigInt(curve_p256_b, 16),
		ec.NewBigInt(curve_p256_gx, 16),
		ec.NewBigInt(curve_p256_gy, 16),
		ec.NewBigInt(curve_p256_n, 10),
		ec.NewBigInt(curve_p256_h, 10))

	p := curve.G.Copy()
	fmt.Println("Before:")
	p.Print()
	r := curve.Add(p, p)
	fmt.Println("After:")
	r.Print()
}