mirror of
https://github.com/selfxyz/self.git
synced 2026-04-05 03:00:53 -04:00
comment splitBytesToWords circuit
This commit is contained in:
@@ -1,67 +0,0 @@
|
||||
pragma circom 2.1.5;
|
||||
|
||||
include "circomlib/circuits/bitify.circom";
|
||||
include "circomlib/circuits/poseidon.circom";
|
||||
include "@zk-email/circuits/helpers/rsa.circom";
|
||||
include "@zk-email/circuits/helpers/extract.circom";
|
||||
include "@zk-email/circuits/helpers/sha.circom";
|
||||
include "./utils/splitBytesToWords.circom";
|
||||
|
||||
template DSC(max_cert_bytes, n, k,l) {
|
||||
signal input raw_dsc_cert[max_cert_bytes];
|
||||
signal input message_padded_bytes;
|
||||
signal input modulus[k];
|
||||
signal input signature[k];
|
||||
signal input dsc_modulus[k];
|
||||
signal input start_index;
|
||||
|
||||
// variables verification
|
||||
assert(max_cert_bytes % 64 == 0);
|
||||
assert(n * k > 2048);
|
||||
assert(n < (255 \ 2));
|
||||
|
||||
// hash raw TBS certificate
|
||||
signal sha[256] <== Sha256Bytes(max_cert_bytes)(raw_dsc_cert, message_padded_bytes);
|
||||
|
||||
var msg_len = (256+n)\n;
|
||||
component base_msg[msg_len];
|
||||
for (var i = 0; i < msg_len; i++) {
|
||||
base_msg[i] = Bits2Num(n);
|
||||
}
|
||||
for (var i = 0; i < 256; i++) {
|
||||
base_msg[i\n].in[i%n] <== sha[255 - i];
|
||||
}
|
||||
for (var i = 256; i < n*msg_len; i++) {
|
||||
base_msg[i\n].in[i%n] <== 0;
|
||||
}
|
||||
|
||||
// verify RSA signature
|
||||
component rsa = RSAVerify65537(n, k);
|
||||
for (var i = 0; i < msg_len; i++) {
|
||||
rsa.base_message[i] <== base_msg[i].out;
|
||||
}
|
||||
for (var i = msg_len; i < k; i++) {
|
||||
rsa.base_message[i] <== 0;
|
||||
}
|
||||
for (var i = 0; i < k; i++) {
|
||||
rsa.modulus[i] <== modulus[i];
|
||||
}
|
||||
for (var i = 0; i < k; i++) {
|
||||
rsa.signature[i] <== signature[i];
|
||||
}
|
||||
|
||||
// verify DSC modulus
|
||||
component shiftLeft = VarShiftLeft(2048, 256);
|
||||
shiftLeft.in <== raw_dsc_cert;
|
||||
shiftLeft.shift <== start_index;
|
||||
|
||||
component splitBytesToWords = SplitBytesToWords(256, 121, 17);
|
||||
splitBytesToWords.in <== shiftLeft.out;
|
||||
for (var i = 0; i < k; i++) {
|
||||
dsc_modulus[i] === splitBytesToWords.out[i];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
component main = DSC(2048, 121, 17, 256);
|
||||
@@ -1,6 +1,15 @@
|
||||
pragma circom 2.1.5;
|
||||
include "circomlib/circuits/bitify.circom";
|
||||
|
||||
/// NOTE: this circuit is unaudited and should not be used in production
|
||||
/// @title SplitBytesToWords
|
||||
/// @notice split an array of bytes into an array of words
|
||||
/// @notice useful for casting a message or modulus before RSA verification
|
||||
/// @param l: number of bytes in the input array
|
||||
/// @param n: number of bits in a word
|
||||
/// @param k: number of words
|
||||
/// @input in: array of bytes
|
||||
/// @output out: array of words
|
||||
template SplitBytesToWords (l,n,k) {
|
||||
signal input in[l];
|
||||
signal output out[k];
|
||||
|
||||
Reference in New Issue
Block a user