Exemple #1
0
func (curve CurveParams) IsOnCurve(x, y *big.Int) bool {
	bnx := C.BN_new()
	if bnx == nil {
		return false
	}
	defer C.BN_free(bnx)
	bny := C.BN_new()
	if bny == nil {
		return false
	}
	defer C.BN_free(bny)

	xs := C.CString(x.String())
	defer C.free(unsafe.Pointer(xs))
	if C.BN_hex2bn(&bnx, xs) == 0 {
		return false
	}
	ys := C.CString(y.String())
	defer C.free(unsafe.Pointer(ys))
	if C.BN_hex2bn(&bny, ys) == 0 {
		return false
	}

	point := C.EC_POINT_new(curve.curve)
	if point == nil {
		return false
	}
	defer C.EC_POINT_free(point)

	if C.EC_POINT_set_affine_coordinates_GFp(curve.curve, point, bnx, bny, nil) != 1 {
		return false
	}
	if C.EC_POINT_is_on_curve(curve.curve, point, nil) == 0 {
		return false
	}
	return true
}
Exemple #2
0
func (p *point) Valid() bool {
	return C.EC_POINT_is_on_curve(p.g, p.p, p.c.ctx) != 0
}