KOPYA

KopyaSecurity

How Kopya’s encryption works

What happens to your password, your files and their names before anything leaves your device, what our server ends up holding, and where the limits are. Every value in the diagrams comes from our published test vectors, so you can check it yourself.

Format
version 1 argon2id-v1
Updated
30 October 2026
Independent audit
not yet (see limits)
Check it
spec · test vectors · verify

01 your password

Your password becomes two separate keys

When you sign in, your browser runs your password through Argon2id, a function built to be slow and memory-hungry, so every guess costs an attacker real time and memory. The result is split into two keys that have nothing in common: one proves to our server that it is you, the other locks your master key and never leaves your device.

You see
The sign-in form. Nothing changes for you.
Leaves your device
The sign-in key (auth_key). It cannot be turned back into your password or into the other key.
Our server holds
Your salt and a password hash of the sign-in key. Never your password, never the KEK.
Details
  • Password: Unicode NFKC normalisation, then UTF-8.
  • Argon2id (v1.3): 64 MiB memory, 3 iterations, parallelism 1, a 16-byte random salt per account, 32-byte output (secret).
  • auth_key = HKDF-SHA256(secret, salt empty, info "upload/auth/v1", 32), sent at sign-in; the server compares it with a stored password_hash.
  • KEK = HKDF-SHA256(secret, salt empty, info "upload/kek/v1", 32), kept on the device.
  • Accounts made before Argon2id used PBKDF2-SHA256 with 600 000 iterations and are moved to Argon2id at their next sign-in.
  • Anyone holding the sign-in key could test password guesses against it, like with any password check. Argon2id is what makes each of those guesses expensive.
key derivationtest vector
passwordcorrect horse battery staple
Argon2id · 64 MiB · 3 passes · salt 00010203…0e0f
secret0d1a3c6523c8f06e4e0af9c515aa5b5448cfebd6838f2d52c3d8b6ef8ddc3c2e
HKDF-SHA256, two different labels
auth_key sentaddc6f4b0e9cbf1bce3264694279b5fec1750a1a759d55e00a96d59878777213
KEK stays here734e7f46dcdf5b9e4b17d6ea5f0500688c0342233b152a2e08040ac230fc694e
Made-up password from the test vectors. The Argon2id output is shown as published; your browser has no built-in Argon2id, so this page doesn’t recompute it. The HKDF split is recomputed when JavaScript is on.

02 master key and recovery key

One master key, locked twice

When you create your account, your device makes a random master key. It protects everything else. It is uploaded only in locked form: once locked with your KEK, and once with a recovery key that is shown to you a single time. Either one opens it. We have neither.

That has a hard consequence, and it is deliberate: if you forget your password and lose your recovery key, nobody can open your files, including us. We can only let you start again with an empty drive.

You see
Your recovery key, once, when the account is made. Keep it somewhere safe.
Leaves your device
Two locked copies of the master key.
Our server holds
Those two locked copies, and no key that opens either of them.
Details
  • Master key: 32 random bytes (AES-256-GCM).
  • wrapped_master = b64(iv ‖ AES-GCM(KEK, master)), no AAD.
  • Recovery key: 32 random bytes, shown as 8 groups of 8 hex characters. wrapped_master_recovery = b64(iv ‖ AES-GCM(recovery_key, master)).
  • In the web app the opened master key is kept in the browser as a non-extractable key; page scripts can use it but cannot read its bytes.
  • Changing your password re-locks the same master key with a new KEK. Your files are not re-encrypted.
key wrappingtest vector
master key202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f
sealed with AES-256-GCM, twice
with the KEK storedZGVmZ2hpamtsbW5vTlsIP43kY11E8+ARndfKDgfFkqp9Ydz9donkzjA9OD/gmp89CDs90yymoIBIDptu
with the recovery key stored0tPU1dbX2Nna29zdKls43C23X160nn6RPhbPEjdf8AwxWZihfyMbbBZkaXwOA2sRGcUQq0hbPaPH9KFr
recovery key, as you’d write it downc8c9cacb-cccdcecf-d0d1d2d3-d4d5d6d7-d8d9dadb-dcdddedf-e0e1e2e3-e4e5e6e7
password+recovery key=no way back
Both locked copies from the test vectors open to the same master key. The bottom line is the trade-off: without either key, the copies stay locked for good.

