Moved the To256

This commit is contained in:
obscuren
2014-10-08 16:11:36 +02:00
parent bd7aca76e1
commit a38dafcc57
2 changed files with 37 additions and 29 deletions

View File

@ -34,6 +34,19 @@ func BigD(data []byte) *big.Int {
return n
}
// To256
//
// "cast" the big int to a 256 big int (i.e., limit to)
var tt256 = new(big.Int).Sub(new(big.Int).Lsh(big.NewInt(1), 256), big.NewInt(1))
func To256(x *big.Int) {
x.And(x, tt256)
if x.Cmp(new(big.Int)) < 0 {
x.SetInt64(0)
}
}
// Big to bytes
//
// Returns the bytes of a big integer with the size specified by **base**