|
3 | 3 | using IntXLib;
|
4 | 4 | using System.Text;
|
5 | 5 | using System.Security.Cryptography;
|
| 6 | +using UnityEngine; |
6 | 7 |
|
7 | 8 | namespace MLAPI.Cryptography
|
8 | 9 | {
|
9 | 10 | internal class EllipticDiffieHellman
|
10 | 11 | {
|
11 | 12 | protected static readonly RNGCryptoServiceProvider rand = new RNGCryptoServiceProvider();
|
12 |
| - public static readonly IntX DEFAULT_PRIME = (new IntX(1) << 255) - 19; |
13 |
| - public static readonly IntX DEFAULT_ORDER = (new IntX(1) << 252) + IntX.Parse("27742317777372353535851937790883648493"); |
14 |
| - public static readonly EllipticCurve DEFAULT_CURVE = new EllipticCurve(486662, 1, DEFAULT_PRIME, EllipticCurve.CurveType.Montgomery); |
15 |
| - public static readonly CurvePoint DEFAULT_GENERATOR = new CurvePoint(9, IntX.Parse("14781619447589544791020593568409986887264606134616475288964881837755586237401")); |
| 13 | + |
| 14 | + public static IntX DEFAULT_PRIME |
| 15 | + { |
| 16 | + get |
| 17 | + { |
| 18 | + if (defaultPrime == null) |
| 19 | + { |
| 20 | + try |
| 21 | + { |
| 22 | + defaultPrime = (new IntX(1) << 255) - 19; |
| 23 | + } |
| 24 | + catch (Exception e) |
| 25 | + { |
| 26 | + Debug.LogError("[MLAPI] CryptoLib failed to parse BigInt. If you are using .NET 2.0 Subset, switch to .NET 2.0 or .NET 4.5"); |
| 27 | + } |
| 28 | + } |
| 29 | + |
| 30 | + return defaultPrime; |
| 31 | + } |
| 32 | + } |
| 33 | + private static IntX defaultPrime; |
| 34 | + |
| 35 | + |
| 36 | + public static IntX DEFAULT_ORDER |
| 37 | + { |
| 38 | + get |
| 39 | + { |
| 40 | + if (defaultOrder == null) |
| 41 | + { |
| 42 | + try |
| 43 | + { |
| 44 | + defaultOrder = (new IntX(1) << 252) + IntX.Parse("27742317777372353535851937790883648493"); |
| 45 | + } |
| 46 | + catch (Exception e) |
| 47 | + { |
| 48 | + Debug.LogError("[MLAPI] CryptoLib failed to parse BigInt. If you are using .NET 2.0 Subset, switch to .NET 2.0 or .NET 4.5"); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + return defaultOrder; |
| 53 | + } |
| 54 | + } |
| 55 | + |
| 56 | + private static IntX defaultOrder; |
| 57 | + |
| 58 | + |
| 59 | + public static EllipticCurve DEFAULT_CURVE |
| 60 | + { |
| 61 | + get |
| 62 | + { |
| 63 | + if (defaultCurve == null) |
| 64 | + { |
| 65 | + try |
| 66 | + { |
| 67 | + defaultCurve = new EllipticCurve(486662, 1, DEFAULT_PRIME, EllipticCurve.CurveType.Montgomery); |
| 68 | + } |
| 69 | + catch (Exception e) |
| 70 | + { |
| 71 | + Debug.LogError("[MLAPI] CryptoLib failed to parse BigInt. If you are using .NET 2.0 Subset, switch to .NET 2.0 or .NET 4.5"); |
| 72 | + } |
| 73 | + } |
| 74 | + |
| 75 | + return defaultCurve; |
| 76 | + } |
| 77 | + } |
| 78 | + private static EllipticCurve defaultCurve; |
| 79 | + |
| 80 | + public static CurvePoint DEFAULT_GENERATOR |
| 81 | + { |
| 82 | + get |
| 83 | + { |
| 84 | + if (defaultGenerator == null) |
| 85 | + { |
| 86 | + try |
| 87 | + { |
| 88 | + defaultGenerator = new CurvePoint(9, IntX.Parse("14781619447589544791020593568409986887264606134616475288964881837755586237401")); |
| 89 | + } |
| 90 | + catch (Exception e) |
| 91 | + { |
| 92 | + Debug.LogError("[MLAPI] CryptoLib failed to parse BigInt. If you are using .NET 2.0 Subset, switch to .NET 2.0 or .NET 4.5"); |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + return defaultGenerator; |
| 97 | + } |
| 98 | + } |
| 99 | + private static CurvePoint defaultGenerator; |
16 | 100 |
|
17 | 101 | protected readonly EllipticCurve curve;
|
18 | 102 | public readonly IntX priv;
|
|
0 commit comments