|
6 | 6 | extern crate libc;
|
7 | 7 | extern crate secp256k1;
|
8 | 8 |
|
9 |
| -use core::fmt::*; |
| 9 | +use core::fmt::{self, write, Write}; |
10 | 10 | use core::intrinsics;
|
11 | 11 | use core::panic::PanicInfo;
|
12 | 12 |
|
| 13 | +use secp256k1::rand::{self, RngCore}; |
| 14 | +use secp256k1::serde::Serialize; |
13 | 15 | use secp256k1::*;
|
14 | 16 |
|
| 17 | +struct FakeRng; |
| 18 | +impl RngCore for FakeRng { |
| 19 | + fn next_u32(&mut self) -> u32 { |
| 20 | + 57 |
| 21 | + } |
| 22 | + fn next_u64(&mut self) -> u64 { |
| 23 | + 57 |
| 24 | + } |
| 25 | + fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand::Error> { |
| 26 | + for i in dest { |
| 27 | + *i = 57; |
| 28 | + } |
| 29 | + Ok(()) |
| 30 | + } |
| 31 | + fn fill_bytes(&mut self, dest: &mut [u8]) { |
| 32 | + self.try_fill_bytes(dest).unwrap(); |
| 33 | + } |
| 34 | +} |
| 35 | + |
15 | 36 | #[start]
|
16 | 37 | fn start(_argc: isize, _argv: *const *const u8) -> isize {
|
17 | 38 | let mut buf = [0u8; 600_000];
|
18 | 39 | let size = Secp256k1::preallocate_size();
|
19 | 40 | unsafe { libc::printf("needed size: %d\n\0".as_ptr() as _, size) };
|
20 | 41 |
|
21 |
| - let secp = Secp256k1::preallocated_new(&mut buf).unwrap(); |
22 |
| - let secret_key = SecretKey::from_slice(&[0xcd; 32]).expect("32 bytes, within curve order"); |
| 42 | + let mut secp = Secp256k1::preallocated_new(&mut buf).unwrap(); |
| 43 | + secp.randomize(&mut FakeRng); |
| 44 | + let secret_key = SecretKey::new(&mut FakeRng); |
23 | 45 | let public_key = PublicKey::from_secret_key(&secp, &secret_key);
|
24 | 46 | let message = Message::from_slice(&[0xab; 32]).expect("32 bytes");
|
25 | 47 |
|
26 | 48 | let sig = secp.sign(&message, &secret_key);
|
27 | 49 | assert!(secp.verify(&message, &sig, &public_key).is_ok());
|
| 50 | + |
28 | 51 | unsafe { libc::printf("Verified Successfully!\n\0".as_ptr() as _) };
|
29 | 52 | 0
|
30 | 53 | }
|
@@ -65,7 +88,7 @@ impl Print {
|
65 | 88 | }
|
66 | 89 |
|
67 | 90 | impl Write for Print {
|
68 |
| - fn write_str(&mut self, s: &str) -> Result { |
| 91 | + fn write_str(&mut self, s: &str) -> Result<(), fmt::Error> { |
69 | 92 | let curr = self.loc;
|
70 | 93 | if curr + s.len() > MAX_PRINT {
|
71 | 94 | unsafe {
|
|
0 commit comments