common-data.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 mathematical = require('../../lib/index');
  11. var constants = require('../../lib/constants');
  12. var forge = require('node-forge');
  13. module.exports = CommonTestData;
  14. var BigInteger = forge.jsbn.BigInteger;
  15. /**
  16. * Provides the common data needed by the mathematical service unit tests.
  17. */
  18. function CommonTestData() {
  19. var mathService = mathematical.newService();
  20. var p_ = new BigInteger('23');
  21. var q_ = new BigInteger('11');
  22. var g_ = new BigInteger('2');
  23. var group_ = mathService.newZpSubgroup(p_, q_, g_);
  24. var qrGroup_ = mathService.newQuadraticResidueGroup(p_, g_);
  25. var anotherP_ = new BigInteger(
  26. '22115396014581083143553195792384915983375949993753365299824374182778648887213105675373952839695834312125954513956465041609718392131788741228259266178434294275575978809365653903991346366383637500069010795276889266879661859362340655085050484891149389971190945080643692669920059928787982790808824970597361825060408436004650739931286605415552480363242364319544423959620330010413847743583301091182870021747196927889763205955078275353307312408480155002017730305672359814713050632922694161739281353676187308501682728826507718002850698488786266115311952718697872338756199429262811547458969260835283688979875294699655014592833');
  27. var anotherQ_ = new BigInteger(
  28. '79783631514788897688995869254536231266441581267248557197866166084121363399063');
  29. var anotherG_ = new BigInteger(
  30. '9484337033848536557358945372517536146444081505783459082983213315915020922388822299017798461933010391712259501201285084235930755858547311934865298396110947362913733900057881561201738951725697128822802249693116611294569213895789823297341865759919045291915705783128173481781221176839434866976235031358969583527093743179257827355453820268832913547364509208164670680381449515691300440305333919098105147193087681183020489724214850151272955879869448467832934822639783688344322183540621808345771717172404141548242866493539424279296365911355186761897533654055060787119955689115570505208857288933136456026541073605147828202749');
  31. var anotherGroup_ =
  32. mathService.newZpSubgroup(anotherP_, anotherQ_, anotherG_);
  33. var elementValue_ = new BigInteger('3');
  34. var element_ = mathService.newZpGroupElement(p_, q_, elementValue_);
  35. var exponentValue_ = new BigInteger('2');
  36. var exponent_ = mathService.newExponent(q_, exponentValue_);
  37. var element1Value_ = new BigInteger('2');
  38. var element2Value_ = new BigInteger('3');
  39. var element3Value_ = new BigInteger('9');
  40. var elements_ = [];
  41. elements_[0] = mathService.newZpGroupElement(p_, q_, element1Value_);
  42. elements_[1] = mathService.newZpGroupElement(p_, q_, element2Value_);
  43. elements_[2] = mathService.newZpGroupElement(p_, q_, element3Value_);
  44. var exponent1Value = new BigInteger('2');
  45. var exponent2Value = new BigInteger('4');
  46. var exponent3Value = new BigInteger('12');
  47. var exponents_ = [];
  48. exponents_[0] = mathService.newExponent(q_, exponent1Value);
  49. exponents_[1] = mathService.newExponent(q_, exponent2Value);
  50. exponents_[2] = mathService.newExponent(q_, exponent3Value);
  51. var elementFromAnotherGroup_ =
  52. mathService.newZpGroupElement(anotherP_, anotherQ_, elementValue_);
  53. var exponentFromAnotherGroup_ =
  54. mathService.newExponent(anotherQ_, exponentValue_);
  55. var pLarge = new BigInteger(
  56. '22588801568735561413035633152679913053449200833478689904902877673687016391844561133376032309307885537704777240609087377993341380751697605235541131273868440070920362148431866829787784445019147999379498503693247429579480289226602748397335327890884464685051682703709742724121783217827040722415360103179289160056581759372475845985438977307323570530753362027145384124771826114651710264766437273044759690955051982839684910462609395741692689616014805965573558015387956017183286848440036954926101719205598449898400180082053755864070690174202432196678045052744337832802051787273056312757384654145455745603262082348042780103679');
  57. var qrGroupLarge_ = mathService.newQuadraticResidueGroup(pLarge, g_);
  58. var exponent1LargeValue_ = new BigInteger(
  59. '129547331161844130899924173735104728702220700682642138851022406761777994632728337153635583150724889632689084497665212926336088840842855597736181764744122977345480665146165524664735861913761423291109155186483836806324970977794125768575887671259015293979900588616487195411477129839925141145884519189238456836206862720534398725375349481201999965487100563522135988094619173050092410477941592825803862292425503577691441721033806466916501473758812704373810862790693842410609705251142958265348495650713103821889837809522418329172422392659115758749365074645804533890934339070499112165048929164809093509978635413193830265570');
  60. var exponent1Large_ = mathService.newExponent(q_, exponent1LargeValue_);
  61. var exponent2LargeValue_ = new BigInteger(
  62. '7533608948657130117198364792462971241599837777629317286887202126604432685322243335715285630236984093165224740099563982076007648728594011814311120331313200895892632245003875959905589367483155794698953057915454892457379023058909518440394905695255170407948701433659375513788930419544151891518689331636455316691827048845766063478445484089208223819510250476623436782404385896353292653750744111841510466992101967325081746747885221256692886521245630131046183525331085171958919416648097910028887247120874015121272894655357197879292253781160838729753609784455892951965051119314203469298666741439497193677501351952497150273389');
  63. var exponent2Large_ = mathService.newExponent(q_, exponent2LargeValue_);
  64. var multiGroupElementValueArray_ = [3, 4, 5, 6, 7, 8, 9, 12, 13, 16, 18];
  65. var multiGroupElementValues_ = [];
  66. var multiGroupElements_ = [];
  67. var value;
  68. var element;
  69. for (var i = 0; i < multiGroupElementValueArray_.length; i++) {
  70. value = new BigInteger('' + multiGroupElementValueArray_[i]);
  71. element = mathService.newZpGroupElement(p_, q_, value);
  72. multiGroupElementValues_.push(value);
  73. multiGroupElements_.push(element);
  74. }
  75. this.getP = function() {
  76. return p_;
  77. };
  78. this.getQ = function() {
  79. return q_;
  80. };
  81. this.getG = function() {
  82. return g_;
  83. };
  84. this.getGroup = function() {
  85. return group_;
  86. };
  87. this.getAnotherP = function() {
  88. return anotherP_;
  89. };
  90. this.getAnotherQ = function() {
  91. return anotherQ_;
  92. };
  93. this.getAnotherG = function() {
  94. return anotherG_;
  95. };
  96. this.getAnotherGroup = function() {
  97. return anotherGroup_;
  98. };
  99. this.getQuadraticResidueGroup = function() {
  100. return qrGroup_;
  101. };
  102. this.getElementValue = function() {
  103. return elementValue_;
  104. };
  105. this.getElement = function() {
  106. return element_;
  107. };
  108. this.getExponentValue = function() {
  109. return exponentValue_;
  110. };
  111. this.getExponent = function() {
  112. return exponent_;
  113. };
  114. this.getElement1Value = function() {
  115. return element1Value_;
  116. };
  117. this.getElement2Value = function() {
  118. return element2Value_;
  119. };
  120. this.getElement3Value = function() {
  121. return element3Value_;
  122. };
  123. this.getElements = function() {
  124. return elements_;
  125. };
  126. this.getExponents = function() {
  127. return exponents_;
  128. };
  129. this.getElementFromAnotherGroup = function() {
  130. return elementFromAnotherGroup_;
  131. };
  132. this.getExponentFromAnotherGroup = function() {
  133. return exponentFromAnotherGroup_;
  134. };
  135. this.getLargeQuadraticResidueGroup = function() {
  136. return qrGroupLarge_;
  137. };
  138. this.getExponent1LargeValue = function() {
  139. return exponent1LargeValue_;
  140. };
  141. this.getExponent1Large = function() {
  142. return exponent1Large_;
  143. };
  144. this.getExponent2LargeValue = function() {
  145. return exponent2LargeValue_;
  146. };
  147. this.getExponent2Large = function() {
  148. return exponent2Large_;
  149. };
  150. this.getMinimumCertaintyLevel = function() {
  151. return constants.MINIMUM_PRIME_CERTAINTY_LEVEL;
  152. };
  153. this.getMultiGroupElementValueArray = function() {
  154. return multiGroupElementValueArray_;
  155. };
  156. this.multiGroupElementValues = function() {
  157. return multiGroupElementValues_;
  158. };
  159. this.getMultiGroupElements = function() {
  160. return multiGroupElements_;
  161. };
  162. }