Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,6 @@ BC_password.txt
*.nuget.targets
*.project.lock.json
project.lock.json
.contributions/
*.log
build_*.txt
Comment thread
KonradSop marked this conversation as resolved.
Outdated
29 changes: 13 additions & 16 deletions crypto/src/crypto/digests/Sha256Digest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@

namespace Org.BouncyCastle.Crypto.Digests
{
/**
* Draft FIPS 180-2 implementation of SHA-256. <b>Note:</b> As this is
* based on a draft this implementation is subject to change.
*
* <pre>
* block word digest
* SHA-1 512 32 160
* SHA-256 512 32 256
* SHA-384 1024 64 384
* SHA-512 1024 64 512
* </pre>
*/
/// <summary>Implementation of SHA-256 as defined in FIPS 180-2.</summary>
/// <remarks>
/// <pre>
/// block word digest
/// SHA-1 512 32 160
/// SHA-256 512 32 256
/// SHA-384 1024 64 384
/// SHA-512 1024 64 512
/// </pre>
/// </remarks>
public class Sha256Digest
: GeneralDigest
{
Expand All @@ -26,15 +24,14 @@ public class Sha256Digest
private uint[] X = new uint[64];
private int xOff;

/// <summary>Initializes a new instance of <see cref="Sha256Digest"/>.</summary>
public Sha256Digest()
{
initHs();
}

/**
* Copy constructor. This will copy the state of the provided
* message digest.
*/
/// <summary>Initializes a new instance of <see cref="Sha256Digest"/> from an existing one.</summary>
/// <param name="t">The digest to copy from.</param>
public Sha256Digest(Sha256Digest t) : base(t)
{
CopyIn(t);
Expand Down
29 changes: 13 additions & 16 deletions crypto/src/crypto/digests/Sha512Digest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,28 @@

namespace Org.BouncyCastle.Crypto.Digests
{
/**
* Draft FIPS 180-2 implementation of SHA-512. <b>Note:</b> As this is
* based on a draft this implementation is subject to change.
*
* <pre>
* block word digest
* SHA-1 512 32 160
* SHA-256 512 32 256
* SHA-384 1024 64 384
* SHA-512 1024 64 512
* </pre>
*/
/// <summary>Implementation of SHA-512 as defined in FIPS 180-2.</summary>
/// <remarks>
/// <pre>
/// block word digest
/// SHA-1 512 32 160
/// SHA-256 512 32 256
/// SHA-384 1024 64 384
/// SHA-512 1024 64 512
/// </pre>
/// </remarks>
public class Sha512Digest
: LongDigest
{
private const int DigestLength = 64;

/// <summary>Initializes a new instance of <see cref="Sha512Digest"/>.</summary>
public Sha512Digest()
{
}

/**
* Copy constructor. This will copy the state of the provided
* message digest.
*/
/// <summary>Initializes a new instance of <see cref="Sha512Digest"/> from an existing one.</summary>
/// <param name="t">The digest to copy from.</param>
public Sha512Digest(
Sha512Digest t)
: base(t)
Expand Down
5 changes: 5 additions & 0 deletions crypto/src/crypto/parameters/DHPrivateKeyParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@

namespace Org.BouncyCastle.Crypto.Parameters
{
/// <summary>Diffie-Hellman private key parameters.</summary>
public class DHPrivateKeyParameters
: DHKeyParameters
{
private readonly BigInteger x;

/// <summary>Initializes a new instance of <see cref="DHPrivateKeyParameters"/>.</summary>
/// <param name="x">The private value X.</param>
/// <param name="parameters">The DH domain parameters.</param>
public DHPrivateKeyParameters(
BigInteger x,
DHParameters parameters)
Expand All @@ -27,6 +31,7 @@ public DHPrivateKeyParameters(
this.x = x;
}

/// <summary>Gets the private value X.</summary>
public BigInteger X
{
get { return x; }
Expand Down
5 changes: 5 additions & 0 deletions crypto/src/crypto/parameters/DHPublicKeyParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Org.BouncyCastle.Crypto.Parameters
{
/// <summary>Diffie-Hellman public key parameters.</summary>
public class DHPublicKeyParameters
: DHKeyParameters
{
Expand Down Expand Up @@ -46,6 +47,9 @@ private static BigInteger Validate(BigInteger y, DHParameters dhParams)

private readonly BigInteger m_y;

/// <summary>Initializes a new instance of <see cref="DHPublicKeyParameters"/>.</summary>
/// <param name="y">The public point Y.</param>
/// <param name="parameters">The DH domain parameters.</param>
public DHPublicKeyParameters(BigInteger y, DHParameters parameters)
: base(false, parameters)
{
Expand All @@ -58,6 +62,7 @@ public DHPublicKeyParameters(BigInteger y, DHParameters parameters, DerObjectIde
m_y = Validate(y, parameters);
}

/// <summary>Gets the public point Y.</summary>
public virtual BigInteger Y => m_y;

public override bool Equals(object obj)
Expand Down
10 changes: 6 additions & 4 deletions crypto/src/crypto/parameters/DsaKeyParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

namespace Org.BouncyCastle.Crypto.Parameters
{
/// <summary>Base class for Digital Signature Algorithm (DSA) key parameters.</summary>
public abstract class DsaKeyParameters
: AsymmetricKeyParameter
{
private readonly DsaParameters parameters;

/// <summary>Initializes a new instance of <see cref="DsaKeyParameters"/>.</summary>
/// <param name="isPrivate">Whether the key is private or not.</param>
/// <param name="parameters">The DSA domain parameters.</param>
protected DsaKeyParameters(
bool isPrivate,
DsaParameters parameters)
Expand All @@ -18,10 +22,8 @@ protected DsaKeyParameters(
this.parameters = parameters;
}

public DsaParameters Parameters
{
get { return parameters; }
}
/// <summary>Gets the DSA domain parameters.</summary>
public DsaParameters Parameters => parameters;

public override bool Equals(
object obj)
Expand Down
10 changes: 6 additions & 4 deletions crypto/src/crypto/parameters/DsaPrivateKeyParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

namespace Org.BouncyCastle.Crypto.Parameters
{
/// <summary>Digital Signature Algorithm (DSA) private key parameters.</summary>
public class DsaPrivateKeyParameters
: DsaKeyParameters
{
private readonly BigInteger x;

/// <summary>Initializes a new instance of <see cref="DsaPrivateKeyParameters"/>.</summary>
/// <param name="x">The private value X.</param>
/// <param name="parameters">The DSA domain parameters.</param>
public DsaPrivateKeyParameters(
BigInteger x,
DsaParameters parameters)
Expand All @@ -20,10 +24,8 @@ public DsaPrivateKeyParameters(
this.x = x;
}

public BigInteger X
{
get { return x; }
}
/// <summary>Gets the private value X.</summary>
public BigInteger X => x;

public override bool Equals(
object obj)
Expand Down
10 changes: 6 additions & 4 deletions crypto/src/crypto/parameters/DsaPublicKeyParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Org.BouncyCastle.Crypto.Parameters
{
/// <summary>Digital Signature Algorithm (DSA) public key parameters.</summary>
public class DsaPublicKeyParameters
: DsaKeyParameters
{
Expand All @@ -25,6 +26,9 @@ private static BigInteger Validate(BigInteger y, DsaParameters parameters)

private readonly BigInteger y;

/// <summary>Initializes a new instance of <see cref="DsaPublicKeyParameters"/>.</summary>
/// <param name="y">The public value Y.</param>
/// <param name="parameters">The DSA domain parameters.</param>
public DsaPublicKeyParameters(
BigInteger y,
DsaParameters parameters)
Expand All @@ -36,10 +40,8 @@ public DsaPublicKeyParameters(
this.y = Validate(y, parameters);
}

public BigInteger Y
{
get { return y; }
}
/// <summary>Gets the public value Y.</summary>
public BigInteger Y => y;

public override bool Equals(object obj)
{
Expand Down
7 changes: 7 additions & 0 deletions crypto/src/crypto/parameters/ECKeyParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Org.BouncyCastle.Crypto.Parameters
{
/// <summary>Base class for elliptic curve key parameters.</summary>
public abstract class ECKeyParameters
: AsymmetricKeyParameter
{
Expand All @@ -26,6 +27,10 @@ public abstract class ECKeyParameters
private readonly string m_algorithm;
private readonly ECDomainParameters m_parameters;

/// <summary>Initializes a new instance of <see cref="ECKeyParameters"/>.</summary>
/// <param name="algorithm">The algorithm name.</param>
/// <param name="isPrivate">Whether the key is private or not.</param>
/// <param name="parameters">The EC domain parameters.</param>
protected ECKeyParameters(string algorithm, bool isPrivate, ECDomainParameters parameters)
: base(isPrivate)
{
Expand All @@ -50,8 +55,10 @@ protected ECKeyParameters(string algorithm, bool isPrivate, DerObjectIdentifier
m_parameters = ECNamedDomainParameters.LookupOid(oid: publicKeyParamSet);
}

/// <summary>Gets the algorithm name.</summary>
public string AlgorithmName => m_algorithm;

/// <summary>Gets the EC domain parameters.</summary>
public ECDomainParameters Parameters => m_parameters;

public DerObjectIdentifier PublicKeyParamSet => (m_parameters as ECNamedDomainParameters)?.Name;
Expand Down
9 changes: 9 additions & 0 deletions crypto/src/crypto/parameters/ECPrivateKeyParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@

namespace Org.BouncyCastle.Crypto.Parameters
{
/// <summary>Elliptic curve private key parameters.</summary>
public class ECPrivateKeyParameters
: ECKeyParameters
{
private readonly BigInteger m_d;

/// <summary>Initializes a new instance of <see cref="ECPrivateKeyParameters"/>.</summary>
/// <param name="d">The private scalar D.</param>
/// <param name="parameters">The EC domain parameters.</param>
public ECPrivateKeyParameters(BigInteger d, ECDomainParameters parameters)
: this("EC", d, parameters)
{
}

/// <summary>Initializes a new instance of <see cref="ECPrivateKeyParameters"/>.</summary>
/// <param name="algorithm">The algorithm name.</param>
/// <param name="d">The private scalar D.</param>
/// <param name="parameters">The EC domain parameters.</param>
public ECPrivateKeyParameters(string algorithm, BigInteger d, ECDomainParameters parameters)
: base(algorithm, true, parameters)
{
Expand All @@ -25,6 +33,7 @@ public ECPrivateKeyParameters(string algorithm, BigInteger d, DerObjectIdentifie
m_d = Parameters.ValidatePrivateScalar(d);
}

/// <summary>Gets the private scalar D.</summary>
public BigInteger D => m_d;

public override bool Equals(object obj) => obj is ECPrivateKeyParameters other && Equals(other);
Expand Down
9 changes: 9 additions & 0 deletions crypto/src/crypto/parameters/ECPublicKeyParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@

namespace Org.BouncyCastle.Crypto.Parameters
{
/// <summary>Elliptic curve public key parameters.</summary>
public class ECPublicKeyParameters
: ECKeyParameters
{
private readonly ECPoint m_q;

/// <summary>Initializes a new instance of <see cref="ECPublicKeyParameters"/>.</summary>
/// <param name="q">The public point Q.</param>
/// <param name="parameters">The EC domain parameters.</param>
public ECPublicKeyParameters(ECPoint q, ECDomainParameters parameters)
: this("EC", q, parameters)
{
}

/// <summary>Initializes a new instance of <see cref="ECPublicKeyParameters"/>.</summary>
/// <param name="algorithm">The algorithm name.</param>
/// <param name="q">The public point Q.</param>
/// <param name="parameters">The EC domain parameters.</param>
public ECPublicKeyParameters(string algorithm, ECPoint q, ECDomainParameters parameters)
: base(algorithm, false, parameters)
{
Expand All @@ -28,6 +36,7 @@ public ECPublicKeyParameters(string algorithm, ECPoint q, DerObjectIdentifier pu
m_q = ECDomainParameters.ValidatePublicPoint(Parameters.Curve, q);
}

/// <summary>Gets the public point Q.</summary>
public ECPoint Q => m_q;

public override bool Equals(object obj) => obj is ECPublicKeyParameters other && Equals(other);
Expand Down
10 changes: 6 additions & 4 deletions crypto/src/crypto/parameters/ElGamalKeyParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

namespace Org.BouncyCastle.Crypto.Parameters
{
/// <summary>Base class for ElGamal key parameters.</summary>
public class ElGamalKeyParameters
: AsymmetricKeyParameter
{
private readonly ElGamalParameters parameters;

/// <summary>Initializes a new instance of <see cref="ElGamalKeyParameters"/>.</summary>
/// <param name="isPrivate">Whether the key is private or not.</param>
/// <param name="parameters">The ElGamal domain parameters.</param>
protected ElGamalKeyParameters(
bool isPrivate,
ElGamalParameters parameters)
Expand All @@ -18,10 +22,8 @@ protected ElGamalKeyParameters(
this.parameters = parameters;
}

public ElGamalParameters Parameters
{
get { return parameters; }
}
/// <summary>Gets the ElGamal domain parameters.</summary>
public ElGamalParameters Parameters => parameters;

public override bool Equals(
object obj)
Expand Down
10 changes: 6 additions & 4 deletions crypto/src/crypto/parameters/ElGamalPrivateKeyParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@

namespace Org.BouncyCastle.Crypto.Parameters
{
/// <summary>ElGamal private key parameters.</summary>
public class ElGamalPrivateKeyParameters
: ElGamalKeyParameters
{
private readonly BigInteger x;

/// <summary>Initializes a new instance of <see cref="ElGamalPrivateKeyParameters"/>.</summary>
/// <param name="x">The private value X.</param>
/// <param name="parameters">The ElGamal domain parameters.</param>
public ElGamalPrivateKeyParameters(
BigInteger x,
ElGamalParameters parameters)
Expand All @@ -20,10 +24,8 @@ public ElGamalPrivateKeyParameters(
this.x = x;
}

public BigInteger X
{
get { return x; }
}
/// <summary>Gets the private value X.</summary>
public BigInteger X => x;

public override bool Equals(
object obj)
Expand Down
Loading