Petersaint › Security design

Petersaint security design

Keys, ciphers, limits and trade-offs · Johannson Limited

Applies to Petersaint 1.2 for iOS 16.4+Revised 24 November 2026 (v4)Author: Jon Hurdle
In one paragraph

Every file gets its own random 256-bit key and is encrypted with AES-256-GCM in 1 MiB chunks. Those file keys are wrapped by a random vault key, and the vault key is encrypted to a P-256 private key that lives in the iPhone's Secure Enclave and can't be exported. Your pattern is never used to make a key. The app checks it against an Argon2id hash, and only then asks the Secure Enclave to unwrap the vault key. That check is done by the app's code: the Secure Enclave doesn't know your pattern. While the vault is open, the unwrapped vault key is in the app's memory. Deleting the Secure Enclave key makes the vault key impossible to unwrap, which is how a wipe works. There's no server and no account, the pattern can't be reset, and the vault is kept out of device backups. Since 1.2 you can export an encrypted backup file: the vault key is sealed to an X25519 key derived from a 12-word recovery phrase that the phone doesn't keep.

Download as PDF

This page is written for people who want to check our work. Every parameter below is taken from the app's source and build specification, not from marketing copy. Weaknesses are in section 13.

  1. Threat model
  2. Key hierarchy
  3. Algorithms and parameters
  4. File format
  5. Pattern verification
  6. Attempt limits and delays
  7. Wipe (crypto-shred)
  8. Duress pattern
  9. Share extension
  10. Storage, metadata and device backups
  11. Encrypted backup
  12. Memory, screen and clipboard
  13. Known limitations
  14. Code review
  15. Design choices compared

01Threat model

iOS Data Protection already encrypts the phone's files, and most of them are unreadable while the phone is locked. Petersaint is a second layer with its own keys, aimed at the time when the phone is unlocked. Three kinds of attacker need separating:

AttackerWhat stops them
Uses the phone's normal screensThe pattern, the attempt limit and the waits. All of these are enforced by the app's code, running inside the iOS sandbox.
Has a copy of the files (device extraction, a backup)Encryption. The vault key can only be unwrapped by this phone's Secure Enclave, so the files alone aren't enough. See the pattern-hash limit in section 13.
Can run code inside the app, or a jailbroken phoneNothing in Petersaint. Such code can call the same Secure Enclave operation the app calls, without knowing the pattern. Out of scope.
In scopeOut of scope
Someone holding your unlocked iPhone: a partner, a colleague, a thief who saw your passcodeMalware on a jailbroken phone reading memory while the vault is open
Copying the app's files off the device, or out of a backup, and reading them elsewhereA camera filming your screen while you draw the pattern
Guessing the pattern on the phoneCode running in the app's process, through an iOS or app vulnerability; code signed by our developer team (see section 9)

One thing the design deliberately allows: with an attempt limit set, anyone holding the phone can destroy the vault by drawing wrong patterns. They can't read it, but they can make sure you can't either. Self-destruct is off by default since version 1.1.3; leaving it off avoids this.

The app makes no network connections of its own and has no server. The App Store privacy label is "Data Not Collected".

02Key hierarchy

Petersaint key hierarchy The Secure Enclave key wraps the vault key with ECIES. The vault key wraps each file key, the index key and the share inbox private key with AES-GCM. The pattern is checked separately against an Argon2id hash and is not part of the key chain. Secure Enclave key (SEK) P-256 · never leaves the chip ECIES wrap (cofactor X9.63, SHA-256, AES-GCM) Vault key (VK) 256-bit random · Keychain (wrapped) Pattern Argon2id check gate AES-GCM wraps File keys (FK) one per file · 256-bit Index key (IK) 256-bit Inbox private key P-256 · share inbox blobs/<uuid>.enc thumbs/<uuid>.enc index.enc opens pending/ shares
Solid lines are key wrapping. The dashed line is a gate, not a derivation: the pattern decides whether the app asks the Secure Enclave to unwrap the vault key. It never contributes key material.

Secure Enclave key. A P-256 private key created with kSecAttrTokenIDSecureEnclave, access control .privateKeyUsage, accessibility WhenUnlockedThisDeviceOnly. iOS will use it only while the phone is unlocked, and the private key can't be exported, synced or restored to another device. No user-presence or application-password constraint is attached, so the Secure Enclave doesn't check the pattern. The app does that before it asks.

