upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/49.md
diff options
context:
space:
mode:
Diffstat (limited to '49.md')
-rw-r--r--49.md38
1 files changed, 26 insertions, 12 deletions
diff --git a/49.md b/49.md
index becc586..731f132 100644
--- a/49.md
+++ b/49.md
@@ -7,26 +7,26 @@ Private Key Encryption
7 7
8`draft` `optional` 8`draft` `optional`
9 9
10This NIP defines a method by which clients can encrypt (and decrypt) a user's private key with a passphrase. 10This NIP defines a method by which clients can encrypt (and decrypt) a user's private key with a password.
11 11
12Symmetric Encryption Key derivation 12Symmetric Encryption Key derivation
13----------------------------------- 13-----------------------------------
14 14
15PASSPHRASE = read from the user 15PASSWORD = Read from the user. The password should be unicode normalized to NFKC format to ensure that the password can be entered identically on other computers/clients.
16 16
17LOG\_N = Let the user or implementer choose one byte representing a power of 2 (e.g. 18 represents 262,144) which is used as the number of rounds for scrypt. Larger numbers take more time and more memory, and offer better protection: 17LOG\_N = Let the user or implementer choose one byte representing a power of 2 (e.g. 18 represents 262,144) which is used as the number of rounds for scrypt. Larger numbers take more time and more memory, and offer better protection:
18 18
19 | LOG\_N | MEMORY REQUIRED | APPROX TIME ON FAST COMPUTER | 19 | LOG_N | MEMORY REQUIRED | APPROX TIME ON FAST COMPUTER |
20 |--------|-----------------|----------------------------- | 20 |-------|-----------------|----------------------------- |
21 | 16 | 64 MiB | 100 ms | 21 | 16 | 64 MiB | 100 ms |
22 | 18 | 256 MiB | | 22 | 18 | 256 MiB | |
23 | 20 | 1 GiB | 2 seconds | 23 | 20 | 1 GiB | 2 seconds |
24 | 21 | 2 GiB | | 24 | 21 | 2 GiB | |
25 | 22 | 4 GiB | | 25 | 22 | 4 GiB | |
26 26
27SALT = 16 random bytes 27SALT = 16 random bytes
28 28
29SYMMETRIC_KEY = scrypt(passphrase=PASSPHRASE, salt=SALT, log\_n=LOG\_N, r=8, p=1) 29SYMMETRIC_KEY = scrypt(password=PASSWORD, salt=SALT, log\_n=LOG\_N, r=8, p=1)
30 30
31The symmetric key should be 32 bytes long. 31The symmetric key should be 32 bytes long.
32 32
@@ -78,6 +78,22 @@ The decryption process operates in the reverse.
78Test Data 78Test Data
79--------- 79---------
80 80
81## Password Unicode Normalization
82
83The following password input: "ÅΩẛ̣"
84- Unicode Codepoints: U+212B U+2126 U+1E9B U+0323
85- UTF-8 bytes: [0xE2, 0x84, 0xAB, 0xE2, 0x84, 0xA6, 0xE1, 0xBA, 0x9B, 0xCC, 0xA3]
86
87Should be converted into the unicode normalized NFKC format prior to use in scrypt: "ÅΩẛ̣"
88- Unicode Codepoints: U+00C5 U+03A9 U+1E69
89- UTF-8 bytes: [0xC3, 0x85, 0xCE, 0xA9, 0xE1, 0xB9, 0xA9]
90
91## Encryption
92
93The encryption process is non-deterministic due to the random nonce.
94
95## Decryption
96
81The following encrypted private key: 97The following encrypted private key:
82 98
83`ncryptsec1qgg9947rlpvqu76pj5ecreduf9jxhselq2nae2kghhvd5g7dgjtcxfqtd67p9m0w57lspw8gsq6yphnm8623nsl8xn9j4jdzz84zm3frztj3z7s35vpzmqf6ksu8r89qk5z2zxfmu5gv8th8wclt0h4p` 99`ncryptsec1qgg9947rlpvqu76pj5ecreduf9jxhselq2nae2kghhvd5g7dgjtcxfqtd67p9m0w57lspw8gsq6yphnm8623nsl8xn9j4jdzz84zm3frztj3z7s35vpzmqf6ksu8r89qk5z2zxfmu5gv8th8wclt0h4p`
@@ -86,8 +102,6 @@ When decrypted with password='nostr' and log_n=16 yields the following hex-encod
86 102
87`3501454135014541350145413501453fefb02227e449e57cf4d3a3ce05378683` 103`3501454135014541350145413501453fefb02227e449e57cf4d3a3ce05378683`
88 104
89The reverse process is non-deterministic due to the random nonce.
90
91Discussion 105Discussion
92---------- 106----------
93 107