03 a file is locked

Every file gets its own key, and is sealed in chunks

Each file gets a fresh random file key, which is itself locked with your master key. The file is cut into 8 MiB chunks (16 MiB for files over 1 GB), and each chunk is sealed with AES-256-GCM under its own random IV. GCM adds a 16-byte tag: change a single bit and the chunk no longer opens.

Each seal also covers the chunk’s position and the total number of chunks. That information is never stored; your device fills it in while reading. So a server cannot hand chunks back in a different order, slip in a chunk from elsewhere, or quietly cut the end off a file: the seal fails and the app shows an error instead of wrong data.

You see
Your file, as it was.
Leaves your device
The sealed chunks, and the file key locked with your master key.
Our server holds
The sealed chunks, the locked file key, the chunk size and count, and the encrypted size.
Details
  • wrapped_key = b64(iv ‖ AES-GCM(master, file_key)). A file’s key never changes, so older versions stay readable.
  • chunk_i = iv[12] ‖ AES-GCM(file_key, iv, plaintext_i, AAD) ‖ tag[16]
  • AAD = u32be(i) ‖ u32be(n): the zero-based index and the total count, 4 bytes each, big-endian.
  • Each chunk is stored as its own object and is 28 bytes larger than its plaintext. An empty file has no chunks.
  • The encrypted size the server sees is the plaintext size plus 28 bytes per chunk, so it reveals the real size almost exactly.
seal and tampertest vector
AES-256-GCM · file key from the vectors · AAD 00000000 00000002
sealed, as the server stores ita0a1a2a3a4a5a6a7a8a9aaab9fea6a538dcbd742091620d2a9df5883817cd5bd891dea0385a12b1c0e67b39536443e8986f6e098

Opens to: Hello Kopya, chunk zero.

Chunk 0 of the test file. With JavaScript on, you can type your own text and tamper with the bytes; it is sealed in this page with a throwaway key and sent nowhere.Sealed in this page with a throwaway key. Nothing is sent anywhere. Flip a byte, and the tag check refuses the whole chunk.

Why chunks can’t be shuffled or cut

Here is a message cut into three tiny chunks, each sealed with its position and the count. Play the dishonest server: swap two chunks, or drop the last one and claim the file only ever had two. Your device rebuilds each position itself and checks every seal.

  1. chunk 0“Delete ”sealed for 0 of 3
  2. chunk 1“the drafts, keep ”sealed for 1 of 3
  3. chunk 2“the backups.”sealed for 2 of 3

your device reads 3 chunks

  1. position 0 · AAD 00000000 00000003opens
  2. position 1 · AAD 00000001 00000003opens
  3. position 2 · AAD 00000002 00000003opens

without the position check you would getDelete the drafts, keep the backups.

All three seals check out: the file is shown.

04 names, notes and thumbnails

The labels are sealed too

A file name can say as much as the file. So the name, type, size and date of every file, the name of every folder, and the title and text of every note are packed into a small JSON record and sealed with your master key. Thumbnails are made on your device and sealed with the file’s own key, marked as thumb so they can never be confused with a piece of the file.

You see
Names, previews, dates taken, notes.
Leaves your device
Each of them sealed, a few dozen bytes per name.
Our server holds
Sealed records and sealed thumbnails. The length of a sealed name follows the length of the name.
Details
  • File: meta = b64(iv ‖ AES-GCM(master, utf8(JSON))) with {"name","mime","size","mtime"}, plus an optional "taken" date for photos.
  • Folder: {"name"}. Note: {"name": title} in meta, and the text as {"t": …} sealed the same way in a separate field.
  • Thumbnail: WebP or JPEG, at most 400 px, sealed with the file key and the ASCII AAD thumb.
  • No padding is added, so the server can tell a short name from a long one.
