Skip to content

Commit 5a28a6d

Browse files
committed
Add client_ed25519 authentication code.
This includes a subset of the code from https://github.com/CodesInChaos/Chaos.NaCl, which is in the public domain. Signed-off-by: Bradley Grainger <[email protected]>
1 parent ffb45f3 commit 5a28a6d

35 files changed

+3940
-0
lines changed

MySqlConnector.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MySqlConnector.Logging.Seri
2020
EndProject
2121
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MySqlConnector.Logging.NLog", "src\MySqlConnector.Logging.NLog\MySqlConnector.Logging.NLog.csproj", "{92015BEE-563A-4595-9243-0510D2B8767F}"
2222
EndProject
23+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MySqlConnector.Authentication.Ed25519", "src\MySqlConnector.Authentication.Ed25519\MySqlConnector.Authentication.Ed25519.csproj", "{5DB4FA2E-910B-47CE-B467-F6852104D567}"
24+
EndProject
2325
Global
2426
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2527
Debug|Any CPU = Debug|Any CPU
@@ -62,6 +64,10 @@ Global
6264
{92015BEE-563A-4595-9243-0510D2B8767F}.Debug|Any CPU.Build.0 = Debug|Any CPU
6365
{92015BEE-563A-4595-9243-0510D2B8767F}.Release|Any CPU.ActiveCfg = Release|Any CPU
6466
{92015BEE-563A-4595-9243-0510D2B8767F}.Release|Any CPU.Build.0 = Release|Any CPU
67+
{5DB4FA2E-910B-47CE-B467-F6852104D567}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
68+
{5DB4FA2E-910B-47CE-B467-F6852104D567}.Debug|Any CPU.Build.0 = Debug|Any CPU
69+
{5DB4FA2E-910B-47CE-B467-F6852104D567}.Release|Any CPU.ActiveCfg = Release|Any CPU
70+
{5DB4FA2E-910B-47CE-B467-F6852104D567}.Release|Any CPU.Build.0 = Release|Any CPU
6571
EndGlobalSection
6672
GlobalSection(SolutionProperties) = preSolution
6773
HideSolutionNode = FALSE
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System;
2+
3+
namespace Chaos.NaCl.Internal.Ed25519Ref10
4+
{
5+
internal struct FieldElement
6+
{
7+
internal int x0;
8+
internal int x1;
9+
internal int x2;
10+
internal int x3;
11+
internal int x4;
12+
internal int x5;
13+
internal int x6;
14+
internal int x7;
15+
internal int x8;
16+
internal int x9;
17+
18+
//public static readonly FieldElement Zero = new FieldElement();
19+
//public static readonly FieldElement One = new FieldElement() { x0 = 1 };
20+
21+
internal FieldElement(params int[] elements)
22+
{
23+
InternalAssert.Assert(elements.Length == 10, "elements.Length != 10");
24+
x0 = elements[0];
25+
x1 = elements[1];
26+
x2 = elements[2];
27+
x3 = elements[3];
28+
x4 = elements[4];
29+
x5 = elements[5];
30+
x6 = elements[6];
31+
x7 = elements[7];
32+
x8 = elements[8];
33+
x9 = elements[9];
34+
}
35+
}
36+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
3+
namespace Chaos.NaCl.Internal.Ed25519Ref10
4+
{
5+
/*
6+
ge means group element.
7+
8+
Here the group is the set of pairs (x,y) of field elements (see fe.h)
9+
satisfying -x^2 + y^2 = 1 + d x^2y^2
10+
where d = -121665/121666.
11+
12+
Representations:
13+
ge_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z
14+
ge_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
15+
ge_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
16+
ge_precomp (Duif): (y+x,y-x,2dxy)
17+
*/
18+
19+
internal struct GroupElementP2
20+
{
21+
public FieldElement X;
22+
public FieldElement Y;
23+
public FieldElement Z;
24+
} ;
25+
26+
internal struct GroupElementP3
27+
{
28+
public FieldElement X;
29+
public FieldElement Y;
30+
public FieldElement Z;
31+
public FieldElement T;
32+
} ;
33+
34+
internal struct GroupElementP1P1
35+
{
36+
public FieldElement X;
37+
public FieldElement Y;
38+
public FieldElement Z;
39+
public FieldElement T;
40+
} ;
41+
42+
internal struct GroupElementPreComp
43+
{
44+
public FieldElement yplusx;
45+
public FieldElement yminusx;
46+
public FieldElement xy2d;
47+
48+
public GroupElementPreComp(FieldElement yplusx, FieldElement yminusx, FieldElement xy2d)
49+
{
50+
this.yplusx = yplusx;
51+
this.yminusx = yminusx;
52+
this.xy2d = xy2d;
53+
}
54+
} ;
55+
}

src/MySqlConnector.Authentication.Ed25519/Chaos.NaCl/Internal/Ed25519Ref10/base.cs

Lines changed: 1357 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace Chaos.NaCl.Internal.Ed25519Ref10
4+
{
5+
internal static partial class LookupTables
6+
{
7+
internal static FieldElement d = new FieldElement(-10913610, 13857413, -15372611, 6949391, 114729, -8787816, -6275908, -3247719, -18696448, -12055116);
8+
}
9+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace Chaos.NaCl.Internal.Ed25519Ref10
4+
{
5+
internal static partial class LookupTables
6+
{
7+
internal static FieldElement d2 = new FieldElement(-21827239, -5839606, -30745221, 13898782, 229458, 15978800, -12551817, -6495438, 29715968, 9444199);
8+
}
9+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
3+
namespace Chaos.NaCl.Internal.Ed25519Ref10
4+
{
5+
internal static partial class FieldOperations
6+
{
7+
public static void fe_0(out FieldElement h)
8+
{
9+
h = default(FieldElement);
10+
}
11+
}
12+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System;
2+
3+
namespace Chaos.NaCl.Internal.Ed25519Ref10
4+
{
5+
internal static partial class FieldOperations
6+
{
7+
public static void fe_1(out FieldElement h)
8+
{
9+
h = default(FieldElement);
10+
h.x0 = 1;
11+
}
12+
}
13+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using System;
2+
3+
namespace Chaos.NaCl.Internal.Ed25519Ref10
4+
{
5+
internal static partial class FieldOperations
6+
{
7+
/*
8+
h = f + g
9+
Can overlap h with f or g.
10+
11+
Preconditions:
12+
|f| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
13+
|g| bounded by 1.1*2^25,1.1*2^24,1.1*2^25,1.1*2^24,etc.
14+
15+
Postconditions:
16+
|h| bounded by 1.1*2^26,1.1*2^25,1.1*2^26,1.1*2^25,etc.
17+
*/
18+
//void fe_add(fe h,const fe f,const fe g)
19+
internal static void fe_add(out FieldElement h, ref FieldElement f, ref FieldElement g)
20+
{
21+
Int32 f0 = f.x0;
22+
Int32 f1 = f.x1;
23+
Int32 f2 = f.x2;
24+
Int32 f3 = f.x3;
25+
Int32 f4 = f.x4;
26+
Int32 f5 = f.x5;
27+
Int32 f6 = f.x6;
28+
Int32 f7 = f.x7;
29+
Int32 f8 = f.x8;
30+
Int32 f9 = f.x9;
31+
Int32 g0 = g.x0;
32+
Int32 g1 = g.x1;
33+
Int32 g2 = g.x2;
34+
Int32 g3 = g.x3;
35+
Int32 g4 = g.x4;
36+
Int32 g5 = g.x5;
37+
Int32 g6 = g.x6;
38+
Int32 g7 = g.x7;
39+
Int32 g8 = g.x8;
40+
Int32 g9 = g.x9;
41+
Int32 h0 = f0 + g0;
42+
Int32 h1 = f1 + g1;
43+
Int32 h2 = f2 + g2;
44+
Int32 h3 = f3 + g3;
45+
Int32 h4 = f4 + g4;
46+
Int32 h5 = f5 + g5;
47+
Int32 h6 = f6 + g6;
48+
Int32 h7 = f7 + g7;
49+
Int32 h8 = f8 + g8;
50+
Int32 h9 = f9 + g9;
51+
h.x0 = h0;
52+
h.x1 = h1;
53+
h.x2 = h2;
54+
h.x3 = h3;
55+
h.x4 = h4;
56+
h.x5 = h5;
57+
h.x6 = h6;
58+
h.x7 = h7;
59+
h.x8 = h8;
60+
h.x9 = h9;
61+
}
62+
}
63+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System;
2+
3+
namespace Chaos.NaCl.Internal.Ed25519Ref10
4+
{
5+
internal static partial class FieldOperations
6+
{
7+
/*
8+
Replace (f,g) with (g,g) if b == 1;
9+
replace (f,g) with (f,g) if b == 0.
10+
11+
Preconditions: b in {0,1}.
12+
*/
13+
14+
//void fe_cmov(fe f,const fe g,unsigned int b)
15+
internal static void fe_cmov(ref FieldElement f, ref FieldElement g, int b)
16+
{
17+
Int32 f0 = f.x0;
18+
Int32 f1 = f.x1;
19+
Int32 f2 = f.x2;
20+
Int32 f3 = f.x3;
21+
Int32 f4 = f.x4;
22+
Int32 f5 = f.x5;
23+
Int32 f6 = f.x6;
24+
Int32 f7 = f.x7;
25+
Int32 f8 = f.x8;
26+
Int32 f9 = f.x9;
27+
Int32 g0 = g.x0;
28+
Int32 g1 = g.x1;
29+
Int32 g2 = g.x2;
30+
Int32 g3 = g.x3;
31+
Int32 g4 = g.x4;
32+
Int32 g5 = g.x5;
33+
Int32 g6 = g.x6;
34+
Int32 g7 = g.x7;
35+
Int32 g8 = g.x8;
36+
Int32 g9 = g.x9;
37+
Int32 x0 = f0 ^ g0;
38+
Int32 x1 = f1 ^ g1;
39+
Int32 x2 = f2 ^ g2;
40+
Int32 x3 = f3 ^ g3;
41+
Int32 x4 = f4 ^ g4;
42+
Int32 x5 = f5 ^ g5;
43+
Int32 x6 = f6 ^ g6;
44+
Int32 x7 = f7 ^ g7;
45+
Int32 x8 = f8 ^ g8;
46+
Int32 x9 = f9 ^ g9;
47+
b = -b;
48+
x0 &= b;
49+
x1 &= b;
50+
x2 &= b;
51+
x3 &= b;
52+
x4 &= b;
53+
x5 &= b;
54+
x6 &= b;
55+
x7 &= b;
56+
x8 &= b;
57+
x9 &= b;
58+
f.x0 = f0 ^ x0;
59+
f.x1 = f1 ^ x1;
60+
f.x2 = f2 ^ x2;
61+
f.x3 = f3 ^ x3;
62+
f.x4 = f4 ^ x4;
63+
f.x5 = f5 ^ x5;
64+
f.x6 = f6 ^ x6;
65+
f.x7 = f7 ^ x7;
66+
f.x8 = f8 ^ x8;
67+
f.x9 = f9 ^ x9;
68+
}
69+
}
70+
}

0 commit comments

Comments
 (0)