Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ML_Common.cs
1using System;
3
4namespace Waher.Security.PQC
5{
9 public abstract class ML_Common
10 {
11 private static readonly RandomNumberGenerator rnd = RandomNumberGenerator.Create();
12
16 public abstract int PublicKeyLength { get; }
17
21 public abstract int PrivateKeyLength { get; }
22
28 protected static byte[] CreateSeed(int NrBytes)
29 {
30 byte[] Seed = new byte[NrBytes];
31
32 lock (rnd)
33 {
34 rnd.GetBytes(Seed);
35 }
36
37 return Seed;
38 }
39
44 protected static byte[] CreateSeed()
45 {
46 return CreateSeed(32);
47 }
48
53 protected static void Clear(byte[] Bin)
54 {
55 Array.Clear(Bin, 0, Bin.Length);
56 }
57
62 protected static void Clear<T>(T[] f)
63 {
64 Array.Clear(f, 0, f.Length);
65 }
66
71 protected static void Clear<T>(T[][] v)
72 {
73 int i, c = v.Length;
74
75 for (i = 0; i < c; i++)
76 Clear(v[i]);
77 }
78
83 protected static readonly ushort[] ushortBitMask =
84 {
85 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F,
86 0x00FF, 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF,
87 0xFFFF
88 };
89
94 protected static readonly int[] intBitMask =
95 {
96 0x00000000, 0x00000001, 0x00000003, 0x00000007,
97 0x0000000F, 0x0000001F, 0x0000003F, 0x0000007F,
98 0x000000FF, 0x000001FF, 0x000003FF, 0x000007FF,
99 0x00000FFF, 0x00001FFF, 0x00003FFF, 0x00007FFF,
100 0x0000FFFF, 0x0001FFFF, 0x0003FFFF, 0x0007FFFF,
101 0x000FFFFF, 0x001FFFFF, 0x003FFFFF, 0x007FFFFF,
102 0x00FFFFFF, 0x01FFFFFF, 0x03FFFFFF, 0x07FFFFFF,
103 0x0FFFFFFF, 0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF
104 };
105
106 }
107}
Methods common to ML algorithms.
Definition: ML_Common.cs:10
static void Clear(byte[] Bin)
Clears a byte array.
Definition: ML_Common.cs:53
static readonly int[] intBitMask
Bit masks corresponding to mod 2^d arithmetic, where d is the index of the mask in the array.
Definition: ML_Common.cs:94
abstract int PrivateKeyLength
Length of the private key.
Definition: ML_Common.cs:21
static readonly ushort[] ushortBitMask
Bit masks corresponding to mod 2^d arithmetic, where d is the index of the mask in the array.
Definition: ML_Common.cs:83
abstract int PublicKeyLength
Length of the public key.
Definition: ML_Common.cs:16
static byte[] CreateSeed(int NrBytes)
Creates a random seed value.
Definition: ML_Common.cs:28
static void Clear< T >(T[] f)
Clears a polynomial coefficient vector.
Definition: ML_Common.cs:62
static byte[] CreateSeed()
Creates a random seed value.
Definition: ML_Common.cs:44