NAME
Picture::Lock::Format - a locked file and the stored password, byte for byte
DESCRIPTION
This is what Picture::Lock writes, said closely enough that another program could read it. It covers version 1 of two things: a locked file, which is a 307 byte header and then a directory sealed in chunks, and the one line string that stands where a password hash would.
A locked file is its header, which comes first here, and then its contents, under "THE CONTENTS". What the contents hold is a directory as one stream of bytes, under "THE TREE".
That is a directory locked with one picture that its owner keeps, and most of what follows is said of that file. A file may also hold one file or bare bytes, may take up to eight pictures, and may have its pictures inside it. The four bytes of flags in the header say which, and what such a file has that the other has not is under "WHAT FOLLOWS THE HEADER". It is one format and one version: a file that uses none of it is, byte for byte, the file this page describes without it.
The last section is of another kind. "THE C INTERFACE" is not bytes on a disk: it is what an extension written in C is promised, from one release to the next.
Every number is little-endian unless it says otherwise. || joins byte strings. LE32(v) is v as 4 bytes, low byte first. header[a..b) is bytes a up to but not including b.
WHAT A READER NEEDS
- BLAKE2b
-
RFC 7693, with a key and with the personalisation field of the BLAKE2 paper. Every use here is one of three, and the digest length is part of the parameter block: none of them is a longer digest cut short.
the picture hash 64 bytes out, no key, personalisation "piclock image" a key from a key 32 bytes out, a 32 byte key, personalisation "piclock wrap", "piclock check" or "piclock stream" the header check 8 bytes out, no key, personalisation "piclock header"A personalisation is the ASCII text followed by zero bytes to make 16. There is no salt.
- Argon2id
-
Version 1.3, RFC 9106, with its secret input and its associated data.
- XChaCha20-Poly1305
-
The subkey is HChaCha20 of the key and the first 16 bytes of the 24 byte nonce. The inner nonce is four zero bytes and then the last 8 bytes of the nonce. From there it is the AEAD of RFC 8439.
- LZ4
-
The block format, a block at a time, with no frame around it. Only the contents of a file need it, and a reader needs only to decode.
Several common libraries offer an Argon2id with no secret input, or a BLAKE2b with no personalisation. Neither will do.
THE PICTURE
The picture is a file, and only its bytes matter. Its hash H is the picture hash above over every byte of the file. The same image saved again is another file and another H.
H is not the checksum that a general tool prints for the file. That is on purpose: a published list of checksums is not a list of keys.
The picture's width and height are in no key and are not stored. They are used twice. When clicks are enrolled, each must be on the picture. When a header is opened or a password validated, the longer side L of the picture offered bounds the width of a cell ("THE CELLS RULE").
THE CLICKS
A click is a pixel (x, y) of the picture as stored, x from the left edge and y from the top, both from 0. There are n of them, 4 to 16, in order.
The tolerance is a radius r, and a cell is a square of side s = 2r + 1. The side is always a power of 3, so r is one of
0, 1, 4, 13, 40, 121, 364, 1093, 3280, 9841, 29524
Division below rounds down, and the remainder is never negative, whatever the sign of what is divided.
Enrolment
For each click, on each axis (shown for x):
corner c = x - r
offset d = c mod s from 0 to s - 1
The corner is the left or top edge of the square of pixels that will be taken for this click. The offset is stored in the clear. The corner is secret.
Enrolment refuses fewer than 4 clicks or more than 16, a click that is not on the picture, and clicks of which no three are in three different places. Two clicks are in the same place when they are within r of each other on both axes.
Finding clicks again
With the stored offset d for a click and axis, a click x given later is in the cell whose corner is
c = ((x - d) div s) * s + d
which is the enrolled corner exactly when x is within r of the enrolled click on that axis. A click below 0 or above 16777215 on either axis has both its corners written as -2147483648, which no enrolment gives.
The click bytes
C is 20 + 8n bytes:
LE32(1) the version of this encoding
LE32(r)
LE32(16777216) twice: the largest picture there is, always
LE32(16777216)
LE32(n)
then for each click in order: its x corner, its y corner, each a signed
32 bit number in two's complement
The two words after the radius are constant so that no key holds the size of the picture. The order of the clicks is part of C.
THE HEADER
307 bytes.
at bytes field
0 7 the ASCII text PICLOCK
7 1 the version, 01
8 4 flags: 1 when a passphrase is expected, else 0, and for a
file that is more than a directory with one picture, the
bits that are listed under the flags, below
12 4 m, the Argon2 memory in KiB
16 4 t, the passes
20 4 p, the lanes
24 4 r
28 4 n
32 16 the salt S
48 128 sixteen slots of 8 bytes. Slot i holds LE32 of the x offset
of click i and then LE32 of its y offset. Slots n to 15 are
zero bytes.
176 19 the stream prefix, random
195 24 the wrap nonce N
219 32 the key check K
251 32 the master key, encrypted
283 16 the tag of that encryption
299 8 the header check over header[0..299)
The version byte is the version of this layout and of everything below it: the click bytes, the context text, the way each key is derived. A change to any of them is another version byte.
What a reader refuses
In this order, on the bytes alone, before any secret is asked for and before any memory is taken:
Fewer than 8 bytes, or bytes 0 to 6 are not
PICLOCK: not made by Picture::Lock.Byte 7 is not 01: made by a later version.
The length is not 307, or the header check does not match: damaged.
A bit of the flags that has no meaning under "The flags" is set, or bits 1 and 2 both are: made by a later version.
ris not one of the eleven,nis not 4 to 16, an offset of a used slot is not less thans, or a byte of an unused slot is not zero: not made by Picture::Lock. With the check right, chance did not put those bytes there.m,torpis outside what the reader will pay, ormis less than8p: asks for more than is allowed here.
A reader bounds the cost before it acts on it. This module will pay 8192 to 4194304 KiB, 1 to 64 passes and 1 to 16 lanes for a locked file.
The header check is not a secret and proves nothing about who wrote the header. Anyone can work it out. It is there so that a header damaged by accident is called damaged and is not taken for a wrong click.
The flags
bit 0 a passphrase is expected
bits 1, 2 what is locked: 0 a directory, 1 one file, 2 bytes
bit 3 the pictures are inside the file
bits 4 to 6 how many pictures the file takes, less one
the rest 0
A directory locked with one picture that stays outside has flags of 0 or 1, and nothing but its contents follows its header. r, n and the offsets in the header are those of the first picture.
The flags are under the key check K and inside what the seal of the master key authenticates, as every byte of the header before byte 219 is. A header whose flags were changed, with its check put right, does not open.
WHAT FOLLOWS THE HEADER
Where the flags say more than one picture, or pictures inside, the header is followed by this, and where they say neither, by nothing:
for each picture after the first, in order, 136 bytes:
4 r for that picture
4 n for that picture, 1 to 16
128 sixteen slots, as in the header
where bit 3 is set, for each picture from the first, 12 bytes:
4 the length of the picture's file, 1 to 33554432
8 BLAKE2b of the file, 8 bytes out, personalisation
"piclock inside"
then 8 bytes:
8 BLAKE2b of all of the above, 8 bytes out, personalisation
"piclock more"
Call it B. With q pictures it is 136(q - 1) + 8 bytes, and 12q more where they are inside. How long it is can be told from the flags, so a reader knows how much to read before it reads any of it. The header and B together are at most 1363 bytes.
Where the pictures are inside, their files follow B, each as it was given and as long as B says, in order. Then come the chunks.
header || B || picture 1 || ... || picture q || chunk 0 || ...
A reader refuses, on the bytes alone and with no memory taken: a file that ends before B does, or a B whose last 8 bytes are not its check, as damaged, and an r, an n, a slot or a length that could not have been written, fewer than 4 clicks over all the pictures, lengths of more than 67108864 together, and pictures inside with no passphrase and fewer than 8 clicks, as not made by Picture::Lock. A picture inside that is not the bytes its 8 byte check says is damaged, and is found before any click is tried.
A set of pictures is held to these rules when it is locked. One picture alone takes 4 to 16 clicks. One of several takes 1 to 16, and the set 4 or more, three of them in different places, where two clicks on different pictures are always in different places. Each picture has an r of its own and must be long enough for sixteen cells of it.
THE KEYS
P the Argon2 password. With no passphrase it is C. With one it is
C || LE32(length of the passphrase) || the passphrase.
X the Argon2 associated data: the 19 ASCII bytes "piclock 1 container"
U Argon2id(password P, salt S, secret H, associated data X,
memory m, passes t, lanes p, 32 bytes out)
Kw a key from the key U, personalisation "piclock wrap", no message
K a key from the key U, personalisation "piclock check",
message header[0..219)
M the master key, 32 random bytes. It is sealed under Kw with the nonce
N and the associated data header[0..251). The 32 bytes of ciphertext
go at 251 and the 16 byte tag at 283.
Ks a key from the key M, personalisation "piclock stream", no message
A passphrase is 1 to 1024 bytes and is used as given. Nothing normalises it.
For a file that takes several pictures there is still one U, from one run of Argon2:
P C of the first picture || C of the second || ... and then, with a
passphrase, LE32(its length) || the passphrase
H BLAKE2b of the hashes of the pictures joined in order, 64 bytes
out, personalisation "piclock set"
and for a file that has a B, whatever it takes:
X "piclock 1 container" || BLAKE2b of B, 32 bytes out,
personalisation "piclock bound"
So nothing is derived or checked for one picture by itself, and what B says of the other pictures, or of the pictures inside, cannot be changed without U being another key. With one picture and no B all three are what they are above.
U is the key of those two hashes and of nothing else. Kw seals one thing once. M is only ever the key of a hash. Ks will seal the contents.
K is there because the seal's tag does not commit to its key: without K a header could be written that several different keys open.
Opening
A header that a reader accepts is opened with H, n clicks, the passphrase if the flags say there is one, and L, the longer side in pixels of the picture offered.
A number of clicks that is not n, or a passphrase given when none is expected or missing when one is, is refused before anything is derived. Both can be read off the header by whoever holds it. So can what the file holds, how many pictures it takes and whether they are inside it, and each of those is refused first where it is not what the caller supposes: the thing held, then the pictures, then the number of clicks on each, then the passphrase.
Then C is found from the clicks and the stored offsets, and P, U, Kw and K are worked out. The header opens when all three of these hold, and all three are worked out before any is looked at:
the K worked out is the K stored, compared in constant time
the tag of the sealed master key matches
(2r + 1) * 16 is not more than L
Otherwise the answer is two words, cannot unlock, whichever failed and whatever was wrong: the picture, a click, the order, the passphrase, or a header that was changed and had its check put right.
THE CELLS RULE
The third test is there because the radius and the offsets belong to whoever wrote the header. Without it, someone who had the picture and not the clicks could write a header whose one cell held the whole picture, and the owner's picture with any clicks at all would open a file of the forger's making. With it a made-up header must still guess, for each click, which of at least sixteen cells along the longer side it falls in.
A header is never made for a picture too short for it, so an honest header always passes on the picture it was made for.
A new header for an old one
A header can be replaced by another that opens to the same M and has the same stream prefix: another picture, other clicks, another passphrase, another cost, under a new salt and a new nonce. The contents are not touched.
When the new clicks are the old ones (the same number, the same radius, and found again under the old offsets) the offsets are kept byte for byte. They are not worked out again from the clicks just given, so the points that are accepted never move.
That is written over the old header where it stands, which a header of one length allows. A file with a B, or one that is to have one, is given its new front another way: a new file is made beside the old, with the new header, the new B, the pictures where they go inside, and the chunks copied as they are. It is read back whole and then takes the old file's name.
This changes what opens one copy of the file. It does not change M. Whoever kept an earlier copy, or only its first 307 bytes, and knows or can guess the old picture and clicks, can still read the contents. To shut them out the directory must be locked again.
A WORKED EXAMPLE
The picture is the eleven ASCII bytes the picture, said to be 1920 by 1080. Any bytes can be a picture.
H 1880d77a7f8747cc63346a722d7fdd9521c3bdd39dff049e64385db2dffceaf2
883ff898e11b4b03a7e6dcab8db8603114ba77cb737a0dda094aa78ab2b915da
Five clicks at a radius of 13, so a cell is 27 pixels across:
click corner offset
412, 96 399, 83 21, 2
1310, 540 1297, 527 1, 14
88, 901 75, 888 21, 24
960, 333 947, 320 2, 23
1702, 77 1689, 64 15, 10
C 010000000d000000000000010000000105000000
8f01000053000000110500000f0200004b000000
78030000b3030000400100009906000040000000
The cost is 8192 KiB, 1 pass, 1 lane. There is no passphrase. The salt is the bytes 00 to 0f, the nonce 10 to 27, the stream prefix 30 to 42 and the master key 80 to 9f.
U 921095286bbfbd3b48db4e39b997aab2b348f0d33d4be4c48a1755ea0a7924ce
Kw 00ede71f64e8710dc93d31100d673deb8054490fc5984dca54ce51e415210d10
K f98718864648637f2842a1a1c3e3497ca84014fa3a99a08a40ad9e2e27871104
Ks a5ad35c6df44a1f0f03875f26bf014ccfb6a45f472803efe92a998bd786dc339
The header:
5049434c4f434b01000000000020000001000000010000000d00000005000000
000102030405060708090a0b0c0d0e0f1500000002000000010000000e000000
150000001800000002000000170000000f0000000a0000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000303132333435363738393a3b3c3d3e3f
404142101112131415161718191a1b1c1d1e1f2021222324252627f987188646
48637f2842a1a1c3e3497ca84014fa3a99a08a40ad9e2e278711044d81f9a8f2
b94c8093e8d98fb9d160643c839cded83316ef07f384714050547f3f73403440
c3607c4e215f01f42b2c69c6d8354ee82bb89e
It opens with the same clicks, and with every click 13 pixels off on both axes. It does not open with any click 14 off.
THE STORED PASSWORD
One line of ASCII with nothing before it and nothing after it:
$piclock$v=1$m=M,t=T,p=P,r=R,n=N$SALT$OFFSETS$TAG
M, T, P, R and N are decimal numbers with no sign, no space and no leading zero. They are the Argon2 memory in KiB, passes and lanes, the radius and the number of clicks.
SALT is 16 bytes, OFFSETS is 8 bytes for each click (the x offset and then the y offset, each as LE32) and TAG is 32 bytes. The three are base64 with the URL-safe alphabet of RFC 4648 section 5 and no padding, and the bits of a last character that carry no data are zero. So each value has one spelling.
C the click bytes, as for a header
X the 18 ASCII bytes "piclock 1 password" || the offset bytes as stored
TAG Argon2id(password C, salt SALT, secret H, associated data X,
memory M, passes T, lanes P, 32 bytes out)
There is no passphrase, no master key and no check of its own. The salt and the cost go into Argon2, the radius and the number of clicks are in C, and the offsets are in X, so nothing in the string can be changed and leave it valid for the same clicks. The context text is not the one a locked file uses, so the same picture and clicks give unrelated keys for the two.
A reader refuses, in this order: a string that does not begin $piclock$v= and a number (not a stored string), a number there that is not 1 (a later version), anything else that departs from the form by a character, a radius that is not one of the eleven, a number of clicks that is not 4 to 16 or an offset that is not less than the side of a cell (not a stored string), and a cost outside what it will pay. This module will pay 1024 to 1048576 KiB, 1 to 16 passes and 1 to 4 lanes for a password.
Clicks validate when there are N of them, the tag worked out from them is the tag stored, compared in constant time, and the cells rule holds for the picture offered. A wrong number of clicks is not told apart from a wrong click and costs the same derivation: whoever tries a login does not hold the string.
A string is never longer than 301 characters.
The example again
The same picture, clicks, radius and salt, at 65536 KiB and 3 passes:
$piclock$v=1$m=65536,t=3,p=1,r=13,n=5$AAECAwQFBgcICQoLDA0ODw$FQAAAAIAAAA
BAAAADgAAABUAAAAYAAAAAgAAABcAAAAPAAAACgAAAA$mTCNveOHDBCRcgu75-fxscwv2kxrc
TP5wY_PSWibZkg
It is one line of 159 characters, broken here to fit the page.
THE CONTENTS
After its header a file is chunks, and nothing else: no trailer, no index and no count. Where a file has something under "WHAT FOLLOWS THE HEADER", the chunks come after that.
header || chunk 0 || chunk 1 || ... || the last chunk
A chunk is its sealed bytes and then a 16 byte tag. Every chunk but the last holds exactly 65536 sealed bytes. The last holds 0 to 65535. There is always a last chunk, and it may hold nothing but its tag. So the length of a file says where its chunks are, and the chunk that is not full is the last.
Chunk i, counting from 0, is sealed with XChaCha20-Poly1305 under Ks, with no associated data and the nonce
header[176..195) || LE32(i) || last
where last is the byte 01 for the last chunk and 00 for every other. i is at most 4294967295.
A chunk that is moved, repeated or left out has the wrong number for its place. A file that is cut short ends on a chunk that was not sealed as the last, and a file that is added to no longer has its last chunk where its length puts it. Each of those is a tag that does not match.
One Ks and one prefix seal the chunks of one file, once.
What the chunks hold is what the flags say is locked. For a directory it is "THE TREE". For bytes it is the bytes. For one file it is 16 bytes and then the file's bytes: its permission bits as LE32, the time it was last modified in whole seconds as 8 bytes, low byte first, and the nanoseconds of that as LE32. The permission bits are 0 to 0777 and no other bit, as for a file in a tree, and the nanoseconds are under a thousand million. A file whose 16 bytes say otherwise, or are not all there, is refused. The name of the file is not kept.
The stream inside
What the chunks hold, put end to end, is frames, then an end, then padding. The cuts between chunks fall wherever 65536 bytes are up and take no notice of frames.
'S' LE16(raw - 1) || the block a block as it is
'C' LE16(raw - 1) || LE16(stored - 1) || lz4 a block compressed
'E' LE64(pad) || pad bytes that are all zero the end
raw is the length of a block, 1 to 65536. lz4 is one LZ4 block that decodes to exactly raw bytes, and stored is its length, which is less than raw. The blocks in order are the tree. Every block but the last is 65536 bytes, and a block that is shorter is followed by the end.
A writer compresses a block when its LZ4 block is at least 3 bytes shorter than the block, which is when the frame comes out the shorter of the two.
The padding
T = the bytes of every frame before the end
L = T + 9
pad = padme(L) - L
padme(L) E = the place of the highest bit set in L
S = the number of bits it takes to write E
L rounded up to a multiple of 2 to the power E - S
So the stream inside is padme(L) bytes long, a length with few significant bits. It is never more than 12 percent over L, and less as files grow. padme(9) is 10, padme(1000) is 1024 and padme(1048577) is 1081344. For a stream inside of P bytes a file is
307 + P + 16 * (P div 65536 + 1)
bytes long.
What a reader of the contents refuses
A chunk is authenticated whole before a byte of it is looked at. A chunk whose tag does not match, a last chunk too short to hold a tag, and a full chunk numbered 4294967295 are damage, and a reader says at which chunk.
Chunks that are sealed rightly and do not hold a stream as above are refused as well, as not written by this version: a frame of another kind, a 'C' that is not shorter than its block or does not decode to exactly its length, a block after a short block, padding of another length or with a byte that is not zero, a byte after the padding, and a last chunk that comes before the end does.
A reader hands each block on as its chunk proves sound. It does not know that a file is whole until the last chunk has, so what it handed on before then is not to be relied on until then.
What the length of a file tells
How large the directory is once it is compressed: to within 12 percent for a small one, and to within about 3 percent for one of a gigabyte. Not how many files it has, nor how well any one of them compressed.
THE TREE
A directory and everything in it is one stream of bytes before it is sealed, and is that stream again when it has been opened. Nothing in this section is secret and nothing in it is authenticated: the sealing does both.
"PICTREE" || 0x01
the root record
a record for every entry, a file's record followed at once by its data
the end record
Nothing comes after the end record. A record is one byte that says its kind, LE32 of the length of its body, and the body. LE16 and LE64 are a number as 2 and as 8 bytes, low byte first.
'D' a directory LE16(length of path) || path || LE32(mode)
|| LE64(seconds) || LE32(nanoseconds)
'F' a file as a directory, then LE64(size)
then size bytes of data, not counted in the body
'L' a link LE16(length of path) || path
|| LE16(length of target) || target
|| LE64(seconds) || LE32(nanoseconds)
'E' the end LE64(records before it) || LE64(sum of the sizes)
|| D
D = BLAKE2b(32 bytes, no key, personal = "piclock archive",
every byte of the stream before the end record)
A body is exactly as long as its fields come to, so a record has one spelling.
- mode
-
The permission bits, 0 to 0777, and no other bit.
- seconds and nanoseconds
-
When the entry was last modified: seconds since 1970 as a signed number, and 0 to 999999999 nanoseconds after that.
- size
-
0 to 9223372036854775807.
- target
-
Where a link points, 1 to 65535 bytes with no zero byte among them. It is kept as it is. It may be absolute, may hold
..and may name nothing.
A path and the order of paths
The root record is a directory whose path is empty. It comes first and nowhere else, and it carries the mode and the time of the directory that was locked. The name of that directory is not kept.
Every other path is relative, with / between its components. A component is 1 to 255 bytes, holds no zero byte, and is neither . nor ... A path has at most 100 components. A name is bytes and need not be text in any encoding.
A directory comes before everything inside it, and the names inside one directory are in byte order, a shorter name before a longer one that begins with it. That is the same as comparing two paths byte by byte with / counted as lower than every other byte. So a/b comes before a-b.
Each entry is later in that order than the entry before it, and its parent is a directory that has a record before it. Together these mean that no path comes twice, that nothing is inside a file or a link, that nothing comes before the directory it is in, and that a reader need remember one path, the last.
What a reader of a tree refuses
Anything that is not exactly the stream above: other first bytes, a kind it does not know, a body of the wrong length, a field out of its range, a path that breaks a rule, an entry out of order, a stream that stops before its end record or inside a record or inside a file's data, a count or a sum or a digest that is not what the reader counted, and any byte after the end.
An entry is refused before it is acted on. A path is checked whole before anything is made on a disk, and a file's record is checked before a byte of its data is taken.
The digest tells a stream that was cut short or put together wrongly from one that is whole. It is no defence against someone who writes a stream on purpose, who writes the digest too.
A tree onto a disk
Nothing is made by joining names into a path. The directory to be filled is opened once, and every entry is made inside the open directory that is its parent, which the reader itself made. A link is never followed. So no entry is written outside the directory that is being filled, whatever the stream says and whatever links it made on the way.
A name is made only where no name is. On a disk that folds case, or that takes two spellings of an accented letter for one, two names of a stream can be one name. That is refused, and never guessed at.
A file is made for its owner alone, filled, and then given its mode and its time. A directory is given its mode and its time when the last thing inside it has been made, so that a directory that is to be read-only does not stop its own filling.
What a tree keeps
Names as bytes, the contents of files, directories that are empty, the permission bits, the time of last modification to the nanosecond, and links as links.
It does not keep an owner or a group, the setuid, setgid and sticky bits, access lists, extended attributes, the fact that two names were one file, holes in a file, or the times of creation and of last reading.
It does not hold a device, a socket or a named pipe at all. A directory with one of those in it is not locked.
A small tree
A directory last modified at 1000000000 seconds, with mode 0755. In it a file a.txt of the six bytes hello and a line feed, mode 0644, modified half a second later. Beside it a directory sub, mode 0700, modified at 1000000001, and in that a link up to ../a.txt, modified at 1000000002.
504943545245450144120000000000ed01000000ca9a3b000000000000000046
1f0000000500612e747874a401000000ca9a3b000000000065cd1d0600000000
00000068656c6c6f0a44150000000300737562c001000001ca9a3b0000000000
0000004c1e00000006007375622f757008002e2e2f612e74787402ca9a3b0000
0000000000004530000000040000000000000006000000000000001e619b5215
4aab6fce3f85f9039bca9e5b931b76b4f0f3d9ce80836d1d2c7630
It is 187 bytes: 8, a root record of 23, a file record of 36 and its 6 bytes of data, a directory record of 26, a link record of 35, and an end record of 53 that counts 4 records and 6 bytes.
The small tree in a file
The small tree under the header of "A WORKED EXAMPLE", whose master key is the bytes 80 to 9f and whose prefix is 30 to 42. It is one block of 187 bytes, and this module's LZ4 block for it is 149 bytes, so the frame is a 'C' of 154. Then L is 163, padme(L) is 176 and there are 13 bytes of padding. The stream inside:
43ba009400b05049435452454501441200010080ed01000000ca9a3b0c000004
00d8461f0000000500612e747874a41c004065cd1d062100f70900000068656c
6c6f0a44150000000300737562c0010000014400604c1e000000061a00812f75
7008002e2e2f4f0017022300634530000000045000045800f0111e619b52154a
ab6fce3f85f9039bca9e5b931b76b4f0f3d9ce80836d1d2c7630450d00000000
00000000000000000000000000000000
It fits one chunk, which is the last, so its nonce is
303132333435363738393a3b3c3d3e3f4041420000000001
and the chunk, 176 sealed bytes and a tag, is
4350c61fcd30636217176d88b45942305bef25e3713fe478108a8c92a72cad1e
3a03befc3b56b206be2b445eba53adbed871ca138d1777a9116a5f509ed39493
a20dad8cdb519eac43c920b9120e1241e783f335b3bfd26e9f2dfe648755dfc2
96963ad608c6a89c69a7900a3d320ed4c86b26fcdb16fa89f4755877f3a492eb
e3b7f8bc841c6cc9b40d5acab5d622a9c7b30c1be71d3ec2857b4a5fde810f96
4c57021e2acd22bba79b36119c90ee7d7617646ce26824f8f0ca663a0d3e1dbf
The 307 bytes of that header and these 192 are a whole file of 499 bytes. Another writer's LZ4 block for the same tree may differ, and then every byte of the chunk does. A reader has only to decode.
WHAT IS IN THE CLEAR
A header and a stored string both say the cost, the radius, the number of clicks, and for each click where its corner falls inside a cell.
With the picture in hand, an offset pair names one pixel in every cell as a candidate for that click. On a picture 1920 by 1080 at a radius of 13 that is 2840 candidates for each click where there were two million pixels. The tolerance is paid for with exactly that.
The offsets depend only on the clicks and the radius. Two headers, or a header and a stored string, made from the same clicks at the same radius have the same offsets and can be matched to each other.
An offset tells a click's corner modulo the side of a cell. Because every side is a power of 3, the same click enrolled at two radii gives away no more than it does at the smaller of the two.
A file that takes several pictures says how many, and says of each what a header says of one: its radius, its number of clicks and its offsets. It says nothing that names a picture or could check one.
Neither holds the picture, a hash or part of a hash of it, its size, its name, a date, or anything that names the machine or the owner.
A file with its pictures inside holds them, in the clear. That is what it was asked for. Whoever has the file has the pictures and the candidates for every click on them, and what is left of the secret is which candidates, in which order.
After its header a file shows its length and nothing more. What that tells is under "What the length of a file tells".
FROM ONE RELEASE TO THE NEXT
Every later release reads every locked file and every stored string that an earlier release wrote.
The locked files that ship in t/data are the test of that. Each was written once and is never written again, and each has to open in every release from then on. The stored string of "The example again" is held the same way.
The version byte of a file, and the v= of a stored string, are 1. A reader that meets another number says that the file was made by a later version and does nothing more with it.
The format can also grow under the same number, as it grew to hold one file, bytes, several pictures and pictures inside: by a bit of the flags that had no meaning, and by bytes that are there only where such a bit is set. A reader that does not know the bit gives the same answer, a later version, and never takes such a file for something else.
THE C INTERFACE
An extension written in C can make and check a stored password with no Perl call in between. It compiles against one header, piclock_abi.h, which is installed with the module, and is handed a table of functions when it loads. The header says what each function takes and answers. This section is the rule the header is held to, and version 1 of the table.
The table
One structure, piclock_abi, in the module's own shared object. It is two 32 bit numbers and then pointers to functions, with nothing else in it and nothing between them:
abi_version the version of the table
size the length of the table in bytes
Nothing is linked. The extension names no symbol of the module, and each of the two is built, installed and replaced without the other.
Asking for it
Picture::Lock::_abi_ptr($version, $size)
answers the address of the table, as an unsigned number. $version is the version the caller was written for. $size is the length of the table as the caller's header declares it, or less where the caller declares only the head of it, and is 8 at the least.
It croaks, naming its own number beside the one asked for, where the version asked for is above the table's, and where the size is. Otherwise the address is given, and it is the same address for as long as the module is loaded.
A caller is given any table at or above the version it asks for. Nothing asks for a version to be equal.
Picture::Lock::_abi_version() answers the version and refuses nothing.
What may change
The table grows at its end and nowhere else. A function is never taken out of it, moved in it or given another meaning, and no structure that a function takes is ever changed. What needs another shape is a new function.
A release that adds a function adds one to the version.
The numbers a function answers with are fixed, and so is every number the header spells.
size is there for two reasons. A table of a high enough version that was all the same too short could only come of a function added without the version being raised, and the size asked for is what catches it. And a caller written for one version that can use a function of a later one asks for its own version and tests for the function with PICLOCK_ABI_HAS, which is arithmetic on size and reads nothing past it.
Version 1
Eight functions, in this order:
picture_bytes the hash and the size of a picture, from its bytes
picture_file the same from its file
password_generate the string to store for a picture and clicks
password_validate whether clicks are the enrolled ones
password_needs_rehash whether a string should be made again
password_rehash a new string for the same clicks at another cost
password_dummy the work of one validation, thrown away
error_message words for an answer
None takes anything of perl's and none calls Perl. None keeps a pointer after it returns, and none frees one. A NULL where bytes are needed is refused.
A function that makes something answers one of these numbers, and has written nothing unless it answers 0 or its own words in the header say what:
0 done
1 the caller's mistake
2 memory that could not be had
3 no random bytes
7 the size of a picture could not be read
8 a file could not be read
9 not 4 to 16 clicks
10 a click is not on the picture
11 no three clicks are three places
12 not a stored string
14 the clicks are not the enrolled ones
15 text that is not clicks
16 a stored string of a later version
17 a stored string that asks more than a password may
A function that answers a question answers 1 or 0 and nothing else, so that it can stand in a condition: password_validate, password_dummy and password_needs_rehash. The first two say why through a pointer that the caller may leave out. password_dummy always answers 0.
A stored string is written into room of 302 bytes: the 301 characters it can run to and a zero byte to end it. Less room is refused whatever the string would have been, and nothing is ever cut short.
password_validate answers at once for a stored value that is not a stored string. For everything else that a person at a login form can be the cause of, clicks that are not clicks among them, it answers after one whole derivation. An answer that came sooner for text that is not clicks would tell whoever sent it that the account is there.
The cost of a new string is the caller's to name. Left out it is 65536 KiB, 3 passes and 1 lane, whatever the package variables of Picture::Lock say: nothing here reads them.
The locked directory and the LZ4 block codec are not in version 1.
The parts under "WHAT A READER NEEDS" are in no version of it. BLAKE2b, Argon2id and the seal are those of Crypt::Symmetric::Primitives, which hands an extension a table of its own in the same way, through a header of its own, symprim_abi.h.
SEE ALSO
AUTHOR
LNATION <email@lnation.org>
LICENSE AND COPYRIGHT
This software is Copyright (c) 2026 by LNATION <email@lnation.org>.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)