| 272 | } |
| 273 | |
| 274 | func TestS256(t *testing.T) { |
| 275 | tests := []struct{ x, y *big.Int }{ |
| 276 | {x: big.NewInt(0), y: big.NewInt(0)}, |
| 277 | {x: big.NewInt(1), y: big.NewInt(1)}, |
| 278 | {x: big.NewInt(2), y: big.NewInt(2)}, |
| 279 | { |
| 280 | x: new(big.Int).Sub(BigPow(2, 255), big.NewInt(1)), |
| 281 | y: new(big.Int).Sub(BigPow(2, 255), big.NewInt(1)), |
| 282 | }, |
| 283 | { |
| 284 | x: BigPow(2, 255), |
| 285 | y: new(big.Int).Neg(BigPow(2, 255)), |
| 286 | }, |
| 287 | { |
| 288 | x: new(big.Int).Sub(BigPow(2, 256), big.NewInt(1)), |
| 289 | y: big.NewInt(-1), |
| 290 | }, |
| 291 | { |
| 292 | x: new(big.Int).Sub(BigPow(2, 256), big.NewInt(2)), |
| 293 | y: big.NewInt(-2), |
| 294 | }, |
| 295 | } |
| 296 | for _, test := range tests { |
| 297 | if y := S256(test.x); y.Cmp(test.y) != 0 { |
| 298 | t.Errorf("S256(%x) = %x, want %x", test.x, y, test.y) |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | func TestExp(t *testing.T) { |
| 304 | tests := []struct{ base, exponent, result *big.Int }{ |