From 3e5ab6fdad95666cd998c52be438f767ee8440c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Mon, 19 Feb 2024 21:53:41 +0100 Subject: [PATCH] egismoc: Convert value check values to big endian only when needed Since the driver seem to require a big-endian value it's just better to use architecture native endianness to compute the check value and eventually just convert to big endian as the chip wants. --- libfprint/drivers/egismoc/egismoc.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/libfprint/drivers/egismoc/egismoc.c b/libfprint/drivers/egismoc/egismoc.c index 841e7e93..0b5e8d2e 100644 --- a/libfprint/drivers/egismoc/egismoc.c +++ b/libfprint/drivers/egismoc/egismoc.c @@ -294,23 +294,21 @@ egismoc_get_check_bytes (const guchar *value, fp_dbg ("Get check bytes"); EgisMocCheckBytes check_bytes; const size_t steps = (value_length + 1) / 2; - guint16 big_endian_values[steps]; + guint16 values[steps]; size_t sum_values = 0; for (int i = 0, j = 0; i < value_length; i += 2, j++) { - big_endian_values[j] = 0; + values[j] = (value[i] << 8 & 0xff00); if (i < value_length - 1) - big_endian_values[j] = value[i + 1] << 8; - - big_endian_values[j] |= (value[i] & 0x00ff); + values[j] |= value[i + 1] & 0x00ff; } for (int i = 0; i < steps; i++) - sum_values += big_endian_values[i]; + sum_values += values[i]; - check_bytes.check_value = GUINT16_TO_LE (0xffff - (sum_values % 0xffff)); + check_bytes.check_value = GUINT16_TO_BE (0xffff - (sum_values % 0xffff)); return check_bytes; }