Skip to content

MGM Mode

Multilinear Galois Mode · RFC 9058 · Magma and Kuznyechik

Seal a message with MGM over a 64-bit or a 128-bit GOST cipher, then take the tag apart block by block: every block gets its own authentication coefficient Hi, where GCM reuses one H.

What MGM is, in plain words

An authenticated-encryption mode takes a key, a nonce, some data to keep secret and some data only to protect, and produces a ciphertext plus a short tag. If anyone changes a single bit, the tag stops matching and the receiver refuses the message. MGM does this with any block cipher of 64 or 128 bits. Its one distinctive move is how it builds the tag: each block of the message is weighted by a different secret value, made fresh for that position by the block cipher.

A teaching demo, not production crypto. The ciphers and the mode are implemented here in plain TypeScript so every value can be shown; they are not constant-time and have not been reviewed for side channels. RFC 9058 is an Independent Submission published for information: it records a Russian national standard and is not an IETF recommendation.

1 Seal and open

The defaults are the key and nonce of RFC 9058's own first example. Seal, then play the receiver: change one bit of the ciphertext, the associated data or the tag and verify. MGM checks the tag before it decrypts anything, so a rejected message releases no plaintext at all.

2 One H, or one H per block

GCM authenticates with a single hash subkey H = EK(0); its tag is a polynomial in that one H, so block i of m is weighted by Hm−i+1. MGM instead runs a second counter: Z1 = EK(1 ‖ ICN), stepped in its left half, and weights block i by Hi = EK(Zi). The weighted blocks are xored together and the sum is encrypted once more to give the tag.

The GCM column is computed with the same cipher and the same field as MGM, to show the structure side by side. It is not AES-GCM, which uses 128-bit AES and a bit-reflected field convention.

Each authenticated position and the coefficient that multiplies it
PositionPadded blockGCM-shaped: power of one HMGM: its own Hi

3 Check every value against RFC 9058

RFC 9058 Appendix A prints not just inputs and tags but every intermediate value. This runs the implementation on an example and sets each computed value beside the one the RFC prints.

4 Repeat the nonce

The encryption counter depends only on the key and the ICN. Encrypt two messages under the same ICN and they share a keystream, so xoring the ciphertexts cancels it.

What MGM does not give you: confidentiality for two messages that share an ICN under one key. Both still decrypt and verify; MGM has no check that fails here, because nothing it checks is wrong.

Not shown, because it is not demonstrated here: a forged tag. GCM's nonce reuse hands an attacker H; MGM encrypts its sum before output, and this lab claims no forgery against it.

5 64 bits versus 128

RFC 9058 section 6 bounds an attacker's advantage against MGM's confidentiality by 3(s + 4q)² / 2n for s blocks in q messages under one key. The formula is the same for both ciphers; only n changes, and it sits in the exponent.

Magma (n = 64)
Kuznyechik (n = 128)

    Real deployments act on this. RFC 9367's GOST cipher suites for TLS 1.3 change the record key inside a connection (TLSTREE): the key for record seqnum depends on seqnum & C3, so one key lasts 2(trailing zero bits of C3) records. Computed from the RFC's constants:

    RFC 9367 Tables 1 and 2: records per key, derived from C3
    Cipher suiteCipherC3Records per keySNMAX

    The 64-bit birthday problem on its own, with a live collision search, is Feistel Forge's Sweet32 exhibit.

    6 Magma's S-box: a choice the old standard left open

    Magma is GOST 28147-89 with its loose ends tied. The 1989 standard defined the network but no S-boxes: RFC 5830 says plainly that "the standard doesn't define any S-boxes", and the tables were issued as secret parameters "in accordance with the established procedure". So "GOST" named a family of ciphers, one per table. GOST R 34.12-2015 fixed one table, id-tc26-gost-28147-param-Z, and also fixed the byte order (RFC 8891 Appendix B).

    param-Z, RFC 8891 section 4.1 (hex). Row Pi'i substitutes nibble i.
    RFC 8891 A.4: Magma(fedcba9876543210)
    Same key, same block, swapped table
    —

    The swapped table is a hypothetical made for this exhibit, not one of the historical parameter sets, and the variant is not a validated GOST 28147-89 implementation (that standard also reads keys and data little-endian).

    What this lab is not

    • Not production crypto: no constant-time guarantees, no side-channel review, keys live in page memory.
    • Not TLS: RFC 9367's key schedule (TLSTREE's KDFs over Streebog) is described, not implemented.
    • Not an attack on MGM: the nonce-reuse exhibit shows a keystream leak, not a forgery.
    • Not GCM: the GCM column in Exhibit 2 is the shape of GHASH over MGM's field, not AES-GCM.