Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Compatibility with other DSTU implementations

dstu-core implements the DSTU standards as written. Where another implementation reads a clause differently, we follow the standard’s text and its own worked examples, and record the difference here. We don’t copy the other implementation’s behaviour.

Compared against:

  • UAPKI: library/uapkic/src/dstu7624.c (vendored under oracles/uapki/), the one-shot encrypt_gmac path. Its self-test vectors are the annex examples of DSTU 7624:2014. Evidence comes from dstu-core ≤ 0.3, a line-by-line port of that file, run on the same inputs before this change. That is uapkic 2.0.2, the version in every tagged UAPKI release up to v2.0.17.
  • UAPKI 2.0.3: uapkic as rewritten on 2026-09-29 (deffe4a, “Fix Kalyna GCM, GMAC and CCM modes”), not yet in a tagged release. Built from master 0bf2b68 and run directly against dstu-core on Kalyna-128/128 only (2026-10-03); dstu7624_self_test passes. Re-run on master 37039b1 (2026-10-18): same results, except that an empty CMAC message is now rejected (62a1bdf).
  • Bouncy Castle: bcprov-jdk18on 1.85 (KGCMBlockCipher, KGMac, KCCMBlockCipher, DSTU7624Mac), run directly.
  • Standard: DSTU 7624:2014 (draft edition), DSTU 7564:2014 (draft edition), DSTU 4145-2002.

“Same” means byte-identical output on the tested inputs. Details and citations are in DECISIONS.md D-204–D-206.

Kalyna (DSTU 7624:2014) modes

ModeInput classdstu-coreUAPKI ≤ 2.0.2UAPKI 2.0.3Bouncy Castle 1.85
Block cipher, ECB, CBC, CFB, OFB, CTR, XTS, KWannex В examplesstandardsamesame (self-test)same where tested
KW-p|M| + l/2 not block-aligned (all annex В.11 examples)standard (kalyna_kw_p, T-253)same encrypt_kw code (read, not run)same (run: 4/4 annex vectors)no padded mode
KW-p|M| + l/2 block-aligned (DSTU 9041 l(p)=384)Б.2 pads a full block (D-241)same encrypt_kw code (read, not run)no padding block: 96 bytes where the text gives 128 (run on Г.2’s M')no padded mode
KW-p unwrapa padding wrap does not producerefused as an integrity error (D-243)strips trailing zeros, length field unchecked (read)same code (read)-
GCM / GMACAAD and ciphertext block-aligned, not both empty (all annex examples)standardsamesamesame
GCM / GMACAAD and data both emptyrejected (§12.1: AAD and data must not both be empty)accepted: the tag is E_K(0), the GHASH key itselfrejectedsame as UAPKI ≤ 2.0.2
GCM / GMACAAD not block-aligned0x80 pad, true length (§12.2)zero padsame as dstu-corezero pad
GCMciphertext not block-aligned0x80 pad, true length0x80 pad, padded lengthsame as dstu-corezero pad, true length
CCMAAD and plaintext block-aligned (annex В.9)standardsamesamesame
CCMempty AADflag bit 7 = 0, B = T(G1)bit 7 = 1, extra G2 blockbit 7 = 0, B = G1 read literally (no T), so the tag differssame as dstu-core when the plaintext is block-aligned; differs otherwise
CCMplaintext not block-aligned (e.g. annex В.9.2)standardsamesamediffers: fails annex В.9.2
CCMAAD mod l > l/8 − N_Б (e.g. 13–15 bytes for a 128-bit block)G2 per §13.2shorter G2same as dstu-coredifferent G2 layout
CCMAAD not block-aligned, otherwisestandardsamesamediffers (len‖AAD‖0, not len‖0‖AAD)
CCMempty plaintextrejected (outside §13.1’s domain)acceptedrejectedaccepted
CMACmessage not block-aligned (annex В.5.2)standardsamesamethrows
CMACsecurity (any input)not EUF-CMA: MAC(0^l ‖ Y) = E_K(Y); hazmat only, removed from uacrypt (T-298, D-247)samesamesame (aligned branch)
CMACempty messagerejected (outside §9’s domain)MAC(ε) = MAC(0^l)rejected (62a1bdf, 2026-10-06)MAC(ε) = MAC(0^l)

Practical consequence: for GCM/GMAC/CCM with arbitrary-length data, UAPKI ≤ 2.0.2, Bouncy Castle and dstu-core produce different tags, so tags exchanged between them only verify on block-aligned inputs. UAPKI 2.0.3 matches dstu-core on every tested GCM/GMAC/CCM input except CCM with an empty AAD, where it reads §13.2’s “B = G1” literally (D-205 (b) explains why we read it as T(G1)).

crypto_secretbox, crypto_secretstream and crypto_box use Kalyna-GCM with a non-block-aligned internal AAD, so their output is not reproducible with UAPKI ≤ 2.0.2’s or Bouncy Castle’s GCM. That doesn’t matter for them: these are this library’s own formats, not a standard interchange format.

Kupyna (DSTU 7564:2014)

Functiondstu-coreUAPKIBouncy Castle
Kupyna-256/512 (byte input, annex Б examples)standardsamesame where tested
Kupyna-384 (annex Б, N = 760)standard, hazmat::kupyna::Kupyna384 (T-254)-same (DSTU7564Digest(384))
Kupyna-48/304 (annex Б)rightmost bytes of the 256/512 cores match; no public API--
Kupyna-KMAC 256/384/512 (annex В.5)standardsamesame

DSTU 4145-2002

The curve parameters for m = 163 and m = 257 (annex Г) match the standard exactly.