metadatatest vector
what your device knows{"name":"Holiday 2025.jpg", "mime":"image/jpeg", "size":4403, "mtime":1727778000000}
AES-256-GCM with the master key
what the server stores metaeHl6e3x9fn+AgYKDAmgLQecW8mOvKcVznkmTIoF2mUz74dl6KJr7f/me7Yr6tkzxNaBKPIYpRTq2osAucmWKAyIYzgeYNpgGWxnpmf0xh5so8m6pWLnfZMrH1d5EUnXpz4UCMqieY83VeRKcgw==
a thumbnail AAD “thumb”vr/AwcLDxMXGx8jJCOTgmaDP0SDe7/dXc0cvOiyWskcNWioYheTYRAVfrEVPSNGH
The record for a photo called “Holiday 2025.jpg”, from the test vectors. 81 bytes of JSON become 109 sealed bytes.

05 what the server stores and sees

What our server has, line by line

Zero-knowledge doesn’t mean we see nothing. We can’t read what you store, but a working drive needs some structure, and a website sees connections. This is the full list, and it matches our privacy policy.

What Kopya’s server stores, and whether we can read it
WhatWhat the server hasCan we read it?
File contentsSealed chunksNo
File and folder names, file typesSealed recordsNo
Thumbnails and previewsSealed thumbnailsNo
NotesSealed titles and textNo
Your password and keysPassword hash of the sign-in key; master and file keys only in locked formNo
Folder layoutWhich item sits in which folder (by random id)Yes
File sizesEncrypted size, about the real size plus 28 bytes per 8 MiBYes
DatesWhen items were created, changed and deletedYes
Your accountEmail address, plan, settings, sign-in times and devicesYes
TrafficWhen you upload and download, and how muchYes
IP addressesKept briefly, for rate limiting and abuse protectionYes
Support messagesWhat you write to usYes

06 sharing

A share link carries its own key

Sharing makes a new random share key, and the file’s key is locked again under it. The share key travels in the link, after the #. Browsers never send that part to a server, so we receive the link’s address but not its key.

Add a password and the link has no key in it at all: the share key is locked with a key derived from the password, which the recipient’s browser works out. Sharing a folder takes a snapshot: your browser locks each file in it for the share, and files added later appear only when you update the share.

You see
A link to send.
Leaves your device
The file key and name, locked with the share key. For password links, a verifier derived from the password.
Our server holds
Those locked copies, and for password links a hash of the verifier. Never the share key.
Details
  • Share key K: 32 random bytes; link /s/<id>#k=b64url(K).
  • wrapped_key = b64(seal(K, file_key)), meta = b64(seal(K, {name, mime, size})), and a copy of K sealed with your master key so you can show the link again.
  • Password links: PBKDF2-SHA256(password, salt, 600 000), then HKDF with upload/share-verify/v1 (the verifier, sent) and upload/share-wrap/v1 (the key that opens K, kept). Wrong guesses are rate limited.
  • Anyone with the full link can open the share, and so can anything that sees the full link, such as a chat app that previews it. Treat a link like the file itself.
share linktest vector
app.kopya.uk/s/<id>#k=WltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHk
file key, locked with the share key stored6+zt7u/w8fLz9PX2vU5ChV+tNkE3PoUnLtASBEJS/ERJLkngMhZPXPThgps10dGx1kZayTFHrPjdn0n8
The share key from the test vectors, as it appears in a link. Only the part before # is ever requested from our server.

07 sessions and two-factor sign-in

Guarding the door to the account

Encryption protects your files from us. These protect your account from other people. You can switch on two-factor sign-in with an authenticator app (TOTP), with one-time backup codes. If you choose to trust a computer, it skips only the code for 30 days, never the password. Repeated wrong passwords and codes are slowed down and then blocked.

You see
Your password, and a six-digit code if two-factor sign-in is on.
Leaves your device
The sign-in key and the code, then a random session token with each request.
Our server holds
A hash of each session token, your authenticator secret (encrypted), and hashes of your backup codes.
Details
  • TOTP per RFC 6238: 6 digits, 30-second steps; a code can’t be used twice.
  • The authenticator secret has to be readable by the server to check codes, so it is encrypted with a server key rather than your keys.
  • “Remember this computer” stores a 30-day token in that browser. It is cancelled when you change your password, turn two-factor sign-in off or reset with your recovery key.
  • Session tokens are random 32-byte values, stored only as hashes. You can see your sessions and sign them out in Settings.
