Exemple #1
0
        public static RandContext init_det(RandGen rand_gen, byte[] seed)
        {
            RandContext rand_ctx     = RandContext.Default();
            IntPtr      rand_ctx_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(rand_ctx.rand_ctx));

            Marshal.StructureToPtr(rand_ctx.rand_ctx, rand_ctx_ptr, false);
            IntPtr rand_gen_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(rand_gen));

            Marshal.StructureToPtr(rand_gen, rand_gen_ptr, false);
            IntPtr seed_ptr = Marshal.AllocHGlobal(seed.Length);

            Marshal.Copy(seed, 0, seed_ptr, seed.Length);
            IntPtr seed_len_ptr = new IntPtr(seed.Length);
            var    result       = ffi.ntru_rand_init_det(rand_ctx_ptr, rand_gen_ptr, seed_ptr, seed_len_ptr);

            if (result.ToInt32() != 0)
            {
                Console.WriteLine("Error: Failed to Initialize Deterministic RandomContext");
            }
            rand_ctx.rand_ctx = (ffi.CNtruRandContext)Marshal.PtrToStructure(rand_ctx_ptr, typeof(ffi.CNtruRandContext));
            //Marshal.FreeHGlobal(rand_ctx_ptr);
            //Marshal.FreeHGlobal(rand_gen_ptr);
            Marshal.FreeHGlobal(seed_ptr);
            return(rand_ctx);
        }
Exemple #2
0
        public RandGen get_rng()
        {
            RandGen get_rng = rand.RNG_DEFAULT;

            Marshal.PtrToStructure(rand_ctx.rand_gen, get_rng);
            return(get_rng);
        }
Exemple #3
0
        public static RandContext init(RandGen rand_gen)
        {
            RandContext rand_ctx     = RandContext.Default();
            IntPtr      rand_ctx_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(rand_ctx.rand_ctx));

            Marshal.StructureToPtr(rand_ctx.rand_ctx, rand_ctx_ptr, false);
            IntPtr rand_gen_ptr = Marshal.AllocHGlobal(Marshal.SizeOf(rand_gen));

            Marshal.StructureToPtr(rand_gen, rand_gen_ptr, false);
            var result = ffi.ntru_rand_init(rand_ctx_ptr, rand_gen_ptr);

            if (result.ToInt32() != 0)
            {
                Console.WriteLine("Error: Failed to Initialize RandomContext");
            }
            rand_ctx.rand_ctx = (ffi.CNtruRandContext)Marshal.PtrToStructure(rand_ctx_ptr, typeof(ffi.CNtruRandContext));
            return(rand_ctx);
        }