0 | |
From 499429a4e9ff96db0e04bd1d3e1523389d66fc50 Mon Sep 17 00:00:00 2001
|
1 | |
From: Richard Hughes <richard@hughsie.com>
|
2 | |
Date: Fri, 1 Sep 2017 17:43:16 +0100
|
3 | |
Subject: [PATCH] Fix the libdfu self test failure on s390 and ppc64
|
4 | |
|
5 | |
We have to be careful converting the little endian keys and values to and from
|
6 | |
a 'bare' uint8 buffer.
|
7 | |
---
|
8 | |
libdfu/dfu-cipher-xtea.c | 32 +++++++++++++++++++++++++++-----
|
9 | |
1 file changed, 27 insertions(+), 5 deletions(-)
|
10 | |
|
11 | |
diff --git a/libdfu/dfu-cipher-xtea.c b/libdfu/dfu-cipher-xtea.c
|
12 | |
index fd97c9f..b697916 100644
|
13 | |
--- a/libdfu/dfu-cipher-xtea.c
|
14 | |
+++ b/libdfu/dfu-cipher-xtea.c
|
15 | |
@@ -29,6 +29,26 @@
|
16 | |
#define XTEA_DELTA 0x9e3779b9
|
17 | |
#define XTEA_NUM_ROUNDS 32
|
18 | |
|
19 | |
+static void
|
20 | |
+dfu_cipher_buf_to_uint32 (const guint8 *buf, guint buflen, guint32 *array)
|
21 | |
+{
|
22 | |
+ guint32 tmp_le;
|
23 | |
+ for (guint i = 0; i < buflen / 4; i++) {
|
24 | |
+ memcpy (&tmp_le, &buf[i * 4], 4);
|
25 | |
+ array[i] = GUINT32_FROM_LE (tmp_le);
|
26 | |
+ }
|
27 | |
+}
|
28 | |
+
|
29 | |
+static void
|
30 | |
+dfu_cipher_uint32_to_buf (guint8 *buf, guint buflen, const guint32 *array)
|
31 | |
+{
|
32 | |
+ guint32 tmp_le;
|
33 | |
+ for (guint i = 0; i < buflen / 4; i++) {
|
34 | |
+ tmp_le = GUINT32_TO_LE (array[i]);
|
35 | |
+ memcpy (&buf[i * 4], &tmp_le, 4);
|
36 | |
+ }
|
37 | |
+}
|
38 | |
+
|
39 | |
static gboolean
|
40 | |
dfu_tool_parse_xtea_key (const gchar *key, guint32 *keys, GError **error)
|
41 | |
{
|
42 | |
@@ -67,11 +87,13 @@ dfu_tool_parse_xtea_key (const gchar *key, guint32 *keys, GError **error)
|
43 | |
}
|
44 | |
} else {
|
45 | |
gsize buf_len = 16;
|
46 | |
+ guint8 buf[16];
|
47 | |
g_autoptr(GChecksum) csum = NULL;
|
48 | |
csum = g_checksum_new (G_CHECKSUM_MD5);
|
49 | |
g_checksum_update (csum, (const guchar *) key, (gssize) key_len);
|
50 | |
- g_checksum_get_digest (csum, (guint8 *) keys, &buf_len);
|
51 | |
+ g_checksum_get_digest (csum, buf, &buf_len);
|
52 | |
g_assert (buf_len == 16);
|
53 | |
+ dfu_cipher_buf_to_uint32 (buf, buf_len, keys);
|
54 | |
}
|
55 | |
|
56 | |
/* success */
|
57 | |
@@ -130,7 +152,7 @@ dfu_cipher_decrypt_xtea (const gchar *key,
|
58 | |
|
59 | |
/* allocate a buffer that can be addressed in 4-byte chunks */
|
60 | |
tmp = g_new0 (guint32, chunks);
|
61 | |
- memcpy (tmp, data, length);
|
62 | |
+ dfu_cipher_buf_to_uint32 (data, length, tmp);
|
63 | |
|
64 | |
/* process buffer using XTEA keys */
|
65 | |
for (j = 0; j < chunks; j += 2) {
|
66 | |
@@ -147,7 +169,7 @@ dfu_cipher_decrypt_xtea (const gchar *key,
|
67 | |
}
|
68 | |
|
69 | |
/* copy the temp buffer back to data */
|
70 | |
- memcpy (data, tmp, length);
|
71 | |
+ dfu_cipher_uint32_to_buf (data, length, tmp);
|
72 | |
return TRUE;
|
73 | |
}
|
74 | |
|
75 | |
@@ -201,7 +223,7 @@ dfu_cipher_encrypt_xtea (const gchar *key,
|
76 | |
|
77 | |
/* allocate a buffer that can be addressed in 4-byte chunks */
|
78 | |
tmp = g_new0 (guint32, chunks);
|
79 | |
- memcpy (tmp, data, length);
|
80 | |
+ dfu_cipher_buf_to_uint32 (data, length, tmp);
|
81 | |
|
82 | |
/* process buffer using XTEA keys */
|
83 | |
for (j = 0; j < chunks; j += 2) {
|
84 | |
@@ -218,6 +240,6 @@ dfu_cipher_encrypt_xtea (const gchar *key,
|
85 | |
}
|
86 | |
|
87 | |
/* copy the temp buffer back to data */
|
88 | |
- memcpy (data, tmp, length);
|
89 | |
+ dfu_cipher_uint32_to_buf (data, length, tmp);
|
90 | |
return TRUE;
|
91 | |
}
|
92 | |
--
|
93 | |
2.7.4
|
94 | |
|