readme, benchmarks, fix verification
This commit is contained in:
@ -4,6 +4,25 @@ import { gcd, mod_exp } from "./math.js";
|
||||
const PAILLIER = 0;
|
||||
const JURIK = 1;
|
||||
|
||||
function RSTransform(g, a, p) {
|
||||
let plainText = p.toString(16);
|
||||
if (plainText.length % 2 !== 0) {
|
||||
plainText = "0" + plainText;
|
||||
}
|
||||
|
||||
let aStr = a.toString(16);
|
||||
if (aStr.length % 2 !== 0) {
|
||||
aStr = "0" + aStr;
|
||||
}
|
||||
|
||||
let hasher = new jsSHA("SHAKE256", "HEX");
|
||||
hasher.update(g.toString(16));
|
||||
hasher.update(plainText);
|
||||
hasher.update(aStr);
|
||||
|
||||
return BigInt("0x" + hasher.getHash("HEX", { outputLen: 2048 }));
|
||||
}
|
||||
|
||||
class Ciphertext {
|
||||
constructor(key, plainText, r, set) {
|
||||
if (set !== undefined) {
|
||||
@ -93,28 +112,12 @@ class Ciphertext {
|
||||
}
|
||||
|
||||
let a = mod_exp(rp, this.pubKey.n, this.pubKey.n2);
|
||||
let hasher = new jsSHA("SHAKE256", "HEX");
|
||||
|
||||
let plainText = this.plainText.toString(16);
|
||||
if (plainText.length % 2 !== 0) {
|
||||
plainText = "0" + plainText;
|
||||
}
|
||||
|
||||
let aStr = a.toString(16);
|
||||
if (aStr.length % 2 !== 0) {
|
||||
aStr = "0" + aStr;
|
||||
}
|
||||
|
||||
hasher.update(this.pubKey.g.toString(16));
|
||||
hasher.update(plainText);
|
||||
hasher.update(aStr);
|
||||
|
||||
let challenge = BigInt("0x" + hasher.getHash("HEX", { outputLen: 2048 }));
|
||||
let challenge = RSTransform(this.pubKey.g, a, this.plainText);
|
||||
|
||||
return {
|
||||
plainText: "0x" + this.plainText.toString(16),
|
||||
a: "0x" + a.toString(16),
|
||||
challenge: "0x" + challenge.toString(16),
|
||||
proof:
|
||||
"0x" +
|
||||
(
|
||||
@ -195,11 +198,17 @@ export class ReadOnlyCiphertext {
|
||||
}
|
||||
|
||||
verifyNI(statement) {
|
||||
let challenge = RSTransform(
|
||||
this.pubKey.g,
|
||||
BigInt(statement.a),
|
||||
BigInt(statement.plainText)
|
||||
);
|
||||
|
||||
let verifier = new ValueProofSessionVerifier(
|
||||
this,
|
||||
BigInt(statement.plainText),
|
||||
BigInt(statement.a),
|
||||
BigInt(statement.challenge)
|
||||
challenge
|
||||
);
|
||||
|
||||
if (verifier.verify(BigInt(statement.proof))) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { mod_exp } from "./math.js";
|
||||
|
||||
export const KEY_SIZE = 512;
|
||||
export const KEY_SIZE = 2048;
|
||||
|
||||
export function cryptoRandom(bits) {
|
||||
if (bits === undefined) {
|
||||
|
Reference in New Issue
Block a user