From 9e05dc3313d5f9df1273e989f310782ba9c6cddc Mon Sep 17 00:00:00 2001 From: Erica Z Date: Wed, 16 Oct 2024 00:02:38 +0200 Subject: [PATCH] use random_bytes directly --- src/ui/setup.vala | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/ui/setup.vala b/src/ui/setup.vala index fa49a0f..2a7b206 100644 --- a/src/ui/setup.vala +++ b/src/ui/setup.vala @@ -100,17 +100,17 @@ public class Ui.Setup : Adw.PreferencesDialog { } private void salt_password (string password, out string token, out string salt) { - uchar salt_bytes[8]; - GCrypt.Random.randomize (salt_bytes); - uchar salt_chars[17]; - for (int i = 0; i < 8; i += 1) { + const int SALT_BYTES = 8; + uchar salt_bytes[SALT_BYTES] = GCrypt.Random.random_bytes (SALT_BYTES); + uchar salt_chars[2*SALT_BYTES+1]; + for (int i = 0; i < SALT_BYTES; i += 1) { salt_chars[2*i+0] = "0123456789abcdef"[(salt_bytes[i]>>4)&0xf]; salt_chars[2*i+1] = "0123456789abcdef"[(salt_bytes[i]>>0)&0xf]; } - salt_chars[16] = 0; + salt_chars[2*SALT_BYTES] = 0; var checksum = new Checksum (ChecksumType.MD5); checksum.update ((uchar[]) password, -1); - checksum.update (salt_chars, 16); + checksum.update (salt_chars, -1); token = checksum.get_string (); salt = (string) salt_chars;