proofs.service.simple_plaintext_equality.spec.js 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  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. describe('Proofs service ...', function() {
  9. 'use strict';
  10. // Initialize variables common to all proof tests.
  11. beforeEach(initializeTestVars);
  12. // Simple plaintext equality proof tests.
  13. describe('should be able to ..', function() {
  14. var num_plaintext_elements = 4;
  15. var num_progress_checks = num_plaintext_elements + 1;
  16. var initialized = false;
  17. var plaintext;
  18. var publicKey;
  19. var primaryPublicKey;
  20. var secondaryPublicKey;
  21. var ciphertext;
  22. var primaryCiphertext;
  23. var secondaryCiphertext;
  24. var witness;
  25. var proof;
  26. var preComputedValues;
  27. var anotherPlaintext;
  28. var anotherPrimaryPublicKey;
  29. var anotherSecondaryPublicKey;
  30. var anotherPrimaryCiphertext;
  31. var anotherSecondaryCiphertext;
  32. var anotherWitness;
  33. var aNonSimplePrimaryCiphertext;
  34. var aNonSimpleSecondaryCiphertext;
  35. var aNonSimpleWitness;
  36. var aShorterPrimaryPublicKey;
  37. var aShorterSecondaryPublicKey;
  38. var aShorterPrimaryCiphertext;
  39. // Initialize variables common to simple plaintext equality proof tests.
  40. beforeEach(function() {
  41. if (!initialized) {
  42. cryptolib('proofs.service', function(box) {
  43. plaintext = generateSimplePlaintext(num_plaintext_elements);
  44. publicKey =
  45. generateElGamalKeyPair(num_plaintext_elements).getPublicKey();
  46. primaryPublicKey = getSubElGamalPublicKey(
  47. publicKey, 0, (num_plaintext_elements / 2));
  48. secondaryPublicKey = getSubElGamalPublicKey(
  49. publicKey, (num_plaintext_elements / 2), num_plaintext_elements);
  50. ciphertext = generateCiphertext(publicKey, plaintext);
  51. primaryCiphertext =
  52. getSubCiphertext(ciphertext, 0, (num_plaintext_elements / 2));
  53. secondaryCiphertext = getSubCiphertext(
  54. ciphertext, (num_plaintext_elements / 2), num_plaintext_elements);
  55. witness = ciphertext.getR();
  56. proof = box.proofs.service.createSimplePlaintextEqualityProof(
  57. primaryCiphertext, primaryPublicKey, witness, secondaryCiphertext,
  58. secondaryPublicKey, _zpSubgroup);
  59. preComputedValues =
  60. box.proofs.service.preComputeSimplePlaintextEqualityProof(
  61. primaryPublicKey, secondaryPublicKey, _zpSubgroup);
  62. do {
  63. anotherPlaintext = generateSimplePlaintext(num_plaintext_elements);
  64. } while (anotherPlaintext.equals(plaintext));
  65. do {
  66. anotherPrimaryPublicKey =
  67. generateElGamalKeyPair(num_plaintext_elements / 2)
  68. .getPublicKey();
  69. } while (anotherPrimaryPublicKey.getGroupElementsArray().equals(
  70. primaryPublicKey.getGroupElementsArray()));
  71. do {
  72. anotherSecondaryPublicKey =
  73. generateElGamalKeyPair(num_plaintext_elements / 2)
  74. .getPublicKey();
  75. } while (anotherSecondaryPublicKey.getGroupElementsArray().equals(
  76. secondaryPublicKey.getGroupElementsArray()));
  77. var subPlaintext;
  78. do {
  79. subPlaintext = generateSimplePlaintext(num_plaintext_elements / 2);
  80. anotherPrimaryCiphertext =
  81. generateCiphertext(primaryPublicKey, subPlaintext);
  82. } while (subPlaintext.equals(
  83. plaintext.slice(0, (num_plaintext_elements / 2))));
  84. do {
  85. subPlaintext = generateSimplePlaintext(num_plaintext_elements / 2);
  86. anotherSecondaryCiphertext =
  87. generateCiphertext(secondaryPublicKey, subPlaintext);
  88. } while (subPlaintext.equals(plaintext.slice(
  89. (num_plaintext_elements / 2), num_plaintext_elements)));
  90. do {
  91. anotherWitness = generateRandomExponent(_zpSubgroup);
  92. } while (anotherWitness.getValue().equals(witness.getValue()));
  93. var nonSimplePlaintext =
  94. generateNonSimplePlaintext(num_plaintext_elements);
  95. var nonSimpleCiphertext =
  96. generateCiphertext(publicKey, nonSimplePlaintext);
  97. aNonSimplePrimaryCiphertext = getSubCiphertext(
  98. nonSimpleCiphertext, 0, (num_plaintext_elements / 2));
  99. aNonSimpleSecondaryCiphertext = getSubCiphertext(
  100. nonSimpleCiphertext, (num_plaintext_elements / 2),
  101. num_plaintext_elements);
  102. aNonSimpleWitness = nonSimpleCiphertext.getR();
  103. aShorterPrimaryPublicKey = getSubElGamalPublicKey(
  104. publicKey, 1, (num_plaintext_elements / 2));
  105. aShorterSecondaryPublicKey = getSubElGamalPublicKey(
  106. publicKey, ((num_plaintext_elements / 2) + 1),
  107. num_plaintext_elements);
  108. aShorterPrimaryCiphertext =
  109. getSubCiphertext(ciphertext, 1, (num_plaintext_elements / 2));
  110. });
  111. }
  112. initialized = true;
  113. });
  114. it('generate and verify a simple plaintext equality proof', function() {
  115. cryptolib('proofs.service', function(box) {
  116. var verification =
  117. box.proofs.service.verifySimplePlaintextEqualityProof(
  118. primaryCiphertext, primaryPublicKey, secondaryCiphertext,
  119. secondaryPublicKey, proof, _zpSubgroup);
  120. expect(verification).toBeTruthy();
  121. });
  122. });
  123. it('and generate and verify a simple plaintext equality proof, using pre-computed values',
  124. function() {
  125. cryptolib('proofs.service', function(box) {
  126. expect(preComputedValues).toBeDefined();
  127. var anotherProof =
  128. box.proofs.service.createSimplePlaintextEqualityProof(
  129. primaryCiphertext, primaryPublicKey, witness,
  130. secondaryCiphertext, secondaryPublicKey, _zpSubgroup,
  131. preComputedValues);
  132. var verification =
  133. box.proofs.service.verifySimplePlaintextEqualityProof(
  134. primaryCiphertext, primaryPublicKey, secondaryCiphertext,
  135. secondaryPublicKey, anotherProof, _zpSubgroup);
  136. expect(verification).toBeTruthy();
  137. });
  138. });
  139. it('and generate and verify a simple plaintext equality proof, using null for the pre-computed values option',
  140. function() {
  141. cryptolib('proofs.service', function(box) {
  142. var anotherProof =
  143. box.proofs.service.createSimplePlaintextEqualityProof(
  144. primaryCiphertext, primaryPublicKey, witness,
  145. secondaryCiphertext, secondaryPublicKey, _zpSubgroup, null);
  146. var verification =
  147. box.proofs.service.verifySimplePlaintextEqualityProof(
  148. primaryCiphertext, primaryPublicKey, secondaryCiphertext,
  149. secondaryPublicKey, anotherProof, _zpSubgroup);
  150. expect(verification).toBeTruthy();
  151. });
  152. });
  153. it('generate and verify a simple plaintext equality proof, using serialization',
  154. function() {
  155. cryptolib('commons.mathematical', 'proofs', function(box) {
  156. var proofAsJson = proof.stringify();
  157. var proofFromJson = box.proofs.utils.deserializeProof(proofAsJson);
  158. var verification =
  159. box.proofs.service.verifySimplePlaintextEqualityProof(
  160. primaryCiphertext, primaryPublicKey, secondaryCiphertext,
  161. secondaryPublicKey, proofFromJson, _zpSubgroup);
  162. expect(verification).toBeTruthy();
  163. });
  164. });
  165. it('generate and verify a simple plaintext equality proof, using pre-computed values and serialization',
  166. function() {
  167. cryptolib('commons.mathematical', 'proofs', function(box) {
  168. var preComputedValuesAsJson = preComputedValues.stringify();
  169. var preComputedValuesFromJson =
  170. box.proofs.utils.deserializeProofPreComputedValues(
  171. preComputedValuesAsJson);
  172. var anotherProof =
  173. box.proofs.service.createSimplePlaintextEqualityProof(
  174. primaryCiphertext, primaryPublicKey, witness,
  175. secondaryCiphertext, secondaryPublicKey, _zpSubgroup,
  176. preComputedValuesFromJson);
  177. var verification =
  178. box.proofs.service.verifySimplePlaintextEqualityProof(
  179. primaryCiphertext, primaryPublicKey, secondaryCiphertext,
  180. secondaryPublicKey, anotherProof, _zpSubgroup);
  181. expect(verification).toBeTruthy();
  182. });
  183. });
  184. it('and measure progress when generating a simple plaintext equality proof',
  185. function() {
  186. cryptolib('proofs.service', function(box) {
  187. initializeProgressMeter();
  188. var anotherProof =
  189. box.proofs.service.createSimplePlaintextEqualityProof(
  190. primaryCiphertext, primaryPublicKey, witness,
  191. secondaryCiphertext, secondaryPublicKey, _zpSubgroup,
  192. progressCallback, PROGRESS_PERCENT_MIN_CHECK_INTERVAL);
  193. expect(_progressPercentSum)
  194. .toBe(getProgressPercentSum(
  195. num_progress_checks, PROGRESS_PERCENT_MIN_CHECK_INTERVAL));
  196. expect(_progressPercentLatest).toBe(100);
  197. var verification =
  198. box.proofs.service.verifySimplePlaintextEqualityProof(
  199. primaryCiphertext, primaryPublicKey, secondaryCiphertext,
  200. secondaryPublicKey, anotherProof, _zpSubgroup);
  201. expect(verification).toBeTruthy();
  202. });
  203. });
  204. it('and measure progress when pre-computing a simple plaintext equality proof',
  205. function() {
  206. cryptolib('proofs.service', function(box) {
  207. initializeProgressMeter();
  208. box.proofs.service.preComputeSimplePlaintextEqualityProof(
  209. primaryPublicKey, secondaryPublicKey, _zpSubgroup,
  210. progressCallback, PROGRESS_PERCENT_MIN_CHECK_INTERVAL);
  211. expect(_progressPercentSum)
  212. .toBe(getProgressPercentSum(
  213. num_progress_checks, PROGRESS_PERCENT_MIN_CHECK_INTERVAL));
  214. expect(_progressPercentLatest).toBe(100);
  215. var anotherProof =
  216. box.proofs.service.createSimplePlaintextEqualityProof(
  217. primaryCiphertext, primaryPublicKey, witness,
  218. secondaryCiphertext, secondaryPublicKey, _zpSubgroup,
  219. preComputedValues);
  220. var verification =
  221. box.proofs.service.verifySimplePlaintextEqualityProof(
  222. primaryCiphertext, primaryPublicKey, secondaryCiphertext,
  223. secondaryPublicKey, anotherProof, _zpSubgroup);
  224. expect(verification).toBeTruthy();
  225. });
  226. });
  227. it('and measure progress when verifying a simple plaintext equality proof',
  228. function() {
  229. cryptolib('proofs.service', function(box) {
  230. initializeProgressMeter();
  231. var verification =
  232. box.proofs.service.verifySimplePlaintextEqualityProof(
  233. primaryCiphertext, primaryPublicKey, secondaryCiphertext,
  234. secondaryPublicKey, proof, _zpSubgroup, progressCallback,
  235. PROGRESS_PERCENT_MIN_CHECK_INTERVAL);
  236. expect(verification).toBeTruthy();
  237. expect(_progressPercentSum)
  238. .toBe(getProgressPercentSum(
  239. num_progress_checks, PROGRESS_PERCENT_MIN_CHECK_INTERVAL));
  240. expect(_progressPercentLatest).toBe(100);
  241. });
  242. });
  243. it('and fail to verify a simple plaintext equality proof that was generated with the wrong primary ciphertext',
  244. function() {
  245. cryptolib('proofs.service', function(box) {
  246. var anotherProof =
  247. box.proofs.service.createSimplePlaintextEqualityProof(
  248. anotherPrimaryCiphertext, primaryPublicKey, witness,
  249. secondaryCiphertext, secondaryPublicKey, _zpSubgroup);
  250. var verification =
  251. box.proofs.service.verifySimplePlaintextEqualityProof(
  252. anotherPrimaryCiphertext, primaryPublicKey,
  253. secondaryCiphertext, secondaryPublicKey, anotherProof,
  254. _zpSubgroup);
  255. expect(verification).toBeFalsy();
  256. });
  257. });
  258. it('and fail to verify a simple plaintext equality proof that was generated with the wrong primary public key',
  259. function() {
  260. cryptolib('proofs.service', function(box) {
  261. var anotherProof =
  262. box.proofs.service.createSimplePlaintextEqualityProof(
  263. primaryCiphertext, anotherPrimaryPublicKey, witness,
  264. secondaryCiphertext, secondaryPublicKey, _zpSubgroup);
  265. var verification =
  266. box.proofs.service.verifySimplePlaintextEqualityProof(
  267. primaryCiphertext, anotherPrimaryPublicKey,
  268. secondaryCiphertext, secondaryPublicKey, anotherProof,
  269. _zpSubgroup);
  270. expect(verification).toBeFalsy();
  271. });
  272. });
  273. it('and fail to verify a simple plaintext equality proof that was generated with the wrong secondary ciphertext',
  274. function() {
  275. cryptolib('proofs.service', function(box) {
  276. var anotherProof =
  277. box.proofs.service.createSimplePlaintextEqualityProof(
  278. primaryCiphertext, primaryPublicKey, witness,
  279. anotherSecondaryCiphertext, secondaryPublicKey, _zpSubgroup);
  280. var verification =
  281. box.proofs.service.verifySimplePlaintextEqualityProof(
  282. primaryCiphertext, primaryPublicKey,
  283. anotherSecondaryCiphertext, secondaryPublicKey, anotherProof,
  284. _zpSubgroup);
  285. expect(verification).toBeFalsy();
  286. });
  287. });
  288. it('and fail to verify a simple plaintext equality proof that was generated with the wrong secondary public key',
  289. function() {
  290. cryptolib('proofs.service', function(box) {
  291. var anotherProof =
  292. box.proofs.service.createSimplePlaintextEqualityProof(
  293. primaryCiphertext, primaryPublicKey, witness,
  294. secondaryCiphertext, anotherSecondaryPublicKey, _zpSubgroup);
  295. var verification =
  296. box.proofs.service.verifySimplePlaintextEqualityProof(
  297. primaryCiphertext, primaryPublicKey, secondaryCiphertext,
  298. anotherSecondaryPublicKey, anotherProof, _zpSubgroup);
  299. expect(verification).toBeFalsy();
  300. });
  301. });
  302. it('and fail to verify a simple plaintext equality proof that was generated with the wrong witness',
  303. function() {
  304. cryptolib('proofs.service', function(box) {
  305. var anotherProof =
  306. box.proofs.service.createSimplePlaintextEqualityProof(
  307. primaryCiphertext, primaryPublicKey, anotherWitness,
  308. secondaryCiphertext, secondaryPublicKey, _zpSubgroup);
  309. var verification =
  310. box.proofs.service.verifySimplePlaintextEqualityProof(
  311. primaryCiphertext, primaryPublicKey, secondaryCiphertext,
  312. secondaryPublicKey, anotherProof, _zpSubgroup);
  313. expect(verification).toBeFalsy();
  314. });
  315. });
  316. it('and fail to verify a simple plaintext equality proof that was generated with plaintext that is not simple',
  317. function() {
  318. cryptolib('proofs.service', function(box) {
  319. var anotherProof =
  320. box.proofs.service.createSimplePlaintextEqualityProof(
  321. aNonSimplePrimaryCiphertext, primaryPublicKey,
  322. aNonSimpleWitness, aNonSimpleSecondaryCiphertext,
  323. secondaryPublicKey, _zpSubgroup);
  324. var verification =
  325. box.proofs.service.verifySimplePlaintextEqualityProof(
  326. aNonSimplePrimaryCiphertext, primaryPublicKey,
  327. aNonSimpleSecondaryCiphertext, secondaryPublicKey,
  328. anotherProof, _zpSubgroup);
  329. expect(verification).toBeFalsy();
  330. });
  331. });
  332. it('and fail to verify a simple plaintext equality proof when using the wrong primary ciphertext',
  333. function() {
  334. cryptolib('proofs.service', function(box) {
  335. var verification =
  336. box.proofs.service.verifySimplePlaintextEqualityProof(
  337. anotherPrimaryCiphertext, primaryPublicKey,
  338. secondaryCiphertext, secondaryPublicKey, proof, _zpSubgroup);
  339. expect(verification).toBeFalsy();
  340. });
  341. });
  342. it('and fail to verify a simple plaintext equality proof when using the wrong primary public key',
  343. function() {
  344. cryptolib('proofs.service', function(box) {
  345. var verification =
  346. box.proofs.service.verifySimplePlaintextEqualityProof(
  347. primaryCiphertext, anotherPrimaryPublicKey,
  348. secondaryCiphertext, secondaryPublicKey, proof, _zpSubgroup);
  349. expect(verification).toBeFalsy();
  350. });
  351. });
  352. it('and fail to verify a simple plaintext equality proof when using the wrong secondary ciphertext',
  353. function() {
  354. cryptolib('proofs.service', function(box) {
  355. var verification =
  356. box.proofs.service.verifySimplePlaintextEqualityProof(
  357. primaryCiphertext, primaryPublicKey,
  358. anotherSecondaryCiphertext, secondaryPublicKey, proof,
  359. _zpSubgroup);
  360. expect(verification).toBeFalsy();
  361. });
  362. });
  363. it('and fail to verify a simple plaintext equality proof when using the wrong secondary public key',
  364. function() {
  365. cryptolib('proofs.service', function(box) {
  366. var verification =
  367. box.proofs.service.verifySimplePlaintextEqualityProof(
  368. primaryCiphertext, primaryPublicKey, secondaryCiphertext,
  369. anotherSecondaryPublicKey, proof, _zpSubgroup);
  370. expect(verification).toBeFalsy();
  371. });
  372. });
  373. it('and throw an exception when generating a simple plaintext equality proof, using null input data',
  374. function() {
  375. cryptolib('proofs.service', function(box) {
  376. expect(function() {
  377. box.proofs.service.createSimplePlaintextEqualityProof(
  378. null, primaryPublicKey, witness, secondaryCiphertext,
  379. secondaryPublicKey, _zpSubgroup);
  380. }).toThrow();
  381. expect(function() {
  382. box.proofs.service.createSimplePlaintextEqualityProof(
  383. primaryCiphertext, null, witness, secondaryCiphertext,
  384. secondaryPublicKey, _zpSubgroup);
  385. }).toThrow();
  386. expect(function() {
  387. box.proofs.service.createSimplePlaintextEqualityProof(
  388. primaryCiphertext, primaryPublicKey, null, secondaryCiphertext,
  389. secondaryPublicKey, _zpSubgroup);
  390. }).toThrow();
  391. expect(function() {
  392. box.proofs.service.createSimplePlaintextEqualityProof(
  393. primaryCiphertext, primaryPublicKey, witness, null,
  394. secondaryPublicKey, _zpSubgroup);
  395. }).toThrow();
  396. expect(function() {
  397. box.proofs.service.createSimplePlaintextEqualityProof(
  398. primaryCiphertext, primaryPublicKey, witness,
  399. secondaryCiphertext, null, _zpSubgroup);
  400. }).toThrow();
  401. expect(function() {
  402. box.proofs.service.createSimplePlaintextEqualityProof(
  403. primaryCiphertext, primaryPublicKey, witness,
  404. secondaryCiphertext, secondaryPublicKey, null);
  405. }).toThrow();
  406. });
  407. });
  408. it('and throw an exception when generating a simple plaintext proof, using the wrong mathematical group',
  409. function() {
  410. cryptolib('proofs.service', function(box) {
  411. expect(function() {
  412. box.proofs.service.createSimplePlaintextEqualityProof(
  413. primaryCiphertext, primaryPublicKey, witness,
  414. secondaryCiphertext, secondaryPublicKey, _anotherZpSubgroup);
  415. }).toThrow();
  416. });
  417. });
  418. it('and throw an exception when generating a simple plaintext equality proof, using primary and secondary public keys with different lengths',
  419. function() {
  420. cryptolib('proofs.service', function(box) {
  421. expect(function() {
  422. box.proofs.service.createSimplePlaintextEqualityProof(
  423. primaryCiphertext, aShorterPrimaryPublicKey, witness,
  424. secondaryCiphertext, secondaryPublicKey, _zpSubgroup);
  425. }).toThrow();
  426. });
  427. });
  428. it('and throw an exception when generating a simple plaintext equality proof, using primary and secondary ciphertexts with different lengths',
  429. function() {
  430. cryptolib('proofs.service', function(box) {
  431. expect(function() {
  432. box.proofs.service.createSimplePlaintextEqualityProof(
  433. aShorterPrimaryCiphertext, primaryPublicKey, witness,
  434. secondaryCiphertext, secondaryPublicKey, _zpSubgroup);
  435. }).toThrow();
  436. });
  437. });
  438. it('and throw an exception when generating a simple plaintext equality proof, using public keys and ciphertexts with a incorrect length relation',
  439. function() {
  440. cryptolib('proofs.service', function(box) {
  441. expect(function() {
  442. box.proofs.service.createSimplePlaintextEqualityProof(
  443. primaryCiphertext, aShorterPrimaryPublicKey, witness,
  444. secondaryCiphertext, aShorterSecondaryPublicKey, _zpSubgroup);
  445. }).toThrow();
  446. });
  447. });
  448. it('and throw an exception when generating a simple plaintext equality proof, using a progress callback function that is not a function',
  449. function() {
  450. cryptolib('proofs.service', function(box) {
  451. expect(function() {
  452. box.proofs.service.createSimplePlaintextEqualityProof(
  453. primaryCiphertext, primaryPublicKey, witness,
  454. secondaryCiphertext, secondaryPublicKey, _zpSubgroup,
  455. PROGRESS_PERCENT_MIN_CHECK_INTERVAL);
  456. }).toThrow();
  457. });
  458. });
  459. it('and throw an exception when generating a simple plaintext equality proof, using a progress percent check interval that is not a number',
  460. function() {
  461. cryptolib('proofs.service', function(box) {
  462. var percentMeasuredLatest = 0;
  463. var progressCallback = function(progressPercent) {
  464. percentMeasuredLatest = progressPercent;
  465. };
  466. expect(function() {
  467. box.proofs.service.createSimplePlaintextEqualityProof(
  468. primaryCiphertext, primaryPublicKey, witness,
  469. secondaryCiphertext, secondaryPublicKey, _zpSubgroup,
  470. progressCallback, progressCallback);
  471. }).toThrow();
  472. });
  473. });
  474. it('and throw an exception when pre-computing values for a simple plaintext equality proof, using null input data',
  475. function() {
  476. cryptolib('proofs.service', function(box) {
  477. expect(function() {
  478. box.proofs.service.preComputeSimplePlaintextEqualityProof(
  479. null, secondaryPublicKey, _zpSubgroup);
  480. }).toThrow();
  481. expect(function() {
  482. box.proofs.service.preComputeSimplePlaintextEqualityProof(
  483. primaryPublicKey, null, _zpSubgroup);
  484. }).toThrow();
  485. expect(function() {
  486. box.proofs.service.preComputeSimplePlaintextEqualityProof(
  487. primaryPublicKey, secondaryPublicKey, null);
  488. }).toThrow();
  489. });
  490. });
  491. it('and throw an exception when verifying a simple plaintext equality proof, using null input data',
  492. function() {
  493. cryptolib('proofs.service', function(box) {
  494. expect(function() {
  495. box.proofs.service.verifySimplePlaintextEqualityProof(
  496. null, primaryPublicKey, secondaryCiphertext,
  497. secondaryPublicKey, proof, _zpSubgroup);
  498. }).toThrow();
  499. expect(function() {
  500. box.proofs.service.verifySimplePlaintextEqualityProof(
  501. primaryCiphertext, null, secondaryCiphertext,
  502. secondaryPublicKey, proof, _zpSubgroup);
  503. }).toThrow();
  504. expect(function() {
  505. box.proofs.service.verifySimplePlaintextEqualityProof(
  506. primaryCiphertext, primaryPublicKey, null, secondaryPublicKey,
  507. proof, _zpSubgroup);
  508. }).toThrow();
  509. expect(function() {
  510. box.proofs.service.verifySimplePlaintextEqualityProof(
  511. primaryCiphertext, primaryPublicKey, secondaryCiphertext, null,
  512. proof, _zpSubgroup);
  513. }).toThrow();
  514. expect(function() {
  515. box.proofs.service.verifySimplePlaintextEqualityProof(
  516. primaryCiphertext, primaryPublicKey, secondaryCiphertext,
  517. secondaryPublicKey, null, _zpSubgroup);
  518. }).toThrow();
  519. expect(function() {
  520. box.proofs.service.verifySimplePlaintextEqualityProof(
  521. primaryCiphertext, primaryPublicKey, secondaryCiphertext,
  522. secondaryPublicKey, proof, null);
  523. }).toThrow();
  524. });
  525. });
  526. it('and throw an exception when verifying a simple plaintext equality proof, using the wrong mathematical group',
  527. function() {
  528. cryptolib('proofs.service', function(box) {
  529. expect(function() {
  530. box.proofs.service.verifySimplePlaintextEqualityProof(
  531. primaryCiphertext, primaryPublicKey, secondaryCiphertext,
  532. secondaryPublicKey, proof, _anotherZpSubgroup);
  533. }).toThrow();
  534. });
  535. });
  536. it('and throw an exception when verifying a simple plaintext equality proof, using primary and secondary public keys with different lengths',
  537. function() {
  538. cryptolib('proofs.service', function(box) {
  539. expect(function() {
  540. box.proofs.service.verifySimplePlaintextEqualityProof(
  541. primaryCiphertext, aShorterPrimaryPublicKey,
  542. secondaryCiphertext, secondaryPublicKey, proof, _zpSubgroup);
  543. }).toThrow();
  544. });
  545. });
  546. it('and throw an exception when verifying a simple plaintext equality proof, using primary and secondary ciphertexts with different lengths',
  547. function() {
  548. cryptolib('proofs.service', function(box) {
  549. expect(function() {
  550. box.proofs.service.verifySimplePlaintextEqualityProof(
  551. aShorterPrimaryCiphertext, primaryPublicKey,
  552. secondaryCiphertext, secondaryPublicKey, proof, _zpSubgroup);
  553. }).toThrow();
  554. });
  555. });
  556. it('and throw an exception when verifying a simple plaintext equality proof, using public keys and ciphertexts with a incorrect length relation',
  557. function() {
  558. cryptolib('proofs.service', function(box) {
  559. expect(function() {
  560. box.proofs.service.verifySimplePlaintextEqualityProof(
  561. primaryCiphertext, aShorterPrimaryPublicKey,
  562. secondaryCiphertext, aShorterSecondaryPublicKey, proof,
  563. _zpSubgroup);
  564. }).toThrow();
  565. });
  566. });
  567. it('and throw an exception when verifying a simple plaintext equality proof, using a progress callback function that is not a function',
  568. function() {
  569. cryptolib('proofs.service', function(box) {
  570. expect(function() {
  571. box.proofs.service.verifySimplePlaintextEqualityProof(
  572. primaryCiphertext, primaryPublicKey, secondaryCiphertext,
  573. secondaryPublicKey, proof, _zpSubgroup, _zpSubgroup,
  574. PROGRESS_PERCENT_MIN_CHECK_INTERVAL);
  575. }).toThrow();
  576. });
  577. });
  578. it('and throw an exception when verifying a simple plaintext equality proof, using a progress percent check interval that is not a number',
  579. function() {
  580. cryptolib('proofs.service', function(box) {
  581. var percentMeasuredLatest = 0;
  582. var progressCallback = function(progressPercent) {
  583. percentMeasuredLatest = progressPercent;
  584. };
  585. expect(function() {
  586. box.proofs.service.verifySimplePlaintextEqualityProof(
  587. primaryCiphertext, primaryPublicKey, secondaryCiphertext,
  588. secondaryPublicKey, proof, _zpSubgroup, progressCallback,
  589. progressCallback);
  590. }).toThrow();
  591. });
  592. });
  593. });
  594. });