sign-intwo checks
  1. 1Something you knowpassword → sign-in key
  2. 2Something you have6-digit code or backup code
Signing in never sends your password. Two-factor sign-in is optional and can be switched on in Settings.

08 limits and trust

What this does not protect, in plain words

We would rather you hear this from us.

  1. We still see some things

    File sizes, dates, how your folders are nested, your email, sign-in times, how much you upload and download, and, kept briefly, the IP addresses requests come from. The table above has the full list.

  2. You trust the code we serve

    The web app is code sent by our server each time you open it. If our server were compromised, it could in principle send altered code that leaks your keys. The desktop app and the Android app reduce this risk, because their code is installed once rather than loaded on every visit, but they do not remove it: you still trust us to build them honestly.

  3. No independent audit yet

    Kopya has not been audited by an outside security firm. The format on this page is published so that anyone can review it, and we welcome that. Write to support@kopya.uk.

  4. Lost password + lost recovery key = lost files

    We cannot reset your way back in. If both are gone, your files cannot be recovered by anyone.

  5. Not open source

    Our source code is not published. You can still read every line of the web app’s code in your browser’s developer tools, because that is the code that runs.

  6. Your device is part of the system

    Malware on your computer or phone, or a browser extension with access to the page, can see what you see. Encryption can’t help once data is open on screen.

09 the published format

The format, byte for byte

Everything above, precisely. The same text is available as a file: kopya-crypto-format.md (9.5 KB).

Kopya encryption format · version 1 · 30 October 2026

How Kopya clients encrypt files, names, notes, thumbnails and keys before anything is uploaded, and what the server receives. Every format has a worked example in crypto-vectors.json. Kopya has not been independently audited yet; if you find a mistake here or a weakness in the design, please write to support@kopya.uk.

0. Notation

  • ‖ joins byte strings (|| in the text file).
  • b64 is standard base64 with padding, used for every value the server stores. b64url is URL-safe base64 without padding, used only in share-link fragments.
  • utf8(x) is the UTF-8 encoding of the text x.
  • All symmetric encryption is AES-256-GCM with a 12-byte random IV and a 16-byte tag appended to the ciphertext. An IV is never reused with the same key.
  • Random values come from the platform’s cryptographic random generator (crypto.getRandomValues in browsers).

1. Sealed blob

Every wrapped key, every piece of metadata and every note uses the same layout:

sealed = iv[12] ‖ ciphertext ‖ tag[16]

seal(key, plaintext, aad) encrypts with a fresh random IV and returns sealed. There is no additional authenticated data (AAD) unless a section says otherwise. A sealed value is 28 bytes longer than its plaintext.

2. Account keys

StepDefinition
Passwordutf8(password.normalize('NFKC'))
Key derivation (current, argon2id-v1)Argon2id (version 0x13), memory 65536 KiB (64 MiB), 3 iterations, parallelism 1, 16-byte random salt per account, 32-byte output, called secret
Key derivation (older accounts, pbkdf2-sha256)PBKDF2-HMAC-SHA256, 600 000 iterations, 32-byte output. These accounts are moved to Argon2id at their next sign-in
SplitHKDF-SHA256(secret, salt = empty, info, length 32). auth_key uses info upload/auth/v1; KEK uses info upload/kek/v1
Master key32 random bytes, made on the device when the account is created
Wrapped master keywrapped_master = b64(seal(KEK, master_key))
Recovery key32 random bytes, shown once as 8 groups of 8 lowercase hex characters joined with -
Recovery copywrapped_master_recovery = b64(seal(recovery_key, master_key))

The upload/ prefix in the HKDF labels is historical (the project’s working name). It is part of the format and does not change.

