Esempio n. 1
0
func BigAbsCmp(x, y big.Int) int {
	// SetBits sets to |v|, thus giving an absolute comparison.
	var x0, y0 big.Int
	x0.SetBits(x.Bits())
	y0.SetBits(y.Bits())
	return x0.Cmp(&y0)
}
Esempio n. 2
0
func scalar2big(out *big.Int, in *[4]C.ulonglong) {
	bits := make([]big.Word, 4)
	for i := range bits {
		bits[i] = big.Word(in[i])
	}
	out.SetBits(bits)
}
Esempio n. 3
0
func scalar2big(out *big.Int, in *[4]C.ulonglong) {
	bits := make([]big.Word, 8)
	for i := 0; i < len(bits); i += 2 {
		bits[i] = big.Word(in[i>>1] & 0x00000000ffffffff)
		bits[i+1] = big.Word((in[i>>1] & 0xffffffff00000000) >> 32)
	}
	out.SetBits(bits)
}
Esempio n. 4
0
File: flag.go Progetto: jloup/utils
// Initialize a Flag that will Intersect with all flags with a value up to (length -1)
func NewBigInt(length int) Flag {
	n := (length + _WORDSIZE - 1) / _WORDSIZE

	wordTable := make([]big.Word, 0)
	for i := 0; i < n; i++ {
		wordTable = append(wordTable, _word1)
	}

	b := big.Int{}
	b.SetBits(wordTable)

	return Flag{N: b}
}
Esempio n. 5
0
func (z fermat) Mul(x, y fermat) fermat {
	n := len(x) - 1
	if n < 30 {
		z = z[:2*n+2]
		basicMul(z, x, y)
		z = z[:2*n+1]
	} else {
		var xi, yi, zi big.Int
		xi.SetBits(x)
		yi.SetBits(y)
		zi.SetBits(z)
		zb := zi.Mul(&xi, &yi).Bits()
		if len(zb) <= n {
			// Short product.
			copy(z, zb)
			for i := len(zb); i < len(z); i++ {
				z[i] = 0
			}
			return z
		}
		z = zb
	}
	// len(z) is at most 2n+1.
	if len(z) > 2*n+1 {
		panic("len(z) > 2n+1")
	}
	i := len(z) - (n + 1) // i <= n
	c := subVV(z[1:i+1], z[1:i+1], z[n+1:])
	z = z[:n+1]
	z[n]++ // Add -1.
	subVW(z[i+1:], z[i+1:], c)
	// Add 1.
	if z[n] == 1 {
		z[n] = 0
	} else {
		addVW(z, z, 1)
	}
	z.norm()
	return z
}
Esempio n. 6
0
// PreallocInt preallocates 128-bits of storage for an existing
// big.Int value. Will not perform the pre-allocation if the given
// pointer is nil, or if the storage has already been allocated.
//
// This function serves very little purpose as it provides no benefits
// whatsoever, and is only included for completeness.
func PreallocInt(i *big.Int) {
	var mem [pS]big.Word
	if i != nil && cap(i.Bits()) == 0 {
		i.SetBits(mem[0:0])
	}
}