Class AesGcmSiv
- Namespace
- CryptoHives.Foundation.Security.Cryptography.Cipher
- Assembly
- CryptoHives.Foundation.Security.Cryptography.dll
AES-GCM-SIV (RFC 8452) nonce-misuse-resistant authenticated encryption.
public abstract class AesGcmSiv : IAeadCipher, IDisposable
- Inheritance
-
AesGcmSiv
- Implements
- Derived
- Inherited Members
Remarks
The tag is derived from the plaintext and then used as the counter-mode IV, so repeating a nonce reveals only whether the same (associated data, plaintext) pair was encrypted twice. It does not leak plaintext or allow forgeries, as a repeated nonce under AES-GCM does. A unique nonce per message remains the intended use.
Fixed sizes: 16- or 32-byte key, 12-byte nonce, 16-byte tag. Each message derives its own authentication and encryption keys from the key and nonce.
Fields
NonceSize
The nonce size in bytes.
public const int NonceSize = 12
Field Value
TagSize
The tag size in bytes.
public const int TagSize = 16
Field Value
Properties
AlgorithmName
Gets the algorithm name.
public abstract string AlgorithmName { get; }
Property Value
KeySizeBytes
Gets the key size in bytes.
public int KeySizeBytes { get; }
Property Value
NonceSizeBytes
Gets the nonce size in bytes.
public int NonceSizeBytes { get; }
Property Value
TagSizeBytes
Gets the authentication tag size in bytes.
public int TagSizeBytes { get; }
Property Value
Methods
Decrypt(ReadOnlySpan<byte>, ReadOnlySpan<byte>, ReadOnlySpan<byte>)
Decrypts the ciphertext (with appended tag) and verifies authenticity.
public byte[] Decrypt(ReadOnlySpan<byte> nonce, ReadOnlySpan<byte> ciphertextWithTag, ReadOnlySpan<byte> associatedData = default)
Parameters
nonceReadOnlySpan<byte>The nonce used during encryption.
ciphertextWithTagReadOnlySpan<byte>The ciphertext with appended authentication tag.
associatedDataReadOnlySpan<byte>Additional authenticated data (must match encryption).
Returns
- byte[]
The decrypted plaintext.
Exceptions
- CryptographicException
Authentication failed - the data has been tampered with or the wrong key/nonce was used.
Decrypt(ReadOnlySpan<byte>, ReadOnlySpan<byte>, ReadOnlySpan<byte>, Span<byte>, ReadOnlySpan<byte>)
Decrypts the ciphertext and verifies the authentication tag.
public bool Decrypt(ReadOnlySpan<byte> nonce, ReadOnlySpan<byte> ciphertext, ReadOnlySpan<byte> tag, Span<byte> plaintext, ReadOnlySpan<byte> associatedData = default)
Parameters
nonceReadOnlySpan<byte>The nonce used during encryption.
ciphertextReadOnlySpan<byte>The encrypted data.
tagReadOnlySpan<byte>The authentication tag to verify.
plaintextSpan<byte>The output buffer for decrypted data (same size as ciphertext).
associatedDataReadOnlySpan<byte>Additional authenticated data (must match encryption).
Returns
- bool
True if decryption and authentication succeeded; false if authentication failed.
Remarks
The plaintext may be the ciphertext buffer itself; any other overlap is not supported.
Exceptions
- ArgumentException
nonceortagis not the correct size, orplaintextbuffer is too small.- ObjectDisposedException
Thrown when the instance has been disposed.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Dispose(bool)
Releases resources used by this instance.
protected virtual void Dispose(bool disposing)
Parameters
Encrypt(ReadOnlySpan<byte>, ReadOnlySpan<byte>, ReadOnlySpan<byte>)
Encrypts the plaintext and returns ciphertext with appended tag.
public byte[] Encrypt(ReadOnlySpan<byte> nonce, ReadOnlySpan<byte> plaintext, ReadOnlySpan<byte> associatedData = default)
Parameters
nonceReadOnlySpan<byte>The unique nonce for this encryption.
plaintextReadOnlySpan<byte>The data to encrypt.
associatedDataReadOnlySpan<byte>Additional data to authenticate (optional).
Returns
- byte[]
The ciphertext with authentication tag appended.
Encrypt(ReadOnlySpan<byte>, ReadOnlySpan<byte>, Span<byte>, Span<byte>, ReadOnlySpan<byte>)
Encrypts the plaintext and computes the authentication tag.
public void Encrypt(ReadOnlySpan<byte> nonce, ReadOnlySpan<byte> plaintext, Span<byte> ciphertext, Span<byte> tag, ReadOnlySpan<byte> associatedData = default)
Parameters
nonceReadOnlySpan<byte>The unique nonce for this encryption.
plaintextReadOnlySpan<byte>The data to encrypt.
ciphertextSpan<byte>The output buffer for ciphertext (same size as plaintext).
tagSpan<byte>The output buffer for the authentication tag.
associatedDataReadOnlySpan<byte>Additional data to authenticate (optional).
Remarks
The ciphertext may be the plaintext buffer itself; any other overlap is not supported.
Exceptions
- ArgumentException
nonceis not the correct size, orciphertextortagbuffers are too small.- ObjectDisposedException
Thrown when the instance has been disposed.