efficient_sm2/
limb.rs

1// Copyright 2020 Yao Pengfei.
2//
3// Permission to use, copy, modify, and/or distribute this software for any
4// purpose with or without fee is hereby granted, provided that the above
5// copyright notice and this permission notice appear in all copies.
6//
7// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
8// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
10// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
14
15// XXX: Not correct for x32 ABIs.
16#[cfg(target_pointer_width = "64")]
17pub type Limb = u64;
18#[cfg(target_pointer_width = "32")]
19pub type Limb = u32;
20#[cfg(target_pointer_width = "64")]
21pub const LIMB_BITS: usize = 64;
22#[cfg(target_pointer_width = "32")]
23pub const LIMB_FULL: Limb = 0xffff_ffff;
24#[cfg(target_pointer_width = "64")]
25pub const LIMB_FULL: Limb = 0xffff_ffff_ffff_ffff;
26#[cfg(target_pointer_width = "32")]
27pub const LIMB_BITS: usize = 32;
28#[cfg(target_pointer_width = "64")]
29pub type DoubleLimb = u128;
30#[cfg(target_pointer_width = "32")]
31pub type DoubleLimb = u64;
32#[cfg(target_pointer_width = "64")]
33pub const LIMB_LENGTH: usize = 4;
34#[cfg(target_pointer_width = "32")]
35pub const LIMB_LENGTH: usize = 8;
36pub const LIMB_BYTES: usize = (LIMB_BITS + 7) / 8;
37#[cfg(target_pointer_width = "64")]
38pub const ONE: [Limb; LIMB_LENGTH] = [1, 0, 0, 0];
39#[cfg(target_pointer_width = "32")]
40pub const ONE: [Limb; LIMB_LENGTH] = [1, 0, 0, 0, 0, 0, 0, 0];