Signing in:

  1. The client asks the server for the account’s key-derivation settings: the method, the salt and, for PBKDF2, the iteration count.
  2. The client derives secret, then auth_key and KEK.
  3. The client sends only b64(auth_key). The server compares it with a password hash of auth_key (PHP password_hash) and, if it matches, returns a session token and wrapped_master.
  4. The client opens wrapped_master with KEK. KEK, the master key and the password never leave the device.

With two-factor sign-in on, the server first answers that a code is required; the client repeats step 3 with a 6-digit TOTP code (RFC 6238, 30-second steps) or a one-time backup code.

The server stores the salt and method, password_hash(auth_key), wrapped_master and wrapped_master_recovery. It cannot open either wrapped copy. If the password and the recovery key are both lost, the master key cannot be recovered by anyone, and neither can anything encrypted under it. Changing the password re-wraps the same master key under a new KEK; files are not re-encrypted. Recovering with the recovery key does the same.

3. Files, folders and notes

File key. Each file has its own random 32-byte key: wrapped_key = b64(seal(master_key, file_key)). The file key never changes for the life of the file, so older versions stay readable with it.

Metadata. meta = b64(seal(master_key, utf8(JSON))), for files, folders and notes:

  • file: {"name": "...", "mime": "...", "size": <plaintext bytes>, "mtime": <ms since epoch>} and, for photos (jpg, jpeg, png, webp), optionally "taken": <ms since epoch>, the EXIF date taken (0 = checked, no date; absent = not checked yet).
  • folder: {"name": "..."}
  • note: {"name": "<title>"}, with the text stored separately as content = b64(seal(master_key, utf8('{"t": "<text>"}'))).

Clients keep fields they do not recognise when they rewrite metadata.

Content. The plaintext is split into chunks of chunk_size bytes. The web client uses 8 MiB (8 388 608 bytes) chunks, and 16 MiB chunks for files larger than 1 GiB; the last chunk is shorter, and an empty file has no chunks. Readers must always use the chunk_size stored with the file. Each chunk is stored as its own object:

chunk_i = iv[12] ‖ AES-256-GCM(file_key, iv, plaintext_i, aad = u32be(i) ‖ u32be(n)) ‖ tag[16]

where i is the zero-based chunk index and n the total number of chunks (4 + 4 bytes, big-endian). The AAD is not stored; the reader rebuilds it from the position it is reading and the chunk count. Because position and count are part of every tag:

  • a chunk moved to another position fails its tag check;
  • a chunk from another file fails (different key);
  • cutting chunks off the end is noticed: if the server also lowers the chunk count it reports, every remaining chunk fails, because each was sealed with the real count; if it does not, the reader finds chunks missing. (The plaintext size is also inside the sealed metadata.)

The size the server records for a file is the sum of the encrypted chunk sizes (plaintext + 28 bytes per chunk), so it reveals the plaintext size to within that overhead.

Thumbnail. Images and videos get a small preview (WebP or JPEG, at most 400 px on the long side), made on the device and sealed with the file key and the ASCII AAD thumb:

thumb = iv[12] ‖ AES-256-GCM(file_key, iv, image_bytes, aad = "thumb") ‖ tag[16]

The different AAD means a thumbnail can never be passed off as a content chunk, or the other way round.

4. Shares

Share key. A share has its own random 32-byte key K. The link is

https://app.kopya.uk/s/<share_id>#k=<b64url(K)>

Browsers do not send the part after # to the server, so the server never receives K.

  • share.meta = b64(seal(K, utf8(JSON {name, mime, size})))
  • file shares: wrapped_key = b64(seal(K, file_key))
  • wrapped_sharekey_owner = b64(seal(master_key, K)), so the owner can show the link again.

Password-protected shares. The link has no #k= part. Instead:

secret   = PBKDF2-HMAC-SHA256(utf8(password.normalize('NFKC')), salt, 600000, 32)
verifier = HKDF-SHA256(secret, salt = empty, info "upload/share-verify/v1", 32)
wrapKey  = HKDF-SHA256(secret, salt = empty, info "upload/share-wrap/v1", 32)
wrapped_sharekey_pw = b64(seal(wrapKey, K))

The visitor’s browser sends b64(verifier). The server stores only a hash of the verifier and returns wrapped_sharekey_pw when it matches; the browser opens it with wrapKey. Attempts are rate limited.

