Merge pull request #257 from openpassport-org/perf/rsa-optimization

[WIP] Perf/rsa optimization
This commit is contained in:
turnoffthiscomputer
2024-12-13 11:47:16 +01:00
committed by GitHub
26 changed files with 4794 additions and 2136 deletions

View File

@@ -100,8 +100,10 @@ export const circuitToSelectorMode = {
export const MAX_DATAHASHES_LEN = 320; // max formatted and concatenated datagroup hashes length in bytes
export const n_dsc = 64;
export const n_dsc_3072 = 96;
export const n_dsc_4096 = 64;
export const k_dsc = 32;
export const k_dsc_3072 = 48;
export const k_dsc_4096 = 64;
export const n_csca = 120;
export const k_csca = 35;
export const n_dsc_ecdsa = 43;

View File

@@ -21,7 +21,9 @@ export type SignatureAlgorithm =
| 'ecdsa_sha384_secp384r1_384'
| 'ecdsa_sha256_brainpoolP256r1_256'
| 'rsa_sha256_3_2048'
| 'rsa_sha256_65537_3072';
| 'rsa_sha256_65537_3072'
| 'rsa_sha256_65537_4096'
| 'rsa_sha512_65537_4096';
export type Proof = {
proof: {

View File

@@ -6,8 +6,10 @@ import { SMT } from '@openpassport/zk-kit-smt';
import forge from 'node-forge';
import {
n_dsc,
n_dsc_3072,
n_dsc_4096,
k_dsc,
k_dsc_3072,
k_dsc_4096,
n_dsc_ecdsa,
k_dsc_ecdsa,
n_csca,
@@ -30,7 +32,7 @@ export function formatMrz(mrz: string) {
export function getNAndK(sigAlg: SignatureAlgorithm) {
if (sigAlg === 'rsa_sha256_65537_3072') {
return { n: n_dsc, k: k_dsc_3072 }; // 3072/32 = 96
return { n: n_dsc_3072, k: k_dsc }; // 3072/32 = 96
}
if (sigAlg.startsWith('ecdsa_')) {
@@ -41,6 +43,10 @@ export function getNAndK(sigAlg: SignatureAlgorithm) {
return { n: n_dsc, k: k_dsc }; // 2048/32 = 64
}
if (sigAlg === 'rsa_sha256_65537_4096' || sigAlg === 'rsa_sha512_65537_4096') {
return { n: n_dsc_4096, k: k_dsc_4096 }; // 4096/32 = 128
}
return { n: n_dsc, k: k_dsc }; // 2048/32 = 64
}