123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479 |
- /*
- * Copyright 2018 Scytl Secure Electronic Voting SA
- *
- * All rights reserved
- *
- * See our extended copyright notice in *file 'Copyright.txt' which is part of this source code package
- */
- /* jshint node:true */
- 'use strict';
- var PlaintextEqualityProofTestData =
- require('../data/plaintext-equality-proof-data');
- var ProgressMeterTestData = require('../data/progress-meter-data');
- var ValidationTestData = require('../data/validation-data');
- var zkProof = require('../../lib/index');
- var elGamal = require('scytl-elgamal');
- describe('The zero-knowledge proof module should be able to ...', function() {
- var proofService_;
- var group_;
- var anotherGroup_;
- var primarySecret_;
- var primaryCiphertext_;
- var secondarySecret_;
- var secondaryCiphertext_;
- var primarySecretFromAnotherGroup_;
- var primaryCiphertextFromAnotherGroup_;
- var secondarySecretFromAnotherGroup_;
- var secondaryCiphertextFromAnotherGroup_;
- var primaryCiphertextWithLessElements_;
- var secondaryCiphertextWithLessElements_;
- var primaryPublicKey_;
- var secondaryPublicKey_;
- var primaryPublicKeyWithLessElements_;
- var secondaryPublicKeyWithLessElements_;
- var primaryPublicKeyFromAnotherGroup_;
- var secondaryPublicKeyFromAnotherGroup_;
- var callback_;
- var nonObject_;
- var emptyObject_;
- var nonNumber_;
- var nonPositiveNumber_;
- var nonString_;
- var nonFunction_;
- var nonAuxiliaryData_;
- var nonProofObject_;
- var proofHandler_;
- var proof_;
- beforeAll(function() {
- proofService_ = zkProof.newService();
- var testData = new PlaintextEqualityProofTestData();
- var elGamalService = elGamal.newService();
- group_ = testData.getGroup();
- anotherGroup_ = testData.getAnotherGroup();
- var primaryEncryptedElements = testData.getPrimaryEncryptedElements();
- primarySecret_ = primaryEncryptedElements.secret;
- primaryCiphertext_ = elGamalService.newEncryptedElements(
- primaryEncryptedElements.gamma, primaryEncryptedElements.phis);
- var secondaryEncryptedElements = testData.getSecondaryEncryptedElements();
- secondarySecret_ = secondaryEncryptedElements.secret;
- secondaryCiphertext_ = elGamalService.newEncryptedElements(
- secondaryEncryptedElements.gamma, secondaryEncryptedElements.phis);
- var encryptedElementsFromAnotherGroup =
- testData.getEncryptedElementsFromAnotherGroup();
- primarySecretFromAnotherGroup_ = encryptedElementsFromAnotherGroup.secret;
- primaryCiphertextFromAnotherGroup_ = elGamalService.newEncryptedElements(
- encryptedElementsFromAnotherGroup.gamma,
- encryptedElementsFromAnotherGroup.phis);
- secondarySecretFromAnotherGroup_ = primarySecretFromAnotherGroup_;
- secondaryCiphertextFromAnotherGroup_ = primaryCiphertextFromAnotherGroup_;
- var encryptedElementsWithLessElements =
- testData.getEncryptedElementsWithLessElements();
- primaryCiphertextWithLessElements_ = elGamalService.newEncryptedElements(
- encryptedElementsWithLessElements.gamma,
- encryptedElementsWithLessElements.phis);
- secondaryCiphertextWithLessElements_ = primaryCiphertextWithLessElements_;
- primaryPublicKey_ = testData.getPrimaryPublicKey();
- secondaryPublicKey_ = testData.getSecondaryPublicKey();
- primaryPublicKeyWithLessElements_ = testData.getPublicKeyWithLessElements();
- secondaryPublicKeyWithLessElements_ =
- testData.getPublicKeyWithLessElements();
- primaryPublicKeyFromAnotherGroup_ = testData.getPublicKeyFromAnotherGroup();
- secondaryPublicKeyFromAnotherGroup_ =
- testData.getPublicKeyFromAnotherGroup();
- var progressMeterTestData = new ProgressMeterTestData();
- callback_ = progressMeterTestData.progressCallback;
- var validationTestData = new ValidationTestData();
- nonObject_ = validationTestData.getNonObject();
- emptyObject_ = validationTestData.getEmptyObject();
- nonNumber_ = validationTestData.getNonNumber();
- nonPositiveNumber_ = validationTestData.getNonPositiveNumber();
- nonString_ = validationTestData.getNonString();
- nonFunction_ = validationTestData.getNonFunction();
- nonAuxiliaryData_ = validationTestData.getNonAuxiliaryData();
- nonProofObject_ = validationTestData.getNonProofObject();
- proofHandler_ = proofService_.newPlaintextEqualityProofHandler(group_).init(
- primaryPublicKey_, secondaryPublicKey_);
- proof_ = proofHandler_.generate(
- primarySecret_, secondarySecret_, primaryCiphertext_,
- secondaryCiphertext_);
- });
- beforeEach(function() {
- proofHandler_ = proofService_.newPlaintextEqualityProofHandler(group_).init(
- primaryPublicKey_, secondaryPublicKey_);
- });
- describe('create a zero-knowledge proof service that should be able to ..', function() {
- describe('create a plaintext equality proof handler that should be able to', function() {
- it('throw an error when being created, using invalid input data',
- function() {
- expect(function() {
- proofService_.newPlaintextEqualityProofHandler();
- }).toThrow();
- expect(function() {
- proofService_.newPlaintextEqualityProofHandler(undefined);
- }).toThrow();
- expect(function() {
- proofService_.newPlaintextEqualityProofHandler(null);
- }).toThrow();
- expect(function() {
- proofService_.newPlaintextEqualityProofHandler(nonObject_);
- }).toThrow();
- expect(function() {
- proofService_.newPlaintextEqualityProofHandler(emptyObject_);
- }).toThrow();
- });
- it('throw an error when being initialized, using an invalid primary public key',
- function() {
- expect(function() {
- proofHandler_.init(undefined, secondaryPublicKey_);
- }).toThrow();
- expect(function() {
- proofHandler_.init(null, secondaryPublicKey_);
- }).toThrow();
- expect(function() {
- proofHandler_.init(nonObject_, secondaryPublicKey_);
- }).toThrow();
- expect(function() {
- proofHandler_.init(emptyObject_, secondaryPublicKey_);
- }).toThrow();
- expect(function() {
- proofHandler_.init(
- primaryPublicKeyWithLessElements_, secondaryPublicKey_);
- }).toThrow();
- expect(function() {
- proofHandler_.init(
- primaryPublicKeyFromAnotherGroup_, secondaryPublicKey_);
- }).toThrow();
- });
- it('throw an error when being initialized, using an invalid secondary public key',
- function() {
- expect(function() {
- proofHandler_.init(primaryPublicKey_);
- }).toThrow();
- expect(function() {
- proofHandler_.init(primaryPublicKey_, undefined);
- }).toThrow();
- expect(function() {
- proofHandler_.init(primaryPublicKey_, null);
- }).toThrow();
- expect(function() {
- proofHandler_.init(primaryPublicKey_, nonObject_);
- }).toThrow();
- expect(function() {
- proofHandler_.init(primaryPublicKey_, emptyObject_);
- }).toThrow();
- expect(function() {
- proofHandler_.init(
- primaryPublicKey_, secondaryPublicKeyFromAnotherGroup_);
- }).toThrow();
- });
- it('throw an error when generating a plaintext equality proof, using an invalid primary secret',
- function() {
- expect(function() {
- proofHandler_.generate(
- undefined, secondarySecret_, primaryCiphertext_,
- secondaryCiphertext_);
- }).toThrow();
- expect(function() {
- proofHandler_.generate(
- null, secondarySecret_, primaryCiphertext_,
- secondaryCiphertext_);
- }).toThrow();
- expect(function() {
- proofHandler_.generate(
- nonObject_, secondarySecret_, primaryCiphertext_,
- secondaryCiphertext_);
- }).toThrow();
- expect(function() {
- proofHandler_.generate(
- emptyObject_, secondarySecret_, primaryCiphertext_,
- secondaryCiphertext_);
- }).toThrow();
- expect(function() {
- proofHandler_.generate(
- primarySecretFromAnotherGroup_, secondarySecret_,
- primaryCiphertext_, secondaryCiphertext_);
- }).toThrow();
- });
- it('throw an error when generating a plaintext equality proof, using an invalid secondary secret',
- function() {
- expect(function() {
- proofHandler_.generate(
- primarySecret_, undefined, primaryCiphertext_,
- secondaryCiphertext_);
- }).toThrow();
- expect(function() {
- proofHandler_.generate(
- primarySecret_, null, primaryCiphertext_,
- secondaryCiphertext_);
- }).toThrow();
- expect(function() {
- proofHandler_.generate(
- primarySecret_, nonObject_, primaryCiphertext_,
- secondaryCiphertext_);
- }).toThrow();
- expect(function() {
- proofHandler_.generate(
- primarySecret_, emptyObject_, primaryCiphertext_,
- secondaryCiphertext_);
- }).toThrow();
- expect(function() {
- proofHandler_.generate(
- primarySecret_, secondarySecretFromAnotherGroup_,
- primaryCiphertext_, secondaryCiphertext_);
- }).toThrow();
- });
- it('throw an error when generating a plaintext equality proof, using an invalid primary ciphertext',
- function() {
- expect(function() {
- proofHandler_.generate(
- primarySecret_, secondarySecret_, undefined,
- secondaryCiphertext_);
- }).toThrow();
- expect(function() {
- proofHandler_.generate(
- primarySecret_, secondarySecret_, null, secondaryCiphertext_);
- }).toThrow();
- expect(function() {
- proofHandler_.generate(
- primarySecret_, secondarySecret_, nonObject_,
- secondaryCiphertext_);
- }).toThrow();
- expect(function() {
- proofHandler_.generate(
- primarySecret_, secondarySecret_, emptyObject_,
- secondaryCiphertext_);
- }).toThrow();
- expect(function() {
- proofHandler_.generate(
- primarySecret_, secondarySecret_,
- primaryCiphertextWithLessElements_, secondaryCiphertext_);
- }).toThrow();
- expect(function() {
- proofHandler_.generate(
- primarySecret_, secondarySecret_,
- primaryCiphertextFromAnotherGroup_, secondaryCiphertext_);
- }).toThrow();
- });
- it('throw an error when generating a plaintext equality proof, using an invalid secondary ciphertext',
- function() {
- expect(function() {
- proofHandler_.generate(
- primarySecret_, secondarySecret_, primaryCiphertext_,
- undefined);
- }).toThrow();
- expect(function() {
- proofHandler_.generate(
- primarySecret_, secondarySecret_, primaryCiphertext_, null);
- }).toThrow();
- expect(function() {
- proofHandler_.generate(
- primarySecret_, secondarySecret_, primaryCiphertext_,
- nonObject_);
- }).toThrow();
- expect(function() {
- proofHandler_.generate(
- primarySecret_, secondarySecret_, primaryCiphertext_,
- emptyObject_);
- }).toThrow();
- expect(function() {
- proofHandler_.generate(
- primarySecret_, secondarySecret_, primaryCiphertext_,
- secondaryCiphertextWithLessElements_);
- }).toThrow();
- expect(function() {
- proofHandler_.generate(
- primarySecret_, secondarySecret_, primaryCiphertext_,
- secondaryCiphertextFromAnotherGroup_);
- }).toThrow();
- });
- it('throw an error when generating a simple plaintext equality proof, using invalid optional data',
- function() {
- expect(function() {
- proofHandler_.generate(
- primarySecret_, secondarySecret_, primaryCiphertext_,
- secondaryCiphertext_, {data: nonAuxiliaryData_});
- }).toThrow();
- expect(function() {
- proofHandler_.generate(
- primarySecret_, secondarySecret_, primaryCiphertext_,
- secondaryCiphertext_, {preComputation: nonObject_});
- }).toThrow();
- expect(function() {
- proofHandler_.generate(
- primarySecret_, secondarySecret_, primaryCiphertext_,
- secondaryCiphertext_, {preComputation: nonProofObject_});
- }).toThrow();
- });
- it('throw an error when verifying a plaintext equality proof, using an invalid proof',
- function() {
- expect(function() {
- proofHandler_.verify(
- undefined, primaryCiphertext_, secondaryCiphertext_);
- }).toThrow();
- expect(function() {
- proofHandler_.verify(
- null, primaryCiphertext_, secondaryCiphertext_);
- }).toThrow();
- expect(function() {
- proofHandler_.verify(
- nonProofObject_, primaryCiphertext_, secondaryCiphertext_);
- }).toThrow();
- });
- it('throw an error when verifying a plaintext equality proof, using an invalid primary ciphertext',
- function() {
- expect(function() {
- proofHandler_.verify(proof_, undefined, secondaryCiphertext_);
- }).toThrow();
- expect(function() {
- proofHandler_.verify(proof_, null, secondaryCiphertext_);
- }).toThrow();
- expect(function() {
- proofHandler_.verify(proof_, nonObject_, secondaryCiphertext_);
- }).toThrow();
- expect(function() {
- proofHandler_.verify(proof_, emptyObject_, secondaryCiphertext_);
- }).toThrow();
- expect(function() {
- proofHandler_.verify(
- proof_, primaryCiphertextWithLessElements_,
- secondaryCiphertext_);
- }).toThrow();
- expect(function() {
- proofHandler_.verify(
- proof_, primaryCiphertextFromAnotherGroup_,
- secondaryCiphertext_);
- }).toThrow();
- });
- it('throw an error when verifying a plaintext equality proof, using an invalid secondary ciphertext',
- function() {
- expect(function() {
- proofHandler_.verify(proof_, primaryCiphertext_, undefined);
- }).toThrow();
- expect(function() {
- proofHandler_.verify(proof_, primaryCiphertext_, null);
- }).toThrow();
- expect(function() {
- proofHandler_.verify(proof_, primaryCiphertext_, nonObject_);
- }).toThrow();
- expect(function() {
- proofHandler_.verify(proof_, primaryCiphertext_, emptyObject_);
- }).toThrow();
- expect(function() {
- proofHandler_.verify(
- proof_, primaryCiphertext_,
- secondaryCiphertextWithLessElements_);
- }).toThrow();
- expect(function() {
- proofHandler_.verify(
- proof_, primaryCiphertext_,
- secondaryCiphertextFromAnotherGroup_);
- }).toThrow();
- });
- it('throw an error when verifying a simple plaintext equality proof, using invalid optional data',
- function() {
- expect(function() {
- proofHandler_.verify(
- proof_, primaryCiphertext_, secondaryCiphertext_,
- {data: nonAuxiliaryData_});
- }).toThrow();
- });
- it('throw an error when measuring plaintext equality proof progress, using invalid input data',
- function() {
- expect(function() {
- proofHandler_.measureProgress();
- }).toThrow();
- expect(function() {
- proofHandler_.measureProgress(undefined);
- }).toThrow();
- expect(function() {
- proofHandler_.measureProgress(null);
- }).toThrow();
- expect(function() {
- proofHandler_.measureProgress(nonFunction_);
- }).toThrow();
- expect(function() {
- proofHandler_.measureProgress(callback_, null);
- }).toThrow();
- expect(function() {
- proofHandler_.measureProgress(callback_, nonNumber_);
- }).toThrow();
- expect(function() {
- proofHandler_.measureProgress(callback_, nonPositiveNumber_);
- }).toThrow();
- });
- });
- });
- });
|