ช่างเถอะ. เพิ่งนำไปใช้ในสนิมแลง
และนี่คือรหัสของฉัน เพียงแค่ดำเนินการ ต้องทำงานต่อไป & อย่าจริงจังกับมัน
ใช้เส้นโค้ง :: เลขคณิต :: ตัวแปลง;
ใช้เส้นโค้ง::elliptic::curves::{ จุด, สเกลาร์, Secp256k1};
ใช้เส้นโค้ง::BigInt;
ใช้ opensl::hash::{Hasher, MessageDigest};
fn หลัก () {
    ให้ mut hasher = Hasher::new(MessageDigest::sha256()).unwrap();
    // คีย์ส่วนตัวของผู้โจมตี
    ให้ v = สเกลาร์::<Secp256k1>::สุ่ม();
    // รหัสสาธารณะของผู้โจมตี
    ให้ V = จุด :: เครื่องกำเนิด () * v.clone ();
    // รหัสส่วนตัวของผู้ใช้
    ให้ D = สเกลาร์::<Secp256k1>::สุ่ม();
    println!("{:?}", D.to_bigint());
    // รหัสสาธารณะของผู้ใช้
    ให้ Q = Point::generator() * D.clone();
    ให้ message1 = String::from("ข้อความแรกที่จะเซ็นชื่อ");
    ให้ message2 = String::from("ข้อความที่สองเพื่อลงชื่อ");
    hasher.update(message1.as_bytes()).expect("แฮชผิดพลาด");
    ให้ m1: สเกลาร์<Secp256k1> =
        สเกลาร์::from_bigint(&(BigInt::from_bytes(hasher.finish().unwrap().as_ref())));
    ให้ k1 = สเกลาร์::<Secp256k1>::สุ่ม();
    ให้ signaturePoint1 = Point::generator() * k1.clone();
    ให้ r1 = สเกลาร์::from_bigint(&(signaturePoint1.x_coord().unwrap()));
    ให้ s1 = k1.clone().invert().unwrap() * (m1.clone() + D.clone() * r1.clone());
    println!("r1: {:?}", r1.to_bigint());
    println!("s1: {:?}", s1.to_bigint());
    hasher.update(message2.as_bytes()).expect("แฮชผิดพลาด");
    ให้ m2: สเกลาร์<Secp256k1> =
        สเกลาร์::from_bigint(&(BigInt::from_bytes(hasher.finish().unwrap().as_ref())));
    ให้ a: สเกลาร์<Secp256k1> = สเกลาร์::สุ่ม();
    ให้ b: สเกลาร์<Secp256k1> = สเกลาร์::สุ่ม();
    ให้ h: สเกลาร์<Secp256k1> = สเกลาร์::สุ่ม();
    ให้ e: สเกลาร์<Secp256k1> = สเกลาร์::สุ่ม();
    ให้คุณ: สเกลาร์<Secp256k1> = สเกลาร์::จาก(0 เป็น u16);
    ให้ j: สเกลาร์<Secp256k1> = สเกลาร์::จาก(0 เป็น u16);
    ให้ Z = a.clone() * k1.clone() * จุด :: เครื่องกำเนิดไฟฟ้า ()
        + b.clone() * k1.clone() * V.โคลน()
        + j.clone() * h.clone() * จุด :: เครื่องกำเนิด ()
        + u.clone() * e.clone() * V.clone();
    ให้ zX = Z.x_coord().แกะ();
    hasher.update(&zX.to_bytes()).expect("แฮชผิดพลาด");
    ให้แฮช =
        สเกลาร์::<Secp256k1>::from_bigint(&(BigInt::from_bytes(hasher.finish().unwrap().as_ref())));
    ให้ k2 = แฮช;
    ให้ signaturePoint2 = k2.clone() * Point::generator();
    ให้ r2 = สเกลาร์::<Secp256k1>::from_bigint(&signaturePoint2.x_coord().unwrap());
    ให้ s2 = k2.clone().invert().unwrap() * (m2.clone() + r2.clone() * D.clone());
    println!("r2: {:?}", r2.to_bigint());
    println!("s2: {:?}", s2.to_bigint());
    ให้กู้คืน = ExtractUsersPrivateKey (message1, message2, a, b, h, e, r1, s1, r2, s2, v, V, Q);
    println!("{:?}",recovered.to_bigint());
}
fn ExtractUsersPrivateKey(
    ข้อความที่ 1: สตริง
    ข้อความที่ 2: สตริง,
    a: สเกลาร์<Secp256k1>,
    b: สเกลาร์<Secp256k1>,
    ชั่วโมง: สเกลาร์<Secp256k1>,
    จ: สเกลาร์<Secp256k1>,
    r1: สเกลาร์<Secp256k1>,
    s1: สเกลาร์<Secp256k1>,
    r2: สเกลาร์<Secp256k1>,
    s2: สเกลาร์<Secp256k1>,
    ผู้โจมตีส่วนตัว: สเกลาร์<Secp256k1>,
    ผู้โจมตีสาธารณะ: จุด<Secp256k1>,
    userPublic: จุด<Secp256k1>,
) -> สเกลาร์<Secp256k1> {
    ให้ mut hasher = Hasher::new(MessageDigest::sha256()).unwrap();
    hasher.update(message1.as_bytes()).expect("แฮชผิดพลาด");
    ให้ m1: สเกลาร์<Secp256k1> =
        สเกลาร์::from_bigint(&(BigInt::from_bytes(hasher.finish().unwrap().as_ref())));
    hasher.update(message2.as_bytes()).expect("แฮชผิดพลาด");
    ให้ m2: สเกลาร์<Secp256k1> =
        สเกลาร์::from_bigint(&(BigInt::from_bytes(hasher.finish().unwrap().as_ref())));
    ให้ w = s1.invert().แกะ();
    ให้ u1 = m1.clone() * w.clone();
    ให้ u2 = r1.clone() * w.clone();
    ให้ VerifyPoint = u1.clone() * Point::generator() + u2.clone() * userPublic.clone();
    ให้ Z1 = VerifyPoint.clone() * a.clone()
        + (verifyPoint.clone() * b.clone() * AttackerPrivate.clone());
    ให้คุณ: สเกลาร์<Secp256k1> = สเกลาร์::จาก(0 เป็น u16);
    ให้ j: สเกลาร์<Secp256k1> = สเกลาร์::จาก(0 เป็น u16);
    ให้ Z2 = Z1.clone()
        + j.clone() * h.clone() * จุด :: เครื่องกำเนิด ()
        + u.clone() * e.clone() * ผู้โจมตี Public.clone();
    ให้ zX: สเกลาร์<Secp256k1> = สเกลาร์::from_bigint(&Z2.x_coord().แกะ());
    hasher.update(&zX.to_bigint().to_bytes()).expect("แฮชผิดพลาด");
    ให้แฮช: สเกลาร์<Secp256k1> =
        สเกลาร์::from_bigint(&BigInt::from_bytes(hasher.finish().unwrap().as_ref()));
    ให้ kCandiate = hash.clone();
    ให้ VerifyPointCandiate = kCandiate.clone() * Point::generator();
    ให้ rCandiate = VerifyPointCandiate.x_coord().แกะ();
    ถ้า rCandiate == r2.to_bigint() {
        ส่งคืน (s2.clone() * kCandiate.clone() - m2) * (r2.invert().unwrap());
    }
    สเกลาร์::สุ่ม()
}
นี่คือห้องสมุดที่ฉันใช้
[การพึ่งพา]
โค้ง-kzen = "0.8"
opensl = "0.10"
opensl-sys = "0.9"