2
0

proofs.service.plaintext_equality.spec.js 26 KB

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