------------------------------------------------------------------------------ ------------------------------------------------------------------------------ -- This file is part of 'Finite Field Arithmetic', aka 'FFA'. -- -- -- -- (C) 2018 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 FZ_Arith; with FZ_Shift; with FZ_Mul; -- Wrapper bodies for routines that we inline, but must enforce preconditions -- on when called by FFA user. package body FFA is ---------------------------------------------------------------------------- --- FZ Basics ---------------------------------------------------------------------------- -- Exchange X and Y procedure FFA_FZ_Swap(X : in out FZ; Y : in out FZ) is begin FZ_Basic.FZ_Swap(X => X, Y => Y); end FFA_FZ_Swap; -- Constant-time MUX: Sel = 0: Result := X; Sel = 1: Result := Y procedure FFA_FZ_Mux(X : in FZ; Y : in FZ; Result : out FZ; Sel : in WBool) is begin FZ_Basic.FZ_Mux(X => X, Y => Y, Result => Result, Sel => Sel); end FFA_FZ_Mux; ---------------------------------------------------------------------------- --- Bitwise Operations on FZ ---------------------------------------------------------------------------- -- Result := X & Y procedure FFA_FZ_And(X : in FZ; Y : in FZ; Result : out FZ) is begin FZ_BitOp.FZ_And(X => X, Y => Y, Result => Result); end FFA_FZ_And; -- Result := X | Y procedure FFA_FZ_Or(X : in FZ; Y : in FZ; Result : out FZ) is begin FZ_BitOp.FZ_Or(X => X, Y => Y, Result => Result); end FFA_FZ_Or; -- Result := X ^ Y procedure FFA_FZ_Xor(X : in FZ; Y : in FZ; Result : out FZ) is begin FZ_BitOp.FZ_Xor(X => X, Y => Y, Result => Result); end FFA_FZ_Xor; -- NotN := ~N ('ones complement') procedure FFA_FZ_Not(N : in FZ; NotN : out FZ) is begin FZ_BitOp.FZ_Not(N => N, NotN => NotN); end FFA_FZ_Not; ---------------------------------------------------------------------------- --- Arithmetic on FZ ---------------------------------------------------------------------------- -- Sum := X + Y; Overflow := Carry procedure FFA_FZ_Add(X : in FZ; Y : in FZ; Sum : out FZ; Overflow : out WBool) is begin FZ_Arith.FZ_Add(X => X, Y => Y, Sum => Sum, Overflow => Overflow); end FFA_FZ_Add; -- Difference := X - Y; Underflow := Borrow procedure FFA_FZ_Subtract(X : in FZ; Y : in FZ; Difference : out FZ; Underflow : out WBool) is begin FZ_Arith.FZ_Sub(X => X, Y => Y, Difference => Difference, Underflow => Underflow); end FFA_FZ_Subtract; ---------------------------------------------------------------------------- --- Multiplication on FZ ---------------------------------------------------------------------------- procedure FFA_FZ_Multiply(X : in FZ; Y : in FZ; XY_Lo : out FZ; XY_Hi : out FZ) is begin FZ_Mul.FZ_Multiply_Buffered(X => X, Y => Y, XY_Lo => XY_Lo, XY_Hi => XY_Hi); end FFA_FZ_Multiply; end FFA;