Exemplo n.º 1
0
 public ProdPoly(ushort n, TernPoly f1, TernPoly f2, TernPoly f3)
 {
     this.n  = n;
     this.f1 = f1;
     this.f2 = f2;
     this.f3 = f3;
 }
Exemplo n.º 2
0
        public override bool Equals(object obj)
        {
            TernPoly other = (TernPoly)obj;

            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            if (this.n == other.n && this.num_ones == other.num_ones && this.num_neg_ones == other.num_neg_ones)
            {
                for (int i = 0; i < types.MAX_ONES; i++)
                {
                    if (this.ones[i] != other.ones[i])
                    {
                        return(false);
                    }
                    if (this.neg_ones[i] != other.neg_ones[i])
                    {
                        return(false);
                    }
                }
            }
            else
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        public static ProdPoly rand(ushort n, ushort df1, ushort df2, ushort df3_ones, ushort df3_neg_ones, RandContext rand_ctx)
        {
            TernPoly f1 = TernPoly.rand(n, df1, df1, rand_ctx);
            TernPoly f2 = TernPoly.rand(n, df2, df2, rand_ctx);
            TernPoly f3 = TernPoly.rand(n, df3_ones, df3_neg_ones, rand_ctx);

            return(new ProdPoly(n, f1, f2, f3));
        }
Exemplo n.º 4
0
        public static TernPoly rand(ushort n, ushort num_ones, ushort num_neg_ones, RandContext rand_ctx)
        {
            TernPoly poly     = TernPoly.Default();
            IntPtr   poly_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(poly));

            Marshal.StructureToPtr(poly, poly_ptr, false);
            IntPtr rand_ctx_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(rand_ctx.rand_ctx));

            Marshal.StructureToPtr(rand_ctx.rand_ctx, rand_ctx_ptr, false);
            var result = ffi.ntru_rand_tern(n, num_ones, num_neg_ones, poly_ptr, rand_ctx_ptr);

            if (result == 0)
            {
                Console.WriteLine("Error: Failed to Generate Random TernPoly");
            }
            poly = (TernPoly)Marshal.PtrToStructure(poly_ptr, typeof(TernPoly));
            Marshal.FreeHGlobal(poly_ptr);
            Marshal.FreeHGlobal(rand_ctx_ptr);
            return(poly);
        }
Exemplo n.º 5
0
 public static PrivPoly new_with_tern_poly(TernPoly poly)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 6
0
 public static ProdPoly Default()
 {
     return(new ProdPoly(0, TernPoly.Default(), TernPoly.Default(), TernPoly.Default()));
 }