Added table-driven inverse for GF(2^8)
This commit is contained in:
29
build.rs
Normal file
29
build.rs
Normal file
@@ -0,0 +1,29 @@
|
||||
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")
|
||||
}
|
||||
Reference in New Issue
Block a user