Skip to content

Commit 26f2155

Browse files
committed
fix: restore missing method signatures accidentally overwritten in CbcBlockCipher and AesEngine
1 parent 4624fd8 commit 26f2155

File tree

3 files changed

+82
-82
lines changed

3 files changed

+82
-82
lines changed

crypto/src/crypto/engines/AesEngine.cs

Lines changed: 39 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,30 @@
66

77
namespace Org.BouncyCastle.Crypto.Engines
88
{
9-
/// <summary>
10-
/// Implementation of the Advanced Encryption Standard (AES), also known as Rijndael, according to FIPS-197.
11-
/// </summary>
12-
/// <remarks>
13-
/// <para>
14-
/// For further details see: <a href="http://csrc.nist.gov/encryption/aes/">http://csrc.nist.gov/encryption/aes/</a>.
15-
/// </para>
16-
/// <para>
17-
/// This implementation is based on optimizations from Dr. Brian Gladman's paper and C code at
18-
/// <a href="http://fp.gladman.plus.com/cryptography_technology/rijndael/">http://fp.gladman.plus.com/cryptography_technology/rijndael/</a>.
19-
/// </para>
20-
/// <para>
21-
/// This specific implementation uses a middle-performance approach with 2Kbytes of static tables
22-
/// for round precomputation, providing a balanced trade-off between speed and memory footprint.
23-
/// </para>
24-
/// </remarks>
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+
*/
2533
public sealed class AesEngine
2634
: IBlockCipher
2735
{
@@ -429,19 +437,21 @@ private uint[][] GenerateWorkingKey(KeyParameter keyParameter, bool forEncryptio
429437

430438
private const int BLOCK_SIZE = 16;
431439

432-
/// <summary>
433-
/// Default constructor. Initializes an AES engine with a 128-bit block size.
434-
/// </summary>
440+
/**
441+
* default constructor - 128 bit block size.
442+
*/
435443
public AesEngine()
436444
{
437445
}
438446

439-
/// <summary>
440-
/// Initialise the AES engine.
441-
/// </summary>
442-
/// <param name="forEncryption">True if initialising for encryption, false for decryption.</param>
443-
/// <param name="parameters">The key parameters, typically a <see cref="KeyParameter"/>.</param>
444-
/// <exception cref="ArgumentException">If the parameters are inappropriate for AES.</exception>
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+
*/
445455
public void Init(bool forEncryption, ICipherParameters parameters)
446456
{
447457
if (!(parameters is KeyParameter keyParameter))
@@ -454,25 +464,17 @@ public void Init(bool forEncryption, ICipherParameters parameters)
454464
this.s = Arrays.Clone(forEncryption ? S : Si);
455465
}
456466

457-
/// <summary>The name of the algorithm this engine implements.</summary>
467+
public string AlgorithmName
458468
{
459469
get { return "AES"; }
460470
}
461471

462-
/// <summary>Return the block size for this cipher (in bytes).</summary>
463-
/// <returns>16 (fixed block size for AES).</returns>
472+
public int GetBlockSize()
464473
{
465474
return BLOCK_SIZE;
466475
}
467476

468-
/// <summary>Process a single block of data.</summary>
469-
/// <param name="input">The input buffer containing the data to be processed.</param>
470-
/// <param name="inOff">The offset into the input buffer.</param>
471-
/// <param name="output">The output buffer to write the processed data to.</param>
472-
/// <param name="outOff">The offset into the output buffer.</param>
473-
/// <returns>The number of bytes processed and produced (16).</returns>
474-
/// <exception cref="InvalidOperationException">If the engine is not initialized.</exception>
475-
/// <exception cref="DataLengthException">If input buffer is too short, or output buffer too small.</exception>
477+
public int ProcessBlock(byte[] input, int inOff, byte[] output, int outOff)
476478
{
477479
if (WorkingKey == null)
478480
throw new InvalidOperationException("AES engine not initialised");
@@ -504,12 +506,7 @@ public void Init(bool forEncryption, ICipherParameters parameters)
504506
}
505507

506508
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
507-
/// <summary>Process a single block of data using Spans.</summary>
508-
/// <param name="input">The input span containing the data to be processed.</param>
509-
/// <param name="output">The output span to write the processed data to.</param>
510-
/// <returns>The number of bytes processed and produced (16).</returns>
511-
/// <exception cref="InvalidOperationException">If the engine is not initialized.</exception>
512-
/// <exception cref="DataLengthException">If input span is too short, or output span too small.</exception>
509+
public int ProcessBlock(ReadOnlySpan<byte> input, Span<byte> output)
513510
{
514511
if (WorkingKey == null)
515512
throw new InvalidOperationException("AES engine not initialised");

crypto/src/crypto/modes/CbcBlockCipher.cs

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

66
namespace Org.BouncyCastle.Crypto.Modes
77
{
8-
/// <summary>
9-
/// Implements Cipher-Block-Chaining (CBC) mode on top of a simple block cipher.
10-
/// </summary>
8+
/**
9+
* implements Cipher-Block-Chaining (CBC) mode on top of a simple cipher.
10+
*/
1111
public sealed class CbcBlockCipher
1212
: IBlockCipherMode
1313
{
@@ -16,10 +16,11 @@ public sealed class CbcBlockCipher
1616
private IBlockCipher cipher;
1717
private bool encrypting;
1818

19-
/// <summary>
20-
/// Basic constructor.
21-
/// </summary>
22-
/// <param name="cipher">The block cipher to be used as the basis of chaining.</param>
19+
/**
20+
* Basic constructor.
21+
*
22+
* @param cipher the block cipher to be used as the basis of chaining.
23+
*/
2324
public CbcBlockCipher(
2425
IBlockCipher cipher)
2526
{
@@ -31,18 +32,23 @@ public CbcBlockCipher(
3132
this.cbcNextV = new byte[blockSize];
3233
}
3334

34-
/// <summary>
35-
/// Return the underlying block cipher that we are wrapping.
36-
/// </summary>
35+
/**
36+
* return the underlying block cipher that we are wrapping.
37+
*
38+
* @return the underlying block cipher that we are wrapping.
39+
*/
3740
public IBlockCipher UnderlyingCipher => cipher;
3841

39-
/// <summary>
40-
/// Initialise the cipher and, possibly, the initialisation vector (IV).
41-
/// If an IV isn't passed as part of the parameter, the IV will be all zeros.
42-
/// </summary>
43-
/// <param name="forEncryption">If true the cipher is initialised for encryption, if false for decryption.</param>
44-
/// <param name="parameters">The key and other data required by the cipher (typically <see cref="ParametersWithIV"/>).</param>
45-
/// <exception cref="ArgumentException">If the parameters are inappropriate.</exception>
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+
*/
4652
public void Init(bool forEncryption, ICipherParameters parameters)
4753
{
4854
bool oldEncrypting = this.encrypting;
@@ -76,35 +82,32 @@ public void Init(bool forEncryption, ICipherParameters parameters)
7682
}
7783
}
7884

79-
/// <summary>
80-
/// Return the algorithm name and mode (e.g., "AES/CBC").
81-
/// </summary>
85+
/**
86+
* return the algorithm name and mode.
87+
*
88+
* @return the name of the underlying algorithm followed by "/CBC".
89+
*/
8290
public string AlgorithmName
8391
{
8492
get { return cipher.AlgorithmName + "/CBC"; }
8593
}
8694

87-
/// <summary>Indicates whether this cipher can handle partial blocks.</summary>
95+
public bool IsPartialBlockOkay
8896
{
8997
get { return false; }
9098
}
9199

92-
/// <summary>
93-
/// Return the block size of the underlying cipher.
94-
/// </summary>
95-
/// <returns>The block size in bytes.</returns>
100+
/**
101+
* return the block size of the underlying cipher.
102+
*
103+
* @return the block size of the underlying cipher.
104+
*/
96105
public int GetBlockSize()
97106
{
98107
return cipher.GetBlockSize();
99108
}
100109

101-
/// <summary>Process a single block of data.</summary>
102-
/// <param name="input">The input buffer containing the data to be processed.</param>
103-
/// <param name="inOff">The offset into the input buffer.</param>
104-
/// <param name="output">The output buffer to write the processed data to.</param>
105-
/// <param name="outOff">The offset into the output buffer.</param>
106-
/// <returns>The number of bytes processed and produced.</returns>
107-
/// <exception cref="DataLengthException">If input block is wrong size, or output buffer too small.</exception>
110+
public int ProcessBlock(byte[] input, int inOff, byte[] output, int outOff)
108111
{
109112
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
110113
return encrypting
@@ -118,21 +121,18 @@ public int GetBlockSize()
118121
}
119122

120123
#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER
121-
/// <summary>Process a single block of data using Spans.</summary>
122-
/// <param name="input">The input span containing the data to be processed.</param>
123-
/// <param name="output">The output span to write the processed data to.</param>
124-
/// <returns>The number of bytes processed and produced.</returns>
125-
/// <exception cref="DataLengthException">If input span is wrong size, or output span too small.</exception>
124+
public int ProcessBlock(ReadOnlySpan<byte> input, Span<byte> output)
126125
{
127126
return encrypting
128127
? EncryptBlock(input, output)
129128
: DecryptBlock(input, output);
130129
}
131130
#endif
132131

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

crypto/src/crypto/modes/IAeadCipher.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public interface IAeadCipher
6161
/// <param name="input">The byte to be processed.</param>
6262
/// <param name="output">The output span.</param>
6363
/// <returns>The number of bytes written to the output span.</returns>
64+
int ProcessByte(byte input, Span<byte> output);
6465
#endif
6566

6667
/// <summary>Process a sequence of bytes from the input buffer.</summary>
@@ -78,6 +79,7 @@ public interface IAeadCipher
7879
/// <param name="input">The input span.</param>
7980
/// <param name="output">The output span.</param>
8081
/// <returns>The number of bytes written to the output span.</returns>
82+
int ProcessBytes(ReadOnlySpan<byte> input, Span<byte> output);
8183
#endif
8284

8385
/// <summary>Finish the operation, generating or verifying the MAC.</summary>
@@ -93,6 +95,7 @@ public interface IAeadCipher
9395
/// <param name="output">The output span for remaining data and/or MAC.</param>
9496
/// <returns>Number of bytes written to the output span.</returns>
9597
/// <exception cref="InvalidCipherTextException">If the MAC check fails.</exception>
98+
int DoFinal(Span<byte> output);
9699
#endif
97100

98101
/// <summary>Return the Message Authentication Code (MAC) generated or verified by the cipher.</summary>

0 commit comments

Comments
 (0)