Curve 25519 is one of the most widely used ECC methods. It uses a curve of \(y^2 = x^3 + 486662 x^2 + x\), and which is a Montgomery curve, over the prime field, and with a prime number of \(2^{255} − 19\). The output is a single x co-ordinate point and the base point is x = 9, with an order of \(2^{252}+27,742,317,777,372,353,535,851,937,790,883,648,493\). Curve 25519 is used in many applications including with TLS 1.3, OpenSSH, SmartFTP, Tor, SAFE (created by Maidsafe), Signal, WhatsApp, and Facebook Messenger. With Curve 25519, we have points on the curve of \((u,v)\), but where we only use the \(u\) co-ordinate. Overall the base point (\(G\)) has a \(u\) co-ordinate value of 9. In this case we will compute the point for \(H=rG\):
Finding a point on Curve 25519 using Rust |
An outline of the Rust code is:
extern crate curve25519_dalek; extern crate rand_core; extern crate sha2; use curve25519_dalek::constants; use curve25519_dalek::scalar::Scalar; use std::env; fn main() { let mut value=1; let args: Vec= env::args().collect(); if args.len() >1 { let ar = args[1].as_str(); value=ar.parse().unwrap(); } // Base point let G = &constants::X25519_BASEPOINT; // let h = Scalar::random(&mut OsRng); let zeros: [u8;32] = [0u8;32]; let mut ro1 = zeros.clone(); ro1[0]=value; let v = Scalar::from_bytes_mod_order(ro1); let H = v*G; println!("--- Montgomery Curve ---"); println!("\nG={:}",hex::encode(G.as_bytes())); println!("\nr={:}",value); println!("\nH=rG={:}",hex::encode(H.as_bytes())); }
A sample run is:
--- Montgomery Curve --- G=0900000000000000000000000000000000000000000000000000000000000000 r=14 H=rG=0af27868864f1754ada4237c2da38f15265e3bc046866ffb3502e515e4842e63