Introduction
Files from Sony’s SonicStage software are usually encrypted. The EA3 header says so with its encryption id (anything but FFFF and FF80), and the tag then holds a key ring in a GEOB frame. Only the sound data is encrypted; the tag and the header are plain, so the explorer shows every field of an encrypted file. The explorer decrypts in your browser and plays the sound with no key typed: it carries the three keys of FFmpeg’s demuxer (listed below), which open files such as 03-Exdous.oma. A file those keys do not open plays when you type its key (hexadecimal, up to 16 bytes) in the Key option. Nothing is sent anywhere.
The key ring
The GEOB frame whose description is OMG_LSI or OMG_BKLSI holds the key ring as its object. It is at least 64 bytes.
| Offset | Size | Field | Meaning |
|---|---|---|---|
| 0 | 2 | Version | 1. Other values only give a warning. |
| 2 | 2 | Key block size | The size of the block of keys that starts at offset 16 (it begins with the letters KEYRING and spaces, 12 bytes in all). |
| 4 | 2 | EKB size | The size of the enabling key block that follows the keys. |
| 6 | 2 | ID block size | The size of the block after the enabling key block. |
| 8 | 2 | Signature size | Read, not used by FFmpeg. |
| 10 | 6 | Reserved | Not read. |
| 16 | 12 | Magic | The text KEYRING and five spaces. Any other bytes make FFmpeg refuse the file. |
| 28 | 16 | Not read | Not used by FFmpeg. |
| 44 | 4 | Record id | A 32-bit number, offset 28 of the key block. |
| 48 | 8 | Key check value | Offset 32 of the key block: decrypted with the key to give m, see below. |
| 56 | 8 | Encrypted key | Offset 40 of the key block: DES-encrypted with m to give the key of the sound data. |
| 16 + sizes | 8 | Check value | After the three blocks: an 8-byte DES CBC-MAC of the ID block, which tells a reader that it has the right key. |
FFmpeg finds the key that opens the ring by trying the key given by the user and then each key of a built-in table (below). The steps, all with DES (a key of 8 bytes) or triple DES (24 bytes), are:
- Key. The key (the user’s, or a built-in one) is up to 16 bytes. It is padded with zeros to 16, and bytes 16 to 23 repeat bytes 0 to 7, which makes a 24-byte triple-DES key.
- Leaf test (
rprobe). With that key, triple-DES decrypt the 8 bytes at offset 48 of the key ring; the result is the value m. DES-encrypt eight zero bytes with m as the key to get s. Compute the DES CBC-MAC with key s over the ID block. When it equals the 8 bytes after the ID block, the key is right. - Node test (
nprobe). When the leaf test fails and the ring has an enabling key block (EKB, after the key block), the user key is tried as the key of the EKB. When the EKB starts with the lettersEKBand a space, its first 32 bytes are skipped. Then at offset 32 is a 4-byte tag length and at offset 36 a 4-byte data length (a multiple of 16), both big-endian; the entries start at offset 44 plus the tag length and are 16 bytes each. Each entry is decrypted with triple DES under the user key; the 16 bytes that come out are padded as in step 1 and the leaf test is run with them as the key. - Content key. The 8 bytes at offset 56 of the ring are DES-encrypted with m as the key; the result e is the key of the sound data.
When no key opens the ring the explorer says that the key does not open the file, and does not guess.
The built-in key table
FFmpeg’s omadec.c holds a table named leaf_table of six 64-bit numbers. When no user key was given, or the user key opens neither the key block
nor the EKB, decrypt_init goes through the table two numbers at a time. Each pair is one 16-byte key: each number is written little-endian (AV_WL64),
the first number first. Each key is then used as in steps 1 to 3 above (leaf test, then node test) and the search stops at the first key that passes.
When none does, the file is refused as having an invalid key. The explorer does the same, and tells which key opened the file.
| Key | First number | Second number |
|---|---|---|
| 1 | 0xd79e8283acea4620 | 0x7a9762f445afd0d8 |
| 2 | 0x354d60a60b8c79f1 | 0x584e1cde00b07aee |
| 3 | 0x1573cd93da7df623 | 0x47f98d79620dd535 |
The two real encrypted files read here (03-Exdous.oma and 002-Roll In My Sweet Baby’s Arms.oma) open with key 1 as the leaf key. The table is copied from the file as published by FFmpeg, which is licensed under the GNU Lesser General Public License, version 2.1 or later (copyright 2008, 2013 Maxim Poliakovski, 2008 Benjamin Larsson, 2011 David Goldwich).
Sound data
The sound data is encrypted with DES in cipher block chaining mode, in 8-byte blocks, with the content key. The initial value is the 8 bytes at offset 88 of the EA3 header. Each packet is decrypted whole: the chain continues from one packet to the next (the last cipher block of a packet is the initial value of the next). A packet that is shorter than the packet size (the last one) is not decrypted, and the chain restarts from zero after it.
The explorer shows the encryption id, the key ring fields and the initial value. When a built-in key or the key in the Key option opens the file, it also decrypts the packets, lists them in the Frames tab and plays them. When none does, it says why the sound cannot be played.
Divergence from spec
No specification of the key ring exists; the steps are those of FFmpeg’s demuxer. Test files with a key of our own were made following those steps and
opened with ffmpeg -cryptokey (the demuxer’s key option) and with the explorer; both give the same sound as the file before it was encrypted.
For the two real encrypted files, the packets the explorer decrypts with the built-in key are byte for byte the packets FFmpeg’s demuxer returns.
The only key material in the explorer is FFmpeg’s table; a file protected by another key opens only when you supply that key.
Sources
- FFmpeg
libavformat/omadec.c(decrypt_init,rprobe,nprobe,read_packet): the key ring sizes and checks, the key derivation and the DES-CBC packets. - FFmpeg
libavformat/omadec.c,leaf_tableand its use indecrypt_init(SHA-256 37533c91c5516d09a0a036761ed8045a9e53b0a4091befc31ebe18bd780d105d; LGPL-2.1-or-later): the built-in key table and the order in which keys are tried. - FFmpeg
libavutil/des.c: the DES and triple-DES routines the demuxer calls (the explorer’s version checked against the test vector 133457799BBCDFF1 and against OpenSSL). - The three SonicStage files in samples/oma were read: their key rings parse as above, and the one with encryption id 1 (03-Exdous.oma, ATRAC3plus) carries a key ring.