mirror of
https://github.com/saymrwulf/risc0-curve25519-dalek-source.git
synced 2026-09-05 20:10:35 +00:00
113 lines
6.9 KiB
Rust
113 lines
6.9 KiB
Rust
// -*- mode: rust; -*-
|
|
//
|
|
// This file is part of curve25519-dalek.
|
|
// Copyright (c) 2016-2017 Isis Lovecruft, Henry de Valence
|
|
// See LICENSE for licensing information.
|
|
//
|
|
// Authors:
|
|
// - Isis Agora Lovecruft <isis@patternsinthevoid.net>
|
|
// - Henry de Valence <hdevalence@hdevalence.ca>
|
|
|
|
//! This module contains constants used by the AVX2 backend.
|
|
|
|
use stdsimd::simd::u32x8;
|
|
|
|
use scalar_mul::window::OddLookupTable;
|
|
use backend::avx2::field::FieldElement32x4;
|
|
use backend::avx2::edwards::{ExtendedPoint, CachedPoint};
|
|
|
|
/// The low limbs of (2p, 2p, 2p, 2p), so that
|
|
/// ```no_run
|
|
/// (2p, 2p, 2p, 2p) = [P_TIMES_2_LO, P_TIMES_2_HI, P_TIMES_2_HI, P_TIMES_2_HI, P_TIMES_2_HI]
|
|
/// ```
|
|
pub(crate) static P_TIMES_2_LO: u32x8 =
|
|
u32x8::new(67108845 << 1, 67108845 << 1, 33554431 << 1, 33554431 << 1, 67108845 << 1, 67108845 << 1, 33554431 << 1, 33554431 << 1);
|
|
|
|
/// The high limbs of (2p, 2p, 2p, 2p), so that
|
|
/// ```no_run
|
|
/// (2p, 2p, 2p, 2p) = [P_TIMES_2_LO, P_TIMES_2_HI, P_TIMES_2_HI, P_TIMES_2_HI, P_TIMES_2_HI]
|
|
/// ```
|
|
pub(crate) static P_TIMES_2_HI: u32x8 =
|
|
u32x8::new(67108863 << 1, 67108863 << 1, 33554431 << 1, 33554431 << 1, 67108863 << 1, 67108863 << 1, 33554431 << 1, 33554431 << 1);
|
|
|
|
/// The low limbs of (16p, 16p, 16p, 16p), so that
|
|
/// ```no_run
|
|
/// (16p, 16p, 16p, 16p) = [P_TIMES_16_LO, P_TIMES_16_HI, P_TIMES_16_HI, P_TIMES_16_HI, P_TIMES_16_HI]
|
|
/// ```
|
|
pub(crate) static P_TIMES_16_LO: u32x8 =
|
|
u32x8::new(67108845 << 4, 67108845 << 4, 33554431 << 4, 33554431 << 4, 67108845 << 4, 67108845 << 4, 33554431 << 4, 33554431 << 4);
|
|
|
|
/// The high limbs of (16p, 16p, 16p, 16p), so that
|
|
/// ```no_run
|
|
/// (16p, 16p, 16p, 16p) = [P_TIMES_16_LO, P_TIMES_16_HI, P_TIMES_16_HI, P_TIMES_16_HI, P_TIMES_16_HI]
|
|
/// ```
|
|
pub(crate) static P_TIMES_16_HI: u32x8 =
|
|
u32x8::new(67108863 << 4, 67108863 << 4, 33554431 << 4, 33554431 << 4, 67108863 << 4, 67108863 << 4, 33554431 << 4, 33554431 << 4);
|
|
|
|
pub(crate) static P_TIMES_2_MASKED: FieldElement32x4 = FieldElement32x4([
|
|
u32x8::new( 0, 134217690, 0, 67108862, 134217690, 0, 67108862, 0),
|
|
u32x8::new( 0, 134217726, 0, 67108862, 134217726, 0, 67108862, 0),
|
|
u32x8::new( 0, 134217726, 0, 67108862, 134217726, 0, 67108862, 0),
|
|
u32x8::new( 0, 134217726, 0, 67108862, 134217726, 0, 67108862, 0),
|
|
u32x8::new( 0, 134217726, 0, 67108862, 134217726, 0, 67108862, 0)
|
|
]);
|
|
|
|
/// Odd multiples of the Ed25519 basepoint:
|
|
pub(crate) static BASEPOINT_ODD_LOOKUP_TABLE: OddLookupTable<CachedPoint> =
|
|
OddLookupTable([
|
|
CachedPoint(FieldElement32x4([
|
|
u32x8::new(3571425, 10045002, 19036563, 1096096, 243332, 65897020, 0, 28963681),
|
|
u32x8::new(30896895, 63055514, 1614915, 5095970, 0, 53791688, 0, 31258312),
|
|
u32x8::new(13347627, 40339464, 2236269, 11185503, 0, 22520087, 0, 8659512),
|
|
u32x8::new(11125413, 29139905, 32037254, 28360723, 0, 64556417, 0, 9635759),
|
|
u32x8::new(33268144, 47262491, 4336918, 15795740, 0, 22027545, 0, 4846528),
|
|
])),
|
|
CachedPoint(FieldElement32x4([
|
|
u32x8::new(47099681, 31447946, 29365447, 24740513, 42991046, 18317844, 16051644, 21404226),
|
|
u32x8::new(31708133, 28909527, 2366091, 13703791, 469246, 54159622, 2601402, 32988002),
|
|
u32x8::new(63432457, 30251794, 15163516, 18491340, 28144087, 35605455, 13682295, 18474872),
|
|
u32x8::new(12221607, 4967598, 26061980, 26008006, 20226147, 9726961, 17410, 18051083),
|
|
u32x8::new(60569645, 62487085, 11911242, 21920922, 4092105, 38186967, 22431483, 31366585),
|
|
])),
|
|
CachedPoint(FieldElement32x4([
|
|
u32x8::new(18147205, 62587998, 2554617, 536692, 11924528, 26674131, 17645433, 24341419),
|
|
u32x8::new(11573357, 27579485, 31491870, 29000885, 10800976, 51902791, 28076395, 20464029),
|
|
u32x8::new(56031649, 10856669, 11791193, 26769430, 25306956, 5922200, 6630685, 9385098),
|
|
u32x8::new(31319348, 23906711, 16290213, 32142166, 61106354, 17181823, 3548308, 12022566),
|
|
u32x8::new(5904298, 50218605, 11826440, 5492249, 10379071, 3472255, 172742, 31948344),
|
|
])),
|
|
CachedPoint(FieldElement32x4([
|
|
u32x8::new(10625852, 15193821, 22918394, 23676410, 53695416, 54987793, 10067515, 11747680),
|
|
u32x8::new(65013325, 1309652, 29616320, 28922974, 60360891, 19621771, 9938982, 30406429),
|
|
u32x8::new(54967954, 65931918, 5595602, 25719523, 64909864, 30566415, 15945272, 8495317),
|
|
u32x8::new(1167157, 55265018, 11507029, 31641054, 43497904, 2367338, 12937761, 27517066),
|
|
u32x8::new(656704, 2544994, 13006713, 480979, 38471594, 62541240, 25353597, 11531760),
|
|
])),
|
|
CachedPoint(FieldElement32x4([
|
|
u32x8::new(22176662, 3984313, 27495285, 4110608, 2909584, 30594106, 15677919, 2549183),
|
|
u32x8::new(33979105, 62269905, 2071511, 6894756, 53189950, 47232857, 6408191, 6123225),
|
|
u32x8::new(32553873, 63948030, 12612401, 3633166, 24054373, 37626618, 14481327, 8520484),
|
|
u32x8::new(56552486, 10749438, 12034813, 28811946, 1445640, 36755601, 12104575, 10257833),
|
|
u32x8::new(22795808, 48761311, 1136056, 9380768, 1411523, 5341811, 27318329, 9686767)])),
|
|
CachedPoint(FieldElement32x4([
|
|
u32x8::new(21157200, 39156966, 20473176, 4934657, 61478183, 45121537, 5429856, 13035023),
|
|
u32x8::new(7954529, 58789246, 31440083, 7054221, 38438565, 36856107, 1364112, 14548122),
|
|
u32x8::new(26120083, 36321360, 4919997, 31687496, 33757765, 36237559, 15243054, 32163861),
|
|
u32x8::new(25878307, 46544824, 19455951, 2414935, 16844726, 56521560, 32680554, 26660660),
|
|
u32x8::new(48360220, 43407178, 12187042, 24925816, 7423722, 25746484, 12814654, 17395963),
|
|
])),
|
|
CachedPoint(FieldElement32x4([
|
|
u32x8::new(63153652, 32195955, 4087908, 8431689, 30392384, 47203165, 8986649, 9053039),
|
|
u32x8::new(63659241, 47988767, 2931872, 19953600, 11747107, 51610101, 20952181, 13364887),
|
|
u32x8::new(3659197, 58790649, 5930099, 2605312, 28477896, 580728, 20579735, 2610622),
|
|
u32x8::new(41781607, 17161358, 10690531, 24368015, 47027031, 36742339, 5414694, 13156365),
|
|
u32x8::new(13237853, 51182423, 8954802, 29006542, 22643989, 56896541, 22830593, 10289708),
|
|
])),
|
|
CachedPoint(FieldElement32x4([
|
|
u32x8::new(1401265, 58846825, 30911620, 32239180, 15391552, 15200821, 6339309, 16403588),
|
|
u32x8::new(55913797, 29541724, 1664461, 21709410, 38470488, 47097092, 17674945, 32666066),
|
|
u32x8::new(22844482, 10797709, 27548106, 31638735, 34500968, 26611503, 19727211, 13160873),
|
|
u32x8::new(31485204, 14496164, 13981208, 10276888, 5748808, 35024436, 2740987, 7479021),
|
|
u32x8::new(58541207, 14866135, 32344041, 545930, 62661488, 6941250, 27940205, 11976112),
|
|
])),
|
|
]);
|