Skip to content

Commit

Permalink
WIP towards new search algorithm
Browse files Browse the repository at this point in the history
refs #12
  • Loading branch information
warner committed Feb 18, 2020
1 parent 7ec2962 commit b43f90b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ rayon = "1.0"
base64 = "0.11"
rand_core = { version = "0.5", default-features = false, features = ["getrandom"] }
x25519-dalek = "0.6"
curve25519-dalek = "2.0"
num_cpus = "1.0"

[dev-dependencies]
Expand Down
60 changes: 60 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,63 @@ pub fn trial(prefix: &str, start: usize, end: usize) -> Option<(String, String)>
None
}
}

use curve25519_dalek::{ scalar::Scalar,
constants::{ X25519_BASEPOINT,
ED25519_BASEPOINT_POINT },
};

fn clamp_scalar(mut scalar: [u8; 32]) -> Scalar {
scalar[0] &= 248;
scalar[31] &= 127;
scalar[31] |= 64;

Scalar::from_bits(scalar)
}
//use rand_core::CryptoRng;
use rand_core::RngCore;

fn random_scalar() -> Scalar {
let mut scalar1 = [0u8; 32];
let mut csprng = OsRng;
csprng.fill_bytes(&mut scalar1);
Scalar::from_bytes_mod_order(scalar1)
}

pub fn testadd() {
let s1 = random_scalar();
let s2 = random_scalar();
let s3 = s1 + s2;
println!("s1 {:02x} {:?} {:02x}", s1.to_bytes()[0], s1.to_bytes(), s1.to_bytes()[31]);
println!("s2 {:02x} {:?} {:02x}", s2.to_bytes()[0], s2.to_bytes(), s2.to_bytes()[31]);
println!("s3 {:02x} {:?} {:02x}", s3.to_bytes()[0], s3.to_bytes(), s3.to_bytes()[31]);

let p1 = s1 * ED25519_BASEPOINT_POINT;
let p2 = s2 * ED25519_BASEPOINT_POINT;
let p3 = s3 * ED25519_BASEPOINT_POINT;

let p3b = p1 + p2;
assert_eq!(ED25519_BASEPOINT_POINT.to_montgomery(),
X25519_BASEPOINT);
assert_eq!(p3, p3b);

let priv1 = StaticSecret::from(s3.to_bytes());
let pub1 = PublicKey::from(p3.to_montgomery().to_bytes());
let pub1b = PublicKey::from(&priv1);
assert_eq!(pub1.as_bytes(), pub1b.as_bytes());
//let pub1 = s3 * X25519_BASEPOINT;


println!("yep equal")
}

#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_add() {
println!("testadd");
testadd();
}

}

0 comments on commit b43f90b

Please sign in to comment.