curve_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Copyright 2015 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package secp256k1
  17. import (
  18. "bytes"
  19. "encoding/hex"
  20. "math/big"
  21. "testing"
  22. )
  23. func TestReadBits(t *testing.T) {
  24. check := func(input string) {
  25. want, _ := hex.DecodeString(input)
  26. int, _ := new(big.Int).SetString(input, 16)
  27. buf := make([]byte, len(want))
  28. readBits(buf, int)
  29. if !bytes.Equal(buf, want) {
  30. t.Errorf("have: %x\nwant: %x", buf, want)
  31. }
  32. }
  33. check("000000000000000000000000000000000000000000000000000000FEFCF3F8F0")
  34. check("0000000000012345000000000000000000000000000000000000FEFCF3F8F0")
  35. check("18F8F8F1000111000110011100222004330052300000000000000000FEFCF3F8F0")
  36. }