raw
ffa_ch14_barrett.kv     1 ------------------------------------------------------------------------------
ffa_ch14_barrett.kv 2 ------------------------------------------------------------------------------
ffa_ch14_barrett.kv 3 -- This file is part of 'Finite Field Arithmetic', aka 'FFA'. --
ffa_ch14_barrett.kv 4 -- --
ffa_ch14_barrett.kv 5 -- (C) 2018 Stanislav Datskovskiy ( www.loper-os.org ) --
ffa_ch14_barrett.kv 6 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
ffa_ch14_barrett.kv 7 -- --
ffa_ch14_barrett.kv 8 -- You do not have, nor can you ever acquire the right to use, copy or --
ffa_ch14_barrett.kv 9 -- distribute this software ; Should you use this software for any purpose, --
ffa_ch14_barrett.kv 10 -- or copy and distribute it to anyone or in any manner, you are breaking --
ffa_ch14_barrett.kv 11 -- the laws of whatever soi-disant jurisdiction, and you promise to --
ffa_ch14_barrett.kv 12 -- continue doing so for the indefinite future. In any case, please --
ffa_ch14_barrett.kv 13 -- always : read and understand any software ; verify any PGP signatures --
ffa_ch14_barrett.kv 14 -- that you use - for any purpose. --
ffa_ch14_barrett.kv 15 -- --
ffa_ch14_barrett.kv 16 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
ffa_ch14_barrett.kv 17 ------------------------------------------------------------------------------
ffa_ch14_barrett.kv 18 ------------------------------------------------------------------------------
ffa_ch14_barrett.kv 19
ffa_ch14_barrett.kv 20 with Words; use Words;
ffa_ch14_barrett.kv 21 with FZ_Type; use FZ_Type;
ffa_ch14_barrett.kv 22
ffa_ch14_barrett.kv 23
ffa_ch14_barrett.kv 24 package FZ_Barr is
ffa_ch14_barrett.kv 25
ffa_ch14_barrett.kv 26 pragma Pure;
ffa_ch14_barrett.kv 27
ffa_ch14_barrett.kv 28 -- Precomputed data for Barrett's Modular Reduction
ffa_ch14_barrett.kv 29 type Barretoid(ZXMLength : Indices;
ffa_ch14_barrett.kv 30 BarretoidLength : Indices) is
ffa_ch14_barrett.kv 31 record
ffa_ch14_barrett.kv 32 ZXM : FZ(1 .. ZXMLength); -- Zero-Extended Modulus
ffa_ch14_barrett.kv 33 J : FZBit_Index; -- Jm
ffa_ch14_barrett.kv 34 B : FZ(1 .. BarretoidLength); -- The Barrettoid itself
ffa_ch14_barrett.kv 35 ZSlide : FZBit_Index; -- Amount to slide Z
ffa_ch14_barrett.kv 36 Degenerate : WBool; -- Is it degenerate case?
ffa_ch14_barrett.kv 37 end record;
ffa_ch14_barrett.kv 38
ffa_ch14_barrett.kv 39
ffa_ch14_barrett.kv 40 -- Prepare the precomputed Barrettoid corresponding to a given Modulus
ffa_ch14_barrett.kv 41 procedure FZ_Make_Barrettoid(Modulus : in FZ;
ffa_ch14_barrett.kv 42 Result : out Barretoid)
ffa_ch14_barrett.kv 43 with Pre => Result.B'Length = 2 * Modulus'Length and
ffa_ch14_barrett.kv 44 Result.ZXM'Length = Modulus'Length + 1;
ffa_ch14_barrett.kv 45
ffa_ch14_barrett.kv 46
ffa_ch14_barrett.kv 47 -- Reduce N using the given precomputed Barrettoid.
ffa_ch14_barrett.kv 48 procedure FZ_Barrett_Reduce(X : in FZ;
ffa_ch14_barrett.kv 49 Bar : in Barretoid;
ffa_ch14_barrett.kv 50 XReduced : in out FZ);
ffa_ch14_barrett.kv 51 pragma Inline_Always(FZ_Barrett_Reduce);
ffa_ch14_barrett.kv 52
ffa_ch14_barrett.kv 53 end FZ_Barr;