public override bool Equals(object obj) { IntPoly other = (IntPoly)obj; if (obj == null || GetType() != obj.GetType()) { return(false); } if (this.n == other.n) { for (int i = 0; i < this.coeffs.Length; i++) { if (this.coeffs[i] != other.coeffs[i]) { return(false); } } } else { return(false); } return(true); }
public void add(IntPoly rhs) { IntPtr this_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(this)); Marshal.StructureToPtr(this, this_ptr, false); IntPtr other_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(rhs)); Marshal.StructureToPtr(rhs, other_ptr, false); ffi.ntru_add(this_ptr, other_ptr); this = (IntPoly)Marshal.PtrToStructure(this_ptr, typeof(IntPoly)); Marshal.FreeHGlobal(this_ptr); Marshal.FreeHGlobal(other_ptr); }
public static IntPoly from_arr(byte[] arr, ushort n, ushort q) { IntPoly p = IntPoly.Default(); IntPtr poly_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(p)); Marshal.StructureToPtr(p, poly_ptr, false); IntPtr arr_ptr = Marshal.AllocHGlobal(arr.Length); Marshal.Copy(arr, 0, arr_ptr, arr.Length); ffi.ntru_from_arr(arr_ptr, n, q, poly_ptr); p = (IntPoly)Marshal.PtrToStructure(poly_ptr, typeof(IntPoly)); Marshal.FreeHGlobal(poly_ptr); Marshal.FreeHGlobal(arr_ptr); return(p); }
public static PublicKey Default() { return(new PublicKey(0, IntPoly.Default())); }
public PublicKey(ushort q, IntPoly h) { this.q = q; this.h = h; }