-
+ 9BD9383546E9B4E6EBD42F6E4DC7BB07A449487CEA22AE1D5EFAC8D74AF48907D827295E6E388A1912D964E3A6D5C818A4250BFCB95505CA6E5310F2CA0FE355
ffa/libffa/ffa.adb
(0 . 0)(1 . 110)
678 ------------------------------------------------------------------------------
679 ------------------------------------------------------------------------------
680 -- This file is part of 'Finite Field Arithmetic', aka 'FFA'. --
681 -- --
682 -- (C) 2018 Stanislav Datskovskiy ( www.loper-os.org ) --
683 -- http://wot.deedbot.org/17215D118B7239507FAFED98B98228A001ABFFC7.html --
684 -- --
685 -- You do not have, nor can you ever acquire the right to use, copy or --
686 -- distribute this software ; Should you use this software for any purpose, --
687 -- or copy and distribute it to anyone or in any manner, you are breaking --
688 -- the laws of whatever soi-disant jurisdiction, and you promise to --
689 -- continue doing so for the indefinite future. In any case, please --
690 -- always : read and understand any software ; verify any PGP signatures --
691 -- that you use - for any purpose. --
692 -- --
693 -- See also http://trilema.com/2015/a-new-software-licensing-paradigm . --
694 ------------------------------------------------------------------------------
695 ------------------------------------------------------------------------------
696
697 with FZ_Arith;
698 with FZ_Shift;
699 with FZ_Mul;
700
701
702 -- Wrapper bodies for routines that we inline, but must enforce preconditions
703 -- on when called by FFA user.
704 package body FFA is
705
706 ----------------------------------------------------------------------------
707 --- FZ Basics
708 ----------------------------------------------------------------------------
709
710 -- Exchange X and Y
711 procedure FFA_FZ_Swap(X : in out FZ; Y : in out FZ) is
712 begin
713 FZ_Basic.FZ_Swap(X => X, Y => Y);
714 end FFA_FZ_Swap;
715
716 -- Constant-time MUX: Sel = 0: Result := X; Sel = 1: Result := Y
717 procedure FFA_FZ_Mux(X : in FZ; Y : in FZ;
718 Result : out FZ; Sel : in WBool) is
719 begin
720 FZ_Basic.FZ_Mux(X => X, Y => Y, Result => Result, Sel => Sel);
721 end FFA_FZ_Mux;
722
723 ----------------------------------------------------------------------------
724 --- Bitwise Operations on FZ
725 ----------------------------------------------------------------------------
726
727 -- Result := X & Y
728 procedure FFA_FZ_And(X : in FZ; Y : in FZ; Result : out FZ) is
729 begin
730 FZ_BitOp.FZ_And(X => X, Y => Y, Result => Result);
731 end FFA_FZ_And;
732
733 -- Result := X | Y
734 procedure FFA_FZ_Or(X : in FZ; Y : in FZ; Result : out FZ) is
735 begin
736 FZ_BitOp.FZ_Or(X => X, Y => Y, Result => Result);
737 end FFA_FZ_Or;
738
739 -- Result := X ^ Y
740 procedure FFA_FZ_Xor(X : in FZ; Y : in FZ; Result : out FZ) is
741 begin
742 FZ_BitOp.FZ_Xor(X => X, Y => Y, Result => Result);
743 end FFA_FZ_Xor;
744
745 -- NotN := ~N ('ones complement')
746 procedure FFA_FZ_Not(N : in FZ; NotN : out FZ) is
747 begin
748 FZ_BitOp.FZ_Not(N => N, NotN => NotN);
749 end FFA_FZ_Not;
750
751 ----------------------------------------------------------------------------
752 --- Arithmetic on FZ
753 ----------------------------------------------------------------------------
754
755 -- Sum := X + Y; Overflow := Carry
756 procedure FFA_FZ_Add(X : in FZ;
757 Y : in FZ;
758 Sum : out FZ;
759 Overflow : out WBool) is
760 begin
761 FZ_Arith.FZ_Add(X => X, Y => Y, Sum => Sum, Overflow => Overflow);
762 end FFA_FZ_Add;
763
764 -- Difference := X - Y; Underflow := Borrow
765 procedure FFA_FZ_Subtract(X : in FZ;
766 Y : in FZ;
767 Difference : out FZ;
768 Underflow : out WBool) is
769 begin
770 FZ_Arith.FZ_Sub(X => X, Y => Y, Difference => Difference,
771 Underflow => Underflow);
772 end FFA_FZ_Subtract;
773
774 ----------------------------------------------------------------------------
775 --- Multiplication on FZ
776 ----------------------------------------------------------------------------
777
778 procedure FFA_FZ_Multiply(X : in FZ;
779 Y : in FZ;
780 XY_Lo : out FZ;
781 XY_Hi : out FZ) is
782 begin
783 FZ_Mul.FZ_Multiply_Buffered(X => X, Y => Y,
784 XY_Lo => XY_Lo, XY_Hi => XY_Hi);
785 end FFA_FZ_Multiply;
786
787 end FFA;