libecdsautil_sys/
lib.rs

1#![allow(non_upper_case_globals)]
2#![allow(non_camel_case_types)]
3#![allow(non_snake_case)]
4
5include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
6
7#[cfg(test)]
8mod tests {
9    use super::*;
10    use std::mem;
11    use hex;
12    // secret: c022af10206c23f7e1f96a538bf9df814eeea39a9300c594b3473593e19c5d66
13    // public: aa353cd1b3e107ff2b6c1957fcabd8656928a07858732b56227a9f6536de7197
14
15    #[test]
16
17    fn test_ecdsa_sign_legacy() {
18        // hash is the one of an empty file
19        unsafe {
20            let expected_signature = "112e4763181666264fce3d6c670070d16e5484711958164e5b89b3772e69c304330db21764b2ad36b498806862c398b2304cb73ebb6c1f382d94f2d4ffbc0c02";
21            let expected_r = hex::decode(&expected_signature[..64]).expect("Decoding failed");
22            let expected_s = hex::decode(&expected_signature[64..]).expect("Decoding failed");
23
24            let hash_bytes = hex::decode("e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855").expect("Decoding failed");
25            let secret_bytes = hex::decode("c022af10206c23f7e1f96a538bf9df814eeea39a9300c594b3473593e19c5d66").expect("Decoding failed");
26
27            let mut signature: ecdsa_signature_t = mem::zeroed();
28            let hash: *const ecc_int256_t = hash_bytes.as_ptr() as *const ecc_int256_t;
29            let secret: *const ecc_int256_t = secret_bytes.as_ptr() as *const ecc_int256_t;
30
31            ecdsa_sign_legacy(&mut signature as *mut _, hash, secret);
32
33            let r = signature.r.p;
34            let s = signature.s.p;
35
36            assert_eq!(expected_r, r);
37            assert_eq!(expected_s, s);
38        }
39    }
40}