From 100e8cc53d30efdc61e29b418223c7fba7a92b04 Mon Sep 17 00:00:00 2001 From: Michael Connor Date: Fri, 8 Nov 2024 15:19:27 +0000 Subject: [PATCH] updat e sig gen code for prover.toml of example dir --- example/Prover.toml | 101 ++------------------------------------ example/src/main.nr | 28 ++++++++--- signature_gen/src/main.rs | 54 +++++++++++--------- 3 files changed, 54 insertions(+), 129 deletions(-) diff --git a/example/Prover.toml b/example/Prover.toml index e4e21e1..0eb171e 100644 --- a/example/Prover.toml +++ b/example/Prover.toml @@ -1,97 +1,4 @@ -bn = [ - [ - '0xab88f7a360f88fd0782e4c8f749bb5', - '0xc4df70a6920b9bc866e6f6b2e32c55', - '0x29d74e3996e0669887d453eaa7e722', - '0x5e46b505c0067332878ccc5ce1745b', - '0xa24be548a41edc60c2476388aa79fa', - '0x2f6b76f137bfc5a5ea6ee25378faa5', - '0xad6db5af4521b0d05fc2c462857ef6', - '0x2d2a256b3ceef4946487989942c112', - '0xff87818701decef601d143ad536e75', - '0x506c7dc017de18ebe07d40e5692be1', - '0x56d47f8f1c1fdb3e6d687a876773f9', - '0x2683a784665e910d9017b94dc74b4d', - '0x522b5736042a326f8654c32be14ffe', - '0xe0351aa5ef4567f5f02110a215def2', - '0x46324a74609f07d86e6fffe0c327da', - '0x462ab654703f35cdacbba7c9049941', - '0xfc6ee90b277b12c6946001652ae11a', - '0xf2', - ], - [ - '0xb80936623ea38314b69abad164724b', - '0x9b4b8b47d45823815eec4f81df519c', - '0xe2a236b6e5bd64cf4fa2c421fcef5b', - '0x283dd152b19fbf8392bd77ef112819', - '0x5a7193fa497343fc66fdecacb11673', - '0xad28a77b9a15484a0912469c065e12', - '0x24e2dc41a8e07f30000d1441168080', - '0x3a9c86d7352fcd56c36f479bc6dd0d', - '0x36f95b26a2135734a919589da7df5a', - '0x4b73efbdf065bb6e3e209933c2a81b', - '0x9ab2788e486374b5407a2915dee603', - '0xff78ebdac2927df46eb09670d99286', - '0xc6c73cf9baa421664e3035e6e03204', - '0xa07bacdb33341dcb13233cbae690c0', - '0xf3533ab7e32063aa7bfcde28a30c2c', - '0x1b304126870b2ebc20f00071899dfc', - '0xb5fffe2de7dd683141a659fb879f97', - '0x10d', - ], -] -hash = [ - 44, - 242, - 77, - 186, - 95, - 176, - 163, - 14, - 38, - 232, - 59, - 42, - 197, - 185, - 226, - 158, - 27, - 22, - 30, - 92, - 31, - 167, - 66, - 94, - 115, - 4, - 51, - 98, - 147, - 139, - 152, - 36, -] -[signature] -limbs = [ - "0x3c1f7a6bdac9d799975076bb401622", - "0x1662d29b2f99dcc51d320c17818a16", - "0x752fb8b42585d53998776c97573b5", - "0xf06107ff8fae798a1c5cf8792274d3", - "0xcfd3b6b58942ac7b6baaf3d5740661", - "0xbdf7adc8288e78c1488e99483e74bd", - "0xd86bc4ebc1e450f6810b24f9d53e37", - "0xf2b6a14967c86bf2d9699c14d8edaa", - "0x3844199077a4324c3fdd2c0319b868", - "0xbdd8679b0d51a763a74c7575debda1", - "0x99c612a61d1466e87d4abeee4379ee", - "0xb6c445ac3aa2cc5ec36505fddfcf8c", - "0xe9d3e597c2e8a1290f5485df403bb3", - "0x3e34cc6ce3f3e266645c8725ac911", - "0x7b9f2ea85922ba5f2b9e74ce5c9dd", - "0x260652f8a7cc82376455e5882eaac0", - "0x221b8273f727efb358b3cf49f94c87", - "0x99", -] +hash = [185, 77, 39, 185, 147, 77, 62, 8, 165, 46, 82, 215, 218, 125, 171, 250, 196, 132, 239, 227, 122, 83, 128, 238, 144, 136, 247, 172, 226, 239, 205, 233] +modulus_limbs = ["0xef368ee527555429e41e399f4cf4f7", "0xa6ee7046f1d4eade05c22cc71aefa8", "0x3c49a567ec0eee765c50edb83d299a", "0x14c9c07d6266ae3402a9a0ac364b2c", "0x1bb76a8a510c341b3b21f35edd33d8", "0x2e4c11fbbf960f967a0ef4bb180dcb", "0x9d84fa8a7db7bc8ba49c1eec64e37d", "0x11fb0636ca84326cfabb360c5e17b3", "0x5c7b4a41e6d9e6b8c246b0554cde5", "0xb14b86dd4cf9383f51d04ec12129", "0x6aa8a6989019189616e02c785fc8e4", "0x4a0317a62b6a22ce68031cb4f23ce8", "0x5ea80d1dd576f56ba9a3089e4099af", "0xacb7f812249b4b278c5b03d78c0afb", "0xfb2118db289e623687ba5298e6e1e2", "0x214352a64a03c909bbd43d9940d460", "0x893bd4b92877df9b2d12bdeb2d2b74", "0xb5"] +redc_limbs = ["0x3c594da174a0effdf4abd5d24891ac", "0xd4339b1877cf5b54bcb15b4451872", "0x4ba438dd5036f8abaaad8ca7398c79", "0x571e77d0eab532e7a539f0f69d18ec", "0xc0a35ddbcf6a7a2383977c5b3eaa24", "0xf14e3e1234a3a4d0cda0023f283481", "0x893d88b750931ab81a9d027fde0c2a", "0xc6a310feacba3e886caca7adf41199", "0x6f46524cd5b7a7eb2253dc8b62c212", "0x4174f6c86d1d3e6e2ba23244ebbd0", "0xf16ecfaa7ee8a299f066df87d4f7a4", "0xab74a3710a4fde3421d187a78b9db1", "0xa3ee2e53aaded37de9abe3414ab2b9", "0x12a0a012b9c643ef0bd5c034f3a366", "0x1f31d710f11ddb44794d3200a3dea", "0x4453d51bc5c08b0063af14b74995b9", "0x215f0286eb418895604ead32ec0a4e", "0x1690"] +signature_limbs = ["0x4b25985bf5f0641557331c5d5f91d5", "0xaf0124feff62f6eb48856da0a46ae6", "0x21ef75eb686d10217a616729003038", "0x9b40883cba0a51e68a1e59fd156686", "0xf95142bdb6164d5e13809014ef55d2", "0x729cbaf6eb698d665bd4d8231d55c4", "0xea48dab6d7db49d605b5378c4c5cb8", "0xac3c80a366f2afd191a3475ea994", "0xe4b99720655b68f7ab8245bcb244c9", "0x1f61d4d35aebbbfa0fcc7d27def7b0", "0xb0024a803527dd449f9a2f91150db9", "0x9355709711a9bd1475fbea10dbede4", "0x2366e18316f9e47b3fe661a9f8b6f5", "0x917aa5e1be5c328a1251fc25d09e76", "0xd40f315491f15781f335c8190aabc", "0xdfb58b8e66e8f5cec40756f5a60a11", "0xf0946746d797bf51488f96b19280bc", "0xa"] diff --git a/example/src/main.nr b/example/src/main.nr index 971a69d..4b36800 100644 --- a/example/src/main.nr +++ b/example/src/main.nr @@ -1,14 +1,31 @@ use dep::bignum::{params::BigNumParams, RuntimeBigNum}; use dep::rsa::{rsa::verify_sha256_pkcs1v15, types::RBN2048}; -fn main(hash: [u8; 32], signature: RBN2048) { +// Examples of the signature limbs, modulus, and redc params can be generated via +// ../../signature_gen/main.rs. +// Note: technically, the `signature` could've been passed into `main` directly, +// for a much cleaner interface. +// The reason we chose this more verbose approach here, was to reduce the amount of +// data to generate for the Prover.toml file. +fn main( + hash: [u8; 32], + signature_limbs: [Field; 18], + modulus_limbs: [Field; 18], + redc_limbs: [Field; 18], +) { + let has_multiplicative_inverse = false; + let params: BigNumParams<18, 2048> = + BigNumParams::new(has_multiplicative_inverse, modulus_limbs, redc_limbs); + + let signature: RBN2048 = RuntimeBigNum::from_array(params, signature_limbs); + assert(verify_sha256_pkcs1v15(hash, signature, 65537)); } #[test] fn test_main() { + // Output of `cargo run -- --msg "hello world"` in the `signature_gen` directory // Create runtime params: - let has_multiplicative_inverse = true; let modulus_limbs = [ 0x65af46d235241cf0e8fbe8cff4abb7, 0xeead39ba3f377ddd5ccb2ef2085190, @@ -49,8 +66,6 @@ fn test_main() { 0xbe4fe7cf98da87ec87638030797e92, 0x1619, ]; - let params: BigNumParams<18, 2048> = - BigNumParams::new(has_multiplicative_inverse, modulus_limbs, redc_limbs); let signature_limbs = [ 0x2f397c4611d4a4271453e1e50e1578, @@ -73,10 +88,7 @@ fn test_main() { 0x26, ]; - let signature: RBN2048 = RuntimeBigNum::from_array(params, signature_limbs); - - // Output of `cargo run -- --msg "hello world"` in the `signature_gen` directory let hash: [u8; 32] = dep::std::hash::sha256("hello world".as_bytes()); - main(hash, signature); + main(hash, signature_limbs, modulus_limbs, redc_limbs); } diff --git a/signature_gen/src/main.rs b/signature_gen/src/main.rs index b1e46df..31a7fee 100644 --- a/signature_gen/src/main.rs +++ b/signature_gen/src/main.rs @@ -56,30 +56,33 @@ fn generate_2048_bit_signature_parameters(msg: &str, as_toml: bool, exponent: u3 let sig_str = bn_limbs(sig_uint.clone(), 2048); let modulus_limbs: Vec = split_into_120_bit_limbs(&pub_key.n().clone(), 2048); - let redc_param = split_into_120_bit_limbs( + let redc_limbs = split_into_120_bit_limbs( &compute_barrett_reduction_parameter(&pub_key.n().clone()), 2048, ); if as_toml { let sig_limbs = split_into_120_bit_limbs(&sig_uint.clone(), 2048); - let signature_toml = Value::Array(format_limbs_as_toml_value(&sig_limbs)); - - let bn = Value::Array(vec![ - Value::Array(format_limbs_as_toml_value(&modulus_limbs)), - Value::Array(format_limbs_as_toml_value(&redc_param)), - ]); - let bn_toml = toml::to_string_pretty(&bn).unwrap(); - println!("bn = {}", bn_toml); + println!("hash = [{}]", hashed_as_bytes); - println!("[signature]"); - println!("limbs = {}", signature_toml); + println!( + "modulus_limbs = {}", + Value::Array(format_limbs_as_toml_value(&modulus_limbs)) + ); + println!( + "redc_limbs = {}", + Value::Array(format_limbs_as_toml_value(&redc_limbs)) + ); + println!( + "signature_limbs = {}", + Value::Array(format_limbs_as_toml_value(&sig_limbs)) + ); } else { println!("let hash: [u8; 32] = [{}];", hashed_as_bytes); println!( "let params: BigNumParams<18, 2048> = BigNumParams::new(\n\tfalse,\n\t[{}],\n\t[{}]\n);", format_limbs_as_hex(&modulus_limbs), - format_limbs_as_hex(&redc_param) + format_limbs_as_hex(&redc_limbs) ); println!( "let signature: RuntimeBigNum<18, 2048> = RuntimeBigNum::from_array(\n\tparams,\n\tlimbs: {}\n);", @@ -116,29 +119,32 @@ fn generate_1024_bit_signature_parameters(msg: &str, as_toml: bool, exponent: u3 let sig_str = bn_limbs(sig_uint.clone(), 1024); let modulus_limbs: Vec = split_into_120_bit_limbs(&pub_key.n().clone(), 1024); - let redc_param = split_into_120_bit_limbs( + let redc_limbs = split_into_120_bit_limbs( &compute_barrett_reduction_parameter(&pub_key.n().clone()), 1024, ); if as_toml { let sig_limbs = split_into_120_bit_limbs(&sig_uint.clone(), 1024); - let signature_toml = Value::Array(format_limbs_as_toml_value(&sig_limbs)); - - let bn = Value::Array(vec![ - Value::Array(format_limbs_as_toml_value(&modulus_limbs)), - Value::Array(format_limbs_as_toml_value(&redc_param)), - ]); - let bn_toml = toml::to_string_pretty(&bn).unwrap(); - println!("bn = {}", bn_toml); + println!("hash = [{}]", hashed_as_bytes); - println!("[signature]"); - println!("limbs = {}", signature_toml); + println!( + "modulus_limbs = {}", + Value::Array(format_limbs_as_toml_value(&modulus_limbs)) + ); + println!( + "redc_limbs = {}", + Value::Array(format_limbs_as_toml_value(&redc_limbs)) + ); + println!( + "signature_limbs = {}", + Value::Array(format_limbs_as_toml_value(&sig_limbs)) + ); } else { println!( "let params: BigNumParams<9, 1024> = BigNumParams::new(\n\tfalse,\n\t[{}],\n\t[{}]\n);", format_limbs_as_hex(&modulus_limbs), - format_limbs_as_hex(&redc_param) + format_limbs_as_hex(&redc_limbs) ); println!( "let signature: RuntimeBigNum<9, 1024> = RuntimeBigNum::from_array(\n\tparams,\n\tlimbs: {}\n);",