Skip to content

Commit

Permalink
add sigAlg in csca leaf
Browse files Browse the repository at this point in the history
  • Loading branch information
remicolin committed Sep 14, 2024
1 parent e07b221 commit f3c904e
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 23 deletions.
9 changes: 5 additions & 4 deletions circuits/circuits/dsc/dsc_rsa_65537_sha1.circom
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include "../utils/Sha1Bytes.circom";
include "../utils/leafHasherLight.circom";
include "../utils/rsaPkcs1.circom";

template DSC_RSA_65537_SHA1(max_cert_bytes, n_dsc, k_dsc, n_csca, k_csca, dsc_mod_len, nLevels ) {
template DSC_RSA_65537_SHA1(max_cert_bytes, n_dsc, k_dsc, n_csca, k_csca, dsc_mod_len, nLevels, signatureAlgorithm) {
signal input raw_dsc_cert[max_cert_bytes];
signal input raw_dsc_cert_padded_bytes;
signal input csca_modulus[k_csca];
Expand All @@ -25,9 +25,10 @@ template DSC_RSA_65537_SHA1(max_cert_bytes, n_dsc, k_dsc, n_csca, k_csca, dsc_mo
signal output blinded_dsc_commitment;

//verify the leaf
component leafHasherLight = LeafHasherLight(k_csca);
leafHasherLight.in <== csca_modulus;
signal leaf <== leafHasherLight.out;
component leafHasher = LeafHasherLightWithSigAlg(k_csca);
leafHasher.sigAlg <== signatureAlgorithm;
leafHasher.in <== csca_modulus;
signal leaf <== leafHasher.out;


signal computed_merkle_root <== BinaryMerkleRoot(nLevels)(leaf, nLevels, path, siblings);
Expand Down
10 changes: 6 additions & 4 deletions circuits/circuits/dsc/dsc_rsa_65537_sha256.circom
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include "../utils/splitBytesToWords.circom";
include "../utils/splitSignalsToWords.circom";
include "../utils/leafHasherLight.circom";

template DSC_RSA_65537_SHA256(max_cert_bytes, n_dsc, k_dsc, n_csca, k_csca, dsc_mod_len, nLevels ) {
template DSC_RSA_65537_SHA256(max_cert_bytes, n_dsc, k_dsc, n_csca, k_csca, dsc_mod_len, nLevels, signatureAlgorithm) {
signal input raw_dsc_cert[max_cert_bytes];
signal input raw_dsc_cert_padded_bytes;
signal input csca_modulus[k_csca];
Expand All @@ -25,9 +25,11 @@ template DSC_RSA_65537_SHA256(max_cert_bytes, n_dsc, k_dsc, n_csca, k_csca, dsc_

signal output blinded_dsc_commitment;

component leafHasherLight = LeafHasherLight(k_csca);
leafHasherLight.in <== csca_modulus;
signal leaf <== leafHasherLight.out;
//verify the leaf
component leafHasher = LeafHasherLightWithSigAlg(k_csca);
leafHasher.sigAlg <== signatureAlgorithm;
leafHasher.in <== csca_modulus;
signal leaf <== leafHasher.out;


signal computed_merkle_root <== BinaryMerkleRoot(nLevels)(leaf, nLevels, path, siblings);
Expand Down
11 changes: 6 additions & 5 deletions circuits/circuits/dsc/dsc_rsapss_65537_sha256.circom
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ include "../utils/splitSignalsToWords.circom";
include "../utils/leafHasherLight.circom";
include "../utils/rsapss/rsapss.circom";

template DSC_RSAPSS_65537_SHA256(max_cert_bytes, n_dsc, k_dsc, n_csca, k_csca, modulus_bits_size, dsc_mod_len, nLevels ) {
template DSC_RSAPSS_65537_SHA256(max_cert_bytes, n_dsc, k_dsc, n_csca, k_csca, modulus_bits_size, dsc_mod_len, nLevels, signatureAlgorithm) {
signal input raw_dsc_cert[max_cert_bytes];
signal input raw_dsc_cert_padded_bytes;
signal input csca_modulus[k_csca];
Expand All @@ -25,10 +25,11 @@ template DSC_RSAPSS_65537_SHA256(max_cert_bytes, n_dsc, k_dsc, n_csca, k_csca, m

signal output blinded_dsc_commitment;

// verify the leaf
component leafHasherLight = LeafHasherLight(k_csca);
leafHasherLight.in <== csca_modulus;
signal leaf <== leafHasherLight.out;
//verify the leaf
component leafHasher = LeafHasherLightWithSigAlg(k_csca);
leafHasher.sigAlg <== signatureAlgorithm;
leafHasher.in <== csca_modulus;
signal leaf <== leafHasher.out;

signal computed_merkle_root <== BinaryMerkleRoot(nLevels)(leaf, nLevels, path, siblings);
merkle_root === computed_merkle_root;
Expand Down
2 changes: 1 addition & 1 deletion circuits/circuits/tests/dsc/dsc_sha1_rsa_2048.circom
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ pragma circom 2.1.6;

include "../../dsc/dsc_rsa_65537_sha1.circom";

component main { public [ merkle_root ] } = DSC_RSA_65537_SHA1(960, 64, 32, 64, 32, 256, 12);
component main { public [ merkle_root ] } = DSC_RSA_65537_SHA1(960, 64, 32, 64, 32, 256, 12, 3);
2 changes: 1 addition & 1 deletion circuits/circuits/tests/dsc/dsc_sha256_rsa_2048.circom
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ pragma circom 2.1.6;

include "../../dsc/dsc_rsa_65537_sha256.circom";

component main { public [ merkle_root ] } = DSC_RSA_65537_SHA256(960, 64, 32, 64, 32, 256, 12);
component main { public [ merkle_root ] } = DSC_RSA_65537_SHA256(960, 64, 32, 64, 32, 256, 12,1);
2 changes: 1 addition & 1 deletion circuits/circuits/tests/dsc/dsc_sha256_rsapss_2048.circom
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ pragma circom 2.1.6;

include "../../dsc/dsc_rsapss_65537_sha256.circom";

component main { public [ merkle_root ] } = DSC_RSAPSS_65537_SHA256(960, 64, 32, 64, 32, 2048, 256, 12);
component main { public [ merkle_root ] } = DSC_RSAPSS_65537_SHA256(960, 64, 32, 64, 32, 2048, 256, 12,4);
6 changes: 3 additions & 3 deletions circuits/tests/dsc/dsc_sha1_rsa_2048.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
mock_dsc_sha1_rsa_2048,
mock_csca_sha1_rsa_2048,
} from '../../../common/src/constants/mockCertificates';
import { k_csca, k_dsc, n_csca, n_dsc } from '../../../common/src/constants/constants';
import { k_dsc, n_dsc } from '../../../common/src/constants/constants';

describe('DSC chain certificate - SHA1 RSA', function () {
this.timeout(0); // Disable timeout
Expand All @@ -23,8 +23,8 @@ describe('DSC chain certificate - SHA1 RSA', function () {
cscaCert,
n_dsc,
k_dsc,
n_csca,
k_csca,
n_dsc,
k_dsc,
max_cert_bytes,
true
);
Expand Down
6 changes: 3 additions & 3 deletions circuits/tests/dsc/dsc_sha256_rsa_2048.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
mock_dsc_sha256_rsa_2048,
mock_csca_sha256_rsa_2048,
} from '../../../common/src/constants/mockCertificates';
import { k_csca, k_dsc, n_csca, n_dsc } from '../../../common/src/constants/constants';
import { k_dsc, n_dsc } from '../../../common/src/constants/constants';

describe('DSC chain certificate - SHA256 RSA', function () {
this.timeout(0); // Disable timeout
Expand All @@ -23,8 +23,8 @@ describe('DSC chain certificate - SHA256 RSA', function () {
cscaCert,
n_dsc,
k_dsc,
n_csca,
k_csca,
n_dsc,
k_dsc,
max_cert_bytes,
true
);
Expand Down
4 changes: 3 additions & 1 deletion common/src/utils/csca.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ export function getCSCAInputs(dscSecret: string, dscCertificate: any, cscaCertif
// console.log('dsc_messagePaddedLen_formatted', dsc_messagePaddedLen_formatted);

// merkle tree saga
const leaf = getLeaf(cscaCertificate, n_csca, k_csca);
const pemContent = forge.pki.certificateToPem(cscaCertificate);
const leaf = getLeaf(pemContent, n_csca, k_csca);
console.log('leaf', leaf);
const [root, proof] = getCSCAModulusProof(leaf, n_csca, k_csca);
const { signatureAlgorithm: signatureAlgorithmName, hashFunction } = getSignatureAlgorithmDetails(signatureAlgorithm);

Expand Down

0 comments on commit f3c904e

Please sign in to comment.