123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847 |
- /*
- * 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
- */
- cryptolib.modules.proofs = cryptolib.modules.proofs || {};
- /**
- * Allows several cryptographic proofs to be generated and verified.
- * <P>
- */
- cryptolib.modules.proofs.service = function(box) {
- 'use strict';
- box.proofs = box.proofs || {};
- box.proofs.service = {};
- var proofsFactory;
- var f = function(box) {
- proofsFactory = new box.proofs.ProofsFactory();
- };
- f.policies = {
- proofs: {
- messagedigest: {
- algorithm: box.policies.proofs.messagedigest.algorithm,
- provider: box.policies.proofs.messagedigest.provider
- },
- secureRandom: {provider: box.policies.proofs.secureRandom.provider},
- charset: box.policies.proofs.charset
- },
- primitives: {
- secureRandom: {provider: box.policies.primitives.secureRandom.provider}
- }
- };
- cryptolib(
- 'proofs.implementation', 'primitives.securerandom', 'commons.exceptions',
- 'commons.mathematical', f);
- /**
- * Creates a Schnorr proof.
- *
- * @param voterID
- * The voter ID. This should be a string.
- * @param electionID
- * The election event ID. This should be a string.
- * @param exponentiatedElement
- * The exponentiated element. This should be an element of the
- * received group.
- * @param witness
- * The witness. This should be an Exponent of the received group.
- * @param group
- * The mathematical group. This should be a Zp subgroup.
- * @param progressCallbackOrPreComputedValues
- * Progress callback function or pre-computed values (optional).
- * @param progressPercentMinCheckInterval
- * Progress percentage minimum check interval, if the previous
- * parameter is a progressCallback function (optional).
- *
- * @returns The Schnorr proof.
- */
- box.proofs.service.createSchnorrProof = function(
- voterID, electionID, exponentiatedElement, witness, group,
- progressCallbackOrPreComputedValues, progressPercentMinCheckInterval) {
- var proofGenerator =
- proofsFactory.createSchnorrProofGenerator(voterID, electionID, group);
- if (!progressCallbackOrPreComputedValues) {
- return proofGenerator.generate(exponentiatedElement, witness);
- } else if (isPreComputedValues(progressCallbackOrPreComputedValues)) {
- var preComputedValues = progressCallbackOrPreComputedValues;
- return proofGenerator.generate(
- exponentiatedElement, witness, preComputedValues);
- } else {
- var progressCallback = progressCallbackOrPreComputedValues;
- return proofGenerator
- .initProgressMeter(progressCallback, progressPercentMinCheckInterval)
- .generate(exponentiatedElement, witness);
- }
- };
- /**
- * Creates an exponentiation proof.
- *
- * @param exponentiatedElements
- * The exponentiated elements. These should consist of the
- * following base elements, exponentiated with the specified
- * exponent.
- * @param baseElements
- * The base elements used for the exponentiations. These should
- * correspond to elements of the specified group.
- * @param exponent
- * The exponent for which this proof is to be generated. It
- * should be an exponent of the specified group.
- * @param group
- * The mathematical group. This should be a Zp subgroup.
- * @param progressCallbackOrPreComputedValues
- * Progress callback function or pre-computed values (optional).
- * @param progressPercentMinCheckInterval
- * Progress percentage minimum check interval, if the previous
- * parameter is a progressCallback function (optional).
- *
- * @returns The exponentiation proof.
- */
- box.proofs.service.createExponentiationProof = function(
- exponentiatedElements, baseElements, exponent, group,
- progressCallbackOrPreComputedValues, progressPercentMinCheckInterval) {
- var proofGenerator =
- proofsFactory.createExponentiationProofGenerator(baseElements, group);
- if (!progressCallbackOrPreComputedValues) {
- return proofGenerator.generate(exponentiatedElements, exponent);
- } else if (isPreComputedValues(progressCallbackOrPreComputedValues)) {
- var preComputedValues = progressCallbackOrPreComputedValues;
- return proofGenerator.generate(
- exponentiatedElements, exponent, preComputedValues);
- } else {
- var progressCallback = progressCallbackOrPreComputedValues;
- return proofGenerator
- .initProgressMeter(progressCallback, progressPercentMinCheckInterval)
- .generate(exponentiatedElements, exponent);
- }
- };
- /**
- * Creates a plaintext proof.
- *
- * @param publicKey
- * The primary public key. This should be an ElGamal public key.
- * @param ciphertext
- * The ciphertext. This should be the output from ElGamal
- * encryption.
- * @param plaintext
- * The plaintext. This should be an array of elements of the
- * received group.
- * @param witness
- * The witness. This should be an Exponent of the received group.
- * @param group
- * The mathematical group. This should be a Zp subgroup.
- * @param progressCallbackOrPreComputedValues
- * Progress callback function or pre-computed values (optional).
- * @param progressPercentMinCheckInterval
- * Progress percentage minimum check interval, if the previous
- * parameter is a progressCallback function (optional).
- *
- * @returns The plaintext proof.
- */
- box.proofs.service.createPlaintextProof = function(
- publicKey, ciphertext, plaintext, witness, group,
- progressCallbackOrPreComputedValues, progressPercentMinCheckInterval) {
- var proofGenerator =
- proofsFactory.createPlaintextProofGenerator(publicKey, group);
- if (!progressCallbackOrPreComputedValues) {
- return proofGenerator.generate(ciphertext, plaintext, witness);
- } else if (isPreComputedValues(progressCallbackOrPreComputedValues)) {
- var preComputedValues = progressCallbackOrPreComputedValues;
- return proofGenerator.generate(
- ciphertext, plaintext, witness, preComputedValues);
- } else {
- var progressCallback = progressCallbackOrPreComputedValues;
- return proofGenerator
- .initProgressMeter(progressCallback, progressPercentMinCheckInterval)
- .generate(ciphertext, plaintext, witness);
- }
- };
- /**
- * Creates a simple plaintext equality Proof.
- *
- * @param primaryCiphertext
- * The primary ciphertext. This should be the output from ElGamal
- * encryption.
- * @param primaryPublicKey
- * The primary public key. This should be an ElGamal public key.
- * @param witness
- * The witness of the proof. This should be an Exponent of the
- * received group.
- * @param secondaryCiphertext
- * The secondary ciphertext. This should be the output from
- * ElGamal encryption.
- * @param secondaryPublicKey
- * The secondary public key. This should be an ElGamal public
- * key.
- * @param group
- * The mathematical group. This should be a Zp subgroup.
- * @param progressCallbackOrPreComputedValues
- * Progress callback function or pre-computed values (optional).
- * @param progressPercentMinCheckInterval
- * Progress percentage minimum check interval, if the previous
- * parameter is a progressCallback function (optional).
- *
- * @returns The simple plaintext equality proof.
- */
- box.proofs.service.createSimplePlaintextEqualityProof = function(
- primaryCiphertext, primaryPublicKey, witness, secondaryCiphertext,
- secondaryPublicKey, group, progressCallbackOrPreComputedValues,
- progressPercentMinCheckInterval) {
- var proofGenerator =
- proofsFactory.createSimplePlaintextEqualityProofGenerator(
- primaryPublicKey, secondaryPublicKey, group);
- if (!progressCallbackOrPreComputedValues) {
- return proofGenerator.generate(
- primaryCiphertext, secondaryCiphertext, witness);
- } else if (isPreComputedValues(progressCallbackOrPreComputedValues)) {
- var preComputedValues = progressCallbackOrPreComputedValues;
- return proofGenerator.generate(
- primaryCiphertext, secondaryCiphertext, witness, preComputedValues);
- } else {
- var progressCallback = progressCallbackOrPreComputedValues;
- return proofGenerator
- .initProgressMeter(progressCallback, progressPercentMinCheckInterval)
- .generate(primaryCiphertext, secondaryCiphertext, witness);
- }
- };
- /**
- * Creates a plaintext equality proof.
- *
- * @param primaryCiphertext
- * The primary ciphertext. This should be the output from ElGamal
- * encryption.
- * @param primaryPublicKey
- * The primary public key. This should be an ElGamal public key.
- * @param primaryWitness
- * The primary witness of the proof. This should be an Exponent
- * of the received group.
- * @param secondaryCiphertext
- * The secondary ciphertext. This should be the output from
- * ElGamal encryption.
- * @param secondaryPublicKey
- * The secondary public key. This should be an ElGamal public
- * key.
- * @param secondaryWitness
- * The secondary witness of the proof. This should be an Exponent
- * of the received group.
- * @param group
- * The mathematical group. This should be a Zp subgroup.
- * @param progressCallbackOrPreComputedValues
- * Progress callback function or pre-computed values (optional).
- * @param progressPercentMinCheckInterval
- * Progress percentage minimum check interval, if the previous
- * parameter is a progressCallback function (optional).
- *
- * @returns The plaintext equality proof.
- */
- box.proofs.service.createPlaintextEqualityProof = function(
- primaryCiphertext, primaryPublicKey, primaryWitness, secondaryCiphertext,
- secondaryPublicKey, secondaryWitness, group,
- progressCallbackOrPreComputedValues, progressPercentMinCheckInterval) {
- var proofGenerator = proofsFactory.createPlaintextEqualityProofGenerator(
- primaryPublicKey, secondaryPublicKey, group);
- if (!progressCallbackOrPreComputedValues) {
- return proofGenerator.generate(
- primaryCiphertext, primaryWitness, secondaryCiphertext,
- secondaryWitness);
- } else if (isPreComputedValues(progressCallbackOrPreComputedValues)) {
- var preComputedValues = progressCallbackOrPreComputedValues;
- return proofGenerator.generate(
- primaryCiphertext, primaryWitness, secondaryCiphertext,
- secondaryWitness, preComputedValues);
- } else {
- var progressCallback = progressCallbackOrPreComputedValues;
- return proofGenerator
- .initProgressMeter(progressCallback, progressPercentMinCheckInterval)
- .generate(
- primaryCiphertext, primaryWitness, secondaryCiphertext,
- secondaryWitness);
- }
- };
- /**
- * Creates a plaintext exponent equality proof.
- *
- * @param ciphertext
- * The ciphertext. This should be the output from ElGamal
- * encryption.
- * @param plaintext
- * The plaintext. It should be an array of members of the
- * received group.
- * @param primaryWitness
- * The primary witness. This should be an Exponent of the
- * received group.
- * @param secondaryWitness
- * The secondary witness. This should be an Exponent of the
- * received group.
- * @param group
- * The mathematical group. This should be a Zp subgroup.
- * @param progressCallbackOrPreComputedValues
- * Progress callback function or pre-computed values (optional).
- * @param progressPercentMinCheckInterval
- * Progress percentage minimum check interval, if the previous
- * parameter is a progressCallback function (optional).
- *
- * @returns The plaintext exponent equality proof.
- */
- box.proofs.service.createPlaintextExponentEqualityProof = function(
- ciphertext, plaintext, primaryWitness, secondaryWitness, group,
- progressCallbackOrPreComputedValues, progressPercentMinCheckInterval) {
- var proofGenerator =
- proofsFactory.createPlaintextExponentEqualityProofGenerator(
- plaintext, group);
- if (!progressCallbackOrPreComputedValues) {
- return proofGenerator.generate(
- ciphertext, primaryWitness, secondaryWitness);
- } else if (isPreComputedValues(progressCallbackOrPreComputedValues)) {
- var preComputedValues = progressCallbackOrPreComputedValues;
- return proofGenerator.generate(
- ciphertext, primaryWitness, secondaryWitness, preComputedValues);
- } else {
- var progressCallback = progressCallbackOrPreComputedValues;
- return proofGenerator
- .initProgressMeter(progressCallback, progressPercentMinCheckInterval)
- .generate(ciphertext, primaryWitness, secondaryWitness);
- }
- };
- /**
- * Creates an OR-proof.
- *
- * @param publicKey
- * The public key. This should be an ElGamal public key.
- * @param ciphertext
- * The ciphertext of the mathematical group element that was
- * encrypted. This should be the output from ElGamal encryption.
- * @param witness
- * The witness used to generate the ciphertext. This should be an
- * Exponent of the received group.
- * @param elements
- * The mathematical group elements, one of which was encrypted.
- * This should be an array of elements of the received group.
- * @param index
- * The index of the mathematical group element that was
- * encrypted. This should be an integer.
- * @param data
- * Any extra data to use for the proof generation. This should be
- * a String. NOTE: If this parameter is null, then data will be set
- * to empty string.
- * @param group
- * The mathematical group. This should be a Zp subgroup.
- * @param progressCallbackOrPreComputedValues
- * Progress callback function or pre-computed values (optional).
- * @param progressPercentMinCheckInterval
- * Progress percentage minimum check interval, if the previous
- * parameter is a progressCallback function (optional).
- *
- * @returns The OR-proof.
- */
- box.proofs.service.createORProof = function(
- publicKey, ciphertext, witness, elements, index, data, group,
- progressCallbackOrPreComputedValues, progressPercentMinCheckInterval) {
- var proofGenerator =
- proofsFactory.createORProofGenerator(publicKey, elements.length, group);
- if (!progressCallbackOrPreComputedValues) {
- return proofGenerator.generate(
- ciphertext, witness, elements, index, data);
- } else if (isPreComputedValues(progressCallbackOrPreComputedValues)) {
- var preComputedValues = progressCallbackOrPreComputedValues;
- return proofGenerator.generate(
- ciphertext, witness, elements, index, data, preComputedValues);
- } else {
- var progressCallback = progressCallbackOrPreComputedValues;
- return proofGenerator
- .initProgressMeter(progressCallback, progressPercentMinCheckInterval)
- .generate(ciphertext, witness, elements, index, data);
- }
- };
- /**
- * Verifies a Schnorr proof.
- *
- * @param exponentiatedElement
- * The exponentiated element. This should be an element of the
- * specified group.
- * @param voterID
- * The voter IS. This should be a string.
- * @param electionID
- * The election event ID. This should be a string.
- * @param proof
- * The proof that is to be verified.
- * @param group
- * The mathematical group. This should be a Zp subgroup.
- * @param progressCallback
- * Progress callback function (optional).
- * @param progressPercentMinCheckInterval
- * Progress percentage minimum check interval (optional).
- *
- * @returns true if the Schnorr Proof can be verified, false otherwise.
- */
- box.proofs.service.verifySchnorrProof = function(
- element, voterID, electionEventID, proof, group, progressCallback,
- progressPercentMinCheckInterval) {
- return proofsFactory
- .createSchnorrProofVerifier(
- element, voterID, electionEventID, proof, group)
- .initProgressMeter(progressCallback, progressPercentMinCheckInterval)
- .verify();
- };
- /**
- * Verifies an exponentiation proof.
- *
- * @param exponentiatedElements
- * The exponentiated elements. These should consist of the
- * following base elements, exponentiated with the specified
- * exponent.
- * @param baseElements
- * The base elements used for the exponentiations. These should
- * correspond to elements of the specified group.
- * @param proof
- * The proof that is to be verified.
- * @param group
- * The mathematical group. This should be a Zp subgroup.
- * @param progressCallback
- * Progress callback function (optional).
- * @param progressPercentMinCheckInterval
- * Progress percentage minimum check interval (optional).
- *
- * @returns true if the exponentiation proof can be verified, false
- * otherwise.
- */
- box.proofs.service.verifyExponentiationProof = function(
- exponentiatedElements, baseElements, proof, group, progressCallback,
- progressPercentMinCheckInterval) {
- return proofsFactory
- .createExponentiationProofVerifier(
- exponentiatedElements, baseElements, proof, group)
- .initProgressMeter(progressCallback, progressPercentMinCheckInterval)
- .verify();
- };
- /**
- * Verifies a plaintext proof.
- *
- * @param publicKey
- * The primary public key. This should be an ElGamal public key.
- * @param ciphertext
- * The ciphertext. This should be the output from ElGamal
- * encryption.
- * @param plaintext
- * The plaintext. This should be an array of elements of the
- * received group.
- * @param proof
- * The proof that is to be verified.
- * @param group
- * The mathematical group. This should be a Zp subgroup.
- * @param progressCallback
- * Progress callback function (optional).
- * @param progressPercentMinCheckInterval
- * Progress percentage minimum check interval (optional).
- * @returns true if the plaintext proof can be verified, false otherwise.
- */
- box.proofs.service.verifyPlaintextProof = function(
- publicKey, ciphertext, plaintext, proof, group, progressCallback,
- progressPercentMinCheckInterval) {
- return proofsFactory.createPlaintextProofVerifier(publicKey, group)
- .initProgressMeter(progressCallback, progressPercentMinCheckInterval)
- .verify(ciphertext, plaintext, proof);
- };
- /**
- * Verifies a simple plaintext equality proof.
- *
- * @param primaryCiphertext
- * The primary ciphertext. This should be the output from ElGamal
- * encryption.
- * @param primaryPublicKey
- * The primary public key. This should be an ElGamal public key.
- * @param secondaryCiphertext
- * The secondary ciphertext. This should be the output from
- * ElGamal encryption.
- * @param secondaryPublicKey
- * The secondary public key. This should be an ElGamal public
- * key.
- * @param proof
- * The proof that is to be verified.
- * @param group
- * The mathematical group. This should be a Zp subgroup.
- * @param progressCallback
- * Progress callback function (optional).
- * @param progressPercentMinCheckInterval
- * Progress percentage minimum check interval (optional).
- *
- * @returns true if the simple plaintext equality proof can be verified,
- * false otherwise.
- */
- box.proofs.service.verifySimplePlaintextEqualityProof = function(
- primaryCiphertext, primaryPublicKey, secondaryCiphertext,
- secondaryPublicKey, proof, group, progressCallback,
- progressPercentMinCheckInterval) {
- return proofsFactory
- .createSimplePlaintextEqualityProofVerifier(
- primaryCiphertext, primaryPublicKey, secondaryCiphertext,
- secondaryPublicKey, proof, group)
- .initProgressMeter(progressCallback, progressPercentMinCheckInterval)
- .verify();
- };
- /**
- * Verifies a plaintext equality proof.
- *
- * @param primaryCiphertext
- * The primary ciphertext. This should be the output from ElGamal
- * encryption.
- * @param primaryPublicKey
- * The primary public key. This should be an ElGamal public key.
- * @param secondaryCiphertext
- * The secondary ciphertext. This should be the output from
- * ElGamal encryption.
- * @param secondaryPublicKey
- * The secondary public key. This should be an ElGamal public
- * key.
- * @param proof
- * The proof that is to be verified.
- * @param group
- * The mathematical group. This should be a Zp subgroup.
- * @param progressCallback
- * Progress callback function (optional).
- * @param progressPercentMinCheckInterval
- * Progress percentage minimum check interval (optional).
- *
- * @returns true if the plaintext equality proof can be verified, false
- * otherwise.
- */
- box.proofs.service.verifyPlaintextEqualityProof = function(
- primaryCiphertext, primaryPublicKey, secondaryCiphertext,
- secondaryPublicKey, proof, group, progressCallback,
- progressPercentMinCheckInterval) {
- return proofsFactory
- .createPlaintextEqualityProofVerifier(
- primaryCiphertext, primaryPublicKey, secondaryCiphertext,
- secondaryPublicKey, proof, group)
- .initProgressMeter(progressCallback, progressPercentMinCheckInterval)
- .verify();
- };
- /**
- * Verifies a plaintext exponent equality proof.
- *
- * @param ciphertext
- * The ciphertext. This should be the output from ElGamal
- * encryption.
- * @param baseElements
- * The array of base elements. All of these elements should be
- * members of the received group.
- * @param witness1
- * The primary witness. This should be an Exponent.
- * @param witness2
- * The secondary witness. This should be an Exponent.
- * @param proof
- * The proof that is to be verified.
- * @param group
- * The mathematical group. This should be a Zp subgroup.
- * @param progressCallback
- * Progress callback function (optional).
- * @param progressPercentMinCheckInterval
- * Progress percentage minimum check interval (optional).
- *
- * @returns true if the plaintext exponent equality proof can be verified,
- * false otherwise.
- */
- box.proofs.service.verifyPlaintextExponentEqualityProof = function(
- ciphertext, baseElements, proof, group, progressCallback,
- progressPercentMinCheckInterval) {
- return proofsFactory
- .createPlaintextExponentEqualityProofVerifier(
- ciphertext, baseElements, proof, group)
- .initProgressMeter(progressCallback, progressPercentMinCheckInterval)
- .verify();
- };
- /**
- * Verifies an OR-proof.
- *
- * @param publicKey
- * The public key. This should be an ElGamal public key.
- * @param ciphertext
- * The ciphertext of the mathematical group element that was
- * encrypted. This should be the output from ElGamal encryption.
- * @param elements
- * The mathematical group elements, one of which was encrypted.
- * This should be an array of elements of the received group.
- * @param data
- * Any extra data used for the proof generation. This should be a
- * String. NOTE: If this parameter is null, then data will be set
- * to empty string.
- * @param proof
- * The proof that is to be verified.
- * @param group
- * The mathematical group. This should be a Zp subgroup.
- * @param progressCallback
- * Progress callback function (optional).
- * @param progressPercentMinCheckInterval
- * Progress percentage minimum check interval (optional).
- * @returns true if the OR-proof can be verified, false otherwise.
- */
- box.proofs.service.verifyORProof = function(
- publicKey, ciphertext, elements, data, proof, group, progressCallback,
- progressPercentMinCheckInterval) {
- return proofsFactory
- .createORProofVerifier(publicKey, elements.length, group)
- .initProgressMeter(progressCallback, progressPercentMinCheckInterval)
- .verify(ciphertext, elements, data, proof);
- };
- /**
- * Pre-computes a Schnorr proof. IMPORTANT: The same pre-computed values
- * must not be used twice.
- *
- * @param voterID
- * The voter ID. This should be a string.
- * @param electionID
- * The election event ID. This should be a string.
- * @param group
- * The mathematical group. This should be a Zp subgroup.
- * @param progressCallback
- * Progress callback function or pre-computed values (optional).
- * @param progressPercentMinCheckInterval
- * Progress percentage minimum check interval, if the previous
- * parameter is a progressCallback function (optional).
- *
- * @returns The Schnorr proof pre-computed values.
- */
- box.proofs.service.preComputeSchnorrProof = function(
- voterID, electionID, group, progressCallbackOrPreComputedValues,
- progressPercentMinCheckInterval) {
- return proofsFactory.createSchnorrProofGenerator(voterID, electionID, group)
- .initProgressMeter(
- progressCallbackOrPreComputedValues,
- progressPercentMinCheckInterval)
- .preCompute();
- };
- /**
- * Pre-computes an exponentiation proof. IMPORTANT: The same pre-computed
- * values must not be used twice.
- *
- * @param baseElements
- * The base elements used for the exponentiations. These should
- * correspond to elements of the specified group.
- * @param group
- * The mathematical group. This should be a Zp subgroup.
- * @param progressCallback
- * Progress callback function or pre-computed values (optional).
- * @param progressPercentMinCheckInterval
- * Progress percentage minimum check interval, if the previous
- * parameter is a progressCallback function (optional).
- *
- * @returns The exponentiation proof pre-computed values.
- */
- box.proofs.service.preComputeExponentiationProof = function(
- baseElements, group, progressCallbackOrPreComputedValues,
- progressPercentMinCheckInterval) {
- return proofsFactory.createExponentiationProofGenerator(baseElements, group)
- .initProgressMeter(
- progressCallbackOrPreComputedValues,
- progressPercentMinCheckInterval)
- .preCompute();
- };
- /**
- * Pre-computes a plaintext proof. IMPORTANT: The same pre-computed values
- * must not be used twice.
- *
- * @param publicKey
- * The primary public key. This should be an ElGamal public key.
- * @param group
- * The mathematical group. This should be a Zp subgroup.
- * @param progressCallback
- * Progress callback function or pre-computed values (optional).
- * @param progressPercentMinCheckInterval
- * Progress percentage minimum check interval, if the previous
- * parameter is a progressCallback function (optional).
- *
- * @returns The plaintext proof pre-computed values.
- */
- box.proofs.service.preComputePlaintextProof = function(
- publicKey, group, progressCallbackOrPreComputedValues,
- progressPercentMinCheckInterval) {
- return proofsFactory.createPlaintextProofGenerator(publicKey, group)
- .initProgressMeter(
- progressCallbackOrPreComputedValues,
- progressPercentMinCheckInterval)
- .preCompute();
- };
- /**
- * Pre-computes values for a simple plaintext equality proof. IMPORTANT: The
- * same pre-computed values must not be used twice.
- *
- * @param primaryPublicKey
- * The primary public key. This should be an ElGamal public key.
- * @param secondaryPublicKey
- * The secondary public key. This should be an ElGamal public
- * key.
- * @param group
- * The mathematical group. This should be a Zp subgroup.
- * @param progressCallback
- * Progress callback function or pre-computed values (optional).
- * @param progressPercentMinCheckInterval
- * Progress percentage minimum check interval, if the previous
- * parameter is a progressCallback function (optional).
- *
- * @returns The simple plaintext equality proof pre-computed values.
- */
- box.proofs.service.preComputeSimplePlaintextEqualityProof = function(
- primaryPublicKey, secondaryPublicKey, group,
- progressCallbackOrPreComputedValues, progressPercentMinCheckInterval) {
- return proofsFactory
- .createSimplePlaintextEqualityProofGenerator(
- primaryPublicKey, secondaryPublicKey, group)
- .initProgressMeter(
- progressCallbackOrPreComputedValues,
- progressPercentMinCheckInterval)
- .preCompute();
- };
- /**
- * Pre-computes values for a plaintext equality proof. IMPORTANT: The same
- * pre-computed values must not be used twice.
- *
- * @param primaryPublicKey
- * The primary public key. This should be an ElGamal public key.
- * @param secondaryPublicKey
- * The secondary public key. This should be an ElGamal public
- * key.
- * @param group
- * The mathematical group. This should be a Zp subgroup.
- * @param progressCallback
- * Progress callback function or pre-computed values (optional).
- * @param progressPercentMinCheckInterval
- * Progress percentage minimum check interval, if the previous
- * parameter is a progressCallback function (optional).
- *
- * @returns The plaintext equality proof pre-computed values.
- */
- box.proofs.service.preComputePlaintextEqualityProof = function(
- primaryPublicKey, secondaryPublicKey, group,
- progressCallbackOrPreComputedValues, progressPercentMinCheckInterval) {
- return proofsFactory
- .createPlaintextEqualityProofGenerator(
- primaryPublicKey, secondaryPublicKey, group)
- .initProgressMeter(
- progressCallbackOrPreComputedValues,
- progressPercentMinCheckInterval)
- .preCompute();
- };
- /**
- * Returns pre-computed values for a plaintext exponent equality proof.
- * IMPORTANT: The same pre-computed values must not be used twice.
- *
- * @param plaintext
- * The plaintext. It should be an array of members of the
- * received group.
- * @param group
- * The mathematical group. This should be a Zp subgroup.
- * @param progressCallback
- * Progress callback function or pre-computed values (optional).
- * @param progressPercentMinCheckInterval
- * Progress percentage minimum check interval, if the previous
- * parameter is a progressCallback function (optional).
- *
- * @returns The plaintext exponent equality proof pre-computed values.
- */
- box.proofs.service.preComputePlaintextExponentEqualityProof = function(
- plaintext, group, progressCallbackOrPreComputedValues,
- progressPercentMinCheckInterval) {
- return proofsFactory
- .createPlaintextExponentEqualityProofGenerator(plaintext, group)
- .initProgressMeter(
- progressCallbackOrPreComputedValues,
- progressPercentMinCheckInterval)
- .preCompute();
- };
- /**
- * Pre-computes an OR-proof. IMPORTANT: The same pre-computed values must
- * not be used twice.
- *
- * @param publicKey
- * The public key. This should be an ElGamal public key.
- * @param numElements
- * The number of elements belonging to the received mathematical
- * group that will be used for the proof, one of which will be
- * encrypted.
- * @param group
- * The mathematical group. This should be a Zp subgroup.
- * @param progressCallback
- * Progress callback function or pre-computed values (optional).
- * @param progressPercentMinCheckInterval
- * Progress percentage minimum check interval, if the previous
- * parameter is a progressCallback function (optional).
- *
- * @returns The OR-proof pre-computed values.
- */
- box.proofs.service.preComputeORProof = function(
- publicKey, numElements, group, progressCallbackOrPreComputedValues,
- progressPercentMinCheckInterval) {
- return proofsFactory.createORProofGenerator(publicKey, numElements, group)
- .initProgressMeter(
- progressCallbackOrPreComputedValues,
- progressPercentMinCheckInterval)
- .preCompute();
- };
- /**
- * Utility method that checks if the argument is instance of type
- * ProofPreComputedValues.
- *
- * @param values
- * argument to check.
- * @returns {boolean} true if values is instance of ProofPreComputedValues.
- */
- function isPreComputedValues(values) {
- return !!(values) && values.className === 'ProofPreComputedValues';
- }
- };
|