Folder shares are snapshots. The owner’s browser seals each item for the share: {node_id, meta: b64(seal(K, ...)), wrapped_key: b64(seal(K, file_key))}. Files added to the folder later are not visible through the link until the owner updates the share.

5. What the server stores

Per account: email address, key-derivation method and salt, password_hash(auth_key), wrapped_master, wrapped_master_recovery, plan and settings, sign-in sessions (a hash of each random session token), and, if two-factor sign-in is on, the TOTP secret (encrypted at rest with a server key, because the server has to check the codes).

Per node: an id, the parent folder’s id, the type (file, folder or note), meta, content (notes), wrapped_key, the encrypted size, chunk_size, chunk count, whether a thumbnail exists, and created, changed and deleted timestamps.

Content chunks and thumbnails are stored as separate objects in EU object storage, under u<user_id>/<blob_id>/<chunk_index | thumb>. Browsers upload and download them directly with short-lived signed addresses. When an upload finishes, the server checks that every chunk is present with the expected size before the file is listed.

The server allows duplicate names in one folder and names that some operating systems cannot use, because it cannot read names; they only mean something after decryption.

6. Rules for any implementation

  • Never log, store or send in plaintext the password, secret, auth_key (other than sending it at sign-in), KEK, the master key, file keys, share keys or the recovery key.
  • Never reuse an IV with the same key; use a fresh random IV for every seal.
  • Always check the GCM tag, and treat a failed check as an error, never as data.
  • Build the chunk AAD yourself from the position being read and the file’s chunk count, and never use a chunk whose tag check fails for that position.
  • Do not trust server-provided sizes for memory allocation: reject a chunk_size above 64 MiB and any chunk larger than chunk_size + 28 bytes.

7. Changes

  • 2026-10-30: first public version of this document.

10 test vectors

Test vectors

Fixed inputs and the exact outputs of every format above. All values are public, made-up test data that belong to no account. They were generated by running our web client’s encryption code with fixed inputs, then checked independently with PHP/OpenSSL and libsodium.

11 verify it yourself

Check the vectors yourself

Two ways, both using standard cryptography that has nothing to do with us.

In this browser

Fetches crypto-vectors.json and checks every AES-GCM, HKDF and PBKDF2 vector with your browser’s own WebCrypto. Argon2id is skipped: browsers don’t include it, and this page loads no outside code.

