Merge pull request #19 from Sunscreen-tech/rweber/bench

Compact public keys
This commit is contained in:
rickwebiii
2022-01-06 20:03:24 -08:00
committed by GitHub
2 changed files with 34 additions and 1 deletions

View File

@@ -31,7 +31,7 @@ Actual values may vary slightly with RNG.
### Size of public key
Actual values may vary slightly with RNG.
Actual values may vary slightly with RNG. Compact keys are half as large.
| n | 1024 | 2048 | 4096 | 8192 | 16384 | 32768 |
|-------|-------|--------|---------|---------|----------|----------|

View File

@@ -264,6 +264,15 @@ impl Clone for PublicKey {
*/
pub struct CompactPublicKey(PublicKey);
impl CompactPublicKey {
/**
* Returns the key as a byte array.
*/
pub fn as_bytes(&self) -> Result<Vec<u8>> {
self.0.as_bytes()
}
}
/**
* Class to store a secret key.
*/
@@ -624,4 +633,28 @@ mod tests {
println!("\tPublic key size poly_degree={} bytes={}", d, public.as_bytes().unwrap().len());
}
}
#[test]
fn compact_public_key_size() {
let degree = [1024, 2048, 4096, 8192, 16384, 32768];
for d in degree {
let params = BfvEncryptionParametersBuilder::new()
.set_poly_modulus_degree(d)
.set_coefficient_modulus(
CoefficientModulus::bfv_default(d, SecurityLevel::default()).unwrap(),
)
.set_plain_modulus_u64(1_000_000)
.build()
.unwrap();
let context = Context::new(&params, false, SecurityLevel::default()).unwrap();
let gen = KeyGenerator::new(&context).unwrap();
let public = gen.create_compact_public_key();
println!("\tCompact public key size poly_degree={} bytes={}", d, public.as_bytes().unwrap().len());
}
}
}