Hallo,
nachdem ich jetzt eine funktionierende Curve25519 habe brauche ich noch einmal eure Unterstützung. Ich möchte nun messages mit dem EC-KCDSA (Elliptic Curve Korean Certificate-based Digital Signature Algorithm) Verfahren signieren und verifizieren. Das Signieren läuft bereits bestens nur das Verifizieren noch nicht so ganz. Ich finde dafür nun allerdings auch keine passenden Quellcodes, die man nahezu 1zu1 übersetzen kann. Lediglich eine JavaScript-Variante die wohl leider keine Longs hat und stattdessen alles mit UInt16Arrays rechnet:
Spoiler anzeigen
Bis Zeile 50. /* prepare the chain */ bin ich durch... nur dann fallen mir die unterschiedlichen Arrays auf die Füße. Denn in der VB/C#-Variante wird alles mit 10 Long-Arrays gelöst und hier eben alles mit UInt16Arrays. Hat von euch jmd vllt. eine Idee wie ich dieses Problem lösen kann? Vllt. einen Arrays-Converter oder so?
Hier noch der VB-Code:
Spoiler anzeigen
Vielen Dank schon mal
nachdem ich jetzt eine funktionierende Curve25519 habe brauche ich noch einmal eure Unterstützung. Ich möchte nun messages mit dem EC-KCDSA (Elliptic Curve Korean Certificate-based Digital Signature Algorithm) Verfahren signieren und verifizieren. Das Signieren läuft bereits bestens nur das Verifizieren noch nicht so ganz. Ich finde dafür nun allerdings auch keine passenden Quellcodes, die man nahezu 1zu1 übersetzen kann. Lediglich eine JavaScript-Variante die wohl leider keine Longs hat und stattdessen alles mit UInt16Arrays rechnet:
Quellcode
- /* Signature verification primitive, calculates Y = vP + hG
- * v [in] signature value
- * h [in] signature hash
- * P [in] public key
- * Returns signature public key
- */
- public static verify(v, h, P) {
- /* Y = v abs(P) + h G */
- let d = new Array(32);
- let p = [Curve25519.createUnpackedArray(), Curve25519.createUnpackedArray()];
- let s = [Curve25519.createUnpackedArray(), Curve25519.createUnpackedArray()];
- let yx = [Curve25519.createUnpackedArray(), Curve25519.createUnpackedArray(), Curve25519.createUnpackedArray()];
- let yz = [Curve25519.createUnpackedArray(), Curve25519.createUnpackedArray(), Curve25519.createUnpackedArray()];
- let t1 = [Curve25519.createUnpackedArray(), Curve25519.createUnpackedArray(), Curve25519.createUnpackedArray()];
- let t2 = [Curve25519.createUnpackedArray(), Curve25519.createUnpackedArray(), Curve25519.createUnpackedArray()];
- let vi = 0, hi = 0, di = 0, nvh = 0, i, j, k;
- /* set p[0] to G and p[1] to P */
- Curve25519.set(p[0], 9);
- Curve25519.unpack(p[1], P);
- /* set s[0] to P+G and s[1] to P-G */
- /* s[0] = (Py^2 + Gy^2 - 2 Py Gy)/(Px - Gx)^2 - Px - Gx - 486662 */
- /* s[1] = (Py^2 + Gy^2 + 2 Py Gy)/(Px - Gx)^2 - Px - Gx - 486662 */
- Curve25519.x_to_y2(t1[0], t2[0], p[1]); /* t2[0] = Py^2 */
- Curve25519.sqrt(t1[0], t2[0]); /* t1[0] = Py or -Py */
- j = Curve25519.is_negative(t1[0]); /* ... check which */
- Curve25519.add(t2[0], t2[0], Curve25519.C39420360); /* t2[0] = Py^2 + Gy^2 */
- Curve25519.mul(t2[1], Curve25519.BASE_2Y, t1[0]); /* t2[1] = 2 Py Gy or -2 Py Gy */
- Curve25519.sub(t1[j], t2[0], t2[1]); /* t1[0] = Py^2 + Gy^2 - 2 Py Gy */
- Curve25519.add(t1[1 - j], t2[0], t2[1]); /* t1[1] = Py^2 + Gy^2 + 2 Py Gy */
- Curve25519.cpy(t2[0], p[1]); /* t2[0] = Px */
- Curve25519.sub(t2[0], t2[0], Curve25519.C9); /* t2[0] = Px - Gx */
- Curve25519.sqr(t2[1], t2[0]); /* t2[1] = (Px - Gx)^2 */
- Curve25519.recip(t2[0], t2[1], 0); /* t2[0] = 1/(Px - Gx)^2 */
- Curve25519.mul(s[0], t1[0], t2[0]); /* s[0] = t1[0]/(Px - Gx)^2 */
- Curve25519.sub(s[0], s[0], p[1]); /* s[0] = t1[0]/(Px - Gx)^2 - Px */
- Curve25519.sub(s[0], s[0], Curve25519.C486671); /* s[0] = X(P+G) */
- Curve25519.mul(s[1], t1[1], t2[0]); /* s[1] = t1[1]/(Px - Gx)^2 */
- Curve25519.sub(s[1], s[1], p[1]); /* s[1] = t1[1]/(Px - Gx)^2 - Px */
- Curve25519.sub(s[1], s[1], Curve25519.C486671); /* s[1] = X(P-G) */
- Curve25519.mul_small(s[0], s[0], 1); /* reduce s[0] */
- Curve25519.mul_small(s[1], s[1], 1); /* reduce s[1] */
- /* prepare the chain */
- for (i = 0; i < 32; i++) {
- vi = (vi >> 8) ^ (v[i] & 0xFF) ^ ((v[i] & 0xFF) << 1);
- hi = (hi >> 8) ^ (h[i] & 0xFF) ^ ((h[i] & 0xFF) << 1);
- nvh = ~(vi ^ hi);
- di = (nvh & (di & 0x80) >> 7) ^ vi;
- di ^= nvh & (di & 0x01) << 1;
- di ^= nvh & (di & 0x02) << 1;
- di ^= nvh & (di & 0x04) << 1;
- di ^= nvh & (di & 0x08) << 1;
- di ^= nvh & (di & 0x10) << 1;
- di ^= nvh & (di & 0x20) << 1;
- di ^= nvh & (di & 0x40) << 1;
- d[i] = di & 0xFF;
- }
- di = ((nvh & (di & 0x80) << 1) ^ vi) >> 8;
- /* initialize state */
- Curve25519.set(yx[0], 1);
- Curve25519.cpy(yx[1], p[di]);
- Curve25519.cpy(yx[2], s[0]);
- Curve25519.set(yz[0], 0);
- Curve25519.set(yz[1], 1);
- Curve25519.set(yz[2], 1);
- /* y[0] is (even)P + (even)G
- * y[1] is (even)P + (odd)G if current d-bit is 0
- * y[1] is (odd)P + (even)G if current d-bit is 1
- * y[2] is (odd)P + (odd)G
- */
- vi = 0;
- hi = 0;
- /* and go for it! */
- for (i = 32; i-- !== 0;) {
- vi = (vi << 8) | (v[i] & 0xFF);
- hi = (hi << 8) | (h[i] & 0xFF);
- di = (di << 8) | (d[i] & 0xFF);
- for (j = 8; j-- !== 0;) {
- Curve25519.mont_prep(t1[0], t2[0], yx[0], yz[0]);
- Curve25519.mont_prep(t1[1], t2[1], yx[1], yz[1]);
- Curve25519.mont_prep(t1[2], t2[2], yx[2], yz[2]);
- k = ((vi ^ vi >> 1) >> j & 1)
- + ((hi ^ hi >> 1) >> j & 1);
- Curve25519.mont_dbl(yx[2], yz[2], t1[k], t2[k], yx[0], yz[0]);
- k = (di >> j & 2) ^ ((di >> j & 1) << 1);
- Curve25519.mont_add(t1[1], t2[1], t1[k], t2[k], yx[1], yz[1],
- p[di >> j & 1]);
- Curve25519.mont_add(t1[2], t2[2], t1[0], t2[0], yx[2], yz[2],
- s[((vi ^ hi) >> j & 2) >> 1]);
- }
- }
- k = (vi & 1) + (hi & 1);
- Curve25519.recip(t1[0], yz[k], 0);
- Curve25519.mul(t1[1], yx[k], t1[0]);
- let Y = [];
- Curve25519.pack(t1[1], Y);
- return Y;
- }
Bis Zeile 50. /* prepare the chain */ bin ich durch... nur dann fallen mir die unterschiedlichen Arrays auf die Füße. Denn in der VB/C#-Variante wird alles mit 10 Long-Arrays gelöst und hier eben alles mit UInt16Arrays. Hat von euch jmd vllt. eine Idee wie ich dieses Problem lösen kann? Vllt. einen Arrays-Converter oder so?
Hier noch der VB-Code:
Quellcode
-
- Public Shared Function verify(ByVal v As Byte(), ByVal h As Byte(), ByVal pk As Byte()) As Byte()
- '/* Y = v abs(P) + h G */
- Dim Input_vStr As String = ByteAry2HEX(v) 'v = bed2c0bd00f2e5002c7376632361a55b2ae6a1796d21a64741a9c020b8d95404
- Dim Input_hStr As String = ByteAry2HEX(h) 'h = 200fb965e1230bec6a9dc576d1bfa2875c3a6521fa9ced997f79ac608da939f6
- Dim Input_pkStr As String = ByteAry2HEX(pk) 'pk = bdb5594cce5dcadb6a4c3af20384a7ad3b8ce045b66535bf0188fdfe7a3b6479
- Dim d(31) As Byte
- Dim p() As RefCurve25519.Long10 = {New RefCurve25519.Long10, New RefCurve25519.Long10}
- Dim s = {New RefCurve25519.Long10, New RefCurve25519.Long10}
- Dim yx = {New RefCurve25519.Long10, New RefCurve25519.Long10, New RefCurve25519.Long10}
- Dim yz = {New RefCurve25519.Long10, New RefCurve25519.Long10, New RefCurve25519.Long10}
- Dim t1 = {New RefCurve25519.Long10, New RefCurve25519.Long10, New RefCurve25519.Long10}
- Dim t2 = {New RefCurve25519.Long10, New RefCurve25519.Long10, New RefCurve25519.Long10}
- Dim vi = 0, hi = 0, di = 0, nvh = 0, jj, k As Integer
- Dim TempPack(31) As Byte
- Dim TempPackStr As String = ""
- '/* set p[0] to G And p[1] to P */
- RefCurve25519.Set(p(0), 9)
- RefCurve25519.Unpack(p(1), pk)
- '/* set s[0] to P+G And s[1] to P-G */
- '/* s[0] = (Py^2 + Gy^2 - 2 Py Gy)/(Px - Gx)^2 - Px - Gx - 486662 */
- '/* s[1] = (Py^2 + Gy^2 + 2 Py Gy)/(Px - Gx)^2 - Px - Gx - 486662 */
- RefCurve25519.CurveEquationInline(t2(0), p(1), t1(0)) '/* t2[0] = Py ^ 2 */
- '#debug#
- RefCurve25519.Pack(p(1), TempPack)
- TempPackStr = ByteAry2HEX(TempPack) 't1(0) = 78d91ac1f1ae1a9e4200a42ac4a9001fa24b44be8e2b58cd123843684b90235f
- ' t2(0) = e34bdb568e732b26e4d8400e4c428751868406323388e0228cb7f8b309ddcd43
- ' p(1) = bdb5594cce5dcadb6a4c3af20384a7ad3b8ce045b66535bf0188fdfe7a3b6479
- RefCurve25519.sqrt(t1(0), t2(0)) '/* t1[0] = Py Or -Py */
- '#debug#
- RefCurve25519.Pack(t1(0), TempPack)
- TempPackStr = ByteAry2HEX(TempPack) 't1(0) = "3e88da5e05657c0d44b02f88e89bc1d5914c2d597d2832e3dcc1c3e6291ca727"
- jj = RefCurve25519.IsNegative(t1(0)) '/* ... check which */
- RefCurve25519.Add(t2(0), t2(0), New RefCurve25519.Long10(RefCurve25519.C39420360, 0, 0, 0, 0, 0, 0, 0, 0, 0)) '/* t2[0] = Py ^ 2 + Gy ^ 2 */
- '#debug#
- RefCurve25519.Pack(t2(0), TempPack)
- TempPackStr = ByteAry2HEX(TempPack) 't2(0) = abcd34598e732b26e4d8400e4c428751868406323388e0228cb7f8b309ddcd43
- '3b586202bb742cac9b3c0725036585db665d6e11a745c23f96f2be8ebccca33e
- 'Dim test As Byte() = HEXStr2ByteAry("3b586202bb742cac9b3c0725036585db665d6e11a745c23f96f2be8ebccca33e")
- 'Dim test2 As RefCurve25519.Long10 = New RefCurve25519.Long10
- 'RefCurve25519.Unpack(test2, test)
- RefCurve25519.Multiply(t2(1), RefCurve25519.Base2Y, t1(0)) '/* t2[1] = 2 Py Gy Or -2 Py Gy */
- '#debug#
- RefCurve25519.Pack(t2(1), TempPack)
- TempPackStr = ByteAry2HEX(TempPack) 't2(1) = "2823ace230af25bebb3175a816310c9bb0f1f387f808cc20e719b6c8ca0a7d17"
- RefCurve25519.Sub(t1(jj), t2(0), t2(1)) '/* t1[0] = Py ^ 2 + Gy ^ 2 - 2 Py Gy */
- '#debug#
- RefCurve25519.Pack(t1(jj), TempPack)
- TempPackStr = ByteAry2HEX(TempPack) 't1(jj = 0) = "83aa88765dc4056828a7cb6535117bb6d59212aa3a7f1402a59d42eb3ed2502c"
- ' t2(0) = "abcd34598e732b26e4d8400e4c428751868406323388e0228cb7f8b309ddcd43"
- ' t2(1) = "2823ace230af25bebb3175a816310c9bb0f1f387f808cc20e719b6c8ca0a7d17"
- 'Dim test1 As Byte() = HEXStr2ByteAry("0000000000000000000000000000000000000000000000000000000000000000")
- 'Dim test1a As RefCurve25519.Long10 = New RefCurve25519.Long10
- 'RefCurve25519.Unpack(test1a, test1)
- 'Dim test2 As Byte() = HEXStr2ByteAry("70aa88765dc4056828a7cb6535117bb6d59212aa3a7f1402a59d42eb3ed250ac")
- 'Dim test2a As RefCurve25519.Long10 = New RefCurve25519.Long10
- 'RefCurve25519.Unpack(test2a, test2)
- 'Dim test3 As Byte() = HEXStr2ByteAry("83aa88765dc4056828a7cb6535117bb6d59212aa3a7f1402a59d42eb3ed2502c")
- 'Dim test3a As RefCurve25519.Long10 = New RefCurve25519.Long10
- 'RefCurve25519.Unpack(test3a, test3)
- 'Dim testresult As RefCurve25519.Long10 = New RefCurve25519.Long10
- 'RefCurve25519.Sub(testresult, test3a, test2a) 'test1a + test2a = (same as ec-kcdsa.js) = 2e78bdcfeb37318e0c800c74815302085c1719dc6d07f52431553b9f48af1e70
- '' test1a + test3a = test2a = abcd34598e732b26e4d8400e4c428751868406323388e0228cb7f8b309ddcd43
- '' test3a - test2a = (same as ec-kcdsa.js) = 6a557789a23bfa97d758349acaee84492a6ded55c580ebfd5a62bd14c12daf53
- '' test2a - test3a = ? = 83aa88765dc4056828a7cb6535117bb6d59212aa3a7f1402a59d42eb3ed2502c
- 'RefCurve25519.Pack(testresult, TempPack)
- 'TempPackStr = ByteAry2HEX(TempPack)
- RefCurve25519.Add(t1(1 - jj), t2(0), t2(1)) '/* t1[1] = Py ^ 2 + Gy ^ 2 + 2 Py Gy */
- '#debug#
- RefCurve25519.Pack(t1(1 - jj), TempPack)
- TempPackStr = ByteAry2HEX(TempPack) '"d3f0e03bbf2251e49f0ab6b6627393ec3676fab92b91ac4373d1ae7cd4e74a5b"
- RefCurve25519.Copy(t2(0), p(1)) '/* t2[0] = Px */
- '#debug#
- RefCurve25519.Pack(t2(0), TempPack)
- TempPackStr = ByteAry2HEX(TempPack) 't2(0) = "bdb5594cce5dcadb6a4c3af20384a7ad3b8ce045b66535bf0188fdfe7a3b6479"
- RefCurve25519.Sub(t2(0), t2(0), New RefCurve25519.Long10(9, 0, 0, 0, 0, 0, 0, 0, 0, 0)) '/* t2[0] = Px - Gx */
- '#debug#
- RefCurve25519.Pack(t2(0), TempPack)
- TempPackStr = ByteAry2HEX(TempPack) 't2(0) = "b4b5594cce5dcadb6a4c3af20384a7ad3b8ce045b66535bf0188fdfe7a3b6479"
- RefCurve25519.Square(t2(1), t2(0)) '/* t2[1] = (Px - Gx) ^ 2 */
- '#debug#
- RefCurve25519.Pack(t2(1), TempPack)
- TempPackStr = ByteAry2HEX(TempPack) 't2(1) = 2d879f6da4f68c482054b78baafbfae784fddfbf931d0c5c097f89d542a50d30
- RefCurve25519.Reciprocal(t2(0), t2(1), 0) '/* t2[0] = 1/(Px - Gx)^2 */
- '#debug#
- RefCurve25519.Pack(t2(0), TempPack)
- TempPackStr = ByteAry2HEX(TempPack) ' t2(0) = cc0db7db039091eeeb2147167228f62106a0bd3a913dd67d93d676537d609b37
- RefCurve25519.Multiply(s(0), t1(0), t2(0)) '/* s[0] = t1[0]/(Px - Gx)^2 */
- '#debug#
- RefCurve25519.Pack(s(0), TempPack)
- TempPackStr = ByteAry2HEX(TempPack) 's(0) = ad4ad72c0f2e272c5c30dc9aa22f927b654cc5105cf42a385f83e5257031ff13
- RefCurve25519.Sub(s(0), s(0), p(1)) '/* s[0] = t1[0]/(Px - Gx)^2 - Px */
- '#debug#
- RefCurve25519.Pack(s(0), TempPack)
- TempPackStr = ByteAry2HEX(TempPack) 's(0) = dd947de040d05c50f1e3a1a89eabeacd29c0e4caa58ef5785dfbe726f5f59a1a
- RefCurve25519.Sub(s(0), s(0), New RefCurve25519.Long10(RefCurve25519.C486671, 0, 0, 0, 0, 0, 0, 0, 0, 0)) '/* s[0] = X(P + G) */
- '#debug#
- RefCurve25519.Pack(s(0), TempPack)
- TempPackStr = ByteAry2HEX(TempPack) ' s(0) = ce2776e040d05c50f1e3a1a89eabeacd29c0e4caa58ef5785dfbe726f5f59a1a
- RefCurve25519.Multiply(s(1), t1(1), t2(0)) '/* s[1] = t1[1]/(Px - Gx)^2 */
- '#debug#
- RefCurve25519.Pack(s(1), TempPack)
- TempPackStr = ByteAry2HEX(TempPack) 's(1) = c687944436aed57827e1842031e8c99b282beaa0810d21715e8e673c051bde5a
- RefCurve25519.Sub(s(1), s(1), p(1)) '/* s[1] = t1[1]/(Px - Gx)^2 - Px */
- '#debug#
- RefCurve25519.Pack(s(1), TempPack)
- TempPackStr = ByteAry2HEX(TempPack) 's(1) = f6d13af867500b9dbc944a2e2d6422eeec9e095bcba7ebb15c066a3d8adf7961
- RefCurve25519.Sub(s(1), s(1), New RefCurve25519.Long10(RefCurve25519.C486671, 0, 0, 0, 0, 0, 0, 0, 0, 0)) '/* s[1] = X(P - G) */
- '#debug#
- RefCurve25519.Pack(s(1), TempPack)
- TempPackStr = ByteAry2HEX(TempPack) 's(1) = e76433f867500b9dbc944a2e2d6422eeec9e095bcba7ebb15c066a3d8adf7961
- RefCurve25519.MulSmall(s(0), s(0), 1) '/* reduce s[0] */
- '#debug#
- RefCurve25519.Pack(s(0), TempPack)
- TempPackStr = ByteAry2HEX(TempPack) 's(0) = ce2776e040d05c50f1e3a1a89eabeacd29c0e4caa58ef5785dfbe726f5f59a1a
- RefCurve25519.MulSmall(s(1), s(1), 1) '/* reduce s[1] */
- '#debug#
- RefCurve25519.Pack(s(1), TempPack)
- TempPackStr = ByteAry2HEX(TempPack) 's(1) = e76433f867500b9dbc944a2e2d6422eeec9e095bcba7ebb15c066a3d8adf7961
- #Region "Tracestop 1"
- 'p(0) =
- 'N0 9 Long
- 'N1 0 Long
- 'N2 0 Long
- 'N3 0 Long
- 'N4 0 Long
- 'N5 0 Long
- 'N6 0 Long
- 'N7 0 Long
- 'N8 0 Long
- 'N9 0 Long
- 'p(1) =
- 'N0 5879229 Long
- 'N1 9925523 Long
- 'N2 26041209 Long
- 'N3 2068946 Long
- 'N4 45522448 Long
- 'N5 31493179 Long
- 'N6 45275938 Long
- 'N7 16791526 Long
- 'N8 61861848 Long
- 'N9 31822061 Long
- 's(0) =
- 'N0 27192331 Long
- 'N1 24318579 Long
- 'N2 17573660 Long
- 'N3 19711439 Long
- 'N4 5413017 Long
- 'N5 30672297 Long
- 'N6 15276307 Long
- 'N7 12279728 Long
- 'N8 5320169 Long
- 'N9 29115157 Long
- 's(1) =
- 'N0 41529697 Long
- 'N1 11249298 Long
- 'N2 3399453 Long
- 'N3 34898 Long
- 'N4 29919506 Long
- 'N5 19270466 Long
- 'N6 25013351 Long
- 'N7 17315350 Long
- 'N8 935140 Long
- 'N9 18909289 Long
- 't1(0) =
- 'N0 97122056 Long
- 'N1 19501385 Long
- 'N2 97391928 Long
- 'N3 9915679 Long
- 'N4 45240380 Long
- 'N5 29422681 Long
- 'N6 9838121 Long
- 'N7 46452542 Long
- 'N8 39555765 Long
- 'N9 35130938 Long
- 't1(1) =
- 'N0 -1203122 Long
- 'N1 9452179 Long
- 'N2 7009362 Long
- 'N3 2725613 Long
- 'N4 -2496042 Long
- 'N5 -28568397 Long
- 'N6 -912119 Long
- 'N7 -14796422 Long
- 'N8 -19207071 Long
- 'N9 417966 Long
- 't1(2) =
- 'N0 0 Long
- 'N1 0 Long
- 'N2 0 Long
- 'N3 0 Long
- 'N4 0 Long
- 'N5 0 Long
- 'N6 0 Long
- 'N7 0 Long
- 'N8 0 Long
- 'N9 0 Long
- 't2(0)=
- 'N0 62328268 Long
- 'N1 6553846 Long
- 'N2 4029906 Long
- 'N3 26260025 Long
- 'N4 8902817 Long
- 'N5 12427270 Long
- 'N6 52349085 Long
- 'N7 13791162 Long
- 'N8 64305005 Long
- 'N9 14577025 Long
- 't2(1) =
- 'N0 27232045 Long
- 'N1 20818203 Long
- 'N2 42207505 Long
- 'N3 22306234 Long
- 'N4 60812270 Long
- 'N5 31456644 Long
- 'N6 34523615 Long
- 'N7 31533953 Long
- 'N8 2971799 Long
- 'N9 12596885 Long
- 't2(2) =
- 'N0 0 Long
- 'N1 0 Long
- 'N2 0 Long
- 'N3 0 Long
- 'N4 0 Long
- 'N5 0 Long
- 'N6 0 Long
- 'N7 0 Long
- 'N8 0 Long
- 'N9 0 Long
- #End Region
- '/* prepare the chain */
- For i As Integer = 0 To 31
- vi = (vi >> 8) Xor (v(i) And &HFF) Xor ((v(i) And &HFF) << 1)
- hi = (hi >> 8) Xor (h(i) And &HFF) Xor ((h(i) And &HFF) << 1)
- nvh = Not (vi Xor hi)
- di = (nvh And (di And &H80) >> 7) Xor vi
- di = di Xor nvh And (di And &H1) << 1
- di = di Xor nvh And (di And &H2) << 1
- di = di Xor nvh And (di And &H4) << 1
- di = di Xor nvh And (di And &H8) << 1
- di = di Xor nvh And (di And &H10) << 1
- di = di Xor nvh And (di And &H20) << 1
- di = di Xor nvh And (di And &H40) << 1
- d(i) = di And &HFF
- Next
- di = ((nvh And (di And &H80) << 1) Xor vi) >> 8
- #Region "Tracestop 2"
- 'd = deee40420112ea03549db9642dbf5a645a3a629ef562ea597f79435f4826b505
- 'hi = 282
- 'vi = 12
- 'di = 0
- #End Region
- '/* initialize state */
- RefCurve25519.Set(yx(0), 1)
- RefCurve25519.Copy(yx(1), p(di))
- RefCurve25519.Copy(yx(2), s(0))
- RefCurve25519.Set(yz(0), 0)
- RefCurve25519.Set(yz(1), 1)
- RefCurve25519.Set(yz(2), 1)
- #Region "Tracestop 3"
- 'yx(0) =
- 'N0 1 Long
- 'N1 0 Long
- 'N2 0 Long
- 'N3 0 Long
- 'N4 0 Long
- 'N5 0 Long
- 'N6 0 Long
- 'N7 0 Long
- 'N8 0 Long
- 'N9 0 Long
- 'yx(1) =
- 'N0 9 Long
- 'N1 0 Long
- 'N2 0 Long
- 'N3 0 Long
- 'N4 0 Long
- 'N5 0 Long
- 'N6 0 Long
- 'N7 0 Long
- 'N8 0 Long
- 'N9 0 Long
- 'yx(2) =
- 'N0 27192331 Long
- 'N1 24318579 Long
- 'N2 17573660 Long
- 'N3 19711439 Long
- 'N4 5413017 Long
- 'N5 30672297 Long
- 'N6 15276307 Long
- 'N7 12279728 Long
- 'N8 5320169 Long
- 'N9 29115157 Long
- 'yz(0) =
- 'N0 0 Long
- 'N1 0 Long
- 'N2 0 Long
- 'N3 0 Long
- 'N4 0 Long
- 'N5 0 Long
- 'N6 0 Long
- 'N7 0 Long
- 'N8 0 Long
- 'N9 0 Long
- 'yz(1) =
- 'N0 1 Long
- 'N1 0 Long
- 'N2 0 Long
- 'N3 0 Long
- 'N4 0 Long
- 'N5 0 Long
- 'N6 0 Long
- 'N7 0 Long
- 'N8 0 Long
- 'N9 0 Long
- 'yz(2) =
- 'N0 1 Long
- 'N1 0 Long
- 'N2 0 Long
- 'N3 0 Long
- 'N4 0 Long
- 'N5 0 Long
- 'N6 0 Long
- 'N7 0 Long
- 'N8 0 Long
- 'N9 0 Long
- #End Region
- '/* y[0] Is (even)P + (even)G
- ' * y[1] Is (even)P + (odd)G if current d-bit Is 0
- ' * y[1] Is (odd)P + (even)G if current d-bit Is 1
- ' * y[2] Is (odd)P + (odd)G
- ' */
- vi = 0
- hi = 0
- 'And go for it!
- For i As Integer = 31 To 0 Step -1
- vi = (vi << 8) Or (v(i) And &HFF)
- hi = (hi << 8) Or (h(i) And &HFF)
- di = (di << 8) Or (d(i) And &HFF)
- For j As Integer = 8 To 0 Step -1
- RefCurve25519.MontyPrepare(t1(0), t2(0), yx(0), yz(0))
- RefCurve25519.MontyPrepare(t1(1), t2(1), yx(1), yz(1))
- RefCurve25519.MontyPrepare(t1(2), t2(2), yx(2), yz(2))
- k = ((vi Xor vi >> 1) >> j And 1) + ((hi Xor hi >> 1) >> j And 1)
- RefCurve25519.MontyDouble(yx(2), yz(2), t1(k), t2(k), yx(0), yz(0))
- k = (di >> j And 2) Or ((di >> j And 1) << 1)
- RefCurve25519.MontyAdd(t1(1), t2(1), t1(k), t2(k), yx(1), yz(1), p(di >> j And 1))
- RefCurve25519.MontyAdd(t1(2), t2(2), t1(0), t2(0), yx(2), yz(2), s(((vi Xor hi) >> j And 2) >> 1))
- Next
- Next
- #Region "Tracestop 4"
- 'vi = -1111436610 Integer
- 'hi = 1706626848 Integer
- 'di = 1111551710 Integer
- 'k = 2
- 't1(0) =
- 'N0 80652174 Long
- 'N1 52304140 Long
- 'N2 30594347 Long
- 'N3 33419878 Long
- 'N4 58886342 Long
- 'N5 46170530 Long
- 'N6 82841748 Long
- 'N7 40879862 Long
- 'N8 78485571 Long
- 'N9 37669871 Long
- 't1(1) =
- 'N0 59101306 Long
- 'N1 14212684 Long
- 'N2 22378684 Long
- 'N3 8174658 Long
- 'N4 18242175 Long
- 'N5 32162007 Long
- 'N6 3725737 Long
- 'N7 6610879 Long
- 'N8 32011420 Long
- 'N9 27005631 Long
- 't1(2) =
- 'N0 43433296 Long
- 'N1 28535350 Long
- 'N2 54616526 Long
- 'N3 3286957 Long
- 'N4 44009088 Long
- 'N5 7814553 Long
- 'N6 21404851 Long
- 'N7 29710982 Long
- 'N8 61374206 Long
- 'N9 29792398 Long
- 't2(0) =
- 'N0 -27974162 Long
- 'N1 10880740 Long
- 'N2 29979591 Long
- 'N3 -522078 Long
- 'N4 -10540188 Long
- 'N5 19609484 Long
- 'N6 18140918 Long
- 'N7 23191440 Long
- 'N8 20903125 Long
- 'N9 17901149 Long
- 't2(1) =
- 'N0 30577412 Long
- 'N1 -8385638 Long
- 'N2 -23853868 Long
- 'N3 17400612 Long
- 'N4 -19780918 Long
- 'N5 -15733788 Long
- 'N6 28290292 Long
- 'N7 -3007844 Long
- 'N8 -23177790 Long
- 'N9 -4652416 Long
- 't2(2) =
- 'N0 -33490657 Long
- 'N1 3984873 Long
- 'N2 11859928 Long
- 'N3 -4786581 Long
- 'N4 -6301271 Long
- 'N5 -10071233 Long
- 'N6 -27201046 Long
- 'N7 10991415 Long
- 'N8 25635918 Long
- 'N9 -26723488 Long
- 'yx(0) =
- 'N0 59150063 Long
- 'N1 4071334 Long
- 'N2 13453948 Long
- 'N3 33019915 Long
- 'N4 30137134 Long
- 'N5 23265735 Long
- 'N6 61416867 Long
- 'N7 3096186 Long
- 'N8 60250062 Long
- 'N9 25932033 Long
- 'yx(1) =
- 'N0 39142553 Long
- 'N1 18963241 Long
- 'N2 20228824 Long
- 'N3 14668816 Long
- 'N4 56781996 Long
- 'N5 9273275 Long
- 'N6 24755442 Long
- 'N7 30808233 Long
- 'N8 44088001 Long
- 'N9 23338255 Long
- 'yx(2) =
- 'N0 54853063 Long
- 'N1 10187929 Long
- 'N2 19951159 Long
- 'N3 7346679 Long
- 'N4 62539145 Long
- 'N5 15066087 Long
- 'N6 16871919 Long
- 'N7 22734774 Long
- 'N8 39982547 Long
- 'N9 6378161 Long
- 'yz(0) =
- 'N0 28785620 Long
- 'N1 22601994 Long
- 'N2 23262302 Long
- 'N3 16422086 Long
- 'N4 60172685 Long
- 'N5 32369462 Long
- 'N6 48153093 Long
- 'N7 24551075 Long
- 'N8 55043262 Long
- 'N9 4839025 Long
- 'yz(1) =
- 'N0 62149839 Long
- 'N1 27250867 Long
- 'N2 81567 Long
- 'N3 6463061 Long
- 'N4 29961849 Long
- 'N5 21022609 Long
- 'N6 33531641 Long
- 'N7 25943479 Long
- 'N8 19667325 Long
- 'N9 8169659 Long
- 'yz(2) =
- 'N0 45499790 Long
- 'N1 8293683 Long
- 'N2 32672976 Long
- 'N3 26337680 Long
- 'N4 50195045 Long
- 'N5 9503606 Long
- 'N6 25823197 Long
- 'N7 21171840 Long
- 'N8 25301773 Long
- 'N9 20206989 Long
- #End Region
- k = (vi And 1) + (hi And 1)
- 'k = 0
- RefCurve25519.Reciprocal(t1(0), yz(k), 0)
- RefCurve25519.Multiply(t1(1), yx(k), t1(0))
- #Region "Tracestop 5"
- 't1(0) =
- 'N0 45872088 Long
- 'N1 33140773 Long
- 'N2 14911662 Long
- 'N3 23898813 Long
- 'N4 62412525 Long
- 'N5 30064514 Long
- 'N6 35380908 Long
- 'N7 14749202 Long
- 'N8 57081376 Long
- 'N9 1274365 Long
- 't1(1) =
- 'N0 4071327 Long
- 'N1 27121515 Long
- 'N2 3684926 Long
- 'N3 13986023 Long
- 'N4 63714629 Long
- 'N5 32417481 Long
- 'N6 65506912 Long
- 'N7 22562823 Long
- 'N8 34259780 Long
- 'N9 2110758 Long
- 't1(2) =
- 'N0 43433296 Long
- 'N1 28535350 Long
- 'N2 54616526 Long
- 'N3 3286957 Long
- 'N4 44009088 Long
- 'N5 7814553 Long
- 'N6 21404851 Long
- 'N7 29710982 Long
- 'N8 61374206 Long
- 'N9 29792398 Long
- #End Region
- Dim Y(31) As Byte
- RefCurve25519.Pack(t1(1), Y)
- ' Soll = d65c6cc6d1841a3deec249841d7bf1ddeb65625efa70f8d98867a3175a1be526
- Dim HEXHEX As String = ByteAry2HEX(Y) 'Y = 0145e6685f5ee3bd65af2821351b2548e7f95fb56d3d368a05c9fc7211481360
- Return Y
- End Function
Vielen Dank schon mal