Table of Contents

Class Magma

Namespace
CryptoHives.Foundation.Security.Cryptography.Cipher
Assembly
CryptoHives.Foundation.Security.Cryptography.dll

Magma (GOST R 34.12-2015, RFC 8891) symmetric cipher implementation.

public sealed class Magma : SymmetricCipher, IDisposable
Inheritance
Magma
Implements
Inherited Members

Remarks

Magma is a 64-bit block cipher with a 256-bit key: the GOST 28147-89 Feistel network with the S-boxes fixed to id-tc26-gost-28147-param-Z and big-endian block and key order. It is not interchangeable with GOST 28147-89 implementations that use other S-boxes or byte orders.

Block size: with 64-bit blocks, ciphertext blocks start to collide after about 2^32 of them (32 GiB), so one key should protect far less data than that.

Example usage:

using var magma = Magma.Create();
magma.Mode = CipherMode.CBC;
magma.Padding = PaddingMode.PKCS7;
magma.GenerateKey();
magma.GenerateIV();

byte[] ciphertext = magma.Encrypt(plaintext);
byte[] decrypted = magma.Decrypt(ciphertext);

Constructors

Magma()

Initializes a new instance of the Magma class.

public Magma()

Fields

KeySizeBits

Key size in bits for Magma.

public const int KeySizeBits = 256

Field Value

int

KeySizeBytes

Key size in bytes for Magma.

public const int KeySizeBytes = 32

Field Value

int

Properties

AlgorithmName

Gets the name of the cipher algorithm.

public override string AlgorithmName { get; }

Property Value

string

Examples

"AES-256", "ChaCha20", "AES-256-GCM"

IVSize

Gets the required IV/nonce size in bytes for the current mode.

public override int IVSize { get; }

Property Value

int

Methods

Create()

Creates a new instance of the Magma cipher.

public static Magma Create()

Returns

Magma

A new Magma cipher instance.

CreateCipherDecryptor(ReadOnlySpan<byte>, ReadOnlySpan<byte>)

Creates a decryptor transform using the specified key and IV.

protected override ICipherTransform CreateCipherDecryptor(ReadOnlySpan<byte> key, ReadOnlySpan<byte> iv)

Parameters

key ReadOnlySpan<byte>

The secret key.

iv ReadOnlySpan<byte>

The initialization vector or nonce.

Returns

ICipherTransform

A new cipher decryptor transform.

CreateCipherEncryptor(ReadOnlySpan<byte>, ReadOnlySpan<byte>)

Creates an encryptor transform using the specified key and IV.

protected override ICipherTransform CreateCipherEncryptor(ReadOnlySpan<byte> key, ReadOnlySpan<byte> iv)

Parameters

key ReadOnlySpan<byte>

The secret key.

iv ReadOnlySpan<byte>

The initialization vector or nonce.

Returns

ICipherTransform

A new cipher encryptor transform.