66
77namespace 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" ) ;
0 commit comments