1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#![no_std]
use core::arch::wasm32::unreachable;
const BUF: usize = 4096;
static mut INPUT: [u8; BUF] = [0; BUF];
static mut OUTPUT: [u8; BUF] = [0; BUF];
#[link(wasm_import_module = "env")]
unsafe extern "C" {
fn keygen(seed_ptr: *const u8, out_ptr: *mut u8) -> i32;
}
#[panic_handler]
fn panic(_: &core::panic::PanicInfo) -> ! {
unreachable()
}
#[unsafe(no_mangle)]
pub extern "C" fn input_ptr() -> *mut u8 {
(&raw mut INPUT).cast()
}
#[unsafe(no_mangle)]
pub extern "C" fn output_ptr() -> *mut u8 {
(&raw mut OUTPUT).cast()
}
#[unsafe(no_mangle)]
pub extern "C" fn run(len: i32) -> i32 {
if len != 32 || unsafe { keygen(input_ptr(), output_ptr()) } != 33 {
unreachable()
}
33
}