//! Tip5 constants โ€” LOOKUP_TABLE, ROUND_CONSTANTS (in raw Montgomery form),
//! MDS_MATRIX_FIRST_COLUMN. Values copied verbatim from `twenty_first` 1.1.0.

use super::scalar::montyred;

/// 256-entry S-box table. See `Tip5::offset_fermat_cube_map`.
#[rustfmt::skip]
pub const LOOKUP_TABLE: [u8; 256] = [
      0,   7,  26,  63, 124, 215,  85, 254, 214, 228,  45, 185, 140, 173,  33, 240,
     29, 177, 176,  32,   8, 110,  87, 202, 204,  99, 150, 106, 230,  14, 235, 128,
    213, 239, 212, 138,  23, 130, 208,   6,  44,  71,  93, 116, 146, 189, 251,  81,
    199,  97,  38,  28,  73, 179,  95,  84, 152,  48,  35, 119,  49,  88, 242,   3,
    148, 169,  72, 120,  62, 161, 166,  83, 175, 191, 137,  19, 100, 129, 112,  55,
    221, 102, 218,  61, 151, 237,  68, 164,  17, 147,  46, 234, 203, 216,  22, 141,
     65,  57, 123,  12, 244,  54, 219, 231,  96,  77, 180, 154,   5, 253, 133, 165,
     98, 195, 205, 134, 245,  30,   9, 188,  59, 142, 186, 197, 181, 144,  92,  31,
    224, 163, 111,  74,  58,  69, 113, 196,  67, 246, 225,  10, 121,  50,  60, 157,
     90, 122,   2, 250, 101,  75, 178, 159,  24,  36, 201,  11, 243, 132, 198, 190,
    114, 233,  39,  52,  21, 209, 108, 238,  91, 187,  18, 104, 194,  37, 153,  34,
    200, 143, 126, 155, 236, 118,  64,  80, 172,  89,  94, 193, 135, 183,  86, 107,
    252,  13, 167, 206, 136, 220, 207, 103, 171, 160,  76, 182, 227, 217, 158,  56,
    174,   4,  66, 109, 139, 162, 184, 211, 249,  47, 125, 232, 117,  43,  16,  42,
    127,  20, 241,  25, 149, 105, 156,  51,  53, 168, 145, 247, 223,  79,  78, 226,
     15, 222,  82, 115,  70, 210,  27,  41,   1, 170,  40, 131, 192, 229, 248, 255,
];

/// MDS-matrix first column, raw signed i64 values from `Tip5` spec.
/// These small constants are used in the `wrapping_mul` arithmetic of
/// `mds_generated`, NOT field-arithmetic โ€” they remain i64.
pub const MDS_MATRIX_FIRST_COLUMN: [i64; 16] = [
    61402, 1108, 28750, 33823, 7454, 43244, 53865, 12034, 56951, 27521, 41351, 40901, 12021, 59689,
    26798, 17845,
];

/// 80 canonical round-constant values (5 rounds ร— 16 lanes) โ€” values that
/// `BFieldElement::new(_)` accepts.
const ROUND_CONSTANTS_CANONICAL: [u64; 80] = [
    13630775303355457758,
    16896927574093233874,
    10379449653650130495,
    1965408364413093495,
    15232538947090185111,
    15892634398091747074,
    3989134140024871768,
    2851411912127730865,
    8709136439293758776,
    3694858669662939734,
    12692440244315327141,
    10722316166358076749,
    12745429320441639448,
    17932424223723990421,
    7558102534867937463,
    15551047435855531404,
    17532528648579384106,
    5216785850422679555,
    15418071332095031847,
    11921929762955146258,
    9738718993677019874,
    3464580399432997147,
    13408434769117164050,
    264428218649616431,
    4436247869008081381,
    4063129435850804221,
    2865073155741120117,
    5749834437609765994,
    6804196764189408435,
    17060469201292988508,
    9475383556737206708,
    12876344085611465020,
    13835756199368269249,
    1648753455944344172,
    9836124473569258483,
    12867641597107932229,
    11254152636692960595,
    16550832737139861108,
    11861573970480733262,
    1256660473588673495,
    13879506000676455136,
    10564103842682358721,
    16142842524796397521,
    3287098591948630584,
    685911471061284805,
    5285298776918878023,
    18310953571768047354,
    3142266350630002035,
    549990724933663297,
    4901984846118077401,
    11458643033696775769,
    8706785264119212710,
    12521758138015724072,
    11877914062416978196,
    11333318251134523752,
    3933899631278608623,
    16635128972021157924,
    10291337173108950450,
    4142107155024199350,
    16973934533787743537,
    11068111539125175221,
    17546769694830203606,
    5315217744825068993,
    4609594252909613081,
    3350107164315270407,
    17715942834299349177,
    9600609149219873996,
    12894357635820003949,
    4597649658040514631,
    7735563950920491847,
    1663379455870887181,
    13889298103638829706,
    7375530351220884434,
    3502022433285269151,
    9231805330431056952,
    9252272755288523725,
    10014268662326746219,
    15565031632950843234,
    1209725273521819323,
    6024642864597845108,
];

/// R^2 mod P where R = 2^64. Used to convert canonical โ†’ Montgomery form.
const R2: u128 = 0xffff_fffe_0000_0001;

/// Round constants in **raw Montgomery form** โ€” what gets added directly to
/// the state. Computed at compile time from the canonical values via
/// `BFieldElement::new(v) = montyred(v * R2)`.
pub const ROUND_CONSTANTS_RAW: [u64; 80] = {
    let mut out = [0u64; 80];
    let mut i = 0;
    while i < 80 {
        out[i] = montyred((ROUND_CONSTANTS_CANONICAL[i] as u128).wrapping_mul(R2));
        i += 1;
    }
    out
};

Homonyms

cyb/honeycrisp/acpu/src/field/tip5/consts.rs
cyb/honeycrisp/.claude/worktrees/agent-ad6c77c38e86bc291/acpu/src/field/tip5/consts.rs

Graph