or-proof-data.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 elGamal = require('scytl-elgamal');
  12. module.exports = OrProofTestData;
  13. /**
  14. * Provides the data needed by the OR zero-knowledge proof of knowledge unit
  15. * tests.
  16. */
  17. function OrProofTestData() {
  18. var NUM_OR_ELEMENTS = 5;
  19. var OR_PROOF_STRING_DATA = 'Test OR Proof Auxilary Data';
  20. var OTHER_OR_PROOF_STRING_DATA = OR_PROOF_STRING_DATA + '0';
  21. var NUM_OR_PROOF_PROGRESS_CHECKS = NUM_OR_ELEMENTS * 2;
  22. var elGamalEncrypter = elGamal.newService().newEncrypter();
  23. var commonTestData = new CommonTestData();
  24. var group_ = commonTestData.getGroup();
  25. var anotherGroup_ = commonTestData.getAnotherGroup();
  26. var publicKey_ = commonTestData.generateKeyPair(group_, 1).publicKey;
  27. var anotherPublicKey_;
  28. do {
  29. anotherPublicKey_ = commonTestData.generateKeyPair(group_, 1).publicKey;
  30. } while (anotherPublicKey_.elements.equals(publicKey_.elements));
  31. var publicKeyWithTooManyElements_ =
  32. commonTestData.generateKeyPair(group_, 2).publicKey;
  33. var publicKeyFromAnotherGroup_ =
  34. commonTestData.generateKeyPair(anotherGroup_, 1).publicKey;
  35. var index_ = commonTestData.generateRandomInteger(0, (NUM_OR_ELEMENTS - 1));
  36. var tooSmallIndex_ = -1;
  37. var tooLargeIndex_ = NUM_OR_ELEMENTS;
  38. var elements_ =
  39. commonTestData.generateRandomGroupElements(group_, NUM_OR_ELEMENTS);
  40. var elementsWithDifferentIndexElement_;
  41. do {
  42. elementsWithDifferentIndexElement_ =
  43. commonTestData.generateRandomGroupElements(group_, NUM_OR_ELEMENTS);
  44. } while (
  45. elementsWithDifferentIndexElement_[index_].equals(elements_[index_]));
  46. var tooFewElements_ = commonTestData.generateRandomGroupElements(group_, 1);
  47. var elementsFromAnotherGroup_ = commonTestData.generateRandomGroupElements(
  48. anotherGroup_, NUM_OR_ELEMENTS);
  49. var encryptedElements_ =
  50. elGamalEncrypter.init(publicKey_).encrypt([elements_[index_]], {
  51. saveSecret: true
  52. });
  53. var otherencryptedElements_ =
  54. elGamalEncrypter.init(anotherPublicKey_).encrypt([elements_[index_]], {
  55. saveSecret: true
  56. });
  57. var encryptedElementsWithTooManyElements_ =
  58. elGamalEncrypter.init(publicKeyWithTooManyElements_)
  59. .encrypt([elements_[0], elements_[1]], {saveSecret: true});
  60. var encryptedElementsFromAnotherGroup_ =
  61. elGamalEncrypter.init(publicKeyFromAnotherGroup_)
  62. .encrypt([elementsFromAnotherGroup_[index_]], {saveSecret: true});
  63. this.getGroup = function() {
  64. return group_;
  65. };
  66. this.getAnotherGroup = function() {
  67. return anotherGroup_;
  68. };
  69. this.getPublicKey = function() {
  70. return publicKey_;
  71. };
  72. this.getAnotherPublicKey = function() {
  73. return anotherPublicKey_;
  74. };
  75. this.getPublicKeyWithTooManyElements = function() {
  76. return publicKeyWithTooManyElements_;
  77. };
  78. this.getPublicKeyFromAnotherGroup = function() {
  79. return publicKeyFromAnotherGroup_;
  80. };
  81. this.getIndex = function() {
  82. return index_;
  83. };
  84. this.getTooSmallIndex = function() {
  85. return tooSmallIndex_;
  86. };
  87. this.getTooLargeIndex = function() {
  88. return tooLargeIndex_;
  89. };
  90. this.getNumElements = function() {
  91. return NUM_OR_ELEMENTS;
  92. };
  93. this.getElements = function() {
  94. return elements_;
  95. };
  96. this.getElementsWithDifferentIndexElement = function() {
  97. return elementsWithDifferentIndexElement_;
  98. };
  99. this.getTooFewElements = function() {
  100. return tooFewElements_;
  101. };
  102. this.getElementsFromAnotherGroup = function() {
  103. return elementsFromAnotherGroup_;
  104. };
  105. this.getEncryptedElements = function() {
  106. return encryptedElements_;
  107. };
  108. this.getOtherEncryptedElements = function() {
  109. return otherencryptedElements_;
  110. };
  111. this.getEncryptedElementsWithTooManyElements = function() {
  112. return encryptedElementsWithTooManyElements_;
  113. };
  114. this.getEncryptedElementsFromAnotherGroup = function() {
  115. return encryptedElementsFromAnotherGroup_;
  116. };
  117. this.getStringData = function() {
  118. return OR_PROOF_STRING_DATA;
  119. };
  120. this.getOtherStringData = function() {
  121. return OTHER_OR_PROOF_STRING_DATA;
  122. };
  123. this.getNumProgressChecks = function() {
  124. return NUM_OR_PROOF_PROGRESS_CHECKS;
  125. };
  126. }