Vault key. 256 random bits, generated once at set-up. It's stored only in wrapped form, encrypted to the SEK's public key with eciesEncryptionCofactorX963SHA256AESGCM. Unwrapping needs this phone's Secure Enclave. Once unwrapped, the 256-bit vault key is ordinary app memory until the vault locks; the Secure Enclave protects the wrapping key, not the keys it releases.

File keys. Each item gets its own random 256-bit key, wrapped by the vault key with AES-GCM. The wrap's additional authenticated data includes the item's UUID, so a wrapped key can't be moved onto a different item.

Index key. A random 256-bit key, wrapped by the vault key and kept in the Keychain. It encrypts the index (file names, types, sizes, dates, folders and the wrapped file keys).

All Keychain items use kSecAttrAccessibleWhenUnlockedThisDeviceOnly, are not synchronisable, and since v1.0 build 2 are pinned to the app's own Keychain access group.

03Algorithms and parameters

PurposeAlgorithm and parameters
File contentsAES-256-GCM, 1 MiB chunks, fresh 96-bit random nonce per chunk, 128-bit tag
IndexSame chunked AES-256-GCM, under the index key
ThumbnailsEncrypted JPEG, same chunked format, under a key derived from the file key with HKDF-SHA256 and its own label, so a thumbnail can't stand in for its file
File key wrapAES-256-GCM under the vault key, AAD bound to item UUID
Vault key wrapECIES, P-256 Secure Enclave key, cofactor ECDH, X9.63 KDF with SHA-256, AES-GCM
Pattern checkArgon2id (v1.3) via libsodium crypto_pwhash: 64 MiB memory, 3 passes, 1 lane, 32-byte output, fresh 16-byte salt every time a pattern is set, constant-time compare. Stored record: salt ‖ hash (48 bytes), plus one grid byte for 3×6
Recovery phrase (1.2)128 bits from SecRandomCopyBytes, encoded as 12 words with the standard BIP-39 English wordlist and checksum. The bundled wordlist's SHA-256 is checked at load
Recovery key (1.2)HKDF-SHA256 over the 128 bits, with Petersaint's own salt and info, to an X25519 private key. Not BIP-39's PBKDF2 seed, so it shares nothing with a wallet made from the same words
Backup key block (1.2)Fresh ephemeral X25519 key per export, ECDH with the recovery public key, HKDF-SHA256 (salt = ephemeral ‖ recipient public keys), AES-256-GCM over the vault key with the file header as AAD
Share inboxEphemeral P-256 ECDH per file, HKDF-SHA256, 64-byte output split into a metadata key and a content key
RandomnessCryptoKit SymmetricKey(size: .bits256) (system CSPRNG) for keys; libsodium randombytes_buf for salts
LibrariesApple CryptoKit and Security framework; swift-sodium pinned to exactly 0.9.1 (libsodium 1.0.18) for Argon2id. No other third-party code.

The building blocks are standard and come from Apple's frameworks and libsodium. The way they're put together (key hierarchy, file format, share inbox, pattern and duress logic) is Petersaint's own and hasn't had a paid independent audit.

04File format

Every encrypted file (blob, thumbnail, index) shares one chunked format:

header   = magic ‖ version ‖ chunkSize (u32, BE) ‖ chunkCount (u64, BE)
chunk[i] = nonce (12) ‖ ciphertext ‖ tag (16)
AAD[i]   = header ‖ itemUUID ‖ i

05Pattern verification

The pattern is a gate, not a key. Drawing it does three things, in order:

  1. Increment and save the wrong-attempt counter in the Keychain, before any hashing starts.
  2. Hash the drawn pattern with Argon2id and the stored salt, and compare in constant time (sodium_memcmp).
  3. Only on a match: reset the counter, ask the Secure Enclave to unwrap the vault key, then unwrap the index key and load the index.

Input. The ordered point indices as ASCII joined by hyphens, e.g. 0-1-2-5-8, prefixed 3x6: on the tall grid, so the two grids can never produce the same input.

Grids. 3×3 (minimum 4 points) or, from v1.1, 3×6 (minimum 6 points). One continuous drag, no point reused; a straight line through an unvisited point collects it. A 3×3 grid with at least 4 points allows 389,112 patterns. Real people choose far fewer of them, so treat that as a ceiling. 3×6 allows many more; we haven't published a count. The grid is recorded as one byte at the end of the stored hash, so 3×3 records are byte-for-byte what v1.0 wrote.

Reduced feedback while drawing. By default the trail isn't drawn, points don't light up, and there are no haptics or sounds that would reveal how many points were drawn. None of this stops someone watching your finger. A half-drawn pattern is discarded if the app goes inactive mid-draw (v1.1).