This needs JavaScript. The Node.js script below does the same on your own computer.

    This shows that the published vectors match the published format, using your browser’s crypto. It does not prove that the app runs identical code: for that, read the app’s code in your browser’s developer tools.

    With Node.js

    Save verify-vectors.js next to crypto-vectors.json and run node verify-vectors.js (Node.js 16 or newer, built-in node:crypto only). It recomputes the HKDF split and opens the master key, file key, metadata, both chunks with their AAD, and the thumbnail.

    // Check Kopya's published crypto test vectors with Node.js's built-in crypto (no packages).
    // Usage: node verify-vectors.js [crypto-vectors.json]      Needs Node.js 16 or newer.
    // Spec: https://kopya.uk/security#spec
    'use strict';
    const crypto = require('node:crypto');
    const fs = require('node:fs');
    
    const v = JSON.parse(fs.readFileSync(process.argv[2] || 'crypto-vectors.json', 'utf8'));
    const hex = (s) => Buffer.from(s, 'hex');
    const b64 = (s) => Buffer.from(s, 'base64');
    let failed = 0;
    const check = (name, ok) => { console.log((ok ? 'PASS  ' : 'FAIL  ') + name); if (!ok) failed++; };
    
    // HKDF-SHA256, empty salt, 32 bytes
    const hkdf = (secret, info) => Buffer.from(crypto.hkdfSync('sha256', secret, Buffer.alloc(0), info, 32));
    
    // sealed = iv[12] || ciphertext || tag[16]; returns null when the tag check fails
    function open(key, sealed, aad) {
      try {
        const d = crypto.createDecipheriv('aes-256-gcm', key, sealed.subarray(0, 12));
        if (aad) d.setAAD(aad);
        d.setAuthTag(sealed.subarray(sealed.length - 16));
        return Buffer.concat([d.update(sealed.subarray(12, sealed.length - 16)), d.final()]);
      } catch (e) { return null; }
    }
    const same = (a, b) => a !== null && Buffer.compare(a, b) === 0;
    
    // chunk AAD = 4-byte big-endian index || 4-byte big-endian total chunk count
    function chunkAad(index, count) {
      const a = Buffer.alloc(8);
      a.writeUInt32BE(index, 0);
      a.writeUInt32BE(count, 4);
      return a;
    }
    
    // 1. the password split: secret -> auth_key (sent at sign-in) and KEK (never leaves the device)
    const a = v.kdf_argon2id;
    const kek = hkdf(hex(a.secret_hex), 'upload/kek/v1');
    check('HKDF auth_key', hkdf(hex(a.secret_hex), 'upload/auth/v1').toString('base64') === a.auth_key_b64);
    check('HKDF KEK', kek.toString('hex') === a.kek_hex);
    
    // 2. the master key, the file key, and the metadata sealed with the master key
    const master = open(kek, b64(v.wrapped_master.wrapped_b64));
    check('master key opened with the KEK', same(master, hex(v.wrapped_master.master_key_hex)));
    const fileKey = open(master, b64(v.file_key.wrapped_key_b64));
    check('file key opened with the master key', same(fileKey, hex(v.file_key.file_key_hex)));
    check('metadata', same(open(master, b64(v.node_meta.meta_b64)), Buffer.from(v.node_meta.plaintext_json)));
    
    // 3. content chunks: each one only opens at its own position, with the right total count
    const n = v.chunks.chunk_count;
    for (const c of v.chunks.items) {
      check('chunk ' + c.index, same(open(fileKey, b64(c.ciphertext_b64), chunkAad(c.index, n)), Buffer.from(c.plaintext_utf8)));
    }
    const first = b64(v.chunks.items[0].ciphertext_b64);
    check('chunk 0 refused at position 1', open(fileKey, first, chunkAad(1, n)) === null);
    check('chunk 0 refused when the count is cut to 1', open(fileKey, first, chunkAad(0, 1)) === null);
    
    // 4. thumbnails use the AAD "thumb"
    check('thumbnail', same(open(fileKey, b64(v.thumbnail.ciphertext_b64), Buffer.from('thumb')), hex(v.thumbnail.plaintext_hex)));
    
    // 5. older accounts: PBKDF2-SHA256, 600 000 iterations (takes a moment)
    const p = v.kdf_pbkdf2_legacy;
    const pSecret = crypto.pbkdf2Sync(Buffer.from(p.password_utf8.normalize('NFKC')), b64(p.salt_b64), p.iterations, 32, 'sha256');
    check('PBKDF2 secret', pSecret.toString('hex') === p.secret_hex);
    
    console.log(failed ? failed + ' check(s) failed' : 'all checks passed');
    console.log('Argon2id is not in node:crypto. Check the secret with an Argon2 library, e.g. PHP with sodium:');
    console.log("  php -r \"echo bin2hex(sodium_crypto_pwhash(32, 'correct horse battery staple', hex2bin('000102030405060708090a0b0c0d0e0f'), 3, 67108864, SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13));\"");
    console.log('  expected ' + a.secret_hex);
    process.exit(failed ? 1 : 0);

    Argon2id isn’t in Node’s built-in crypto. With PHP and its sodium extension:

    php -r "echo bin2hex(sodium_crypto_pwhash(32, 'correct horse battery staple', hex2bin('000102030405060708090a0b0c0d0e0f'), 3, 67108864, SODIUM_CRYPTO_PWHASH_ALG_ARGON2ID13)), PHP_EOL;"

    It should print 0d1a3c6523c8f06e4e0af9c515aa5b5448cfebd6838f2d52c3d8b6ef8ddc3c2e. Python users can use argon2-cffi (see the README).

    Found a security problem?

    Please tell us at support@kopya.uk before making it public, and we’ll work with you on a fix. Our security.txt has the same details.