MCPcopy Create free account
hub / github.com/docknetwork/crypto / check

Function check

saver/src/encryption.rs:923–1052  ·  view source on GitHub ↗
(chunk_bit_size: u8)

Source from the content-addressed store, hash-verified

921 #[test]
922 fn encrypt_decrypt() {
923 fn check(chunk_bit_size: u8) {
924 let mut rng = StdRng::seed_from_u64(0u64);
925 let n = chunks_count::<Fr>(chunk_bit_size) as u32;
926 // Get random numbers that are of chunk_bit_size at most
927 let m = gen_messages(&mut rng, n, chunk_bit_size);
928 let (gens, g_i, sk, ek, dk) = enc_setup(chunk_bit_size, &mut rng);
929
930 let prepared_gens = PreparedEncryptionGens::from(gens.clone());
931 let prepared_ek = PreparedEncryptionKey::from(ek.clone());
932 let prepared_dk = PreparedDecryptionKey::from(dk.clone());
933
934 let start = Instant::now();
935 let (ct, _) =
936 Encryption::encrypt_decomposed_message(&mut rng, m.clone(), &ek, &g_i).unwrap();
937 println!(
938 "Time taken to encrypt {}-bit chunks {:?}",
939 chunk_bit_size,
940 start.elapsed()
941 );
942
943 assert_eq!(ct.len(), m.len() + 2);
944 let start = Instant::now();
945 Encryption::verify_ciphertext_commitment(
946 &ct[0],
947 &ct[1..m.len() + 1],
948 &ct[m.len() + 1],
949 ek.clone(),
950 gens.clone(),
951 )
952 .unwrap();
953 println!(
954 "Time taken to verify commitment of {}-bit chunks {:?}",
955 chunk_bit_size,
956 start.elapsed()
957 );
958
959 let start = Instant::now();
960 Encryption::verify_ciphertext_commitment(
961 &ct[0],
962 &ct[1..m.len() + 1],
963 &ct[m.len() + 1],
964 prepared_ek,
965 prepared_gens.clone(),
966 )
967 .unwrap();
968 println!(
969 "Time taken to verify commitment of {}-bit chunks using prepared parameters {:?}",
970 chunk_bit_size,
971 start.elapsed()
972 );
973
974 let start = Instant::now();
975 let (m_, _) = Encryption::decrypt_to_chunks(
976 &ct[0],
977 &ct[1..m.len() + 1],
978 &sk,
979 dk.clone(),
980 &g_i,

Callers 3

encrypt_decryptFunction · 0.70
encrypt_decrypt_timingFunction · 0.70

Calls 10

gen_messagesFunction · 0.85
enc_setupFunction · 0.85
randFunction · 0.85
cloneMethod · 0.80
pairing_powersMethod · 0.80
verify_decryptionMethod · 0.80
decomposeFunction · 0.70
lenMethod · 0.45
decryptMethod · 0.45

Tested by 3

encrypt_decryptFunction · 0.56
encrypt_decrypt_timingFunction · 0.56