Skip to content

Commit e80df80

Browse files
committed
docs: add XML documentation for AES, AEAD modes and Dilithium
This commit adds XML documentation to the core symmetric suite and the Dilithium signer. Critical security warnings regarding Nonce reuse were added to GCM and ChaCha20Poly1305.
1 parent 5200dfd commit e80df80

File tree

8 files changed

+276
-125
lines changed

8 files changed

+276
-125
lines changed

crypto/src/crypto/IBlockCipher.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace Org.BouncyCastle.Crypto
44
{
5-
/// <remarks>Base interface for a symmetric key block cipher.</remarks>
5+
/// <summary>
6+
/// Base interface for a symmetric key block cipher.
7+
/// </summary>
68
public interface IBlockCipher
79
{
810
/// <summary>The name of the algorithm this cipher implements.</summary>
@@ -13,6 +15,9 @@ public interface IBlockCipher
1315
/// <param name="parameters">The key or other data required by the cipher.</param>
1416
void Init(bool forEncryption, ICipherParameters parameters);
1517

18+
/// <summary>
19+
/// Return the block size for this cipher (in bytes).
20+
/// </summary>
1621
/// <returns>The block size for this cipher, in bytes.</returns>
1722
int GetBlockSize();
1823

crypto/src/crypto/engines/AesEngine.cs

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,25 @@
66

77
namespace Org.BouncyCastle.Crypto.Engines
88
{
9-
/**
10-
* an implementation of the AES (Rijndael), from FIPS-197.
11-
* <p>
12-
* For further details see: <a href="http://csrc.nist.gov/encryption/aes/">http://csrc.nist.gov/encryption/aes/</a>.
13-
*
14-
* This implementation is based on optimizations from Dr. Brian Gladman's paper and C code at
15-
* <a href="http://fp.gladman.plus.com/cryptography_technology/rijndael/">http://fp.gladman.plus.com/cryptography_technology/rijndael/</a>
16-
*
17-
* There are three levels of tradeoff of speed vs memory
18-
* Because java has no preprocessor, they are written as three separate classes from which to choose
19-
*
20-
* The fastest uses 8Kbytes of static tables to precompute round calculations, 4 256 word tables for encryption
21-
* and 4 for decryption.
22-
*
23-
* The middle performance version uses only one 256 word table for each, for a total of 2Kbytes,
24-
* adding 12 rotate operations per round to compute the values contained in the other tables from
25-
* the contents of the first.
26-
*
27-
* The slowest version uses no static tables at all and computes the values in each round.
28-
* </p>
29-
* <p>
30-
* This file contains the middle performance version with 2Kbytes of static tables for round precomputation.
31-
* </p>
32-
*/
9+
/// <summary>An implementation of the AES (Rijndael), from FIPS-197.</summary>
10+
/// <remarks>
11+
/// For further details see: <a href="http://csrc.nist.gov/encryption/aes/">http://csrc.nist.gov/encryption/aes/</a>.
12+
/// <para>
13+
/// This implementation is based on optimizations from Dr. Brian Gladman's paper and C code at
14+
/// <a href="http://fp.gladman.plus.com/cryptography_technology/rijndael/">http://fp.gladman.plus.com/cryptography_technology/rijndael/</a>
15+
/// </para>
16+
/// <para>
17+
/// There are three levels of tradeoff of speed vs memory:
18+
/// </para>
19+
/// <list type="bullet">
20+
/// <item>The fastest uses 8Kbytes of static tables to precompute round calculations.</item>
21+
/// <item>The middle performance version uses only one 256 word table for each, for a total of 2Kbytes, adding 12 rotate operations per round.</item>
22+
/// <item>The slowest version uses no static tables at all and computes the values in each round.</item>
23+
/// </list>
24+
/// <para>
25+
/// This file contains the middle performance version with 2Kbytes of static tables for round precomputation.
26+
/// </para>
27+
/// </remarks>
3328
public sealed class AesEngine
3429
: IBlockCipher
3530
{
@@ -437,21 +432,15 @@ private uint[][] GenerateWorkingKey(KeyParameter keyParameter, bool forEncryptio
437432

438433
private const int BLOCK_SIZE = 16;
439434

440-
/**
441-
* default constructor - 128 bit block size.
442-
*/
435+
/// <summary>Default constructor - 128 bit block size.</summary>
443436
public AesEngine()
444437
{
445438
}
446439

447-
/**
448-
* initialise an AES cipher.
449-
*
450-
* @param forEncryption whether or not we are for encryption.
451-
* @param parameters the parameters required to set up the cipher.
452-
* @exception ArgumentException if the parameters argument is
453-
* inappropriate.
454-
*/
440+
/// <summary>Initialise an AES cipher.</summary>
441+
/// <param name="forEncryption">Whether or not we are using it for encryption.</param>
442+
/// <param name="parameters">The parameters required to set up the cipher.</param>
443+
/// <exception cref="ArgumentException">If the parameters argument is inappropriate.</exception>
455444
public void Init(bool forEncryption, ICipherParameters parameters)
456445
{
457446
if (!(parameters is KeyParameter keyParameter))
@@ -464,16 +453,27 @@ public void Init(bool forEncryption, ICipherParameters parameters)
464453
this.s = Arrays.Clone(forEncryption ? S : Si);
465454
}
466455

456+
/// <summary>The name of the algorithm this engine implements.</summary>
467457
public string AlgorithmName
468458
{
469459
get { return "AES"; }
470460
}
471461

462+
/// <summary>Return the block size for this cipher (in bytes).</summary>
463+
/// <returns>16 (fixed block size for AES).</returns>
472464
public int GetBlockSize()
473465
{
474466
return BLOCK_SIZE;
475467
}
476468

469+
/// <summary>Process a single block of data.</summary>
470+
/// <param name="input">The input buffer containing the data to be processed.</param>
471+
/// <param name="inOff">The offset into the input buffer.</param>
472+
/// <param name="output">The output buffer to store the result.</param>
473+
/// <param name="outOff">The offset into the output buffer.</param>
474+
/// <returns>The number of bytes processed and produced.</returns>
475+
/// <exception cref="DataLengthException">If the input buffer is too small, or the output buffer is too small.</exception>
476+
/// <exception cref="InvalidOperationException">If the cipher isn't initialised.</exception>
477477
public int ProcessBlock(byte[] input, int inOff, byte[] output, int outOff)
478478
{
479479
if (WorkingKey == null)

crypto/src/crypto/modes/CbcBlockCipher.cs

Lines changed: 16 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55

66
namespace Org.BouncyCastle.Crypto.Modes
77
{
8-
/**
9-
* implements Cipher-Block-Chaining (CBC) mode on top of a simple cipher.
10-
*/
8+
/// <summary>Implements Cipher-Block-Chaining (CBC) mode on top of a simple cipher.</summary>
119
public sealed class CbcBlockCipher
1210
: IBlockCipherMode
1311
{
@@ -16,11 +14,8 @@ public sealed class CbcBlockCipher
1614
private IBlockCipher cipher;
1715
private bool encrypting;
1816

19-
/**
20-
* Basic constructor.
21-
*
22-
* @param cipher the block cipher to be used as the basis of chaining.
23-
*/
17+
/// <summary>Basic constructor.</summary>
18+
/// <param name="cipher">The block cipher to be used as the basis of chaining.</param>
2419
public CbcBlockCipher(
2520
IBlockCipher cipher)
2621
{
@@ -32,23 +27,15 @@ public CbcBlockCipher(
3227
this.cbcNextV = new byte[blockSize];
3328
}
3429

35-
/**
36-
* return the underlying block cipher that we are wrapping.
37-
*
38-
* @return the underlying block cipher that we are wrapping.
39-
*/
30+
/// <summary>Return the underlying block cipher that we are wrapping.</summary>
31+
/// <returns>The underlying block cipher that we are wrapping.</returns>
4032
public IBlockCipher UnderlyingCipher => cipher;
4133

42-
/**
43-
* Initialise the cipher and, possibly, the initialisation vector (IV).
44-
* If an IV isn't passed as part of the parameter, the IV will be all zeros.
45-
*
46-
* @param forEncryption if true the cipher is initialised for
47-
* encryption, if false for decryption.
48-
* @param param the key and other data required by the cipher.
49-
* @exception ArgumentException if the parameters argument is
50-
* inappropriate.
51-
*/
34+
/// <summary>Initialise the cipher and, possibly, the initialisation vector (IV).</summary>
35+
/// <remarks>If an IV isn't passed as part of the parameter, the IV will be all zeros.</remarks>
36+
/// <param name="forEncryption">If true the cipher is initialised for encryption, if false for decryption.</param>
37+
/// <param name="parameters">The key and other data required by the cipher.</param>
38+
/// <exception cref="ArgumentException">If the parameters argument is inappropriate.</exception>
5239
public void Init(bool forEncryption, ICipherParameters parameters)
5340
{
5441
bool oldEncrypting = this.encrypting;
@@ -82,26 +69,21 @@ public void Init(bool forEncryption, ICipherParameters parameters)
8269
}
8370
}
8471

85-
/**
86-
* return the algorithm name and mode.
87-
*
88-
* @return the name of the underlying algorithm followed by "/CBC".
89-
*/
72+
/// <summary>Return the algorithm name and mode.</summary>
73+
/// <returns>The name of the underlying algorithm followed by "/CBC".</returns>
9074
public string AlgorithmName
9175
{
9276
get { return cipher.AlgorithmName + "/CBC"; }
9377
}
9478

79+
/// <summary>Indicates whether this cipher can handle partial blocks.</summary>
9580
public bool IsPartialBlockOkay
9681
{
9782
get { return false; }
9883
}
9984

100-
/**
101-
* return the block size of the underlying cipher.
102-
*
103-
* @return the block size of the underlying cipher.
104-
*/
85+
/// <summary>Return the block size of the underlying cipher.</summary>
86+
/// <returns>The block size in bytes.</returns>
10587
public int GetBlockSize()
10688
{
10789
return cipher.GetBlockSize();
@@ -129,10 +111,7 @@ public int ProcessBlock(ReadOnlySpan<byte> input, Span<byte> output)
129111
}
130112
#endif
131113

132-
/**
133-
* reset the chaining vector back to the IV and reset the underlying
134-
* cipher.
135-
*/
114+
/// <summary>Reset the chaining vector back to the IV and reset the underlying cipher.</summary>
136115
public void Reset()
137116
{
138117
Array.Copy(IV, 0, cbcV, 0, IV.Length);

0 commit comments

Comments
 (0)