@ -5,6 +5,7 @@ pub mod protobuf_impl;
mod serde_impl ;
mod serde_impl ;
use std ::fmt ;
use std ::fmt ;
use std ::hash ::{ Hash , Hasher } ;
use byteorder ::{ BigEndian , ByteOrder } ;
use byteorder ::{ BigEndian , ByteOrder } ;
use init_with ::InitWith ;
use init_with ::InitWith ;
@ -31,6 +32,12 @@ impl<E: Engine> PartialEq for PublicKey<E> {
}
}
}
}
impl < E : Engine > Hash for PublicKey < E > {
fn hash < H : Hasher > ( & self , state : & mut H ) {
self . 0. into_affine ( ) . into_compressed ( ) . as_ref ( ) . hash ( state ) ;
}
}
impl < E : Engine > PublicKey < E > {
impl < E : Engine > PublicKey < E > {
/// Returns `true` if the signature matches the element of `E::G2`.
/// Returns `true` if the signature matches the element of `E::G2`.
pub fn verify_g2 < H : Into < E ::G2Affine > > ( & self , sig : & Signature < E > , hash : H ) -> bool {
pub fn verify_g2 < H : Into < E ::G2Affine > > ( & self , sig : & Signature < E > , hash : H ) -> bool {
@ -85,6 +92,12 @@ impl<E: Engine> PartialEq for Signature<E> {
}
}
}
}
impl < E : Engine > Hash for Signature < E > {
fn hash < H : Hasher > ( & self , state : & mut H ) {
self . 0. into_affine ( ) . into_compressed ( ) . as_ref ( ) . hash ( state ) ;
}
}
impl < E : Engine > Signature < E > {
impl < E : Engine > Signature < E > {
pub fn parity ( & self ) -> bool {
pub fn parity ( & self ) -> bool {
let uncomp = self . 0. into_affine ( ) . into_uncompressed ( ) ;
let uncomp = self . 0. into_affine ( ) . into_uncompressed ( ) ;
@ -160,6 +173,14 @@ impl<E: Engine> PartialEq for Ciphertext<E> {
}
}
}
}
impl < E : Engine > Hash for Ciphertext < E > {
fn hash < H : Hasher > ( & self , state : & mut H ) {
self . 0. into_affine ( ) . into_compressed ( ) . as_ref ( ) . hash ( state ) ;
self . 1. hash ( state ) ;
self . 2. into_affine ( ) . into_compressed ( ) . as_ref ( ) . hash ( state ) ;
}
}
impl < E : Engine > Ciphertext < E > {
impl < E : Engine > Ciphertext < E > {
/// Returns `true` if this is a valid ciphertext. This check is necessary to prevent
/// Returns `true` if this is a valid ciphertext. This check is necessary to prevent
/// chosen-ciphertext attacks.
/// chosen-ciphertext attacks.
@ -180,8 +201,14 @@ impl<E: Engine> PartialEq for DecryptionShare<E> {
}
}
}
}
impl < E : Engine > Hash for DecryptionShare < E > {
fn hash < H : Hasher > ( & self , state : & mut H ) {
self . 0. into_affine ( ) . into_compressed ( ) . as_ref ( ) . hash ( state ) ;
}
}
/// A public key and an associated set of public key shares.
/// A public key and an associated set of public key shares.
#[ derive(Serialize, Deserialize, Clone, Debug) ]
#[ derive(Serialize, Deserialize, Clone, Debug, Hash ) ]
pub struct PublicKeySet < E : Engine > {
pub struct PublicKeySet < E : Engine > {
/// The coefficients of a polynomial whose value at `0` is the "master key", and value at
/// The coefficients of a polynomial whose value at `0` is the "master key", and value at
/// `i + 1` is key share number `i`.
/// `i + 1` is key share number `i`.