P434
using Org.BouncyCastle.Utilities.IO.Compression;
using System.Collections.Generic;
using System.IO;
namespace Org.BouncyCastle.Pqc.Crypto.Sike
{
internal class P434 : Internal
{
internal P434(bool isCompressed)
{
COMPRESS = isCompressed;
CRYPTO_SECRETKEYBYTES = 374;
CRYPTO_PUBLICKEYBYTES = 330;
CRYPTO_BYTES = 16;
CRYPTO_CIPHERTEXTBYTES = 346;
if (isCompressed) {
CRYPTO_SECRETKEYBYTES = 350;
CRYPTO_PUBLICKEYBYTES = 197;
CRYPTO_CIPHERTEXTBYTES = 236;
}
NWORDS_FIELD = 7;
PRIME_ZERO_WORDS = 3;
NBITS_FIELD = 434;
MAXBITS_FIELD = 448;
MAXWORDS_FIELD = (MAXBITS_FIELD + Internal.RADIX - 1) / Internal.RADIX;
NWORDS64_FIELD = (NBITS_FIELD + 63) / 64;
NBITS_ORDER = 256;
NWORDS_ORDER = (NBITS_ORDER + Internal.RADIX - 1) / Internal.RADIX;
NWORDS64_ORDER = (NBITS_ORDER + 63) / 64;
MAXBITS_ORDER = NBITS_ORDER;
ALICE = 0;
BOB = 1;
OALICE_BITS = 216;
OBOB_BITS = 218;
OBOB_EXPON = 137;
MASK_ALICE = 255;
MASK_BOB = 1;
PARAM_A = 6;
PARAM_C = 1;
MAX_INT_POINTS_ALICE = 7;
MAX_INT_POINTS_BOB = 8;
MAX_Alice = 108;
MAX_Bob = 137;
MSG_BYTES = 16;
SECRETKEY_A_BYTES = (OALICE_BITS + 7) / 8;
SECRETKEY_B_BYTES = (OBOB_BITS - 1 + 7) / 8;
FP2_ENCODED_BYTES = 2 * ((NBITS_FIELD + 7) / 8);
PRIME = new ulong[7] {
ulong.MaxValue,
ulong.MaxValue,
ulong.MaxValue,
18285026232267440127,
8918917783347572387,
7853257225132122198,
620258357900100
};
PRIMEx2 = new ulong[7] {
18446744073709551614,
ulong.MaxValue,
ulong.MaxValue,
18123308390825328639,
17837835566695144775,
15706514450264244396,
1240516715800200
};
PRIMEx4 = new ulong[7] {
18446744073709551612,
ulong.MaxValue,
ulong.MaxValue,
17799872707941105663,
17228927059680737935,
12966284826818937177,
2481033431600401
};
PRIMEp1 = new ulong[7] {
0,
0,
0,
18285026232267440128,
8918917783347572387,
7853257225132122198,
620258357900100
};
PRIMEx16p = new ulong[14] {
16,
0,
0,
5174970926147567616,
9742536112230509440,
6950185827705812272,
6073522028379477874,
14222146884144505874,
8299186480726035350,
7225369840861796773,
2456441653404885428,
12555258408051429121,
1781491355331495958,
333691781277
};
Alice_order = new ulong[4] {
0,
0,
0,
16777216
};
Bob_order = new ulong[4] {
6390225231553133283,
14204448314335459377,
1689769520075363969,
36970279
};
A_gen = new ulong[42] {
409251790387889599,
10489829510628224043,
12674510860217942615,
8135632727773423537,
17840997995551181005,
2414452085739184671,
11115521240260,
8395851790856910728,
2986355008512957707,
14652235704098559445,
10149113683644317610,
12102338175217582495,
15452390807072906892,
281073067659850,
18358614117343242043,
15178862300246045126,
17939401953738004679,
16301132844359752451,
1973682341831588061,
8312799048378913301,
497853136119926,
12515775166124391894,
7710088909771808848,
7498146198864584751,
2174778336782639988,
16347399334629616021,
12025936272585254152,
438485524985150,
124497379906645117,
3220114552465917457,
2709773247140401691,
6980995868580086445,
4225536559282510125,
4701685901084574963,
609687130428995,
13307499667408479562,
17265918823005609453,
6350294504100107936,
8618087912213766372,
308885086986017528,
15792880328099440610,
202858940514502
};
B_gen = new ulong[42] {
7950145635403778211,
3053921039650069509,
16974511502399211645,
6369396808518798415,
13295737116337704235,
2507423554624419257,
491294718579999,
0,
0,
0,
0,
0,
0,
0,
18078192145093323662,
5280595860558773788,
17229246200424940156,
5300724274592529762,
12685182915280535178,
17596270270016357247,
57208989669550,
0,
0,
0,
0,
0,
0,
0,
2898969037767559396,
10522929125730281031,
9073321008578907802,
7539793830764276893,
9328908741686588507,
148738643701593348,
139132528504375,
12932288373210664113,
7856701733796155952,
16996962201367356265,
3113577795642755667,
4926779461749210259,
13761095186437813579,
408994988652499
};
Montgomery_R2 = new ulong[7] {
2946862024238734128,
12460461157234743490,
12332992403615082637,
1683438818023996427,
12379712300517307518,
7629496211932212634,
41406098690346
};
Montgomery_one = new ulong[7] {
29740,
0,
0,
13335145323912232960,
15564903186549419220,
16803585881028378892,
260509760564954
};
strat_Alice = new uint[107] {
48,
28,
16,
8,
4,
2,
1,
1,
2,
1,
1,
4,
2,
1,
1,
2,
1,
1,
8,
4,
2,
1,
1,
2,
1,
1,
4,
2,
1,
1,
2,
1,
1,
13,
7,
4,
2,
1,
1,
2,
1,
1,
3,
2,
1,
1,
1,
1,
5,
4,
2,
1,
1,
2,
1,
1,
2,
1,
1,
1,
21,
12,
7,
4,
2,
1,
1,
2,
1,
1,
3,
2,
1,
1,
1,
1,
5,
3,
2,
1,
1,
1,
1,
2,
1,
1,
1,
9,
5,
3,
2,
1,
1,
1,
1,
2,
1,
1,
1,
4,
2,
1,
1,
1,
2,
1,
1
};
strat_Bob = new uint[136] {
66,
33,
17,
9,
5,
3,
2,
1,
1,
1,
1,
2,
1,
1,
1,
4,
2,
1,
1,
1,
2,
1,
1,
8,
4,
2,
1,
1,
1,
2,
1,
1,
4,
2,
1,
1,
2,
1,
1,
16,
8,
4,
2,
1,
1,
1,
2,
1,
1,
4,
2,
1,
1,
2,
1,
1,
8,
4,
2,
1,
1,
2,
1,
1,
4,
2,
1,
1,
2,
1,
1,
32,
16,
8,
4,
3,
1,
1,
1,
1,
2,
1,
1,
4,
2,
1,
1,
2,
1,
1,
8,
4,
2,
1,
1,
2,
1,
1,
4,
2,
1,
1,
2,
1,
1,
16,
8,
4,
2,
1,
1,
2,
1,
1,
4,
2,
1,
1,
2,
1,
1,
8,
4,
2,
1,
1,
2,
1,
1,
4,
2,
1,
1,
2,
1,
1
};
if (isCompressed) {
MASK2_BOB = 0;
MASK3_BOB = 127;
ORDER_A_ENCODED_BYTES = SECRETKEY_A_BYTES;
ORDER_B_ENCODED_BYTES = SECRETKEY_B_BYTES;
PARTIALLY_COMPRESSED_CHUNK_CT = 4 * ORDER_A_ENCODED_BYTES + FP2_ENCODED_BYTES + 2;
COMPRESSED_CHUNK_CT = 3 * ORDER_A_ENCODED_BYTES + FP2_ENCODED_BYTES + 2;
UNCOMPRESSEDPK_BYTES = 330;
TABLE_R_LEN = 17;
TABLE_V_LEN = 34;
TABLE_V3_LEN = 20;
W_2 = 4;
W_3 = 3;
ELL2_W = (uint)(1 << (int)W_2);
ELL3_W = 27;
ELL2_EMODW = (uint)(1 << (int)(OALICE_BITS % W_2));
ELL3_EMODW = 9;
DLEN_2 = (OALICE_BITS + W_2 - 1) / W_2;
DLEN_3 = (OBOB_EXPON + W_3 - 1) / W_3;
PLEN_2 = 55;
PLEN_3 = 47;
Dictionary<string, string> dictionary = new Dictionary<string, string>();
using (Stream stream = typeof(P434).Assembly.GetManifestResourceStream("Org.BouncyCastle.pqc.crypto.sike.p434.bz2"))
using (StreamReader streamReader = new StreamReader(Bzip2.DecompressInput(stream, false))) {
int num = 0;
for (string text = streamReader.ReadLine(); text != null; text = streamReader.ReadLine()) {
string text2 = text;
if (text2 != "") {
if (num > 1)
text2 = text2.Replace(",", "");
int num2 = text2.IndexOf('=');
string key = text2.Substring(0, num2).Trim();
string value = text2.Substring(num2 + 1).Trim();
dictionary.Add(key, value);
num++;
}
}
}
ph2_path = Internal.ReadIntsFromProperty(dictionary, "ph2_path", PLEN_2);
ph3_path = Internal.ReadIntsFromProperty(dictionary, "ph3_path", PLEN_3);
A_gen = Internal.ReadFromProperty(dictionary, "A_gen", 6 * NWORDS64_FIELD);
B_gen = Internal.ReadFromProperty(dictionary, "B_gen", 6 * NWORDS64_FIELD);
XQB3 = Internal.ReadFromProperty(dictionary, "XQB3", 2 * NWORDS64_FIELD);
A_basis_zero = Internal.ReadFromProperty(dictionary, "A_basis_zero", 8 * NWORDS64_FIELD);
B_basis_zero = Internal.ReadFromProperty(dictionary, "B_basis_zero", 8 * NWORDS64_FIELD);
B_gen_3_tors = Internal.ReadFromProperty(dictionary, "B_gen_3_tors", 16 * NWORDS64_FIELD);
g_R_S_im = Internal.ReadFromProperty(dictionary, "g_R_S_im", NWORDS64_FIELD);
g_phiR_phiS_re = Internal.ReadFromProperty(dictionary, "g_phiR_phiS_re", NWORDS64_FIELD);
g_phiR_phiS_im = Internal.ReadFromProperty(dictionary, "g_phiR_phiS_im", NWORDS64_FIELD);
Montgomery_RB1 = Internal.ReadFromProperty(dictionary, "Montgomery_RB1", NWORDS64_FIELD);
Montgomery_RB2 = Internal.ReadFromProperty(dictionary, "Montgomery_RB2", NWORDS64_FIELD);
threeinv = Internal.ReadFromProperty(dictionary, "threeinv", NWORDS64_FIELD);
u_entang = Internal.ReadFromProperty(dictionary, "u_entang", 2 * NWORDS64_FIELD);
u0_entang = Internal.ReadFromProperty(dictionary, "u0_entang", 2 * NWORDS64_FIELD);
table_r_qr = Internal.ReadFromProperty(dictionary, "table_r_qr", TABLE_R_LEN, NWORDS64_FIELD);
table_r_qnr = Internal.ReadFromProperty(dictionary, "table_r_qnr", TABLE_R_LEN, NWORDS64_FIELD);
table_v_qr = Internal.ReadFromProperty(dictionary, "table_v_qr", TABLE_V_LEN, NWORDS64_FIELD);
table_v_qnr = Internal.ReadFromProperty(dictionary, "table_v_qnr", TABLE_V_LEN, NWORDS64_FIELD);
v_3_torsion = Internal.ReadFromProperty(dictionary, "v_3_torsion", TABLE_V3_LEN, 2, NWORDS64_FIELD);
T_tate3 = Internal.ReadFromProperty(dictionary, "T_tate3", (6 * (OBOB_EXPON - 1) + 4) * NWORDS64_FIELD);
T_tate2_firststep_P = Internal.ReadFromProperty(dictionary, "T_tate2_firststep_P", 4 * NWORDS64_FIELD);
T_tate2_P = Internal.ReadFromProperty(dictionary, "T_tate2_P", 3 * (OALICE_BITS - 2) * NWORDS64_FIELD);
T_tate2_firststep_Q = Internal.ReadFromProperty(dictionary, "T_tate2_firststep_Q", 4 * NWORDS64_FIELD);
T_tate2_Q = Internal.ReadFromProperty(dictionary, "T_tate2_Q", 3 * (OALICE_BITS - 2) * NWORDS64_FIELD);
ph2_T = Internal.ReadFromProperty(dictionary, "ph2_T", DLEN_2 * (ELL2_W >> 1) * 2 * NWORDS64_FIELD);
ph3_T1 = Internal.ReadFromProperty(dictionary, "ph3_T1", DLEN_3 * (ELL3_W >> 1) * 2 * NWORDS64_FIELD);
ph3_T2 = Internal.ReadFromProperty(dictionary, "ph3_T2", DLEN_3 * (ELL3_W >> 1) * 2 * NWORDS64_FIELD);
ph2_T1 = new ulong[2 * ((DLEN_2 - 1) * (ELL2_W / 2) + (ph2_path[PLEN_2 - 1] - 1))];
ph2_T2 = new ulong[2 * ((DLEN_2 - 1) * (ELL2_W / 2) + (ph2_path[PLEN_2 - 1] - 1))];
ph3_T = new ulong[2 * ((DLEN_3 - 1) * (ELL3_W / 2) + (ph3_path[PLEN_3 - 1] - 1))];
}
}
}
}