mirror of
https://gitlab.freedesktop.org/libfprint/libfprint.git
synced 2025-11-15 07:38:12 +00:00
egismoc: Simplify check bytes computation
We use big endian values for generating the check bytes, but we can do the same logic in a simpler way.
This commit is contained in:
@@ -293,19 +293,21 @@ egismoc_get_check_bytes (const guchar *value,
|
||||
{
|
||||
fp_dbg ("Get check bytes");
|
||||
EgisMocCheckBytes check_bytes;
|
||||
guint16 big_endian_values[(int) ((value_length + 1) / 2)];
|
||||
const size_t steps = (value_length + 1) / 2;
|
||||
guint16 big_endian_values[steps];
|
||||
size_t sum_values = 0;
|
||||
int s = 0;
|
||||
|
||||
for (int i = 0; i < value_length; i = i + 2, s++)
|
||||
for (int i = 0, j = 0; i < value_length; i += 2, j++)
|
||||
{
|
||||
if (i + 1 < value_length)
|
||||
big_endian_values[s] = (((guint16) value[i + 1]) << 8) | (0x00ff & value[i]);
|
||||
else
|
||||
big_endian_values[s] = (((guint16) 0x00) << 8) | (0x00ff & value[i]);
|
||||
big_endian_values[j] = 0;
|
||||
|
||||
if (i < value_length - 1)
|
||||
big_endian_values[j] = value[i + 1] << 8;
|
||||
|
||||
big_endian_values[j] |= (value[i] & 0x00ff);
|
||||
}
|
||||
|
||||
for (int i = 0; i < s; i++)
|
||||
for (int i = 0; i < steps; i++)
|
||||
sum_values += big_endian_values[i];
|
||||
|
||||
check_bytes.check_value = 0xffff - (sum_values % 0xffff);
|
||||
|
||||
Reference in New Issue
Block a user