Skip to content

Commit

Permalink
Convert to 2018 edition
Browse files Browse the repository at this point in the history
  • Loading branch information
djc committed Aug 15, 2019
1 parent f41e32a commit b37a969
Show file tree
Hide file tree
Showing 33 changed files with 201 additions and 231 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 = "gmp")]
pub mod big_gmp;
pub mod traits;
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
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,11 +6,11 @@
*/

use super::traits::Hash;
use arithmetic::traits::Converter;
use elliptic::curves::traits::{ECPoint, ECScalar};
use crate::arithmetic::traits::Converter;
use crate::elliptic::curves::traits::{ECPoint, ECScalar};
use crate::BigInt;
use crate::{FE, GE};
use ring::digest::{Context, SHA256};
use BigInt;
use {FE, GE};

pub struct HSha256;

Expand Down Expand Up @@ -41,10 +41,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]
// Very basic test here, TODO: suggest better testing
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,11 +6,11 @@
*/

use super::traits::Hash;
use arithmetic::traits::Converter;
use elliptic::curves::traits::{ECPoint, ECScalar};
use crate::arithmetic::traits::Converter;
use crate::elliptic::curves::traits::{ECPoint, ECScalar};
use crate::BigInt;
use crate::{FE, GE};
use ring::digest::{Context, SHA512};
use BigInt;
use {FE, GE};

pub struct HSha512;

Expand Down Expand Up @@ -41,10 +41,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]
// Very basic test here, TODO: suggest better testing
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 ring::{digest, hmac};
use zeroize::Zeroize;
pub struct HMacSha512;
Expand All @@ -31,9 +31,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
8 changes: 4 additions & 4 deletions src/cryptographic_primitives/hashing/merkle_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
License MIT: https://github.com/KZen-networks/curv/blob/master/LICENSE
*/

use crate::GE;
use merkle::{MerkleTree, Proof};
use ring::digest::{Context, SHA256};
use GE;
/*
pub struct MT256<'a> {
tree: MerkleTree<GE>,
Expand Down Expand Up @@ -45,9 +45,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
14 changes: 7 additions & 7 deletions src/cryptographic_primitives/proofs/sigma_ec_ddh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
*/

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, GE};
use zeroize::Zeroize;
use {FE, GE};

/// This protocol is the elliptic curve form of the protocol from :
/// D. Chaum, T. P. Pedersen. Transferred cash grows in size. In Advances in Cryptology, EUROCRYPT , volume 658 of Lecture Notes in Computer Science, pages 390 - 407, 1993.
Expand Down Expand Up @@ -81,9 +81,9 @@ impl NISigmaProof<ECDDHProof, ECDDHWitness, ECDDHStatement> for ECDDHProof {

#[cfg(test)]
mod tests {
use cryptographic_primitives::proofs::sigma_ec_ddh::*;
use elliptic::curves::traits::{ECPoint, ECScalar};
use {FE, GE};
use crate::cryptographic_primitives::proofs::sigma_ec_ddh::*;
use crate::elliptic::curves::traits::{ECPoint, ECScalar};
use crate::{FE, GE};

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

use super::ProofError;
use cryptographic_primitives::commitments::pedersen_commitment::PedersenCommitment;
use cryptographic_primitives::commitments::traits::Commitment;
use cryptographic_primitives::hashing::hash_sha256::HSha256;
use cryptographic_primitives::hashing::traits::Hash;
use elliptic::curves::traits::*;
use crate::cryptographic_primitives::commitments::pedersen_commitment::PedersenCommitment;
use crate::cryptographic_primitives::commitments::traits::Commitment;
use crate::cryptographic_primitives::hashing::hash_sha256::HSha256;
use crate::cryptographic_primitives::hashing::traits::Hash;
use crate::elliptic::curves::traits::*;
use crate::{FE, GE};
use zeroize::Zeroize;
use {FE, GE};

/// protocol for proving that Pedersen commitment c was constructed correctly which is the same as
/// proof of knowledge of (m,r) such that c = mG + rH.
Expand Down Expand Up @@ -109,8 +109,8 @@ impl ProvePederesen for PedersenProof {

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

#[test]
fn test_pedersen_proof() {
Expand Down

0 comments on commit b37a969

Please sign in to comment.