<PackageReference Include="BouncyCastle.Cryptography" Version="2.5.1" />

Hrss1373Polynomial

using Org.BouncyCastle.Pqc.Crypto.Ntru.ParameterSets; namespace Org.BouncyCastle.Pqc.Crypto.Ntru.Polynomials { internal class Hrss1373Polynomial : HrssPolynomial { private static readonly int L = 1376; private static readonly int M = L / 4; private static readonly int K = L / 16; internal Hrss1373Polynomial(NtruHrssParameterSet parameters) : base(parameters) { } public override byte[] SqToBytes(int len) { byte[] array = new byte[len]; short[] array2 = new short[4]; int i; for (i = 0; i < ParameterSet.PackDegree() / 4; i++) { for (int j = 0; j < 4; j++) { array2[j] = (short)Polynomial.ModQ((uint)(coeffs[4 * i + j] & 65535), (uint)ParameterSet.Q()); } array[7 * i] = (byte)(array2[0] & 255); array[7 * i + 1] = (byte)((array2[0] >> 8) | ((array2[1] & 3) << 6)); array[7 * i + 2] = (byte)((array2[1] >> 2) & 255); array[7 * i + 3] = (byte)((array2[1] >> 10) | ((array2[2] & 15) << 4)); array[7 * i + 4] = (byte)((array2[2] >> 4) & 255); array[7 * i + 5] = (byte)((array2[2] >> 12) | ((array2[3] & 63) << 2)); array[7 * i + 6] = (byte)(array2[3] >> 6); } if (ParameterSet.PackDegree() % 4 == 2) { array2[0] = (short)Polynomial.ModQ((uint)(coeffs[ParameterSet.PackDegree() - 2] & 65535), (uint)ParameterSet.Q()); array2[1] = (short)Polynomial.ModQ((uint)(coeffs[ParameterSet.PackDegree() - 1] & 65535), (uint)ParameterSet.Q()); array[7 * i] = (byte)(array2[0] & 255); array[7 * i + 1] = (byte)((array2[0] >> 8) | ((array2[1] & 3) << 6)); array[7 * i + 2] = (byte)((array2[1] >> 2) & 255); array[7 * i + 3] = (byte)(array2[1] >> 10); } return array; } public override void SqFromBytes(byte[] a) { int i; for (i = 0; i < ParameterSet.PackDegree() / 4; i++) { coeffs[4 * i] = (ushort)((a[7 * i] & 255) | (((ushort)(a[7 * i + 1] & 255) & 63) << 8)); coeffs[4 * i + 1] = (ushort)(((a[7 * i + 1] & 255) >> 6) | ((ushort)(a[7 * i + 2] & 255) << 2) | ((short)(a[7 * i + 3] & 15) << 10)); coeffs[4 * i + 2] = (ushort)(((a[7 * i + 3] & 255) >> 4) | (((ushort)(a[7 * i + 4] & 255) & 255) << 4) | ((short)(a[7 * i + 5] & 3) << 12)); coeffs[4 * i + 3] = (ushort)(((a[7 * i + 5] & 255) >> 2) | ((ushort)(a[7 * i + 6] & 255) << 6)); } if (ParameterSet.PackDegree() % 4 == 2) { coeffs[4 * i] = (ushort)(a[7 * i] | ((a[7 * i + 1] & 63) << 8)); coeffs[4 * i + 1] = (ushort)((a[7 * i + 1] >> 6) | (a[7 * i + 2] << 2) | ((a[7 * i + 3] & 15) << 10)); } coeffs[ParameterSet.N - 1] = 0; } } }