asmcrypto 0.1.2

Register-parallel cryptographic primitives: 8-lane AVX-512 Keccak-256 batch and secp256k1 ECDSA batch address recovery, outperforming libsecp256k1.
Documentation
//! Code generator: emit `src/ecdsa_ref/g_tables_generated.rs` with static G table data.
//!
//! Run:
//!   cargo run --example gen_g_tables --release > src/ecdsa_ref/g_tables_generated.rs
//!
//! The generated file is `include!`d inside `ecdsa_ref/mod.rs` and provides
//! `PRE_G_DATA` and `PRE_G128_DATA` as compile-time statics, replacing the
//! runtime OnceLock approach.  Each entry stores the 5×52-bit limbs for x
//! and y packed as `[u64; 10]`; all table entries have `infinity = false`.

use asmcrypto::ecdsa_ref::{TABLE_SIZE_G, build_g_tables_vec};

fn main() {
    let (pre_g, pre_g128) = build_g_tables_vec();
    assert_eq!(pre_g.len(), TABLE_SIZE_G);
    assert_eq!(pre_g128.len(), TABLE_SIZE_G);

    println!("// Auto-generated by `cargo run --example gen_g_tables --release`.");
    println!("// WINDOW_G = 15, TABLE_SIZE_G = {TABLE_SIZE_G}");
    println!("// Do not edit.  Re-generate if WINDOW_G or G changes.");
    println!();

    // Emit the pre_g table.
    println!("pub static PRE_G_DATA: [[u64; 10]; TABLE_SIZE_G] = [");
    for ge in &pre_g {
        let x = &ge.x.n;
        let y = &ge.y.n;
        println!(
            "    [{:#018x},{:#018x},{:#018x},{:#018x},{:#018x},\
             {:#018x},{:#018x},{:#018x},{:#018x},{:#018x}],",
            x[0], x[1], x[2], x[3], x[4], y[0], y[1], y[2], y[3], y[4],
        );
    }
    println!("];");
    println!();

    // Emit the pre_g128 table.
    println!("pub static PRE_G128_DATA: [[u64; 10]; TABLE_SIZE_G] = [");
    for ge in &pre_g128 {
        let x = &ge.x.n;
        let y = &ge.y.n;
        println!(
            "    [{:#018x},{:#018x},{:#018x},{:#018x},{:#018x},\
             {:#018x},{:#018x},{:#018x},{:#018x},{:#018x}],",
            x[0], x[1], x[2], x[3], x[4], y[0], y[1], y[2], y[3], y[4],
        );
    }
    println!("];");
    println!();

    // Emit the lookup helper (included inside ecdsa_ref so Ge/Fe are in scope).
    println!(
        r#"/// Look up entry `n` (odd, ≠ 0) from a raw G table; negate y when n < 0.
#[inline(always)]
pub fn g_table_get_ge(data: &[[u64; 10]], n: i32) -> Ge {{
    if n > 0 {{
        let d = data[((n - 1) / 2) as usize];
        Ge {{ x: Fe {{ n: [d[0], d[1], d[2], d[3], d[4]] }},
             y: Fe {{ n: [d[5], d[6], d[7], d[8], d[9]] }},
             infinity: false }}
    }} else {{
        let d = data[((-n - 1) / 2) as usize];
        Ge {{ x: Fe {{ n: [d[0], d[1], d[2], d[3], d[4]] }},
             y: fe_negate(&Fe {{ n: [d[5], d[6], d[7], d[8], d[9]] }}, 1),
             infinity: false }}
    }}
}}"#
    );
}