---------------------------------------------------------------- -- Polynomial Montgomery squaring (bsquare_montgomery.adb) -- -- Based on classic montgomery multiplier -- computes C(x) = A(x).A(x).x^(-k) mod F(x) -- ---------------------------------------------------------------- with Gnat.Io; use Gnat.Io; with GF2m; use GF2m; with finite_fields_GF2m; use finite_fields_GF2m; procedure bsquarer_montgomery is A,C: poly_vector; F: constant poly_vector := (1,1,0,0,0,0,1,1); -- F(x) = x^8 + x^7 + x^6 + x + 1 x: Bit; begin for i in 0 .. m-1 loop Put("A(");Put(i);Put(") = "); Get(x); A(i) := x; end loop; New_Line; for i in 0 .. m-1 loop C(i) := 0; end loop; for i in 0 .. m-1 loop C := m2xvv(C,m2abv(A(i),A)); if C(0) = 1 then C := m2xvv(C,m2abv(C(0),F)); C := lshift(C); C(m-1) := 1; else C := lshift(C); end if; end loop; ----------------------------------------------------- Put("C = "); for i in 0 .. m-1 loop Put(C(i)); end loop; New_Line; end bsquarer_montgomery;