Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
NistPrimeCurve.cs
1using System;
2using System.IO;
3using System.Numerics;
4
6{
10 public abstract class NistPrimeCurve : WeierstrassCurve
11 {
18 public NistPrimeCurve(BigInteger Prime, PointOnCurve BasePoint, BigInteger Order)
19 : base(Prime, BasePoint, -3, Order, 1)
20 {
21 }
22
30 public NistPrimeCurve(BigInteger Prime, PointOnCurve BasePoint, BigInteger Order,
31 byte[] Secret)
32 : base(Prime, BasePoint, -3, Order, 1, Secret)
33 {
34 }
35
41 protected static BigInteger ToBigInteger(uint[] BigEndianDWords)
42 {
43 int i, c = BigEndianDWords.Length;
44 int j = c << 2;
45 byte[] B = new byte[((BigEndianDWords[0] & 0x80000000) != 0) ? j + 1 : j];
46 uint k;
47
48 for (i = 0; i < c; i++)
49 {
50 k = BigEndianDWords[i];
51
52 B[j - 4] = (byte)k;
53 k >>= 8;
54 B[j - 3] = (byte)k;
55 k >>= 8;
56 B[j - 2] = (byte)k;
57 k >>= 8;
58 B[j - 1] = (byte)k;
59
60 j -= 4;
61 }
62
63 return ToInt(B);
64 }
65
69 public virtual HashFunction HashFunction => HashFunction.SHA256;
70
76 public override byte[] Sign(byte[] Data)
77 {
78 return ECDSA.Sign(Data, this.PrivateKey,
79 Bin => Hashes.ComputeHash(this.HashFunction, Bin),
80 this.orderBytes, this.msbOrderMask, this);
81 }
82
88 public override byte[] Sign(Stream Data)
89 {
90 return ECDSA.Sign(Data, this.PrivateKey,
91 Bin => Hashes.ComputeHash(this.HashFunction, Bin),
92 this.orderBytes, this.msbOrderMask, this);
93 }
94
102 public override bool Verify(byte[] Data, byte[] PublicKey, byte[] Signature)
103 {
104 return ECDSA.Verify(Data, PublicKey,
105 Bin => Hashes.ComputeHash(this.HashFunction, Bin),
106 this.orderBytes, this.msbOrderMask, this, Signature);
107 }
108
116 public override bool Verify(Stream Data, byte[] PublicKey, byte[] Signature)
117 {
118 return ECDSA.Verify(Data, PublicKey,
119 Bin => Hashes.ComputeHash(this.HashFunction, Bin),
120 this.orderBytes, this.msbOrderMask, this, Signature);
121 }
122
123 }
124}
Implements the Elliptic Curve Digital Signature Algorithm (ECDSA).
Definition: ECDSA.cs:11
static bool Verify(byte[] Data, byte[] PublicKey, HashFunctionArray HashFunction, int ScalarBytes, byte MsbMask, PrimeFieldCurve Curve, byte[] Signature)
Verifies a signature of Data made by the ECDSA algorithm.
Definition: ECDSA.cs:161
static byte[] Sign(byte[] Data, byte[] PrivateKey, HashFunctionArray HashFunction, int ScalarBytes, byte MsbMask, PrimeFieldCurve Curve)
Signs data using the ECDSA algorithm.
Definition: ECDSA.cs:22
static BigInteger ToInt(byte[] Binary)
Converts a little-endian binary representation of a big integer to a BigInteger.
virtual byte[] PublicKey
Encoded public key
PointOnCurve BasePoint
Base-point of curve.
Base class of Elliptic curves over a prime field defined by NIST.
static BigInteger ToBigInteger(uint[] BigEndianDWords)
Converts a sequence of unsigned 32-bit integers to a BigInteger.
NistPrimeCurve(BigInteger Prime, PointOnCurve BasePoint, BigInteger Order, byte[] Secret)
Base class of Elliptic curves over a prime field defined by NIST.
override byte[] Sign(byte[] Data)
Creates a signature of Data using the ECDSA algorithm.
override bool Verify(byte[] Data, byte[] PublicKey, byte[] Signature)
Verifies a signature of Data made by the ECDSA algorithm.
override byte[] Sign(Stream Data)
Creates a signature of Data using the ECDSA algorithm.
override bool Verify(Stream Data, byte[] PublicKey, byte[] Signature)
Verifies a signature of Data made by the ECDSA algorithm.
NistPrimeCurve(BigInteger Prime, PointOnCurve BasePoint, BigInteger Order)
Base class of Elliptic curves over a prime field defined by NIST.
Base class of Weierstrass curves (y²=x³+ax+b) over a prime field.
Contains methods for simple hash calculations.
Definition: Hashes.cs:59
static byte[] ComputeHash(HashFunction Function, byte[] Data)
Computes a hash of a block of binary data.
Definition: Hashes.cs:214
HashFunction
Hash method enumeration.
Definition: Hashes.cs:28
Represents a point on a curve.
Definition: PointOnCurve.cs:11