2
0

schnorr-proof-data.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright 2018 Scytl Secure Electronic Voting SA
  3. *
  4. * All rights reserved
  5. *
  6. * See our extended copyright notice in *file 'Copyright.txt' which is part of this source code package
  7. */
  8. /* jshint node:true */
  9. 'use strict';
  10. var CommonTestData = require('./common-data');
  11. var mathematical = require('scytl-mathematical');
  12. module.exports = SchnorrProofTestData;
  13. /**
  14. * Provides the data needed by the Schnorr zero-knowledge proof of knowledge
  15. * unit tests.
  16. */
  17. function SchnorrProofTestData() {
  18. var SCHNORR_PROOF_STRING_DATA = 'Test Schnorr Proof Auxilary Data';
  19. var OTHER_SCHNORR_PROOF_STRING_DATA = SCHNORR_PROOF_STRING_DATA + '0';
  20. var VOTER_ID = '11111';
  21. var ELECTION_ID = '22222';
  22. var NUM_SCHNORR_PROOF_PROGRESS_CHECKS = 1;
  23. var mathRandomGenerator = mathematical.newService().newRandomGenerator();
  24. var commonTestData = new CommonTestData();
  25. var group_ = commonTestData.getGroup();
  26. var anotherGroup_ = commonTestData.getAnotherGroup();
  27. var secret_ = mathRandomGenerator.nextExponent(group_);
  28. var anotherSecret_;
  29. do {
  30. anotherSecret_ = mathRandomGenerator.nextExponent(group_);
  31. } while (anotherSecret_.value.equals(secret_.value));
  32. var secretFromAnotherGroup_ = mathRandomGenerator.nextExponent(anotherGroup_);
  33. var gamma_ = group_.generator.exponentiate(secret_);
  34. var gammaForAnotherSecret_ = group_.generator.exponentiate(anotherSecret_);
  35. var gammaFromAnotherGroup_ = anotherGroup_.generator.exponentiate(
  36. mathRandomGenerator.nextExponent(anotherGroup_));
  37. this.getGroup = function() {
  38. return group_;
  39. };
  40. this.getAnotherGroup = function() {
  41. return anotherGroup_;
  42. };
  43. this.getSecret = function() {
  44. return secret_;
  45. };
  46. this.getAnotherSecret = function() {
  47. return anotherSecret_;
  48. };
  49. this.getSecretFromAnotherGroup = function() {
  50. return secretFromAnotherGroup_;
  51. };
  52. this.getGamma = function() {
  53. return gamma_;
  54. };
  55. this.getGammaForAnotherSecret = function() {
  56. return gammaForAnotherSecret_;
  57. };
  58. this.getGammaFromAnotherGroup = function() {
  59. return gammaFromAnotherGroup_;
  60. };
  61. this.getStringData = function() {
  62. return SCHNORR_PROOF_STRING_DATA;
  63. };
  64. this.getOtherStringData = function() {
  65. return OTHER_SCHNORR_PROOF_STRING_DATA;
  66. };
  67. this.getVoterId = function() {
  68. return VOTER_ID;
  69. };
  70. this.getElectionId = function() {
  71. return ELECTION_ID;
  72. };
  73. this.getNumProgressChecks = function() {
  74. return NUM_SCHNORR_PROOF_PROGRESS_CHECKS;
  75. };
  76. }