main.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. fmt.Printf("ell = %d\n", ell)
  42. var privkey kyber.Scalar
  43. var i uint32
  44. for i = 0; i < N32; i++ {
  45. if i == ell {
  46. privkey = group.Scalar().Pick(rand)
  47. Cs[i] = group.Point().Mul(privkey, params.B)
  48. } else {
  49. Cs[i] = group.Point().Pick(rand)
  50. }
  51. }
  52. pub, priv := ProofStep1(params, Cs, ell, privkey)
  53. x := GenChallenge(params, pub)
  54. proof := ProofStep2(params, priv, x)
  55. if Verify(params, Cs, pub, x, proof) {
  56. fmt.Printf("SUCCESS\n")
  57. } else {
  58. fmt.Printf("VERIFICATION FAILED\n")
  59. }
  60. }