On BPFS

I've been wanting to take my PicoCalc, and turn it into an post-apocalyptic exocortex and lightweight general environmental programming tool.

Well, I've handwritten one editor before, so it should be fairly straightforward.

Well, except one little problem.

My editors work on Unix systems, where my notes are written to an encrypted file system. On the picocalc, I would be writing plaintext to the SD card, and any old bandit could pull my SD card and find my weapons stashes. I also want to be able to associate notes with tags so I can do some queries, and those tags shouldn't be plaintext either.

There are complications too: with limited memory and processor power, I don't necessarily want to put everything in memory. Long story short, I built something that I'm calling [1] "BPFS" - the binary portable file system. Part of that is because of how the initial idea started out rather than where it ended up (more of a binary portable record system).

There are a few quirks:

  1. It generally appends records, including tombstones, rather than editing in place, because that seems to work better with SD cards. You can do the expensive cleanups and compactions later.
  2. It is heavily aimed at devices in the range of Cortex M4 to the RP2350. These are generally the devices I build handhelds on.
  3. The only records I need for now are strings and lists of strings.

The design doc is on git but generally it's a TLV system with encryptable records. The general implementation for ZoneBook [2] is:

  1. An encryption key, generated from a password, and its salt, are provisioned and stored in the PSRAM. This is used as a KEK [3].
  2. System commands that allow you to clear the key (and optionally, the salt for complete destruction).
  3. notebook.bpfs is the mapping of filename (a BPFS file) and an encryption key, secured with the KEK.
  4. tags.bpfs is the mapping of tags to filenames.

Like with the editor, I used AI to write a lot of it, mostly for shits and grins [4]. I'd like to do a Go package and tooling to verify interoperability. It'll be hand-written to check my understanding.

After that, I have to start building out the system. I found a framework / SDK for the PicoCalc that seems promising and uses ANSI escape codes, which is the same thing I used for ke. I've built a little bit out, still working out the interface. I'm thinking of using the F keys for everything: F1-F5 for main functions, F6-F10 for app-specific functions. So top-level:

  • F1: SYS, the system menu (boot to bootsel, unlock, provision, clear)
  • F2: EDIT, the editor
  • F3: EXO, querying tags for files
  • F4: PGM, a programming text editor (e.g. cleartext)
  • F5: RUN, running programs

I haven't decided on a programming language (maybe a forth-like for simplicity). It would be interesting to consider encrypted programs, too, but that'd be for a later revision.

[1]And naming is one of the two great problems in computer science.
[2]ZoneBook, because I like the suffix Book, and named after the S.T.A.L.K.E.R. environment known as The Zone.
[3]A Key Encryption Key, where the master key is used to encrypt other keys.
[4]I'm still somewhat sceptical, but if I'm going to pick up a new skill, I need to use it a lot.

Tags: , , , , ,