How SecureKeys makes passwords

SecureKeys stores nothing: it recalculates the same password from your passphrase every time. This page describes exactly how, so that you can always get your passwords back, with or without the app.

You don't need anything on this page to use SecureKeys. It is here as a promise: if the app ever disappears from your phone or from Google Play, the steps, the reference program and the test vectors below are enough to rebuild it.

Inputs

InputValues
PassphraseAny text. Ordinary spaces are ignored and capitals count as lowercase, so Correct Horse and correcthorse give the same password. Which lowercase letter a capital becomes depends on the phone's language in a few cases.
Length5 to 25 characters in the app.
Mixed caseOn or off.
Special charactersOn or off.
NumbersOn or off.
Phone languageOnly matters for Turkish, Azerbaijani and Lithuanian, and only for some capitals.

The steps

  1. Clean the passphrase. Remove every space (U+0020), then lowercase it by the rules of the phone's language. For most languages these are Unicode's default rules.
  2. Make one character per position. For each position i from 0 to length − 1:
    1. Append the number i, in decimal, to the cleaned phrase.
    2. Rotate that text left by i characters: move the first i characters to the end. If the text is shorter than i, first double it (append it to itself) until it is at least i characters long: 3 characters at i = 7 become 12, not 9.
    3. Take the MD5 hash of the result (UTF-8 bytes) as 32 hex digits, and read the last 8 hex digits as an unsigned number, the seed.
    4. Choose a character pool by the 1-based position p = i + 1, checking in this order: digits if Numbers is on and p is a multiple of 3; capitals if Mixed case is on and p is a multiple of 4; symbols if Special is on and p is a multiple of 5; otherwise lowercase letters.
    5. The character is pool[seed mod pool length].
  3. Rotate the result. Take the character code of the first character (for example 97 for a), find the remainder after dividing it by the length, and rotate the whole password left by that many characters.

The pools, exactly as the app uses them (the symbols pool really does contain - twice):

lowercase  abcdefghijklmnopqrstuvwxyz
capitals   ABCDEFGHIJKLMNOPQRSTUVWXYZ
digits     1234567890
symbols    ()-.?[]_~!#$^*-+=|{}

Phone language

The 2014 app (version 3.0) and SecureKeys 4.0.2 onwards lowercase the passphrase using the phone's language. Almost all languages give the same result. These differ; apply the rules below, and Unicode's default rules to everything else:

Phone languageWhat changes
Turkish, Azerbaijani
  • İ (U+0130) becomes i. (Elsewhere it becomes i followed by a combining dot above, U+0307.)
  • I followed by a combining dot above (U+0307) becomes i, and that dot is removed.
  • Any other I becomes dotless ı (U+0131).
Lithuanian
  • Ì (U+00CC) becomes U+0069 U+0307 U+0300.
  • Í (U+00CD) becomes U+0069 U+0307 U+0301.
  • Ĩ (U+0128) becomes U+0069 U+0307 U+0303.
  • I, J or Į (U+012E) followed by an accent above becomes its lowercase letter, then U+0307. The accent stays where it was.

“Followed by” looks at the combining marks after the letter, skipping any whose Unicode canonical combining class is neither 0 nor 230 (a dot below, for example). For Turkish and Azerbaijani, the first mark not skipped must be U+0307. For Lithuanian, an “accent above” means the first character not skipped has class 230.

To rebuild such a password, add --language=tr, --language=az or --language=lt to the reference program, as the last argument.

Versions 4.0 and 4.0.1 ignored the phone's language. For a password made with one of them, leave the option out. On a Turkish, Azerbaijani or Lithuanian phone, updating to 4.0.2 changes the password for passphrases with the capitals above; the reference program without the option still gives the old one.

Example

Passphrase correct horse, length 12, with mixed case, special characters and numbers, gives D3~o5sl3Y!7i.

Reference implementation and test vectors

A short Python 3 program, using only the standard library, that follows the steps above. It reproduces all 13,992 test vectors, which were captured from the original SecureKeys library. None of them covers the Lithuanian rules or I followed by a combining dot: for those, the program follows the description above.

python3 securekeys.py "correct horse" 12 --mixed-case --special --numbers
python3 securekeys.py --check golden_extended.tsv
python3 securekeys.py --check golden_locale_tr.tsv --language=tr
FileWhat it is
securekeys.pyReference implementation (MIT licence)
golden.tsv192 vectors: 6 phrases, lengths 5, 8, 16 and 25, every option combination
golden_extended.tsv9,000 vectors: 45 phrases (including accents, emoji and other scripts), lengths 1 to 25, every option combination
golden_locale_en.tsv1,600 vectors: 8 phrases with dotted and dotless I on an English phone, lengths 1 to 25, every option combination
golden_locale_tr.tsvThe same 1,600 inputs on a Turkish phone (check with --language=tr)
golden_locale_az.tsvThe same 1,600 inputs on an Azerbaijani phone (check with --language=az)

Each line is tab-separated: passphrase, length, mixed case, special, numbers, expected password. In passphrases, a tab, a newline and a backslash are written as \t, \n and \\.

Fine print