Skip to content

Commit 04d307d

Browse files
vojtechtrefnymbroz
authored andcommitted
bitlk: Fix unlocking bitlocker with multibyte utf8 characters
Fixes: #950 Co-authored-by: Thomas Lidén
1 parent 6c7c8d3 commit 04d307d

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

lib/bitlk/bitlk.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,7 @@ static int bitlk_kdf(const char *password,
982982
struct crypt_hash *hd = NULL;
983983
int len = 0;
984984
char16_t *utf16Password = NULL;
985+
size_t utf16Len = 0;
985986
int i = 0;
986987
int r = 0;
987988

@@ -1007,7 +1008,8 @@ static int bitlk_kdf(const char *password,
10071008
if (r < 0)
10081009
goto out;
10091010

1010-
crypt_hash_write(hd, (char*)utf16Password, passwordLen * 2);
1011+
utf16Len = crypt_char16_strlen(utf16Password);
1012+
crypt_hash_write(hd, (char*)utf16Password, utf16Len * 2);
10111013
r = crypt_hash_final(hd, kdf.initial_sha256, len);
10121014
if (r < 0)
10131015
goto out;

lib/crypto_backend/crypto_backend.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ int crypt_base64_decode(char **out, size_t *out_length, const char *in, size_t i
9393
/* UTF8/16 */
9494
int crypt_utf16_to_utf8(char **out, const char16_t *s, size_t length /* bytes! */);
9595
int crypt_utf8_to_utf16(char16_t **out, const char *s, size_t length);
96+
size_t crypt_char16_strlen(const char16_t *s);
9697

9798
/* Block ciphers */
9899
int crypt_cipher_ivsize(const char *name, const char *mode);

lib/crypto_backend/utf8.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,3 +274,20 @@ int crypt_utf8_to_utf16(char16_t **out, const char *s, size_t length)
274274
*p = 0;
275275
return 0;
276276
}
277+
278+
/**
279+
* crypt_char16_strlen()
280+
* @s: string to get length of
281+
*
282+
* Returns: number of 16-bit words in the string
283+
*/
284+
size_t crypt_char16_strlen(const char16_t *s) {
285+
size_t n = 0;
286+
287+
assert(s);
288+
289+
while (*s != 0)
290+
n++, s++;
291+
292+
return n;
293+
}

0 commit comments

Comments
 (0)