-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #147 from zk-passport/csca-sha1-rsapss
- Loading branch information
Showing
72 changed files
with
3,591 additions
and
1,686 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: Proof of Passport CI/CD | ||
on: | ||
push: | ||
branches: | ||
- dev | ||
- main | ||
pull_request: | ||
branches: | ||
- dev | ||
- main | ||
jobs: | ||
run_circuit_tests: | ||
runs-on: ubuntu-latest | ||
environment: development | ||
steps: | ||
- uses: actions/checkout@v3 | ||
|
||
# Circom installation from https://github.com/erhant/circomkit/blob/main/.github/workflows/tests.yml | ||
- name: Install dependencies | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install --yes \ | ||
build-essential \ | ||
libgmp-dev \ | ||
libsodium-dev \ | ||
nasm \ | ||
nlohmann-json3-dev | ||
- name: Set Node.js 18.x | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: 18 | ||
|
||
- name: Setup Rust | ||
uses: dtolnay/rust-toolchain@stable | ||
|
||
- name: Download Circom Binary v2.1.8 | ||
run: | | ||
wget -qO /home/runner/work/circom https://github.com/iden3/circom/releases/download/v2.1.8/circom-linux-amd64 | ||
chmod +x /home/runner/work/circom | ||
sudo mv /home/runner/work/circom /bin/circom | ||
- name: Print Circom version | ||
run: circom --version | ||
|
||
- name: Install Yarn dependencies | ||
working-directory: ./circuits | ||
run: yarn install-circuits --immutable | ||
|
||
- name: Run Tests | ||
working-directory: ./circuits | ||
run: yarn test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
pragma circom 2.1.5; | ||
include "circomlib/circuits/bitify.circom"; | ||
include "circomlib/circuits/poseidon.circom"; | ||
include "circomlib/circuits/comparators.circom"; | ||
include "binary-merkle-root.circom"; | ||
include "../utils/splitBytesToWords.circom"; | ||
include "../utils/splitSignalsToWords.circom"; | ||
include "../utils/Sha1Bytes.circom"; | ||
include "../utils/leafHasher.circom"; | ||
include "../utils/rsaPkcs1.circom"; | ||
|
||
template DSC_SHA1_RSA(max_cert_bytes, n_dsc, k_dsc, n_csca, k_csca, dsc_mod_len, nLevels ) { | ||
signal input raw_dsc_cert[max_cert_bytes]; | ||
signal input raw_dsc_cert_padded_bytes; | ||
signal input csca_modulus[k_csca]; | ||
signal input dsc_signature[k_csca]; | ||
signal input dsc_modulus[k_dsc]; | ||
signal input start_index; | ||
signal input secret; | ||
|
||
signal input merkle_root; | ||
signal input path[nLevels]; | ||
signal input siblings[nLevels]; | ||
|
||
signal output blinded_dsc_commitment; | ||
|
||
//verify the leaf | ||
component leafHasher = LeafHasher(n_csca,k_csca); | ||
leafHasher.in <== csca_modulus; | ||
signal leaf <== leafHasher.out; | ||
|
||
|
||
signal computed_merkle_root <== BinaryMerkleRoot(nLevels)(leaf, nLevels, path, siblings); | ||
merkle_root === computed_merkle_root; | ||
|
||
// variables verification | ||
assert(max_cert_bytes % 64 == 0); | ||
assert(n_csca * k_csca > max_cert_bytes); | ||
assert(n_csca <= (255 \ 2)); | ||
|
||
// hash raw TBS certificate | ||
signal sha[160] <== Sha1Bytes(max_cert_bytes)(raw_dsc_cert, raw_dsc_cert_padded_bytes); | ||
component sstw_1 = SplitSignalsToWords(1,160, n_csca, k_csca); | ||
for (var i = 0; i < 160; i++) { | ||
sstw_1.in[i] <== sha[159 - i]; | ||
} | ||
|
||
//verify RSA dsc_signature | ||
component rsa = RSAVerify65537(n_csca, k_csca); | ||
for (var i = 0; i < k_csca; i++) { | ||
rsa.base_message[i] <== sstw_1.out[i]; | ||
rsa.modulus[i] <== csca_modulus[i]; | ||
rsa.signature[i] <== dsc_signature[i]; | ||
} | ||
|
||
// verify DSC csca_modulus | ||
component shiftLeft = VarShiftLeft(max_cert_bytes, dsc_mod_len); | ||
shiftLeft.in <== raw_dsc_cert; | ||
shiftLeft.shift <== start_index; | ||
component spbt_1 = SplitBytesToWords(dsc_mod_len, n_dsc, k_dsc); | ||
spbt_1.in <== shiftLeft.out; | ||
for (var i = 0; i < k_dsc; i++) { | ||
dsc_modulus[i] === spbt_1.out[i]; | ||
} | ||
// generate blinded commitment | ||
component sstw_2 = SplitSignalsToWords(n_dsc,k_dsc, 230, 9); | ||
sstw_2.in <== dsc_modulus; | ||
component poseidon = Poseidon(10); | ||
poseidon.inputs[0] <== secret; | ||
for (var i = 0; i < 9; i++) { | ||
poseidon.inputs[i+1] <== sstw_2.out[i]; | ||
} | ||
blinded_dsc_commitment <== poseidon.out; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.