소스 검색

add vesta pasta curve script

narodnik 5 년 전
부모
커밋
ef6ee7e4bd
3개의 변경된 파일51개의 추가작업 그리고 0개의 파일을 삭제
  1. 15 0
      scripts/pasta/Cargo.toml
  2. 14 0
      scripts/pasta/main.rs
  3. 22 0
      scripts/pasta/vesta.sage

+ 15 - 0
scripts/pasta/Cargo.toml

@@ -0,0 +1,15 @@
+[package]
+name = "pasta"
+version = "0.1.0"
+authors = ["narodnik <x@x.org>"]
+edition = "2018"
+
+[dependencies]
+pasta_curves = { path = "/home/narodnik/src/sw/zectings/pasta_curves" }
+ff = "0.9"
+group = "0.9"
+
+[[bin]]
+name = "pasta"
+path = "main.rs"
+

+ 14 - 0
scripts/pasta/main.rs

@@ -0,0 +1,14 @@
+use pasta_curves as pasta;
+use group::{Group, Curve};
+
+fn main() {
+    let a = pasta::vesta::Point::generator();
+    println!("a = {:?}", a.to_affine());
+    let x = pasta::vesta::Scalar::from(87u64);
+    println!("x = {:?}", x);
+    let b = a * x;
+    println!("b = {:?}", b.to_affine());
+
+    let y = x - pasta::vesta::Scalar::from(90u64);
+    println!("y = {:?}", y);
+}

+ 22 - 0
scripts/pasta/vesta.sage

@@ -0,0 +1,22 @@
+q = 0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000001
+K = GF(q)
+a = K(0x00)
+b = K(0x05)
+E = EllipticCurve(K, (a, b))
+G = E(0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000000, 0x02)
+E.set_order(0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001 * 0x01)
+p = 0x40000000000000000000000000000000224698fc094cf91b992d30ed00000001
+Scalar = GF(p)
+
+A = E(0x40000000000000000000000000000000224698fc0994a8dd8c46eb2100000000, 0x0000000000000000000000000000000000000000000000000000000000000002)
+x = Scalar(0x0000000000000000000000000000000000000000000000000000000000000057)
+print(int(x))
+#print([hex(x) for x in (x * A).xy()])
+B = E(0x04cbd122b054187ff98f0726651096de7f55a213c233902764fe87d376eeb99c, 0x2d5c8c632b1f33eb42726cda0af9f95eaf3dfa8511e6a7b657713dbf62bb13a5)
+assert int(x) * A == B
+
+yy = Scalar(0x40000000000000000000000000000000224698fc094cf91b992d30ecfffffffe)
+y = x - Scalar(90)
+print(hex(int(y)))
+assert yy == y
+