---------------------------------------------------------------- -- Bit level Montgomery modular multiplication (bmult_montgomey.adb) -- a second equivalent version -- -- compures c=a.b.(r**-1) mod f, being r = 2**k -- ---------------------------------------------------------------- with Gnat.Io; use Gnat.Io; with GF2m; use GF2m; with finite_fields_GF2m; use finite_fields_GF2m; procedure bmult_montgomery_v2 is A,B,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 -- F: constant poly_vector := (1,1,0,1,1,0,0,0); prev_c0 : 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 Put("B(");Put(i);Put(") = "); Get(x); B(i) := x; end loop; New_Line; A:=(1,1,0,1,0,1,0,1); B:=(0,1,0,1,0,1,0,1); 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),B)); prev_C0 := C(0); C := m2xvv(C,m2abv(C(0),F)); C := lshift(C); C(m-1) := prev_C0; Put("C ("); put(i); Put(") = "); for i in 0 .. m-1 loop Put(C(i)); end loop; New_Line; end loop; ----------------------------------------------------- Put("C (v2) = "); for i in 0 .. m-1 loop Put(C(i)); end loop; New_Line; end bmult_montgomery_v2;