From 9fb19d9df94721662cd2138b91ab7cf0f0e39352 Mon Sep 17 00:00:00 2001 From: Konradsop Date: Fri, 27 Mar 2026 13:24:06 +0100 Subject: [PATCH] docs: add XML documentation for core parameter classes and digests Added XML documentation for RSA, EC, DH, DSA, and ElGamal parameter classes. Converted Sha256Digest and Sha512Digest JavaDoc to C# XML tags. Updated KeyParameter documentation for better IntelliSense. --- .gitignore | 3 ++ crypto/src/crypto/digests/Sha256Digest.cs | 29 +++++++++---------- crypto/src/crypto/digests/Sha512Digest.cs | 29 +++++++++---------- .../parameters/DHPrivateKeyParameters.cs | 5 ++++ .../parameters/DHPublicKeyParameters.cs | 5 ++++ .../src/crypto/parameters/DsaKeyParameters.cs | 10 ++++--- .../parameters/DsaPrivateKeyParameters.cs | 10 ++++--- .../parameters/DsaPublicKeyParameters.cs | 10 ++++--- .../src/crypto/parameters/ECKeyParameters.cs | 7 +++++ .../parameters/ECPrivateKeyParameters.cs | 9 ++++++ .../parameters/ECPublicKeyParameters.cs | 9 ++++++ .../crypto/parameters/ElGamalKeyParameters.cs | 10 ++++--- .../parameters/ElGamalPrivateKeyParameters.cs | 10 ++++--- .../parameters/ElGamalPublicKeyParameters.cs | 10 ++++--- crypto/src/crypto/parameters/KeyParameter.cs | 10 +++++++ .../src/crypto/parameters/RsaKeyParameters.cs | 7 +++++ .../parameters/RsaPrivateCrtKeyParameters.cs | 16 ++++++++++ 17 files changed, 133 insertions(+), 56 deletions(-) diff --git a/.gitignore b/.gitignore index 65339dcef1..5bfbe02e13 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,6 @@ BC_password.txt *.nuget.targets *.project.lock.json project.lock.json +.contributions/ +*.log +build_*.txt diff --git a/crypto/src/crypto/digests/Sha256Digest.cs b/crypto/src/crypto/digests/Sha256Digest.cs index 51859697e5..b1e7dac86b 100644 --- a/crypto/src/crypto/digests/Sha256Digest.cs +++ b/crypto/src/crypto/digests/Sha256Digest.cs @@ -5,18 +5,16 @@ namespace Org.BouncyCastle.Crypto.Digests { - /** - * Draft FIPS 180-2 implementation of SHA-256. Note: As this is - * based on a draft this implementation is subject to change. - * - *
-    *         block  word  digest
-    * SHA-1   512    32    160
-    * SHA-256 512    32    256
-    * SHA-384 1024   64    384
-    * SHA-512 1024   64    512
-    * 
- */ + /// Implementation of SHA-256 as defined in FIPS 180-2. + /// + ///
+    ///         block  word  digest
+    /// SHA-1   512    32    160
+    /// SHA-256 512    32    256
+    /// SHA-384 1024   64    384
+    /// SHA-512 1024   64    512
+    /// 
+ ///
public class Sha256Digest : GeneralDigest { @@ -26,15 +24,14 @@ public class Sha256Digest private uint[] X = new uint[64]; private int xOff; + /// Initializes a new instance of . public Sha256Digest() { initHs(); } - /** - * Copy constructor. This will copy the state of the provided - * message digest. - */ + /// Initializes a new instance of from an existing one. + /// The digest to copy from. public Sha256Digest(Sha256Digest t) : base(t) { CopyIn(t); diff --git a/crypto/src/crypto/digests/Sha512Digest.cs b/crypto/src/crypto/digests/Sha512Digest.cs index 9156c24bf9..3b70fdc98e 100644 --- a/crypto/src/crypto/digests/Sha512Digest.cs +++ b/crypto/src/crypto/digests/Sha512Digest.cs @@ -5,31 +5,28 @@ namespace Org.BouncyCastle.Crypto.Digests { - /** - * Draft FIPS 180-2 implementation of SHA-512. Note: As this is - * based on a draft this implementation is subject to change. - * - *
-     *         block  word  digest
-     * SHA-1   512    32    160
-     * SHA-256 512    32    256
-     * SHA-384 1024   64    384
-     * SHA-512 1024   64    512
-     * 
- */ + /// Implementation of SHA-512 as defined in FIPS 180-2. + /// + ///
+    ///         block  word  digest
+    /// SHA-1   512    32    160
+    /// SHA-256 512    32    256
+    /// SHA-384 1024   64    384
+    /// SHA-512 1024   64    512
+    /// 
+ ///
public class Sha512Digest : LongDigest { private const int DigestLength = 64; + /// Initializes a new instance of . public Sha512Digest() { } - /** - * Copy constructor. This will copy the state of the provided - * message digest. - */ + /// Initializes a new instance of from an existing one. + /// The digest to copy from. public Sha512Digest( Sha512Digest t) : base(t) diff --git a/crypto/src/crypto/parameters/DHPrivateKeyParameters.cs b/crypto/src/crypto/parameters/DHPrivateKeyParameters.cs index fc724df810..2c99ea1b77 100644 --- a/crypto/src/crypto/parameters/DHPrivateKeyParameters.cs +++ b/crypto/src/crypto/parameters/DHPrivateKeyParameters.cs @@ -5,11 +5,15 @@ namespace Org.BouncyCastle.Crypto.Parameters { + /// Diffie-Hellman private key parameters. public class DHPrivateKeyParameters : DHKeyParameters { private readonly BigInteger x; + /// Initializes a new instance of . + /// The private value X. + /// The DH domain parameters. public DHPrivateKeyParameters( BigInteger x, DHParameters parameters) @@ -27,6 +31,7 @@ public DHPrivateKeyParameters( this.x = x; } + /// Gets the private value X. public BigInteger X { get { return x; } diff --git a/crypto/src/crypto/parameters/DHPublicKeyParameters.cs b/crypto/src/crypto/parameters/DHPublicKeyParameters.cs index be4a93eb68..c0833cf0a1 100644 --- a/crypto/src/crypto/parameters/DHPublicKeyParameters.cs +++ b/crypto/src/crypto/parameters/DHPublicKeyParameters.cs @@ -7,6 +7,7 @@ namespace Org.BouncyCastle.Crypto.Parameters { + /// Diffie-Hellman public key parameters. public class DHPublicKeyParameters : DHKeyParameters { @@ -46,6 +47,9 @@ private static BigInteger Validate(BigInteger y, DHParameters dhParams) private readonly BigInteger m_y; + /// Initializes a new instance of . + /// The public point Y. + /// The DH domain parameters. public DHPublicKeyParameters(BigInteger y, DHParameters parameters) : base(false, parameters) { @@ -58,6 +62,7 @@ public DHPublicKeyParameters(BigInteger y, DHParameters parameters, DerObjectIde m_y = Validate(y, parameters); } + /// Gets the public point Y. public virtual BigInteger Y => m_y; public override bool Equals(object obj) diff --git a/crypto/src/crypto/parameters/DsaKeyParameters.cs b/crypto/src/crypto/parameters/DsaKeyParameters.cs index 4097144a5d..04042f24b7 100644 --- a/crypto/src/crypto/parameters/DsaKeyParameters.cs +++ b/crypto/src/crypto/parameters/DsaKeyParameters.cs @@ -4,11 +4,15 @@ namespace Org.BouncyCastle.Crypto.Parameters { + /// Base class for Digital Signature Algorithm (DSA) key parameters. public abstract class DsaKeyParameters : AsymmetricKeyParameter { private readonly DsaParameters parameters; + /// Initializes a new instance of . + /// Whether the key is private or not. + /// The DSA domain parameters. protected DsaKeyParameters( bool isPrivate, DsaParameters parameters) @@ -18,10 +22,8 @@ protected DsaKeyParameters( this.parameters = parameters; } - public DsaParameters Parameters - { - get { return parameters; } - } + /// Gets the DSA domain parameters. + public DsaParameters Parameters => parameters; public override bool Equals( object obj) diff --git a/crypto/src/crypto/parameters/DsaPrivateKeyParameters.cs b/crypto/src/crypto/parameters/DsaPrivateKeyParameters.cs index 2abdd0e4f5..39e7860ed8 100644 --- a/crypto/src/crypto/parameters/DsaPrivateKeyParameters.cs +++ b/crypto/src/crypto/parameters/DsaPrivateKeyParameters.cs @@ -4,11 +4,15 @@ namespace Org.BouncyCastle.Crypto.Parameters { + /// Digital Signature Algorithm (DSA) private key parameters. public class DsaPrivateKeyParameters : DsaKeyParameters { private readonly BigInteger x; + /// Initializes a new instance of . + /// The private value X. + /// The DSA domain parameters. public DsaPrivateKeyParameters( BigInteger x, DsaParameters parameters) @@ -20,10 +24,8 @@ public DsaPrivateKeyParameters( this.x = x; } - public BigInteger X - { - get { return x; } - } + /// Gets the private value X. + public BigInteger X => x; public override bool Equals( object obj) diff --git a/crypto/src/crypto/parameters/DsaPublicKeyParameters.cs b/crypto/src/crypto/parameters/DsaPublicKeyParameters.cs index 3a81bfdd08..356e92b9c9 100644 --- a/crypto/src/crypto/parameters/DsaPublicKeyParameters.cs +++ b/crypto/src/crypto/parameters/DsaPublicKeyParameters.cs @@ -4,6 +4,7 @@ namespace Org.BouncyCastle.Crypto.Parameters { + /// Digital Signature Algorithm (DSA) public key parameters. public class DsaPublicKeyParameters : DsaKeyParameters { @@ -25,6 +26,9 @@ private static BigInteger Validate(BigInteger y, DsaParameters parameters) private readonly BigInteger y; + /// Initializes a new instance of . + /// The public value Y. + /// The DSA domain parameters. public DsaPublicKeyParameters( BigInteger y, DsaParameters parameters) @@ -36,10 +40,8 @@ public DsaPublicKeyParameters( this.y = Validate(y, parameters); } - public BigInteger Y - { - get { return y; } - } + /// Gets the public value Y. + public BigInteger Y => y; public override bool Equals(object obj) { diff --git a/crypto/src/crypto/parameters/ECKeyParameters.cs b/crypto/src/crypto/parameters/ECKeyParameters.cs index f18c8fd763..d3bb156d55 100644 --- a/crypto/src/crypto/parameters/ECKeyParameters.cs +++ b/crypto/src/crypto/parameters/ECKeyParameters.cs @@ -8,6 +8,7 @@ namespace Org.BouncyCastle.Crypto.Parameters { + /// Base class for elliptic curve key parameters. public abstract class ECKeyParameters : AsymmetricKeyParameter { @@ -26,6 +27,10 @@ public abstract class ECKeyParameters private readonly string m_algorithm; private readonly ECDomainParameters m_parameters; + /// Initializes a new instance of . + /// The algorithm name. + /// Whether the key is private or not. + /// The EC domain parameters. protected ECKeyParameters(string algorithm, bool isPrivate, ECDomainParameters parameters) : base(isPrivate) { @@ -50,8 +55,10 @@ protected ECKeyParameters(string algorithm, bool isPrivate, DerObjectIdentifier m_parameters = ECNamedDomainParameters.LookupOid(oid: publicKeyParamSet); } + /// Gets the algorithm name. public string AlgorithmName => m_algorithm; + /// Gets the EC domain parameters. public ECDomainParameters Parameters => m_parameters; public DerObjectIdentifier PublicKeyParamSet => (m_parameters as ECNamedDomainParameters)?.Name; diff --git a/crypto/src/crypto/parameters/ECPrivateKeyParameters.cs b/crypto/src/crypto/parameters/ECPrivateKeyParameters.cs index b14ee27e4e..8b5d21ff09 100644 --- a/crypto/src/crypto/parameters/ECPrivateKeyParameters.cs +++ b/crypto/src/crypto/parameters/ECPrivateKeyParameters.cs @@ -3,16 +3,24 @@ namespace Org.BouncyCastle.Crypto.Parameters { + /// Elliptic curve private key parameters. public class ECPrivateKeyParameters : ECKeyParameters { private readonly BigInteger m_d; + /// Initializes a new instance of . + /// The private scalar D. + /// The EC domain parameters. public ECPrivateKeyParameters(BigInteger d, ECDomainParameters parameters) : this("EC", d, parameters) { } + /// Initializes a new instance of . + /// The algorithm name. + /// The private scalar D. + /// The EC domain parameters. public ECPrivateKeyParameters(string algorithm, BigInteger d, ECDomainParameters parameters) : base(algorithm, true, parameters) { @@ -25,6 +33,7 @@ public ECPrivateKeyParameters(string algorithm, BigInteger d, DerObjectIdentifie m_d = Parameters.ValidatePrivateScalar(d); } + /// Gets the private scalar D. public BigInteger D => m_d; public override bool Equals(object obj) => obj is ECPrivateKeyParameters other && Equals(other); diff --git a/crypto/src/crypto/parameters/ECPublicKeyParameters.cs b/crypto/src/crypto/parameters/ECPublicKeyParameters.cs index f2fe1cc68c..c8b1449643 100644 --- a/crypto/src/crypto/parameters/ECPublicKeyParameters.cs +++ b/crypto/src/crypto/parameters/ECPublicKeyParameters.cs @@ -6,16 +6,24 @@ namespace Org.BouncyCastle.Crypto.Parameters { + /// Elliptic curve public key parameters. public class ECPublicKeyParameters : ECKeyParameters { private readonly ECPoint m_q; + /// Initializes a new instance of . + /// The public point Q. + /// The EC domain parameters. public ECPublicKeyParameters(ECPoint q, ECDomainParameters parameters) : this("EC", q, parameters) { } + /// Initializes a new instance of . + /// The algorithm name. + /// The public point Q. + /// The EC domain parameters. public ECPublicKeyParameters(string algorithm, ECPoint q, ECDomainParameters parameters) : base(algorithm, false, parameters) { @@ -28,6 +36,7 @@ public ECPublicKeyParameters(string algorithm, ECPoint q, DerObjectIdentifier pu m_q = ECDomainParameters.ValidatePublicPoint(Parameters.Curve, q); } + /// Gets the public point Q. public ECPoint Q => m_q; public override bool Equals(object obj) => obj is ECPublicKeyParameters other && Equals(other); diff --git a/crypto/src/crypto/parameters/ElGamalKeyParameters.cs b/crypto/src/crypto/parameters/ElGamalKeyParameters.cs index 146049acac..83a140cf3a 100644 --- a/crypto/src/crypto/parameters/ElGamalKeyParameters.cs +++ b/crypto/src/crypto/parameters/ElGamalKeyParameters.cs @@ -4,11 +4,15 @@ namespace Org.BouncyCastle.Crypto.Parameters { + /// Base class for ElGamal key parameters. public class ElGamalKeyParameters : AsymmetricKeyParameter { private readonly ElGamalParameters parameters; + /// Initializes a new instance of . + /// Whether the key is private or not. + /// The ElGamal domain parameters. protected ElGamalKeyParameters( bool isPrivate, ElGamalParameters parameters) @@ -18,10 +22,8 @@ protected ElGamalKeyParameters( this.parameters = parameters; } - public ElGamalParameters Parameters - { - get { return parameters; } - } + /// Gets the ElGamal domain parameters. + public ElGamalParameters Parameters => parameters; public override bool Equals( object obj) diff --git a/crypto/src/crypto/parameters/ElGamalPrivateKeyParameters.cs b/crypto/src/crypto/parameters/ElGamalPrivateKeyParameters.cs index 6363f2bbb3..42450aa206 100644 --- a/crypto/src/crypto/parameters/ElGamalPrivateKeyParameters.cs +++ b/crypto/src/crypto/parameters/ElGamalPrivateKeyParameters.cs @@ -4,11 +4,15 @@ namespace Org.BouncyCastle.Crypto.Parameters { + /// ElGamal private key parameters. public class ElGamalPrivateKeyParameters : ElGamalKeyParameters { private readonly BigInteger x; + /// Initializes a new instance of . + /// The private value X. + /// The ElGamal domain parameters. public ElGamalPrivateKeyParameters( BigInteger x, ElGamalParameters parameters) @@ -20,10 +24,8 @@ public ElGamalPrivateKeyParameters( this.x = x; } - public BigInteger X - { - get { return x; } - } + /// Gets the private value X. + public BigInteger X => x; public override bool Equals( object obj) diff --git a/crypto/src/crypto/parameters/ElGamalPublicKeyParameters.cs b/crypto/src/crypto/parameters/ElGamalPublicKeyParameters.cs index 25ac625d5f..d1608aa4fa 100644 --- a/crypto/src/crypto/parameters/ElGamalPublicKeyParameters.cs +++ b/crypto/src/crypto/parameters/ElGamalPublicKeyParameters.cs @@ -4,11 +4,15 @@ namespace Org.BouncyCastle.Crypto.Parameters { + /// ElGamal public key parameters. public class ElGamalPublicKeyParameters : ElGamalKeyParameters { private readonly BigInteger y; + /// Initializes a new instance of . + /// The public value Y. + /// The ElGamal domain parameters. public ElGamalPublicKeyParameters( BigInteger y, ElGamalParameters parameters) @@ -20,10 +24,8 @@ public ElGamalPublicKeyParameters( this.y = y; } - public BigInteger Y - { - get { return y; } - } + /// Gets the public value Y. + public BigInteger Y => y; public override bool Equals( object obj) diff --git a/crypto/src/crypto/parameters/KeyParameter.cs b/crypto/src/crypto/parameters/KeyParameter.cs index 87612a67ea..0199b3ffd2 100644 --- a/crypto/src/crypto/parameters/KeyParameter.cs +++ b/crypto/src/crypto/parameters/KeyParameter.cs @@ -7,6 +7,7 @@ namespace Org.BouncyCastle.Crypto.Parameters { + /// Base class for symmetric key parameters. public class KeyParameter : ICipherParameters { @@ -26,11 +27,17 @@ public static KeyParameter Create(int length, TState state, SpanActionInitializes a new instance of . + /// The byte array containing the key material. public KeyParameter(byte[] key) { m_key = Arrays.CopyBuffer(key); } + /// Initializes a new instance of . + /// The byte array containing the key material. + /// The offset into the byte array where the key starts. + /// The length of the key material. public KeyParameter(byte[] key, int keyOff, int keyLen) { m_key = Arrays.CopySegment(key, keyOff, keyLen); @@ -62,8 +69,11 @@ public void CopyTo(byte[] buf, int off, int len) Array.Copy(m_key, 0, buf, off, len); } + /// Gets the key material. + /// A copy of the key material as a byte array. public byte[] GetKey() => Arrays.InternalCopyBuffer(m_key); + /// Gets the length of the key material in bytes. public int KeyLength => m_key.Length; internal bool FixedTimeEquals(byte[] data) => Arrays.FixedTimeEquals(m_key, data); diff --git a/crypto/src/crypto/parameters/RsaKeyParameters.cs b/crypto/src/crypto/parameters/RsaKeyParameters.cs index f982a14ac6..85f1651c37 100644 --- a/crypto/src/crypto/parameters/RsaKeyParameters.cs +++ b/crypto/src/crypto/parameters/RsaKeyParameters.cs @@ -6,6 +6,7 @@ namespace Org.BouncyCastle.Crypto.Parameters { + /// Base class for RSA key parameters. public class RsaKeyParameters : AsymmetricKeyParameter { @@ -49,6 +50,10 @@ private static BigInteger Validate(BigInteger modulus) private readonly BigInteger modulus; private readonly BigInteger exponent; + /// Initializes a new instance of . + /// Whether the key is private or not. + /// The RSA modulus. + /// The RSA exponent (public exponent for public keys, private exponent for private keys). public RsaKeyParameters( bool isPrivate, BigInteger modulus, @@ -70,11 +75,13 @@ public RsaKeyParameters( this.exponent = exponent; } + /// Gets the RSA modulus. public BigInteger Modulus { get { return modulus; } } + /// Gets the RSA exponent. public BigInteger Exponent { get { return exponent; } diff --git a/crypto/src/crypto/parameters/RsaPrivateCrtKeyParameters.cs b/crypto/src/crypto/parameters/RsaPrivateCrtKeyParameters.cs index 557ee94e2f..bbc539f79c 100644 --- a/crypto/src/crypto/parameters/RsaPrivateCrtKeyParameters.cs +++ b/crypto/src/crypto/parameters/RsaPrivateCrtKeyParameters.cs @@ -6,11 +6,21 @@ namespace Org.BouncyCastle.Crypto.Parameters { + /// RSA key parameters for use with the Chinese Remainder Theorem. public class RsaPrivateCrtKeyParameters : RsaKeyParameters { private readonly BigInteger e, p, q, dP, dQ, qInv; + /// Initializes a new instance of . + /// The RSA modulus. + /// The public exponent. + /// The private exponent. + /// The first prime factor (p) of the modulus. + /// The second prime factor (q) of the modulus. + /// The CRT exponent for prime p. + /// The CRT exponent for prime q. + /// The CRT coefficient (inverse of q mod p). public RsaPrivateCrtKeyParameters( BigInteger modulus, BigInteger publicExponent, @@ -50,31 +60,37 @@ public RsaPrivateCrtKeyParameters(RsaPrivateKeyStructure rsaPrivateKey) { } + /// Gets the public exponent. public BigInteger PublicExponent { get { return e; } } + /// Gets the first prime factor (p) of the modulus. public BigInteger P { get { return p; } } + /// Gets the second prime factor (q) of the modulus. public BigInteger Q { get { return q; } } + /// Gets the CRT exponent for prime p. public BigInteger DP { get { return dP; } } + /// Gets the CRT exponent for prime q. public BigInteger DQ { get { return dQ; } } + /// Gets the CRT coefficient (inverse of q mod p). public BigInteger QInv { get { return qInv; }