plaintext-exponent-equality-proof-data.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 = PlaintextExponentEqualityProofTestData;
  13. /**
  14. * Provides the data needed by the plaintext exponent equality zero-knowledge
  15. * proof of knowledge unit tests.
  16. */
  17. function PlaintextExponentEqualityProofTestData() {
  18. var NUM_BASE_ELEMENTS = 5;
  19. var PLAINTEXT_EXPONENT_EQUALITY_PROOF_STRING_DATA =
  20. 'Test Plaintext Exponent Equality Proof Auxilary Data';
  21. var OTHER_PLAINTEXT_EXPONENT_EQUALITY_PROOF_STRING_DATA =
  22. PLAINTEXT_EXPONENT_EQUALITY_PROOF_STRING_DATA + '0';
  23. var NUM_PLAINTEXT_EXPONENT_EQUALITY_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 firstSecret_ = mathRandomGenerator.nextExponent(group_);
  29. var secondSecret_ = mathRandomGenerator.nextExponent(group_);
  30. var anotherFirstSecret_;
  31. do {
  32. anotherFirstSecret_ = mathRandomGenerator.nextExponent(group_);
  33. } while (anotherFirstSecret_.value.equals(firstSecret_.value));
  34. var anotherSecondSecret_;
  35. do {
  36. anotherSecondSecret_ = mathRandomGenerator.nextExponent(group_);
  37. } while (anotherSecondSecret_.value.equals(secondSecret_.value));
  38. var firstSecretFromAnotherGroup_ =
  39. mathRandomGenerator.nextExponent(anotherGroup_);
  40. var secondSecretFromAnotherGroup_ =
  41. mathRandomGenerator.nextExponent(anotherGroup_);
  42. var baseElements_ =
  43. commonTestData.generateRandomGroupElements(group_, NUM_BASE_ELEMENTS);
  44. var otherBaseElements_;
  45. do {
  46. otherBaseElements_ =
  47. commonTestData.generateRandomGroupElements(group_, NUM_BASE_ELEMENTS);
  48. } while (otherBaseElements_.equals(baseElements_));
  49. var lessBaseElements_ = commonTestData.generateRandomGroupElements(
  50. group_, (NUM_BASE_ELEMENTS - 2));
  51. var baseElementsFromAnotherGroup_ =
  52. commonTestData.generateRandomGroupElements(
  53. anotherGroup_, NUM_BASE_ELEMENTS);
  54. var ciphertext_ =
  55. commonTestData.generatePlaintextExponentEqualityProofCiphertext(
  56. baseElements_, firstSecret_, secondSecret_);
  57. var anotherCiphertext_ =
  58. commonTestData.generatePlaintextExponentEqualityProofCiphertext(
  59. otherBaseElements_, firstSecret_, secondSecret_);
  60. var ciphertextWithLessElements_ =
  61. commonTestData.generatePlaintextExponentEqualityProofCiphertext(
  62. lessBaseElements_, firstSecret_, secondSecret_);
  63. var ciphertextFromAnotherGroup_ =
  64. commonTestData.generatePlaintextExponentEqualityProofCiphertext(
  65. baseElementsFromAnotherGroup_, firstSecretFromAnotherGroup_,
  66. secondSecretFromAnotherGroup_);
  67. this.getGroup = function() {
  68. return group_;
  69. };
  70. this.getAnotherGroup = function() {
  71. return anotherGroup_;
  72. };
  73. this.getFirstSecret = function() {
  74. return firstSecret_;
  75. };
  76. this.getSecondSecret = function() {
  77. return secondSecret_;
  78. };
  79. this.getAnotherFirstSecret = function() {
  80. return anotherFirstSecret_;
  81. };
  82. this.getAnotherSecondSecret = function() {
  83. return anotherSecondSecret_;
  84. };
  85. this.getFirstSecretFromAnotherGroup = function() {
  86. return firstSecretFromAnotherGroup_;
  87. };
  88. this.getSecondSecretFromAnotherGroup = function() {
  89. return secondSecretFromAnotherGroup_;
  90. };
  91. this.getBaseElements = function() {
  92. return baseElements_;
  93. };
  94. this.getOtherBaseElements = function() {
  95. return otherBaseElements_;
  96. };
  97. this.getLessBaseElements = function() {
  98. return lessBaseElements_;
  99. };
  100. this.getBaseElementsFromAnotherGroup = function() {
  101. return baseElementsFromAnotherGroup_;
  102. };
  103. this.getCiphertext = function() {
  104. return ciphertext_;
  105. };
  106. this.getAnotherCiphertext = function() {
  107. return anotherCiphertext_;
  108. };
  109. this.getCiphertextWithLessElements = function() {
  110. return ciphertextWithLessElements_;
  111. };
  112. this.getCiphertextFromAnotherGroup = function() {
  113. return ciphertextFromAnotherGroup_;
  114. };
  115. this.getStringData = function() {
  116. return PLAINTEXT_EXPONENT_EQUALITY_PROOF_STRING_DATA;
  117. };
  118. this.getOtherStringData = function() {
  119. return OTHER_PLAINTEXT_EXPONENT_EQUALITY_PROOF_STRING_DATA;
  120. };
  121. this.getNumProgressChecks = function() {
  122. return NUM_PLAINTEXT_EXPONENT_EQUALITY_PROOF_PROGRESS_CHECKS;
  123. };
  124. }