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); }
public static ProdPoly Default() { return(new ProdPoly(0, TernPoly.Default(), TernPoly.Default(), TernPoly.Default())); }