2018-04-07 12:01:27 -07:00
|
|
|
/*
|
|
|
|
One-time encryption - keyspace of the OTE is also the range of the pseudo-random function
|
|
|
|
*/
|
|
|
|
|
|
|
|
use std::fmt;
|
|
|
|
use bn::{Group, Fr, G1};
|
|
|
|
use rand;
|
|
|
|
|
|
|
|
pub struct OTMessage {
|
2018-04-08 00:46:17 -07:00
|
|
|
pub m1: G1,
|
|
|
|
pub m2: G1
|
2018-04-07 12:01:27 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct OTCiphertext {
|
|
|
|
c1: G1,
|
|
|
|
c2: G1
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn keygen() -> G1 {
|
|
|
|
let rng = &mut rand::thread_rng();
|
|
|
|
let k = G1::random(rng);
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
|
|
|
// encryption scheme can be implemented by encoding the plaintext as an element in a cyclic group G
|
|
|
|
// and multiplying by a random group element.
|
|
|
|
pub fn otenc(k: G1, m: &OTMessage) -> OTCiphertext {
|
|
|
|
let c1 = k + m.m1;
|
|
|
|
let c2 = k + m.m2;
|
|
|
|
assert!(c1 != c2);
|
|
|
|
return OTCiphertext { c1: c1, c2: c2 };
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn otdec(k: G1, c: &OTCiphertext) -> OTMessage {
|
|
|
|
let X = c.c1 - k;
|
|
|
|
let Y = c.c2 - k;
|
|
|
|
return OTMessage { m1: X, m2: Y};
|
|
|
|
}
|