private static PointMulStep EdDSA_PointMul_step(PointMulStep step, BigInteger p, BigInteger d) { if ((step.s % 2) == 1) { step.Q = EdDSA_PointAdd(step.Q, step.P, p, d); } step.P = EdDSA_PointAdd(step.P, step.P, p, d); step.s = step.s / 2; return(step); }
private static PointMulStep EdDSA_PointMul_ByRange(PointMulStep initialStep, int itNum, BigInteger p, BigInteger d) { PointMulStep stepRecord = initialStep; for (int i = 0; i < itNum; i++) { stepRecord = EdDSA_PointMul_step(stepRecord, p, d); } return(stepRecord); }
private static bool ChallengeEdDSA_PointMul_Setp(int i, int n) { PointMulStep initialStep = getStateFromStorage("step", i); PointMulStep res = EdDSA_PointMul_ByRange(initialStep, n, p, d); if ((initialStep.Q[0] == res.Q[0]) & (initialStep.Q[1] == res.Q[1]) & (initialStep.Q[2] == res.Q[2]) & (initialStep.Q[3] == res.Q[3]) & (initialStep.s == res.s) & (initialStep.P[0] == res.P[0]) & (initialStep.P[1] == res.P[1]) & (initialStep.P[2] == res.P[2]) & (initialStep.P[1] == res.P[1])) { return(true); } else { return(false); } }
public static bool Main(params object[] args) { byte[] byteX = { 0x6b, 0xef, 0x5e, 0xac, 0x02, 0xc3, 0x50, 0x83, 0x30, 0x3a, 0xf1, 0x52, 0xbb, 0xa1, 0xda, 0x6d, 0x41, 0xe4, 0xda, 0xfe, 0xa9, 0x2d, 0x9e, 0x3a, 0x78, 0x8f, 0x6a, 0x57, 0x12, 0xc7, 0x5e, 0x0d }; BigInteger x = byteX.AsBigInteger(); byte[] byteY = { 0xd3, 0x76, 0x9d, 0x8a, 0x1f, 0x78, 0xb4, 0xc1, 0x7a, 0x96, 0x5f, 0x7a, 0x30, 0xd4, 0x18, 0x1f, 0xab, 0xbd, 0x1f, 0x96, 0x9f, 0x46, 0xd3, 0xc8, 0xe8, 0x3b, 0x5a, 0xd4, 0x84, 0x54, 0x21, 0x58 }; BigInteger y = byteY.AsBigInteger(); byte[] compressed = { 211, 118, 157, 138, 31, 120, 180, 193, 122, 150, 95, 122, 48, 212, 24, 31, 171, 189, 31, 150, 159, 70, 211, 200, 232, 59, 90, 212, 132, 84, 33, 216 }; //byte[] s_byteX = {0x42, 0x71, 0x50, 0x0a, 0x66, 0xb9, 0xa6, 0x78, 0x73, 0x3d, 0x95, 0xa5, 0x8a, 0xf9, 0x83, 0xd3, 0x0e, 0x11, 0xc1, 0xbc, 0xd7, 0xe1, 0x90, 0x71, 0xf7, 0x28, 0x5a, 0xbe, 0x64, 0x6f, 0x2f, 0x07}; BigInteger s_x = (BigInteger)args[0]; //s_byteX.AsBigInteger(); //byte[] s_byteY = {0x88, 0x54, 0x07, 0x0a, 0xc1, 0x7c, 0x6a, 0xed, 0xf5, 0x1e, 0x64, 0x4f, 0x68, 0xc5, 0x61, 0x31, 0x5e, 0xb2, 0x4a, 0x7b, 0x46, 0xee, 0x61, 0x29, 0xb9, 0x7f, 0x8d, 0xf4, 0xad, 0x57, 0x73, 0x5b}; BigInteger s_y = (BigInteger)args[1]; //s_byteY.AsBigInteger(); //byte[] s_compressed = (byte[])args[2];//{136, 84, 7, 10, 193, 124, 106, 237, 245, 30, 100, 79, 104, 197, 97, 49, 94, 178, 74, 123, 70, 238, 97, 41, 185, 127, 141, 244, 173, 87, 115, 91}; //int ini = 1; //int fin = (int)args[2];//1488; byte[] msg = (byte[])args[2];//{0x88, 0x54, 0x7, 0xa, 0xc1, 0x7c, 0x6a, 0xed, 0xf5, 0x1e, 0x64, 0x4f, 0x68, 0xc5, 0x61, 0x31, 0x5e, 0xb2, 0x4a, 0x7b, 0x46, 0xee, 0x61, 0x29, 0xb9, 0x7f, 0x8d, 0xf4, 0xad, 0x57, 0x73, 0x5b, 0xd3, 0x76, 0x9d, 0x8a, 0x1f, 0x78, 0xb4, 0xc1, 0x7a, 0x96, 0x5f, 0x7a, 0x30, 0xd4, 0x18, 0x1f, 0xab, 0xbd, 0x1f, 0x96, 0x9f, 0x46, 0xd3, 0xc8, 0xe8, 0x3b, 0x5a, 0xd4, 0x84, 0x54, 0x21, 0xd8, 0x79, 0x8, 0x2, 0x11, 0x9c, 0x5, 0xff, 0x2, 0x0, 0x0, 0x0, 0x0, 0x22, 0x48, 0xa, 0x20, 0xdf, 0x47, 0xf7, 0x85, 0x7b, 0x58, 0x28, 0xe3, 0x93, 0xf9, 0x5f, 0xe7, 0xdd, 0xca, 0x2a, 0x83, 0xd5, 0x81, 0xc4, 0xca, 0x9b, 0xb8, 0x47, 0x3d, 0xba, 0xc0, 0x75, 0x87, 0x18, 0x5d, 0x41, 0xf8, 0x12, 0x24, 0xa, 0x20, 0xb, 0xc9, 0xa9, 0x70, 0x61, 0xef, 0xe7, 0x2b, 0x48, 0xd3, 0xc1, 0xa3, 0xaa, 0x15, 0xab, 0x54, 0x5, 0xf5, 0x2b, 0x23, 0x3e, 0x7f, 0x62, 0x7f, 0x8, 0x6f, 0x2b, 0xc1, 0x8c, 0xd2, 0x87, 0xe4, 0x10, 0x1, 0x2a, 0xc, 0x8, 0xb6, 0xef, 0xe1, 0xee, 0x5, 0x10, 0x8d, 0xd6, 0xce, 0xec, 0x1, 0x32, 0x14, 0x42, 0x69, 0x6e, 0x61, 0x6e, 0x63, 0x65, 0x2d, 0x43, 0x68, 0x61, 0x69, 0x6e, 0x2d, 0x54, 0x69, 0x67, 0x72, 0x69, 0x73}; ulong[] pre = new ulong[32]; pre[0] = 1296317917737685967; pre[1] = 13981333602131557087; pre[2] = 3185692199772433046; pre[3] = 2532817210862269712; pre[4] = 15237539605813703873; pre[5] = 8833352697543661599; pre[6] = 12375082082861765576; pre[7] = 16734068709224882648; pre[8] = 8721222951469718275; pre[9] = 575146528; pre[10] = 2927900583220848078; pre[11] = 6744662265980110442; pre[12] = 9259850152741919814; pre[13] = 8859619218704344643; pre[14] = 1307180926696539348; pre[15] = 4347061948580949543; pre[16] = 14519575115237742329; pre[17] = 1542202332366152652; pre[18] = 16403717990576630284; pre[19] = 623982258751344827; pre[20] = 12027570899811320425; pre[21] = 7953759790091289448; pre[22] = 7019262635202406258; pre[23] = 7598557733792514048; pre[24] = 0; pre[25] = 0; pre[26] = 0; pre[27] = 0; pre[28] = 0; pre[29] = 0; pre[30] = 0; pre[31] = 1488; byte[] hash = (byte[])args[3];//{0xdf, 0x47, 0xf7, 0x85, 0x7b, 0x58, 0x28, 0xe3, 0x93, 0xf9, 0x5f, 0xe7, 0xdd, 0xca, 0x2a, 0x83, 0xd5, 0x81, 0xc4, 0xca, 0x9b, 0xb8, 0x47, 0x3d, 0xba, 0xc0, 0x75, 0x87, 0x18, 0x5d, 0x41, 0xf8}; //byte[] sbytes = (byte[])args[6];//{0xcf, 0x41, 0x33, 0x8f, 0xc2, 0x18, 0xd3, 0x7b, 0x2a, 0x63, 0x6e, 0xdc, 0x83, 0xee, 0x63, 0xe1, 0x4f, 0x6c, 0x0c, 0x4e, 0x14, 0x9a, 0x8f, 0x05, 0x73, 0xe4, 0x8d, 0x70, 0x12, 0xab, 0x15, 0x0d}; byte[] signature = (byte[])args[4]; byte[] g1bytes = { 0x1a, 0xd5, 0x25, 0x8f, 0x60, 0x2d, 0x56, 0xc9, 0xb2, 0xa7, 0x25, 0x95, 0x60, 0xc7, 0x2c, 0x69, 0x5c, 0xdc, 0xd6, 0xfd, 0x31, 0xe2, 0xa4, 0xc0, 0xfe, 0x53, 0x6e, 0xcd, 0xd3, 0x36, 0x69, 0x21 }; BigInteger g1 = g1bytes.AsBigInteger(); byte[] g2bytes = { 0x58, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66 }; BigInteger g2 = g2bytes.AsBigInteger(); byte[] g4bytes = { 0xa3, 0xdd, 0xb7, 0xa5, 0xb3, 0x8a, 0xde, 0x6d, 0xf5, 0x52, 0x51, 0x77, 0x80, 0x9f, 0xf0, 0x20, 0x7d, 0xe3, 0xab, 0x64, 0x8e, 0x4e, 0xea, 0x66, 0x65, 0x76, 0x8b, 0xd7, 0x0f, 0x5f, 0x87, 0x67 }; BigInteger g4 = g4bytes.AsBigInteger(); BigInteger[] G = { g1, g2, 1, g4 }; PointMulStep myStep = new PointMulStep(); myStep.Q = new BigInteger[] { 0, 1, 1, 0 }; myStep.s = signature.Range(32, 32).AsBigInteger(); myStep.P = G; byte[] byteP = { 0xed, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x7f }; BigInteger p = byteP.AsBigInteger(); byte[] byteD = { 0xa3, 0x78, 0x59, 0x13, 0xca, 0x4d, 0xeb, 0x75, 0xab, 0xd8, 0x41, 0x41, 0x4d, 0x0a, 0x70, 0x00, 0x98, 0xe8, 0x79, 0x77, 0x79, 0x40, 0xc7, 0x8c, 0x73, 0xfe, 0x6f, 0x2b, 0xee, 0x6c, 0x03, 0x52 }; BigInteger d = byteD.AsBigInteger(); PointMulStep res = EdDSA_PointMul_ByRange(myStep, 9, p, d); Storage.Put("q0", res.Q[0]); Storage.Put("q1", res.Q[1]); Storage.Put("q2", res.Q[2]); Storage.Put("q3", res.Q[3]); Storage.Put("s", res.s); Storage.Put("p0", res.P[0]); Storage.Put("p1", res.P[1]); Storage.Put("p2", res.P[2]); Storage.Put("p3", res.P[1]); Storage.Put("v", verify_signature(x, y, compressed, signature, s_x, s_y, pre, msg, hash)?"true":"false"); return(false); }