29 lines
780 B
Rust
29 lines
780 B
Rust
use std::path::Path;
|
|
use crate::gf256::GF256;
|
|
|
|
#[path="src/gf.rs"]
|
|
mod gf;
|
|
#[path="src/gf256.rs"]
|
|
mod gf256;
|
|
|
|
fn write_tbl(path: impl AsRef<Path>, name: &str, tbl: &[u8; 256]) {
|
|
let mut res = format!("const INV_TBL: [{name}; {tbl_len}] = [\n", tbl_len=tbl.len());
|
|
for v in tbl {
|
|
res += &format!("\t{name}({v}),\n");
|
|
}
|
|
res += "];\n";
|
|
|
|
std::fs::write(path, res).unwrap();
|
|
}
|
|
|
|
pub fn main() {
|
|
let mut gf256_inv_tbl = [0;256];
|
|
for i in 0..256 {
|
|
gf256_inv_tbl[i] = u8::from(GF256::from(i as u8).minv_slow());
|
|
}
|
|
let mut out_file = std::path::PathBuf::from(std::env::var_os("OUT_DIR").unwrap());
|
|
out_file.push("gf256_inv.rs");
|
|
write_tbl(&out_file, "GF256", &gf256_inv_tbl);
|
|
|
|
println!("cargo::rustc-cfg=rssss_have_codegen")
|
|
} |