File : fz_modex.ads
1 ------------------------------------------------------------------------------
2 ------------------------------------------------------------------------------
3 -- This file is part of 'Finite Field Arithmetic', aka 'FFA'. --
4 -- --
5 -- (C) 2019 Stanislav Datskovskiy ( www.loper-os.org ) --
6 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
7 -- --
8 -- You do not have, nor can you ever acquire the right to use, copy or --
9 -- distribute this software ; Should you use this software for any purpose, --
10 -- or copy and distribute it to anyone or in any manner, you are breaking --
11 -- the laws of whatever soi-disant jurisdiction, and you promise to --
12 -- continue doing so for the indefinite future. In any case, please --
13 -- always : read and understand any software ; verify any PGP signatures --
14 -- that you use - for any purpose. --
15 -- --
16 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
17 ------------------------------------------------------------------------------
18 ------------------------------------------------------------------------------
19
20 with FZ_Type; use FZ_Type;
21 with FZ_Barr; use FZ_Barr;
22
23
24 package FZ_ModEx is
25
26 pragma Pure;
27
28 -- (Conventional) Modular Multiply: Product := X*Y mod Modulus
29 procedure FZ_Mod_Mul(X : in FZ;
30 Y : in FZ;
31 Modulus : in FZ;
32 Product : out FZ)
33 with Pre => X'Length = Y'Length and
34 Modulus'Length = X'Length and
35 Product'Length = Modulus'Length;
36
37 -- (Conventional) Modular Squaring: Product := X*X mod Modulus
38 procedure FZ_Mod_Sqr(X : in FZ;
39 Modulus : in FZ;
40 Product : out FZ)
41 with Pre => Modulus'Length = X'Length and
42 Product'Length = Modulus'Length;
43
44 -- (Barrettronic) Modular Squaring, using given Barrettoid
45 procedure FZ_Mod_Sqr_Barrett(X : in FZ;
46 Bar : in Barretoid;
47 Product : out FZ);
48 pragma Inline_Always(FZ_Mod_Sqr_Barrett);
49
50 -- Barrettronic Modular Exponent, using given Barrettoid
51 procedure FZ_Mod_Exp_Barrett(Base : in FZ;
52 Exponent : in FZ;
53 Bar : in Barretoid;
54 Result : out FZ);
55 pragma Inline_Always(FZ_Mod_Exp_Barrett);
56
57 -- (Barrettronic) Modular Exponent: Result := Base^Exponent mod Modulus
58 procedure FZ_Mod_Exp(Base : in FZ;
59 Exponent : in FZ;
60 Modulus : in FZ;
61 Result : out FZ) with
62 Pre => Base'Length = Exponent'Length and
63 Base'Length = Result'Length and
64 Base'Length = Modulus'Length;
65
66 end FZ_ModEx;