------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- This file is part of 'Finite Field Arithmetic', aka 'FFA'. -- -- -- -- (C) 2019 Stanislav Datskovskiy ( www.loper-os.org ) -- -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html -- -- -- -- You do not have, nor can you ever acquire the right to use, copy or -- -- distribute this software ; Should you use this software for any purpose, -- -- or copy and distribute it to anyone or in any manner, you are breaking -- -- the laws of whatever soi-disant jurisdiction, and you promise to -- -- continue doing so for the indefinite future. In any case, please -- -- always : read and understand any software ; verify any PGP signatures -- -- that you use - for any purpose. -- -- -- -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . -- ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ with Words; use Words; with FZ_Type; use FZ_Type; package FZ_Barr is pragma Pure; -- Precomputed data for Barrett's Modular Reduction type Barretoid(ZXMLength : Indices; BarretoidLength : Indices) is record ZXM : FZ(1 .. ZXMLength); -- Zero-Extended Modulus J : FZBit_Index; -- Jm B : FZ(1 .. BarretoidLength); -- The Barrettoid itself ZSlide : FZBit_Index; -- Amount to slide Z Degenerate : WBool; -- Is it degenerate case? end record; -- Prepare the precomputed Barrettoid corresponding to a given Modulus procedure FZ_Make_Barrettoid(Modulus : in FZ; Result : out Barretoid) with Pre => Result.B'Length = 2 * Modulus'Length and Result.ZXM'Length = Modulus'Length + 1; -- Reduce N using the given precomputed Barrettoid. procedure FZ_Barrett_Reduce(X : in FZ; Bar : in Barretoid; XReduced : in out FZ); pragma Inline_Always(FZ_Barrett_Reduce); end FZ_Barr;