Skip to Content
oxcrypto

Magma

Magma block cipher selector.

from oxcrypto.cipher.magma import MAGMA
from oxcrypto.cipher.hazmat import decrypt_block, encrypt_block

cipher = MAGMA.GOST89_CRYPTOPRO_D
key = cipher.generate_key()
block = bytes(cipher.block_size)
assert decrypt_block(key, encrypt_block(key, block, cipher=cipher), cipher=cipher) == block

Variants: MAGMA.MAGMA, MAGMA.GOST89_CRYPTOPRO_A, MAGMA.GOST89_CRYPTOPRO_B, MAGMA.GOST89_CRYPTOPRO_C, MAGMA.GOST89_CRYPTOPRO_D.

Standard: GOST R 34.12-2015 (Magma, RFC 8891) and GOST 28147-89 with the RFC 4357 CryptoPro S-boxes.

All variants use the big-endian key and block byte order of GOST R 34.12-2015. Classic GOST 28147-89 implementations such as RFC 4357 and OpenSSL's GOST engine use little-endian order, so GOST89_CRYPTOPRO_* ciphertext does not interoperate with them unless you reverse the byte order of each key word and block half.

Pass the selector as cipher= to any mode. Raw single-block functions live in oxcrypto.cipher.hazmat.

The RustCrypto block-ciphers README states that this crate is not implemented in constant time and has no published audit. oxcrypto has not verified its timing behavior.