diff --git a/Readme.org b/Readme.org index 687732c..cd27152 100644 --- a/Readme.org +++ b/Readme.org @@ -84,6 +84,9 @@ default, and the data would not open. Store the cost with the data. as different code points: ~é~ as one, or as ~e~ and a combining accent. Both are normalized to Unicode NFC before Argon2id, so they give the same key. It is NFC and not NFKC, as in RFC 8265: ~fi~ and ~fi~ are different passwords. +The normalization is ~string-nfc~ of ~(std unicode normalize)~, which has +its own tables, so a phone and a desktop give the same bytes. It needs a +Bjolang with that module, which is newer than 0.3.0. | Cipher | Key | Nonce | Tag | |---------------------+-----+-------+-----| diff --git a/src/impl.bjo b/src/impl.bjo index 32dcc61..3e504a2 100644 --- a/src/impl.bjo +++ b/src/impl.bjo @@ -40,6 +40,7 @@ random-bytes wipe!) (import (std prelude)) +(import (only (std unicode normalize) string-nfc)) (type (: Cipher (Union Aegis256 XChaCha20Poly1305))) @@ -81,8 +82,6 @@ ;; random salt. (clr-argon2-hash (: LibSodium.CryptoPasswordHashArgon.HashPassword (-> (RoSpan byte) int int string))) (clr-argon2-verify (: LibSodium.CryptoPasswordHashArgon.VerifyPassword (-> string (RoSpan byte) bool))) - ;; String.Normalize() with no argument: Unicode normalization form C. - (clr-nfc (: System.String.Normalize (-> string string))) (clr-arm-aes? (: System.Runtime.Intrinsics.Arm.Aes.IsSupported #:get)) (clr-x86-aes? (: System.Runtime.Intrinsics.X86.Aes.IsSupported #:get)) (clr-x86-avx? (: System.Runtime.Intrinsics.X86.Avx.IsSupported #:get))) @@ -369,9 +368,11 @@ ;; The UTF-8 bytes of `password` in Unicode NFC. The same password typed on ;; two devices can come as different code points: "é" as one, or as "e" and -;; a combining accent. NFC makes them the same bytes. +;; a combining accent. NFC makes them the same bytes. (std unicode normalize) +;; has its own tables, so every platform gives the same bytes; .NET's +;; String.Normalize would follow the ICU of each platform. (: (-> string (Array byte))) -(defun (password-bytes password) (string->bytes (clr-nfc password))) +(defun (password-bytes password) (string->bytes (string-nfc password))) ;; The value of a thread's result, or its exception raised again. (: (-> (Result Exception %a) %a))