Skip to content

Commit

Permalink
Convert to 2018 edition (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
djc authored and omershlo committed Aug 20, 2019
1 parent 7f0586f commit c0afe51
Show file tree
Hide file tree
Showing 35 changed files with 213 additions and 245 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "curv"
version = "0.1.0"
edition = "2018"


[lib]
Expand Down
2 changes: 0 additions & 2 deletions examples/diffie_hellman_key_exchange.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate curv;

/// Diffie Hellman Key Exchange:
/// TO RUN:
/// cargo run --example diffie_hellman_key_exchange --features CURVE_NAME
Expand Down
2 changes: 0 additions & 2 deletions examples/pedersen_commitment.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate curv;

use curv::BigInt;

/// Pedesen Commitment:
Expand Down
2 changes: 0 additions & 2 deletions examples/proof_of_knowledge_of_dlog.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate curv;

/// Sigma protocol for proof of knowledge of discrete log
/// TO RUN:
/// cargo run --example proof_of_knowledge_of_dlog --features CURVE_NAME
Expand Down
2 changes: 0 additions & 2 deletions examples/verifiable_secret_sharing.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate curv;

/// secret_sharing_3_out_of_5
/// Feldman VSS, based on Paul Feldman. 1987. A practical scheme for non-interactive verifiable secret sharing.
/// In Foundations of Computer Science, 1987., 28th Annual Symposium on.IEEE, 427–43
Expand Down
4 changes: 1 addition & 3 deletions src/arithmetic/big_gmp.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
#![cfg(feature="rust-gmp")]

/*
Curv
Expand All @@ -16,12 +14,12 @@
@license GPL-3.0+ <https://github.com/KZen-networks/curv/blob/master/LICENSE>
*/

use super::gmp::mpz::Mpz;
use super::rand::rngs::OsRng;
use super::rand::RngCore;
use super::traits::{
BitManipulation, ConvertFrom, Converter, Modulo, NumberTests, Samplable, ZeroizeBN, EGCD,
};
use gmp::mpz::Mpz;

use std::borrow::Borrow;
use std::ptr;
Expand Down
5 changes: 2 additions & 3 deletions src/arithmetic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
@license GPL-3.0+ <https://github.com/KZen-networks/cryptography-utils/blob/master/LICENSE>
*/

#[cfg(feature = "rust-gmp")]
extern crate gmp;
extern crate rand;
use rand;

const HEX_RADIX: u8 = 16;

#[cfg(feature = "rust-gmp")]
pub mod big_gmp;
pub mod traits;
6 changes: 3 additions & 3 deletions src/arithmetic/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ pub trait Samplable {
}

pub trait NumberTests {
fn is_zero(&Self) -> bool;
fn is_even(&Self) -> bool;
fn is_zero(_: &Self) -> bool;
fn is_even(_: &Self) -> bool;
fn is_negative(me: &Self) -> bool;
}

Expand All @@ -60,6 +60,6 @@ pub trait BitManipulation {
}

pub trait ConvertFrom<T> {
fn _from(&T) -> Self;
fn _from(_: &T) -> Self;
}
//use std::ops::{Add, Div, Mul, Neg, Rem, Shr, Sub};
8 changes: 4 additions & 4 deletions src/cryptographic_primitives/commitments/hash_commitment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
/// r is 256bit blinding factor, m is the commited value
pub struct HashCommitment;

use BigInt;
use crate::BigInt;

use super::traits::Commitment;
use super::SECURITY_BITS;
use arithmetic::traits::Samplable;
use crate::arithmetic::traits::Samplable;
use sha3::{Digest, Sha3_256};
//TODO: using the function with BigInt's as input instead of string's makes it impossible to commit to empty message or use empty randomness
impl Commitment<BigInt> for HashCommitment {
Expand Down Expand Up @@ -45,9 +45,9 @@ mod tests {
use super::Commitment;
use super::HashCommitment;
use super::SECURITY_BITS;
use arithmetic::traits::Samplable;
use crate::arithmetic::traits::Samplable;
use crate::BigInt;
use sha3::{Digest, Sha3_256};
use BigInt;

#[test]
fn test_bit_length_create_commitment() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@

use super::traits::Commitment;
use super::SECURITY_BITS;
use arithmetic::traits::Samplable;
use crate::arithmetic::traits::Samplable;

use elliptic::curves::traits::*;
use {BigInt, FE, GE};
use crate::elliptic::curves::traits::*;
use crate::{BigInt, FE, GE};

/// compute c = mG + rH
/// where m is the commited value, G is the group generator,
Expand Down
2 changes: 1 addition & 1 deletion src/cryptographic_primitives/commitments/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
License MIT: https://github.com/KZen-networks/curv/blob/master/LICENSE
*/

use BigInt;
use crate::BigInt;

pub trait Commitment<T> {
fn create_commitment_with_user_defined_randomness(
Expand Down
14 changes: 7 additions & 7 deletions src/cryptographic_primitives/hashing/blake2b512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
(https://github.com/KZen-networks/curv)
License MIT: https://github.com/KZen-networks/curv/blob/master/LICENSE
*/
use arithmetic::traits::Converter;
use crate::arithmetic::traits::Converter;
use crate::elliptic::curves::traits::{ECPoint, ECScalar};
use crate::{BigInt, FE, GE};
use blake2b_simd::Params;
use elliptic::curves::traits::{ECPoint, ECScalar};
use {BigInt, FE, GE};

pub struct Blake;

Expand Down Expand Up @@ -38,10 +38,10 @@ impl Blake {
#[cfg(test)]
mod tests {
use super::Blake;
use elliptic::curves::traits::ECPoint;
use elliptic::curves::traits::ECScalar;
use BigInt;
use GE;
use crate::elliptic::curves::traits::ECPoint;
use crate::elliptic::curves::traits::ECScalar;
use crate::BigInt;
use crate::GE;

#[test]
// Very basic test here, TODO: suggest better testing
Expand Down
16 changes: 8 additions & 8 deletions src/cryptographic_primitives/hashing/hash_sha256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
*/

use super::traits::Hash;
use arithmetic::traits::Converter;
use crate::arithmetic::traits::Converter;
use crate::elliptic::curves::traits::{ECPoint, ECScalar};
use crypto::digest::Digest;
use crypto::sha2::Sha256;
use elliptic::curves::traits::{ECPoint, ECScalar};
use hex::decode;

use BigInt;
use {FE, GE};
use crate::BigInt;
use crate::{FE, GE};

pub struct HSha256;

Expand Down Expand Up @@ -49,10 +49,10 @@ impl Hash for HSha256 {
mod tests {
use super::HSha256;
use super::Hash;
use elliptic::curves::traits::ECPoint;
use elliptic::curves::traits::ECScalar;
use BigInt;
use GE;
use crate::elliptic::curves::traits::ECPoint;
use crate::elliptic::curves::traits::ECScalar;
use crate::BigInt;
use crate::GE;

#[test]
// Test Vectors taken from:
Expand Down
16 changes: 8 additions & 8 deletions src/cryptographic_primitives/hashing/hash_sha512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
*/

use super::traits::Hash;
use arithmetic::traits::Converter;
use crate::arithmetic::traits::Converter;
use crate::elliptic::curves::traits::{ECPoint, ECScalar};
use crypto::digest::Digest;
use crypto::sha2::Sha512;
use elliptic::curves::traits::{ECPoint, ECScalar};
use hex::decode;

use BigInt;
use {FE, GE};
use crate::BigInt;
use crate::{FE, GE};

pub struct HSha512;

Expand Down Expand Up @@ -49,10 +49,10 @@ impl Hash for HSha512 {
mod tests {
use super::HSha512;
use super::Hash;
use elliptic::curves::traits::ECPoint;
use elliptic::curves::traits::ECScalar;
use BigInt;
use GE;
use crate::elliptic::curves::traits::ECPoint;
use crate::elliptic::curves::traits::ECScalar;
use crate::BigInt;
use crate::GE;

#[test]
// Test Vectors taken from:
Expand Down
10 changes: 5 additions & 5 deletions src/cryptographic_primitives/hashing/hmac_sha512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
License MIT: https://github.com/KZen-networks/curv/blob/master/LICENSE
*/

use BigInt;
use crate::BigInt;

use super::traits::KeyedHash;
use arithmetic::traits::Converter;
use crate::arithmetic::traits::Converter;

use crypto::hmac::Hmac;
use crypto::mac::Mac;
Expand Down Expand Up @@ -37,9 +37,9 @@ impl KeyedHash for HMacSha512 {
mod tests {

use super::HMacSha512;
use arithmetic::traits::Samplable;
use cryptographic_primitives::hashing::traits::KeyedHash;
use BigInt;
use crate::arithmetic::traits::Samplable;
use crate::cryptographic_primitives::hashing::traits::KeyedHash;
use crate::BigInt;

#[test]
fn create_hmac_test() {
Expand Down
10 changes: 5 additions & 5 deletions src/cryptographic_primitives/hashing/merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use crypto::sha3::Sha3;
use merkle::{MerkleTree, Proof};

use elliptic::curves::traits::ECPoint;
use GE;
use crate::elliptic::curves::traits::ECPoint;
use crate::GE;
/*
pub struct MT256<'a> {
tree: MerkleTree<GE>,
Expand Down Expand Up @@ -58,9 +58,9 @@ impl MT256 {

#[cfg(test)]
mod tests {
use cryptographic_primitives::hashing::merkle_tree::MT256;
use elliptic::curves::traits::ECPoint;
use GE;
use crate::cryptographic_primitives::hashing::merkle_tree::MT256;
use crate::elliptic::curves::traits::ECPoint;
use crate::GE;
#[test]
fn test_mt_functionality_four_leaves() {
let ge1: GE = ECPoint::generator();
Expand Down
4 changes: 2 additions & 2 deletions src/cryptographic_primitives/hashing/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
License MIT: https://github.com/KZen-networks/curv/blob/master/LICENSE
*/

use BigInt;
use {FE, GE};
use crate::BigInt;
use crate::{FE, GE};

pub trait Hash {
fn create_hash(big_ints: &[&BigInt]) -> BigInt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
*/

use super::ProofError;
use cryptographic_primitives::hashing::hash_sha256::HSha256;
use cryptographic_primitives::hashing::traits::Hash;
use elliptic::curves::traits::*;
use crate::cryptographic_primitives::hashing::hash_sha256::HSha256;
use crate::cryptographic_primitives::hashing::traits::Hash;
use crate::elliptic::curves::traits::*;
use crate::FE;
use crate::GE;
use zeroize::Zeroize;
use FE;
use GE;

/// This is a proof of knowledge that a pair of group elements {D, E}
/// form a valid homomorphic ElGamal encryption (”in the exponent”) using public key Y .
Expand Down Expand Up @@ -81,8 +81,8 @@ impl HomoELGamalProof {

#[cfg(test)]
mod tests {
use cryptographic_primitives::proofs::sigma_correct_homomorphic_elgamal_enc::*;
use {FE, GE};
use crate::cryptographic_primitives::proofs::sigma_correct_homomorphic_elgamal_enc::*;
use crate::{FE, GE};

#[test]
fn test_correct_general_homo_elgamal() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
*/

use super::ProofError;
use cryptographic_primitives::hashing::hash_sha256::HSha256;
use cryptographic_primitives::hashing::traits::Hash;
use elliptic::curves::traits::*;
use crate::cryptographic_primitives::hashing::hash_sha256::HSha256;
use crate::cryptographic_primitives::hashing::traits::Hash;
use crate::elliptic::curves::traits::*;
use crate::FE;
use crate::GE;
use zeroize::Zeroize;
use FE;
use GE;

/// This is a proof of knowledge that a pair of group elements {D, E}
/// form a valid homomorphic ElGamal encryption (”in the exponent”) using public key Y .
Expand Down Expand Up @@ -84,8 +84,8 @@ impl HomoELGamalDlogProof {

#[cfg(test)]
mod tests {
use cryptographic_primitives::proofs::sigma_correct_homomorphic_elgamal_encryption_of_dlog::*;
use {FE, GE};
use crate::cryptographic_primitives::proofs::sigma_correct_homomorphic_elgamal_encryption_of_dlog::*;
use crate::{FE, GE};

#[test]
fn test_correct_homo_elgamal() {
Expand Down
14 changes: 7 additions & 7 deletions src/cryptographic_primitives/proofs/sigma_dlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
*/

use super::ProofError;
use FE;
use GE;
use crate::FE;
use crate::GE;

use elliptic::curves::traits::*;
use crate::elliptic::curves::traits::*;

use cryptographic_primitives::hashing::hash_sha256::HSha256;
use cryptographic_primitives::hashing::traits::Hash;
use crate::cryptographic_primitives::hashing::hash_sha256::HSha256;
use crate::cryptographic_primitives::hashing::traits::Hash;
use zeroize::Zeroize;

/// This is implementation of Schnorr's identification protocol for elliptic curve groups or a
Expand Down Expand Up @@ -90,8 +90,8 @@ impl ProveDLog for DLogProof {

#[cfg(test)]
mod tests {
use cryptographic_primitives::proofs::sigma_dlog::*;
use FE;
use crate::cryptographic_primitives::proofs::sigma_dlog::*;
use crate::FE;

#[test]
fn test_dlog_proof() {
Expand Down

0 comments on commit c0afe51

Please sign in to comment.