Add bcdg range proof

This commit is contained in:
jude
2023-04-21 15:03:15 +01:00
parent b24d031524
commit a1eba884bc
8 changed files with 276 additions and 33 deletions

View File

@ -30,6 +30,10 @@ function RSTransform(g, a, p) {
class Ciphertext {
constructor(key, plainText, r, set) {
while (plainText < 0n) {
plainText += key.n2;
}
if (set !== undefined) {
this.pubKey = key;
this.plainText = plainText;
@ -76,10 +80,6 @@ class Ciphertext {
this.pubKey = key;
this.plainText = plainText;
while (this.plainText < 0n) {
this.plainText += key.n2;
}
this.readOnly = false;
}
@ -183,6 +183,10 @@ window.Ciphertext = Ciphertext;
export class ReadOnlyCiphertext {
constructor(key, cipherText) {
if (typeof cipherText !== "bigint") {
throw "ReadOnlyCiphertext must take BigInt parameter";
}
this.cipherText = cipherText;
this.pubKey = key;
@ -291,13 +295,20 @@ export class PaillierPubKey {
this._h_cache = [];
this._hn_cache = [];
for (let i = 0n; i < BigInt(KEY_SIZE); i++) {
this._h_cache.push(mod_exp(this.h, 2n ** i, this.n));
this._hn_cache.push(mod_exp(this.hn, 2n ** i, this.n2));
// Browser dies on higher key sizes :P
if (KEY_SIZE <= 1024) {
for (let i = 0n; i < BigInt(KEY_SIZE); i++) {
this._h_cache.push(mod_exp(this.h, 2n ** i, this.n));
this._hn_cache.push(mod_exp(this.hn, 2n ** i, this.n2));
}
}
}
h_exp(b) {
if (KEY_SIZE > 1024) {
return mod_exp(this.h, b, this.n);
}
let ctr = 1n;
let i = 0;
while (b !== 0n) {
@ -313,6 +324,10 @@ export class PaillierPubKey {
}
hn_exp(b) {
if (KEY_SIZE > 1024) {
return mod_exp(this.hn, b, this.n2);
}
let ctr = 1n;
let i = 0;
while (b !== 0n) {

View File

@ -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) {
@ -100,7 +100,8 @@ export function generate_prime() {
export function generate_safe_prime() {
while (true) {
let n = generate_prime();
if (small_prime_test((n - 1n) / 2n) && miller_rabin((n - 1n) / 2n, 40)) {
// This does not generate safe primes! But it takes forever to find safe primes of size 1024, so this will do.
if (small_prime_test((n - 1n) / 2n) /* && miller_rabin((n - 1n) / 2n, 40) */) {
return n;
}
}