readme, benchmarks, fix verification

This commit is contained in:
jude
2023-04-15 14:28:13 +01:00
parent 35dbf321e9
commit ad26788927
8 changed files with 575 additions and 33 deletions

View File

@ -7,7 +7,8 @@
<script src="https://cdn.socket.io/4.5.4/socket.io.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>
<script src="{{ url_for('static', filename='js/sha3.js') }}" type="module"></script>
<script src="{{ url_for('static', filename='js/lz-string.js') }}"></script>
<script src="{{ url_for('static', filename='js/sha3.js') }}"></script>
<script src="{{ url_for('static', filename='js/modules/interface/main.js') }}" type="module"></script>
<script src="{{ url_for('static', filename='js/modules/crypto/main.js') }}" type="module"></script>
</head>
@ -188,6 +189,8 @@
function RSABench() {
console.log("Warming up")
const ROUNDS = 250;
for (let i = 0n; i < 100n; i++) {
window.rsa.pubKey.encrypt(i);
}
@ -195,17 +198,19 @@
console.log("Benching")
performance.mark("rsa-start")
for (let i = 0n; i < 250n; i++) {
for (let i = 0n; i < BigInt(ROUNDS); i++) {
window.rsa.pubKey.encrypt(i);
}
performance.mark("rsa-end")
console.log(`Bench done. Duration: ${performance.measure("rsa-duration", "rsa-start", "rsa-end").duration}`)
console.log(`Bench done. Time per encrypt: ${performance.measure("rsa-duration", "rsa-start", "rsa-end").duration / ROUNDS}`)
}
function PaillierBench() {
console.log("Warming up")
const ROUNDS = 250
for (let i = 0n; i < 100n; i++) {
window.paillier.pubKey.encrypt(i);
}
@ -213,12 +218,162 @@
console.log("Benching")
performance.mark("paillier-start")
for (let i = 0n; i < 250n; i++) {
for (let i = 0n; i < BigInt(ROUNDS); i++) {
window.paillier.pubKey.encrypt(i);
}
performance.mark("paillier-end")
console.log(`Bench done. Duration: ${performance.measure("paillier-duration", "paillier-start", "paillier-end").duration}`)
console.log(`Bench done. Time per encrypt: ${performance.measure("paillier-duration", "paillier-start", "paillier-end").duration / ROUNDS}`)
}
function ZeroProofBench() {
console.log("Warming up")
const cipherText = paillier.pubKey.encrypt(0n)
const ROUNDS = 20;
for (let i = 0; i < 5; i++) {
cipherText.proveNI();
}
console.log("Benching")
performance.mark("paillier-start")
for (let i = 0; i < ROUNDS; i++) {
cipherText.proveNI()
}
performance.mark("paillier-end")
console.log(`Bench done. Time per proof: ${performance.measure("paillier-duration", "paillier-start", "paillier-end").duration / ROUNDS}`)
}
function ZeroProofVerifierBench() {
console.log("Warming up")
const ROUNDS = 20
const cipherText = paillier.pubKey.encrypt(1n)
const readOnly = cipherText.asReadOnlyCiphertext();
const proof = cipherText.proveNI()
for (let i = 0; i < 5; i++) {
readOnly.verifyNI(proof)
}
console.log("Benching")
performance.mark("paillier-start")
for (let i = 0; i < ROUNDS; i++) {
readOnly.verifyNI(proof)
}
performance.mark("paillier-end")
console.log(`Bench done. Time per verification: ${performance.measure("paillier-duration", "paillier-start", "paillier-end").duration / ROUNDS}`)
}
function Protocol4Bench() {
console.log("Warming up")
const regions = {
A: paillier.pubKey.encrypt(0n),
B: paillier.pubKey.encrypt(1n),
C: paillier.pubKey.encrypt(0n),
D: paillier.pubKey.encrypt(0n),
E: paillier.pubKey.encrypt(0n)
}
const ROUNDS = 20;
for (let i = 0; i < 5; i++) {
proveRegions(regions)
}
console.log("Benching")
performance.mark("paillier-start")
for (let i = 0; i < ROUNDS; i++) {
proveRegions(regions)
}
performance.mark("paillier-end")
console.log(`Bench done. Time per proof: ${performance.measure("paillier-duration", "paillier-start", "paillier-end").duration / ROUNDS}`)
}
function Protocol4VerifierBench() {
console.log("Warming up")
const ROUNDS = 20;
const regions = {
A: paillier.pubKey.encrypt(0n),
B: paillier.pubKey.encrypt(1n),
C: paillier.pubKey.encrypt(0n),
D: paillier.pubKey.encrypt(0n),
E: paillier.pubKey.encrypt(0n)
}
let proof = proveRegions(regions)
for (let i = 0; i < 5; i++) {
verifyRegions(proof, paillier.pubKey)
}
console.log("Benching")
performance.mark("paillier-start")
for (let i = 0; i < ROUNDS; i++) {
verifyRegions(proof, paillier.pubKey)
}
performance.mark("paillier-end")
console.log(`Bench done. Time per verification: ${performance.measure("paillier-duration", "paillier-start", "paillier-end").duration / ROUNDS}`)
}
// https://gist.github.com/kawanet/352a2ed1d1656816b2bc
function string_to_buffer(src) {
return (new Uint16Array([].map.call(src, function(c) {
return c.charCodeAt(0)
}))).buffer;
}
function Protocol4Size() {
const regions = {
A: paillier.pubKey.encrypt(0n),
B: paillier.pubKey.encrypt(1n),
C: paillier.pubKey.encrypt(0n),
D: paillier.pubKey.encrypt(0n),
E: paillier.pubKey.encrypt(0n)
}
let ROUNDS = 10;
let size = 0;
let compressedSize = 0;
for (let x = 0; x < ROUNDS; x++) {
let s = JSON.stringify(proveRegions(regions));
size += string_to_buffer(s).byteLength;
compressedSize += LZString.compressToUint8Array(s).length;
}
return {
size: size / ROUNDS,
compressedSize: compressedSize / ROUNDS
};
}
function ZeroProofSize() {
const ROUNDS = 100;
const cipherText = paillier.pubKey.encrypt(0n)
let size = 0;
let compressedSize = 0;
for (let x = 0; x < ROUNDS; x++) {
let s = JSON.stringify(cipherText.proveNI());
size += string_to_buffer(s).byteLength;
compressedSize += LZString.compressToUint8Array(s).length;
}
return {
size: size / ROUNDS,
compressedSize: compressedSize / ROUNDS
};
}
</script>
</body>