-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathBrainpoolPrimeCurve.cs
More file actions
112 lines (104 loc) · 4.84 KB
/
BrainpoolPrimeCurve.cs
File metadata and controls
112 lines (104 loc) · 4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using System.IO;
using System.Numerics;
namespace Waher.Security.EllipticCurves
{
/// <summary>
/// Base class of Elliptic curves over a prime field defined by Brainpool.
/// </summary>
public abstract class BrainpoolPrimeCurve : WeierstrassCurve
{
/// <summary>
/// Base class of Elliptic curves over a prime field defined by Brainpool.
/// </summary>
/// <param name="Prime">Prime base of field.</param>
/// <param name="BasePoint">Base-point.</param>
/// <param name="A">A coefficient in Elliptic Curve.</param>
/// <param name="B">B coefficient in Elliptic Curve.</param>
/// <param name="Order">Order of base-point.</param>
public BrainpoolPrimeCurve(BigInteger Prime, PointOnCurve BasePoint, BigInteger A,
BigInteger B, BigInteger Order)
: base(Prime, BasePoint, A, B, Order, 1)
{
}
/// <summary>
/// Base class of Elliptic curves over a prime field defined by Brainpool.
/// </summary>
/// <param name="Prime">Prime base of field.</param>
/// <param name="BasePoint">Base-point.</param>
/// <param name="A">A coefficient in Elliptic Curve.</param>
/// <param name="B">B coefficient in Elliptic Curve.</param>
/// <param name="Order">Order of base-point.</param>
/// <param name="Secret">Secret.</param>
public BrainpoolPrimeCurve(BigInteger Prime, PointOnCurve BasePoint, BigInteger A,
BigInteger B, BigInteger Order, byte[] Secret)
: base(Prime, BasePoint, A, B, Order, 1, Secret)
{
}
/// <summary>
/// Base class of Elliptic curves over a prime field defined by Brainpool.
/// </summary>
/// <param name="Prime">Prime base of field.</param>
/// <param name="BasePoint">Base-point.</param>
/// <param name="A">A coefficient in Elliptic Curve.</param>
/// <param name="B">B coefficient in Elliptic Curve.</param>
/// <param name="Order">Order of base-point.</param>
/// <param name="Secret">Secret.</param>
public BrainpoolPrimeCurve(BigInteger Prime, PointOnCurve BasePoint, BigInteger A,
BigInteger B, BigInteger Order, uint[] Secret)
: base(Prime, BasePoint, A, B, Order, 1, Secret)
{
}
/// <summary>
/// Creates a signature of <paramref name="Data"/> using the ECDSA algorithm.
/// </summary>
/// <param name="Data">Payload to sign.</param>
/// <param name="BigEndian">Indicates if the signature should be in big-endian format.</param>
/// <returns>Signature.</returns>
public override byte[] Sign(byte[] Data, bool BigEndian)
{
return ECDSA.Sign(Data, BigEndian, this.PrivateKey,
Bin => Hashes.ComputeHash(this.HashFunction, Bin),
this.orderBytes, this.bigIntegerBytes, this.msbOrderMask, this);
}
/// <summary>
/// Creates a signature of <paramref name="Data"/> using the ECDSA algorithm.
/// </summary>
/// <param name="Data">Payload to sign.</param>
/// <param name="BigEndian">Indicates if the signature should be in big-endian format.</param>
/// <returns>Signature.</returns>
public override byte[] Sign(Stream Data, bool BigEndian)
{
return ECDSA.Sign(Data, BigEndian, this.PrivateKey,
Bin => Hashes.ComputeHash(this.HashFunction, Bin),
this.orderBytes, this.bigIntegerBytes, this.msbOrderMask, this);
}
/// <summary>
/// Verifies a signature of <paramref name="Data"/> made by the ECDSA algorithm.
/// </summary>
/// <param name="Data">Payload to sign.</param>
/// <param name="PublicKey">Public Key of the entity that generated the signature.</param>
/// <param name="BigEndian">Indicates if the public key is in big-endian format.</param>
/// <param name="Signature">Signature</param>
/// <returns>If the signature is valid.</returns>
public override bool Verify(byte[] Data, byte[] PublicKey, bool BigEndian, byte[] Signature)
{
return ECDSA.Verify(Data, PublicKey, BigEndian,
Bin => Hashes.ComputeHash(this.HashFunction, Bin),
this.orderBytes, this.bigIntegerBytes, this.msbOrderMask, this, Signature);
}
/// <summary>
/// Verifies a signature of <paramref name="Data"/> made by the ECDSA algorithm.
/// </summary>
/// <param name="Data">Payload to sign.</param>
/// <param name="PublicKey">Public Key of the entity that generated the signature.</param>
/// <param name="BigEndian">Indicates if the public key is in big-endian format.</param>
/// <param name="Signature">Signature</param>
/// <returns>If the signature is valid.</returns>
public override bool Verify(Stream Data, byte[] PublicKey, bool BigEndian, byte[] Signature)
{
return ECDSA.Verify(Data, PublicKey, BigEndian,
Bin => Hashes.ComputeHash(this.HashFunction, Bin),
this.orderBytes, this.bigIntegerBytes, this.msbOrderMask, this, Signature);
}
}
}