Why not derive the key from the pattern? Because the pattern space is small. A key derived from it can be attacked offline by anyone with a copy of the files, at whatever speed their hardware allows. Here a copy of the files is useless without this phone's Secure Enclave. The cost of that choice is in section 13.

06Attempt limits and delays

SettingBehaviour
Self-destruct: 3, 5 or 10Opt-in. The Nth consecutive wrong pattern destroys the key. Vaults created before 1.1.3 keep their stored limit, which was 5 unless changed
Single-strikeLimit of 1, behind a bold warning
Never (default for new vaults since 1.1.3)The key is never destroyed by wrong patterns; waits keep growing instead. Shown in Settings as Self-destruct: Never
Delays0, 0, 2 s, 10 s, 30 s before each attempt. With self-destruct off (the default since 1.1.3), then 1, 2, 5, 10, 30 min, then 1 hour per attempt
CounterIn the Keychain, not UserDefaults. Reset only by a correct pattern; never by restart, time or app update

Like the pattern check, the limit and the waits are enforced by the app's code, not by hardware. They hold against someone using the phone's screens, not against code running inside the app. Each attempt is counted and saved before hashing starts, and attempts are handled one at a time.

Clock changes. Each delay is recorded against both the wall clock and the phone's time since start-up, which keeps counting during sleep and can't be changed in Settings. A delay ends only when both agree. After a restart, the full delay for that step starts again. In testing, moving the clock forward or back doesn't shorten it.

Reinstalling doesn't reset anything usefully: a fresh install goes to set-up, and set-up deletes the old Secure Enclave key and Keychain items first.

07Wipe (crypto-shred)

A wipe destroys keys, not files. Order matters:

  1. Delete the Secure Enclave key. Once that succeeds, the stored vault key can't be unwrapped anywhere, so the files on disk can't be decrypted.
  2. Delete every Keychain item the app holds: the wrapped keys, the pattern and duress hashes, and the attempt counter.
  3. Zero the in-memory keys and drop the decrypted index.
  4. Rename the vault folder, then delete it on a background queue.

Each step runs even if an earlier one fails, and nothing is logged. Steps 1 and 2 together mean no wrapped key survives unless both deletions fail. The wipe can't undo anything captured earlier: a vault key read out of memory, a file someone exported or screenshotted, or a copy taken while the vault was open. Triggers: the attempt limit, the duress pattern, or "Destroy vault" in Settings (which asks for the real pattern). Not triggers: restart, app or iOS update, low storage, time passing.

We say "the key is destroyed, making the files unrecoverable". We don't say "securely erased": flash storage gives no such guarantee for the ciphertext, which is exactly why the design relies on destroying the key.

08Duress pattern (Pro)

For personal safety: if someone is pressuring you to open the vault, a second pattern you set in advance destroys the real vault and opens an empty one, as if freshly installed.

It's a destructive alternative unlock, not a guarantee of safety. An empty vault may itself raise questions, and the decoy isn't meant to defeat forensic examination. We don't claim it's undetectable.

09Share extension: add, never read

You can send files to Petersaint from other apps without opening the vault. By design the share extension holds only a public key: it can encrypt files to the vault but has nothing that decrypts.

Trust limit. The App Group is writable by any code signed by our developer team, and the design trusts that code. Something that could replace inbox.pub would receive files shared until the next unlock. Since v1.1 the app writes inbox.pub.sha256 beside it and the extension refuses to share if they disagree. That's a tamper and corruption check, not authentication: an attacker who can replace both files can redirect new shares to their own key.

10Storage, metadata and device backups

<App Group>/Library/Application Support/Vault/
  index.enc          encrypted index
  blobs/<uuid>.enc   encrypted files
  thumbs/<uuid>.enc  encrypted thumbnails
  inbox.pub          share inbox public key (+ .sha256)
  pending/           share-extension drop zone

11Encrypted backup (optional, since 1.2)

Backup is off until you turn it on. It adds one secret, a 12-word recovery phrase, and one file format. It adds no server, no account and no network code: the app still makes no connections, and a backup goes only where you save it.

Recovery phrase and key

The backup file (.psbackup)

