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

P610

class P610 : Internal
using Org.BouncyCastle.Utilities.IO.Compression; using System.Collections.Generic; using System.IO; namespace Org.BouncyCastle.Pqc.Crypto.Sike { internal class P610 : Internal { internal P610(bool isCompressed) { COMPRESS = isCompressed; CRYPTO_SECRETKEYBYTES = 524; CRYPTO_PUBLICKEYBYTES = 462; CRYPTO_BYTES = 24; CRYPTO_CIPHERTEXTBYTES = 486; if (isCompressed) { CRYPTO_SECRETKEYBYTES = 491; CRYPTO_PUBLICKEYBYTES = 274; CRYPTO_CIPHERTEXTBYTES = 336; } NWORDS_FIELD = 10; PRIME_ZERO_WORDS = 4; NBITS_FIELD = 610; MAXBITS_FIELD = 640; MAXWORDS_FIELD = (MAXBITS_FIELD + Internal.RADIX - 1) / Internal.RADIX; NWORDS64_FIELD = (NBITS_FIELD + 63) / 64; NBITS_ORDER = 320; 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 = 305; OBOB_BITS = 305; OBOB_EXPON = 192; MASK_ALICE = 1; MASK_BOB = 255; PARAM_A = 6; PARAM_C = 1; MAX_INT_POINTS_ALICE = 8; MAX_INT_POINTS_BOB = 10; MAX_Alice = 152; MAX_Bob = 192; MSG_BYTES = 24; 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[10] { ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, 7926898294125494271, 12788056803604344878, 11162100504611256747, 12850373898864436522, 9335980454322886796, 10669696872 }; PRIMEx2 = new ulong[10] { 18446744073709551614, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, 15853796588250988543, 7129369533499138140, 3877456935512961879, 7254003724019321429, 225216834936221977, 21339393745 }; PRIMEx4 = new ulong[10] { 18446744073709551612, ulong.MaxValue, ulong.MaxValue, ulong.MaxValue, 13260849102792425471, 14258739066998276281, 7754913871025923758, 14508007448038642858, 450433669872443954, 42678787490 }; PRIMEp1 = new ulong[10] { 0, 0, 0, 0, 7926898294125494272, 12788056803604344878, 11162100504611256747, 12850373898864436522, 9335980454322886796, 10669696872 }; PRIMEx16p = new ulong[20] { 16, 0, 0, 0, 4593671619917905920, 15057295979980651058, 11747665326630816393, 13063148931657718444, 14843274714729999977, 9213098133652443887, 16184711284518687079, 15152855274923543935, 15339866525258615080, 10917383248197352654, 423414579105418765, 10355422686146848012, 17970659541427193412, 4932507286707963453, 13697982395128707963, 98 }; Alice_order = new ulong[5] { 0, 0, 0, 0, 562949953421312 }; Bob_order = new ulong[5] { 2806962120998467329, 16114585662381217980, 15671691495630785907, 603808853150554410, 349624627118280 }; A_gen = new ulong[60] { 5771904529248994682, 10009829002276161265, 270330086766583390, 6481898407746275289, 7865854910092666580, 15620069539765408586, 10893576880820336051, 9414097477218394383, 5194719131280954495, 1729770898, 16481658151656772596, 13633773755204448979, 1977403254395278860, 2726390535525409621, 18198696508619478634, 12992673620297984156, 15585820391321559058, 4095961562244124488, 13529435761498453802, 5102423139, 2124736252400681868, 11123746024777819577, 2202127831239085027, 15189163262449832501, 4313963896834226850, 13370300494042345640, 4921946642166740880, 14640789545148115673, 15809041940818907362, 7907518294, 2200917311302176889, 2939498022256786432, 16162577001789154273, 9557432669551130207, 15389712118992921126, 13586216826660735913, 10514164377495492777, 334500554730375393, 6399318707077975086, 8976719684, 2746580562334225805, 14004852227026191121, 11466649160507921918, 11799630227884196955, 6714415832701611114, 10112136743029452510, 7010145936394111770, 18042795605720766895, 11307052907097731807, 3478841981, 13366757749870367424, 3119472779256121459, 4709779656408495164, 16568419043672081405, 14691179270073594708, 5893360609436446022, 6635037533545129430, 5031143778661013925, 2711723078310815363, 10114015515 }; B_gen = new ulong[60] { 14323946558550738106, 2405435625630280597, 14697550786434646162, 15511184413509320248, 7035179512456608727, 17358557897062455236, 2237320506219039519, 14307448527707612354, 16412911138814384653, 5379123413, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 17692069297427191936, 8155755975969367465, 11338564383465294727, 5678382275401384545, 12501231795214209584, 4726463275275376934, 17083766455683877101, 4479281637794437063, 17540154893918510969, 9074793307, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8829176751768485847, 4330345099806588278, 6439066249656508832, 17672114398665101563, 12943163433490994938, 9363570836893509813, 16984122743018654352, 9683040719332474896, 16255205449832888349, 9017845420, 6790521807624498538, 16155971635292829987, 4283588130542979409, 514645655039295889, 8912678322428419353, 6038404330050892853, 17176157232408721930, 9916604761775707332, 910728456329037494, 5513273805 }; Montgomery_R2 = new ulong[10] { 16672146738007078695, 16192790745003276590, 7764610893679053117, 15888490136859680965, 8311396451547473226, 9580492030289074780, 9136860735727631175, 14248068042486481075, 8077651299688882586, 2385055731 }; Montgomery_one = new ulong[10] { 1728891110, 0, 0, 0, 11111506180629856256, 5591714530040314431, 741431724485104668, 15183360670812525026, 1398651832995983165, 4438944100 }; strat_Alice = new uint[151] { 67, 37, 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, 16, 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, 2, 1, 1, 4, 2, 1, 1, 2, 1, 1, 33, 16, 8, 5, 2, 1, 1, 1, 2, 1, 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, 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 }; strat_Bob = new uint[191] { 86, 48, 27, 15, 8, 4, 2, 1, 1, 2, 1, 1, 4, 2, 1, 1, 2, 1, 1, 7, 4, 2, 1, 1, 2, 1, 1, 3, 2, 1, 1, 1, 1, 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, 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, 38, 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, 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 }; if (COMPRESS) { MASK2_BOB = 7; MASK3_BOB = 255; ORDER_A_ENCODED_BYTES = SECRETKEY_A_BYTES; ORDER_B_ENCODED_BYTES = SECRETKEY_B_BYTES + 1; 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 = 480; TABLE_R_LEN = 17; TABLE_V_LEN = 34; TABLE_V3_LEN = 20; W_2 = 5; W_3 = 3; ELL2_W = (uint)(1 << (int)W_2); ELL3_W = 27; ELL2_EMODW = (uint)(1 << (int)(OALICE_BITS % W_2)); ELL3_EMODW = 1; DLEN_2 = (OALICE_BITS + W_2 - 1) / W_2; DLEN_3 = (OBOB_EXPON + W_3 - 1) / W_3; PLEN_2 = 62; PLEN_3 = 65; Dictionary<string, string> dictionary = new Dictionary<string, string>(); using (Stream stream = typeof(P610).Assembly.GetManifestResourceStream("Org.BouncyCastle.pqc.crypto.sike.p610.bz2")) using (StreamReader streamReader = new StreamReader(Bzip2.DecompressInput(stream, false))) { string text = streamReader.ReadLine(); int num = 0; while (text != null) { 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++; } text = streamReader.ReadLine(); } } 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); Montgomery_R2 = Internal.ReadFromProperty(dictionary, "Montgomery_R2", NWORDS64_FIELD); Montgomery_RB1 = Internal.ReadFromProperty(dictionary, "Montgomery_RB1", NWORDS64_FIELD); Montgomery_RB2 = Internal.ReadFromProperty(dictionary, "Montgomery_RB2", NWORDS64_FIELD); Montgomery_one = Internal.ReadFromProperty(dictionary, "Montgomery_one", 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_T = Internal.ReadFromProperty(dictionary, "ph3_T", DLEN_3 * (ELL3_W >> 1) * 2 * NWORDS64_FIELD); Montgomery_R = new ulong[NWORDS64_FIELD]; ph3_T1 = new ulong[DLEN_3 * (ELL3_W >> 1) * 2 * NWORDS64_FIELD]; ph3_T2 = new ulong[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))]; } } } }