Example #1
0
func newCurve(nid C.int) *C.EC_GROUP {
	if !availableCurves[nid] {
		return nil
	}
	curve := C.EC_GROUP_new_by_curve_name(nid)
	if curve == nil {
		panic("problem creating ec: " + sslerr.SSLErrorMessage().String())
	}
	return curve
}
Example #2
0
func (c *curve) initNamedCurve(name string, nid C.int) *curve {
	c.name = name

	c.ctx = C.BN_CTX_new()
	if c.ctx == nil {
		panic("C.BN_CTX_new: " + getErrString())
	}

	c.g = C.EC_GROUP_new_by_curve_name(nid)
	if c.g == nil {
		panic("can't find create P256 curve: " + getErrString())
	}

	// Get this curve's prime field
	c.p = newBigNum()
	if C.EC_GROUP_get_curve_GFp(c.g, c.p.bn, nil, nil, c.ctx) == 0 {
		panic("EC_GROUP_get_curve_GFp: " + getErrString())
	}
	c.plen = (c.p.BitLen() + 7) / 8

	// Get the curve's group order
	c.n = newBigNum()
	if C.EC_GROUP_get_order(c.g, c.n.bn, c.ctx) == 0 {
		panic("EC_GROUP_get_order: " + getErrString())
	}
	c.nlen = (c.n.BitLen() + 7) / 8

	// Get the curve's cofactor
	c.cofact = newBigNum()
	if C.EC_GROUP_get_cofactor(c.g, c.cofact.bn, c.ctx) == 0 {
		panic("EC_GROUP_get_cofactor: " + getErrString())
	}

	// Stash a copy of the point at infinity
	c.null = newPoint(c)
	c.null.Null()

	return c
}