PartContents
HeaderMagic PSBK, format version, fingerprint of the recovery public key, creation date. Plaintext
Key blockEphemeral X25519 public key, and the vault key sealed with AES-256-GCM under a key from HKDF over the ECDH secret. The header is the AAD, so it can't be changed
IndexThe wrapped index key and the encrypted index, byte for byte as stored on the phone
RecordsEach encrypted file and thumbnail, byte for byte, keeping its UUID. Nothing is decrypted to make a backup, and each file's own AAD still verifies after a restore
FooterItem count, total length and an unkeyed SHA-256 of everything before it, to catch truncation and damage early. Integrity comes from GCM, not from this hash

Export asks for your pattern, streams the file into a protected temporary folder that only ever holds ciphertext, and hands it to the iOS save sheet. The temporary copy is removed when the sheet closes, on lock, and at launch.

Restore

Handling the phrase on the phone

What backup changes about wipe and duress

A backup file is a full copy of the vault and outlives a wipe. Self-destruct, the duress pattern and "Destroy vault now" destroy the key on the phone; they can't reach a file you saved somewhere else. Both wipe paths also delete the recovery public key, so the empty vault looks like a fresh install with backup off. If a copy that survives a wipe is a risk for you, don't turn backup on, or keep the file somewhere only you control.

What a backup file shows without the phrase. Not contents, names, folders, types or dates of items. It does show: when the file was made and its total size; how many items it holds; each file's size, roughly each thumbnail's size, and which items have one; and the recovery key's fingerprint, so two files made with the same phrase can be linked. Hiding these would need a new format version.

12Memory, screen and clipboard

13Known limitations

Software-enforced gate. The pattern, attempt limit and waits are checked by Petersaint's code. Anyone who can run code inside the app on an unlocked phone can ask the Secure Enclave for the vault key without the pattern. That needs an iOS or app vulnerability or a jailbreak, but it's the boundary of what we protect.

No recovery without your own backup. Forget the pattern, or lose or replace the phone, and the files on it are gone. There is no reset and no support override. The only way back is a backup file you exported and its 12-word phrase (section 11). This is the price of keeping the only key on one device.

14Code review

On 19 October 2026, before release, the code was reviewed against 24 specific threats by a reviewer that had no part in writing it: an AI coding agent working in a fresh session, with the full source and spec. It ran the test suite, added failing tests to prove each finding, and inspected the Release binary for debug code.

It found no path for someone without the pattern to read vault contents. It reported ten findings, all about availability, the delay clock and defence in depth. Eight were fixed in v1.0 build 2 and 3; the other two (duress timing and the inbox key check) were fixed in v1.1. Its notes on residual risk are the basis for section 13.

On 21 November 2026 the 1.2 backup code (the phrase, the key block, the file format, restore, and the screens that show or accept the phrase) was reviewed in the same way against 26 threats. It found no way to open a backup file without the 12 words and no way for a restore to replace or half-build a vault. It reported no critical or high findings. Two medium findings (auto-lock stopping long exports and restores, and third-party keyboards seeing the phrase) and one low finding (a pasted phrase left on the clipboard) were fixed before release. One low finding, what a backup file shows without the phrase, is accepted for this format version and described in section 11.

That's internal evidence, not assurance. An AI review of 24 chosen threats isn't a paid third-party audit, and passing tests don't prove there are no undiscovered bugs. Some checks in it need a signed build on a real iPhone.

15Design choices compared

Vault apps make different trade-offs. None of these is wrong; they suit different people. This is where Petersaint stands.

ChoiceCommon alternativePetersaint
Where the key comes fromDerived from the PIN or pattern with PBKDF2 or similarRandom vault key, wrapped by a Secure Enclave key; pattern is a gate only
Key per fileOne master key for every fileA separate random key for every file
Pattern hashingPBKDF2 (CPU-hard)Argon2id, 64 MiB (memory-hard)
BackupAutomatic encrypted cloud backupOptional encrypted file you export and store yourself; the vault stays out of device backups
RecoveryRecovery phrase or account reset12-word recovery phrase with a backup file; no pattern reset and no account
Wrong guessesDelays or lockoutsGrowing delays, plus an optional key-destroying limit

A key derived from your PIN or pattern can be re-created on another phone, which makes backup and recovery easier to build. A Secure Enclave key can't leave the phone, and that's the point. Petersaint's backup works around that by sealing the vault key to a second key that only your 12 words can rebuild. If you want backups that happen automatically, a vault built around a cloud may suit you better.

Background reading: Apple Platform Security: the Secure Enclave, RFC 9106: Argon2, NIST SP 800-38D: GCM. For a plain-English version, see what "encrypted" really means.

Petersaint: every file encrypted with its own key, protected by your iPhone's Secure Enclave. No account, no cloud, no data collected.

Download on the App Store