main.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "strconv"
  6. "math/big"
  7. "go.dedis.ch/kyber"
  8. "go.dedis.ch/kyber/pairing/bn256"
  9. "go.dedis.ch/kyber/util/random"
  10. )
  11. func main() {
  12. /* Command-line arg is N, the number of commitments */
  13. var N int
  14. var err error
  15. if len(os.Args) > 1 {
  16. N, err = strconv.Atoi(os.Args[1])
  17. if err != nil {
  18. panic(err)
  19. }
  20. } else {
  21. N = 25
  22. }
  23. if (N < 2) {
  24. panic("N must be at least 2")
  25. }
  26. N32 := uint32(N)
  27. group := bn256.NewSuite().G1()
  28. rand := random.New()
  29. params := GroupParams {
  30. group,
  31. group.Point().Pick(rand),
  32. group.Point().Pick(rand),
  33. group.Point().Pick(rand),
  34. }
  35. // Create an array of commitments, one of which is a commitment
  36. // to 0
  37. Cs := make([]kyber.Point, N32)
  38. // Which one do we know? Pick a random 0 <= ell < N
  39. Nbig := big.NewInt(int64(N))
  40. ell := uint32(random.Int(Nbig, rand).Int64())
  41. var privkey kyber.Scalar
  42. var i uint32
  43. for i = 0; i < N32; i++ {
  44. if i == ell {
  45. privkey = group.Scalar().Pick(rand)
  46. Cs[i] = group.Point().Mul(privkey, params.B)
  47. } else {
  48. Cs[i] = group.Point().Pick(rand)
  49. }
  50. }
  51. pub, priv := ProofStep1(params, Cs, ell, privkey)
  52. x := GenChallenge(params, pub)
  53. proof := ProofStep2(params, priv, x)
  54. if Verify(params, pub, x, proof) {
  55. fmt.Printf("SUCCESS\n")
  56. } else {
  57. fmt.Printf("VERIFICATION FAILED\n")
  58. }
  59. }