diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-09-12 19:19:31 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-09-12 19:19:31 +0700 |
commit | 55f307cec78f2822254a04857bc0219e91e07d3a (patch) | |
tree | de64d8021e2fdba2d1c81eccb9e41d4a18e11ccb /crypto | |
parent | Separate out new IBlockCipherMode from IBlockCipher (diff) | |
download | BouncyCastle.NET-ed25519-55f307cec78f2822254a04857bc0219e91e07d3a.tar.xz |
Mark some classes sealed
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/src/crypto/engines/AesEngine.cs | 18 | ||||
-rw-r--r-- | crypto/src/crypto/engines/AesLightEngine.cs | 18 | ||||
-rw-r--r-- | crypto/src/crypto/modes/CbcBlockCipher.cs | 6 | ||||
-rw-r--r-- | crypto/src/crypto/modes/GCMBlockCipher.cs | 36 |
4 files changed, 32 insertions, 46 deletions
diff --git a/crypto/src/crypto/engines/AesEngine.cs b/crypto/src/crypto/engines/AesEngine.cs index 8ccadf1bf..914550d6d 100644 --- a/crypto/src/crypto/engines/AesEngine.cs +++ b/crypto/src/crypto/engines/AesEngine.cs @@ -31,7 +31,7 @@ namespace Org.BouncyCastle.Crypto.Engines * This file contains the middle performance version with 2Kbytes of static tables for round precomputation. * </p> */ - public class AesEngine + public sealed class AesEngine : IBlockCipher { // The S box @@ -447,13 +447,9 @@ namespace Org.BouncyCastle.Crypto.Engines * @exception ArgumentException if the parameters argument is * inappropriate. */ - public virtual void Init( - bool forEncryption, - ICipherParameters parameters) + public void Init(bool forEncryption, ICipherParameters parameters) { - KeyParameter keyParameter = parameters as KeyParameter; - - if (keyParameter == null) + if (!(parameters is KeyParameter keyParameter)) throw new ArgumentException("invalid parameter passed to AES init - " + Platform.GetTypeName(parameters)); @@ -463,17 +459,17 @@ namespace Org.BouncyCastle.Crypto.Engines this.s = Arrays.Clone(forEncryption ? S : Si); } - public virtual string AlgorithmName + public string AlgorithmName { get { return "AES"; } } - public virtual int GetBlockSize() + public int GetBlockSize() { return BLOCK_SIZE; } - public virtual int ProcessBlock(byte[] input, int inOff, byte[] output, int outOff) + public int ProcessBlock(byte[] input, int inOff, byte[] output, int outOff) { if (WorkingKey == null) throw new InvalidOperationException("AES engine not initialised"); @@ -505,7 +501,7 @@ namespace Org.BouncyCastle.Crypto.Engines } #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER - public virtual int ProcessBlock(ReadOnlySpan<byte> input, Span<byte> output) + public int ProcessBlock(ReadOnlySpan<byte> input, Span<byte> output) { if (WorkingKey == null) throw new InvalidOperationException("AES engine not initialised"); diff --git a/crypto/src/crypto/engines/AesLightEngine.cs b/crypto/src/crypto/engines/AesLightEngine.cs index 6ce714fde..8d76f4388 100644 --- a/crypto/src/crypto/engines/AesLightEngine.cs +++ b/crypto/src/crypto/engines/AesLightEngine.cs @@ -33,7 +33,7 @@ namespace Org.BouncyCastle.Crypto.Engines * for round precomputation, but it has the smallest foot print. * </p> */ - public class AesLightEngine + public sealed class AesLightEngine : IBlockCipher { // The S box @@ -342,13 +342,9 @@ namespace Org.BouncyCastle.Crypto.Engines * @exception ArgumentException if the parameters argument is * inappropriate. */ - public virtual void Init( - bool forEncryption, - ICipherParameters parameters) + public void Init(bool forEncryption, ICipherParameters parameters) { - KeyParameter keyParameter = parameters as KeyParameter; - - if (keyParameter == null) + if (!(parameters is KeyParameter keyParameter)) throw new ArgumentException("invalid parameter passed to AES init - " + Platform.GetTypeName(parameters)); @@ -357,17 +353,17 @@ namespace Org.BouncyCastle.Crypto.Engines this.forEncryption = forEncryption; } - public virtual string AlgorithmName + public string AlgorithmName { get { return "AES"; } } - public virtual int GetBlockSize() + public int GetBlockSize() { return BLOCK_SIZE; } - public virtual int ProcessBlock(byte[] input, int inOff, byte[] output, int outOff) + public int ProcessBlock(byte[] input, int inOff, byte[] output, int outOff) { if (WorkingKey == null) throw new InvalidOperationException("AES engine not initialised"); @@ -399,7 +395,7 @@ namespace Org.BouncyCastle.Crypto.Engines } #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER - public virtual int ProcessBlock(ReadOnlySpan<byte> input, Span<byte> output) + public int ProcessBlock(ReadOnlySpan<byte> input, Span<byte> output) { if (WorkingKey == null) throw new InvalidOperationException("AES engine not initialised"); diff --git a/crypto/src/crypto/modes/CbcBlockCipher.cs b/crypto/src/crypto/modes/CbcBlockCipher.cs index 2a2db2437..8e2b3c2a4 100644 --- a/crypto/src/crypto/modes/CbcBlockCipher.cs +++ b/crypto/src/crypto/modes/CbcBlockCipher.cs @@ -7,7 +7,7 @@ namespace Org.BouncyCastle.Crypto.Modes /** * implements Cipher-Block-Chaining (CBC) mode on top of a simple cipher. */ - public class CbcBlockCipher + public sealed class CbcBlockCipher : IBlockCipherMode { private byte[] IV, cbcV, cbcNextV; @@ -48,9 +48,7 @@ namespace Org.BouncyCastle.Crypto.Modes * @exception ArgumentException if the parameters argument is * inappropriate. */ - public void Init( - bool forEncryption, - ICipherParameters parameters) + public void Init(bool forEncryption, ICipherParameters parameters) { bool oldEncrypting = this.encrypting; diff --git a/crypto/src/crypto/modes/GCMBlockCipher.cs b/crypto/src/crypto/modes/GCMBlockCipher.cs index 58e83c257..538e0e749 100644 --- a/crypto/src/crypto/modes/GCMBlockCipher.cs +++ b/crypto/src/crypto/modes/GCMBlockCipher.cs @@ -18,7 +18,7 @@ namespace Org.BouncyCastle.Crypto.Modes /// Implements the Galois/Counter mode (GCM) detailed in /// NIST Special Publication 800-38D. /// </summary> - public class GcmBlockCipher + public sealed class GcmBlockCipher : IAeadBlockCipher { private static IGcmMultiplier CreateGcmMultiplier() @@ -86,7 +86,7 @@ namespace Org.BouncyCastle.Crypto.Modes this.multiplier = m; } - public virtual string AlgorithmName + public string AlgorithmName { get { return cipher.AlgorithmName + "/GCM"; } } @@ -96,7 +96,7 @@ namespace Org.BouncyCastle.Crypto.Modes return cipher; } - public virtual int GetBlockSize() + public int GetBlockSize() { return BlockSize; } @@ -105,9 +105,7 @@ namespace Org.BouncyCastle.Crypto.Modes /// MAC sizes from 32 bits to 128 bits (must be a multiple of 8) are supported. The default is 128 bits. /// Sizes less than 96 are not recommended, but are supported for specialized applications. /// </remarks> - public virtual void Init( - bool forEncryption, - ICipherParameters parameters) + public void Init(bool forEncryption, ICipherParameters parameters) { this.forEncryption = forEncryption; this.macBlock = null; @@ -229,15 +227,14 @@ namespace Org.BouncyCastle.Crypto.Modes } } - public virtual byte[] GetMac() + public byte[] GetMac() { return macBlock == null ? new byte[macSize] : Arrays.Clone(macBlock); } - public virtual int GetOutputSize( - int len) + public int GetOutputSize(int len) { int totalData = len + bufOff; @@ -249,8 +246,7 @@ namespace Org.BouncyCastle.Crypto.Modes return totalData < macSize ? 0 : totalData - macSize; } - public virtual int GetUpdateOutputSize( - int len) + public int GetUpdateOutputSize(int len) { int totalData = len + bufOff; if (!forEncryption) @@ -264,7 +260,7 @@ namespace Org.BouncyCastle.Crypto.Modes return totalData - totalData % BlockSize; } - public virtual void ProcessAadByte(byte input) + public void ProcessAadByte(byte input) { CheckStatus(); @@ -278,7 +274,7 @@ namespace Org.BouncyCastle.Crypto.Modes } } - public virtual void ProcessAadBytes(byte[] inBytes, int inOff, int len) + public void ProcessAadBytes(byte[] inBytes, int inOff, int len) { #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER ProcessAadBytes(inBytes.AsSpan(inOff, len)); @@ -318,7 +314,7 @@ namespace Org.BouncyCastle.Crypto.Modes } #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER - public virtual void ProcessAadBytes(ReadOnlySpan<byte> input) + public void ProcessAadBytes(ReadOnlySpan<byte> input) { CheckStatus(); @@ -372,7 +368,7 @@ namespace Org.BouncyCastle.Crypto.Modes } } - public virtual int ProcessByte(byte input, byte[] output, int outOff) + public int ProcessByte(byte input, byte[] output, int outOff) { CheckStatus(); @@ -404,7 +400,7 @@ namespace Org.BouncyCastle.Crypto.Modes } #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER - public virtual int ProcessByte(byte input, Span<byte> output) + public int ProcessByte(byte input, Span<byte> output) { CheckStatus(); @@ -428,7 +424,7 @@ namespace Org.BouncyCastle.Crypto.Modes } #endif - public virtual int ProcessBytes(byte[] input, int inOff, int len, byte[] output, int outOff) + public int ProcessBytes(byte[] input, int inOff, int len, byte[] output, int outOff) { CheckStatus(); @@ -537,7 +533,7 @@ namespace Org.BouncyCastle.Crypto.Modes } #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER - public virtual int ProcessBytes(ReadOnlySpan<byte> input, Span<byte> output) + public int ProcessBytes(ReadOnlySpan<byte> input, Span<byte> output) { CheckStatus(); @@ -751,7 +747,7 @@ namespace Org.BouncyCastle.Crypto.Modes } #if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER - public virtual int DoFinal(Span<byte> output) + public int DoFinal(Span<byte> output) { CheckStatus(); @@ -862,7 +858,7 @@ namespace Org.BouncyCastle.Crypto.Modes } #endif - public virtual void Reset() + public void Reset() { Reset(true); } |