exponentiation-proof-data.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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 = ExponentiationProofTestData;
  13. /**
  14. * Provides the data needed by the exponentiation zero-knowledge proof of
  15. * knowledge unit tests.
  16. */
  17. function ExponentiationProofTestData() {
  18. var NUM_BASE_ELEMENTS = 3;
  19. var EXPONENTIATION_PROOF_STRING_DATA =
  20. 'Test Exponentation Proof Auxilary Data';
  21. var OTHER_EXPONENTIATION_PROOF_STRING_DATA =
  22. EXPONENTIATION_PROOF_STRING_DATA + '0';
  23. var NUM_EXPONENTIATION_PROOF_PROGRESS_CHECKS = NUM_BASE_ELEMENTS;
  24. var mathRandomGenerator = mathematical.newService().newRandomGenerator();
  25. var commonTestData = new CommonTestData();
  26. var group_ = commonTestData.getGroup();
  27. var anotherGroup_ = commonTestData.getAnotherGroup();
  28. var secret_ = mathRandomGenerator.nextExponent(group_);
  29. var anotherSecret_;
  30. do {
  31. anotherSecret_ = mathRandomGenerator.nextExponent(group_);
  32. } while (anotherSecret_.value.equals(secret_.value));
  33. var secretFromAnotherGroup_ = mathRandomGenerator.nextExponent(anotherGroup_);
  34. var baseElements_ =
  35. commonTestData.generateRandomGroupElements(group_, NUM_BASE_ELEMENTS);
  36. var otherBaseElements_;
  37. do {
  38. otherBaseElements_ =
  39. commonTestData.generateRandomGroupElements(group_, NUM_BASE_ELEMENTS);
  40. } while (otherBaseElements_.equals(baseElements_));
  41. var lessBaseElements_ = baseElements_.slice(1);
  42. var baseElementsFromAnotherGroup_ =
  43. commonTestData.generateRandomGroupElements(
  44. anotherGroup_, NUM_BASE_ELEMENTS);
  45. var exponentiatedElements_ =
  46. commonTestData.exponentiateElements(baseElements_, secret_);
  47. var otherExponentiatedElements_ =
  48. commonTestData.exponentiateElements(baseElements_, anotherSecret_);
  49. var tooManyBaseElements =
  50. commonTestData.generateRandomGroupElements(group_, NUM_BASE_ELEMENTS + 1);
  51. var tooManyExponentiatedElements_ =
  52. commonTestData.exponentiateElements(tooManyBaseElements, secret_);
  53. var exponentiatedElementsFromAnotherGroup_ =
  54. commonTestData.exponentiateElements(
  55. baseElementsFromAnotherGroup_, secretFromAnotherGroup_);
  56. this.getGroup = function() {
  57. return group_;
  58. };
  59. this.getAnotherGroup = function() {
  60. return anotherGroup_;
  61. };
  62. this.getSecret = function() {
  63. return secret_;
  64. };
  65. this.getAnotherSecret = function() {
  66. return anotherSecret_;
  67. };
  68. this.getSecretFromAnotherGroup = function() {
  69. return secretFromAnotherGroup_;
  70. };
  71. this.getBaseElements = function() {
  72. return baseElements_;
  73. };
  74. this.getOtherBaseElements = function() {
  75. return otherBaseElements_;
  76. };
  77. this.getLessBaseElements = function() {
  78. return lessBaseElements_;
  79. };
  80. this.getBaseElementsFromAnotherGroup = function() {
  81. return baseElementsFromAnotherGroup_;
  82. };
  83. this.getExponentiatedElements = function() {
  84. return exponentiatedElements_;
  85. };
  86. this.getOtherExponentiatedElements = function() {
  87. return otherExponentiatedElements_;
  88. };
  89. this.getTooManyExponentiatedElements = function() {
  90. return tooManyExponentiatedElements_;
  91. };
  92. this.getExponentiatedElementsFromAnotherGroup = function() {
  93. return exponentiatedElementsFromAnotherGroup_;
  94. };
  95. this.getStringData = function() {
  96. return EXPONENTIATION_PROOF_STRING_DATA;
  97. };
  98. this.getOtherStringData = function() {
  99. return OTHER_EXPONENTIATION_PROOF_STRING_DATA;
  100. };
  101. this.getNumProgressChecks = function() {
  102. return NUM_EXPONENTIATION_PROOF_PROGRESS_CHECKS;
  103. };
  104. }