Split out the CRC and sum functions to new source files

This commit is contained in:
Richard Hughes 2022-06-06 11:33:07 +01:00 committed by Mario Limonciello
parent 0d1ba6667f
commit 3fe9c0de34
38 changed files with 549 additions and 437 deletions

62
contrib/migrate.py Executable file
View File

@ -0,0 +1,62 @@
#!/usr/bin/python3
#
# Copyright (C) 2022 Richard Hughes <richard@hughsie.com>
#
# SPDX-License-Identifier: LGPL-2.1+
#
# import os
import sys
import glob
if __name__ == "__main__":
fns = []
if len(sys.argv) > 1:
fns.extend(sys.argv[1:])
else:
exts = ["c", "h", "map"]
for ext in exts:
for fn in glob.glob("**/*.{}".format(ext), recursive=True):
if fn.startswith("build"):
continue
if fn.startswith("subprojects"):
continue
if fn.startswith(".git"):
continue
fns.append(fn)
for fn in fns:
modified: bool = False
with open(fn, "r") as f:
buf = f.read()
for old, new in {
"fu_common_sum8": "fu_sum8",
"fu_common_sum8_bytes": "fu_sum8_bytes",
"fu_common_sum16": "fu_sum16",
"fu_common_sum16_bytes": "fu_sum16_bytes",
"fu_common_sum16w": "fu_sum16w",
"fu_common_sum16w_bytes": "fu_sum16w_bytes",
"fu_common_sum32": "fu_sum32",
"fu_common_sum32_bytes": "fu_sum32_bytes",
"fu_common_sum32w": "fu_sum32w",
"fu_common_sum32w_bytes": "fu_sum32w_bytes",
"fu_common_crc8": "fu_crc8",
"fu_common_crc8_full": "fu_crc8_full",
"fu_common_crc16": "fu_crc16",
"fu_common_crc16_full": "fu_crc16_full",
"fu_common_crc32": "fu_crc32",
"fu_common_crc32_full": "fu_crc32_full",
}.items():
if buf.find(old) == -1:
continue
buf = buf.replace(old, new)
modified = True
if modified:
print("MODIFIED: {}".format(fn))
with open(fn, "w") as f:
f.write(buf)
sys.exit(0)

View File

@ -4,6 +4,8 @@ This library is only partially API and ABI stable. Keeping unused, unsafe and
deprecated functions around forever is a maintenance burden and so symbols are
removed when branching for new minor versions.
Use `./contrib/migrate.py` to migrate up out-of-tree plugins to the new API.
Remember: Plugins should be upstream!
## 1.5.5
@ -58,3 +60,5 @@ Remember: Plugins should be upstream!
* `fu_backend_coldplug`: Now requires a `FuProgress`, although it can be ignored.
* `FuPluginVfuncs->setup`: Now requires a `FuProgress`, although it can be ignored.
* `FuPluginVfuncs->coldplug`: Now requires a `FuProgress`, although it can be ignored.
* `fu_common_crc*`: Use `fu_crc` prefix, i.e. remove the `_common`
* `fu_common_sum*`: Use `fu_sum` prefix, i.e. remove the `_common`

View File

@ -3631,343 +3631,6 @@ fu_common_get_esp_for_path(const gchar *esp_path, GError **error)
return NULL;
}
/**
* fu_common_crc8_full:
* @buf: memory buffer
* @bufsz: size of @buf
* @crc_init: initial CRC value, typically 0x00
* @polynomial: CRC polynomial, e.g. 0x07 for CCITT
*
* Returns the cyclic redundancy check value for the given memory buffer.
*
* Returns: CRC value
*
* Since: 1.7.1
**/
guint8
fu_common_crc8_full(const guint8 *buf, gsize bufsz, guint8 crc_init, guint8 polynomial)
{
guint32 crc = crc_init;
for (gsize j = bufsz; j > 0; j--) {
crc ^= (*(buf++) << 8);
for (guint32 i = 8; i; i--) {
if (crc & 0x8000)
crc ^= ((polynomial | 0x100) << 7);
crc <<= 1;
}
}
return ~((guint8)(crc >> 8));
}
/**
* fu_common_crc8:
* @buf: memory buffer
* @bufsz: size of @buf
*
* Returns the cyclic redundancy check value for the given memory buffer.
*
* Returns: CRC value
*
* Since: 1.5.0
**/
guint8
fu_common_crc8(const guint8 *buf, gsize bufsz)
{
return fu_common_crc8_full(buf, bufsz, 0x00, 0x07);
}
/**
* fu_common_crc16_full:
* @buf: memory buffer
* @bufsz: size of @buf
* @crc: initial CRC value, typically 0xFFFF
* @polynomial: CRC polynomial, typically 0xA001 for IBM or 0x1021 for CCITT
*
* Returns the cyclic redundancy check value for the given memory buffer.
*
* Returns: CRC value
*
* Since: 1.6.2
**/
guint16
fu_common_crc16_full(const guint8 *buf, gsize bufsz, guint16 crc, guint16 polynomial)
{
for (gsize len = bufsz; len > 0; len--) {
crc = (guint16)(crc ^ (*buf++));
for (guint8 i = 0; i < 8; i++) {
if (crc & 0x1) {
crc = (crc >> 1) ^ polynomial;
} else {
crc >>= 1;
}
}
}
return ~crc;
}
/**
* fu_common_crc16:
* @buf: memory buffer
* @bufsz: size of @buf
*
* Returns the CRC-16-IBM cyclic redundancy value for the given memory buffer.
*
* Returns: CRC value
*
* Since: 1.5.0
**/
guint16
fu_common_crc16(const guint8 *buf, gsize bufsz)
{
return fu_common_crc16_full(buf, bufsz, 0xFFFF, 0xA001);
}
/**
* fu_common_crc32_full:
* @buf: memory buffer
* @bufsz: size of @buf
* @crc: initial CRC value, typically 0xFFFFFFFF
* @polynomial: CRC polynomial, typically 0xEDB88320
*
* Returns the cyclic redundancy check value for the given memory buffer.
*
* Returns: CRC value
*
* Since: 1.5.0
**/
guint32
fu_common_crc32_full(const guint8 *buf, gsize bufsz, guint32 crc, guint32 polynomial)
{
for (guint32 idx = 0; idx < bufsz; idx++) {
guint8 data = *buf++;
crc = crc ^ data;
for (guint32 bit = 0; bit < 8; bit++) {
guint32 mask = -(crc & 1);
crc = (crc >> 1) ^ (polynomial & mask);
}
}
return ~crc;
}
/**
* fu_common_crc32:
* @buf: memory buffer
* @bufsz: size of @buf
*
* Returns the cyclic redundancy check value for the given memory buffer.
*
* Returns: CRC value
*
* Since: 1.5.0
**/
guint32
fu_common_crc32(const guint8 *buf, gsize bufsz)
{
return fu_common_crc32_full(buf, bufsz, 0xFFFFFFFF, 0xEDB88320);
}
/**
* fu_common_sum8:
* @buf: memory buffer
* @bufsz: size of @buf
*
* Returns the arithmetic sum of all bytes in @buf.
*
* Returns: sum value
*
* Since: 1.7.3
**/
guint8
fu_common_sum8(const guint8 *buf, gsize bufsz)
{
guint8 checksum = 0;
g_return_val_if_fail(buf != NULL, G_MAXUINT8);
for (gsize i = 0; i < bufsz; i++)
checksum += buf[i];
return checksum;
}
/**
* fu_common_sum8_bytes:
* @blob: a #GBytes
*
* Returns the arithmetic sum of all bytes in @blob.
*
* Returns: sum value
*
* Since: 1.7.3
**/
guint8
fu_common_sum8_bytes(GBytes *blob)
{
g_return_val_if_fail(blob != NULL, G_MAXUINT8);
if (g_bytes_get_size(blob) == 0)
return 0;
return fu_common_sum8(g_bytes_get_data(blob, NULL), g_bytes_get_size(blob));
}
/**
* fu_common_sum16:
* @buf: memory buffer
* @bufsz: size of @buf
*
* Returns the arithmetic sum of all bytes in @buf, adding them one byte at a time.
*
* Returns: sum value
*
* Since: 1.7.3
**/
guint16
fu_common_sum16(const guint8 *buf, gsize bufsz)
{
guint16 checksum = 0;
g_return_val_if_fail(buf != NULL, G_MAXUINT16);
for (gsize i = 0; i < bufsz; i++)
checksum += buf[i];
return checksum;
}
/**
* fu_common_sum16_bytes:
* @blob: a #GBytes
*
* Returns the arithmetic sum of all bytes in @blob, adding them one byte at a time.
*
* Returns: sum value
*
* Since: 1.7.3
**/
guint16
fu_common_sum16_bytes(GBytes *blob)
{
g_return_val_if_fail(blob != NULL, G_MAXUINT16);
return fu_common_sum16(g_bytes_get_data(blob, NULL), g_bytes_get_size(blob));
}
/**
* fu_common_sum16w:
* @buf: memory buffer
* @bufsz: size of @buf
* @endian: an endian type, e.g. %G_LITTLE_ENDIAN
*
* Returns the arithmetic sum of all bytes in @buf, adding them one word at a time.
* The caller must ensure that @bufsz is a multiple of 2.
*
* Returns: sum value
*
* Since: 1.7.3
**/
guint16
fu_common_sum16w(const guint8 *buf, gsize bufsz, FuEndianType endian)
{
guint16 checksum = 0;
g_return_val_if_fail(buf != NULL, G_MAXUINT16);
g_return_val_if_fail(bufsz % 2 == 0, G_MAXUINT16);
for (gsize i = 0; i < bufsz; i += 2)
checksum += fu_common_read_uint16(&buf[i], endian);
return checksum;
}
/**
* fu_common_sum16w_bytes:
* @blob: a #GBytes
* @endian: an endian type, e.g. %G_LITTLE_ENDIAN
*
* Returns the arithmetic sum of all bytes in @blob, adding them one word at a time.
* The caller must ensure that the size of @blob is a multiple of 2.
*
* Returns: sum value
*
* Since: 1.7.3
**/
guint16
fu_common_sum16w_bytes(GBytes *blob, FuEndianType endian)
{
g_return_val_if_fail(blob != NULL, G_MAXUINT16);
return fu_common_sum16w(g_bytes_get_data(blob, NULL), g_bytes_get_size(blob), endian);
}
/**
* fu_common_sum32:
* @buf: memory buffer
* @bufsz: size of @buf
*
* Returns the arithmetic sum of all bytes in @buf, adding them one byte at a time.
*
* Returns: sum value
*
* Since: 1.7.3
**/
guint32
fu_common_sum32(const guint8 *buf, gsize bufsz)
{
guint32 checksum = 0;
g_return_val_if_fail(buf != NULL, G_MAXUINT32);
for (gsize i = 0; i < bufsz; i++)
checksum += buf[i];
return checksum;
}
/**
* fu_common_sum32_bytes:
* @blob: a #GBytes
*
* Returns the arithmetic sum of all bytes in @blob, adding them one byte at a time.
*
* Returns: sum value
*
* Since: 1.7.3
**/
guint32
fu_common_sum32_bytes(GBytes *blob)
{
g_return_val_if_fail(blob != NULL, G_MAXUINT32);
return fu_common_sum32(g_bytes_get_data(blob, NULL), g_bytes_get_size(blob));
}
/**
* fu_common_sum32w:
* @buf: memory buffer
* @bufsz: size of @buf
* @endian: an endian type, e.g. %G_LITTLE_ENDIAN
*
* Returns the arithmetic sum of all bytes in @buf, adding them one dword at a time.
* The caller must ensure that @bufsz is a multiple of 4.
*
* Returns: sum value
*
* Since: 1.7.3
**/
guint32
fu_common_sum32w(const guint8 *buf, gsize bufsz, FuEndianType endian)
{
guint32 checksum = 0;
g_return_val_if_fail(buf != NULL, G_MAXUINT32);
g_return_val_if_fail(bufsz % 4 == 0, G_MAXUINT32);
for (gsize i = 0; i < bufsz; i += 4)
checksum += fu_common_read_uint32(&buf[i], endian);
return checksum;
}
/**
* fu_common_sum32w_bytes:
* @blob: a #GBytes
* @endian: an endian type, e.g. %G_LITTLE_ENDIAN
*
* Returns the arithmetic sum of all bytes in @blob, adding them one dword at a time.
* The caller must ensure that the size of @blob is a multiple of 4.
*
* Returns: sum value
*
* Since: 1.7.3
**/
guint32
fu_common_sum32w_bytes(GBytes *blob, FuEndianType endian)
{
g_return_val_if_fail(blob != NULL, G_MAXUINT32);
return fu_common_sum32w(g_bytes_get_data(blob, NULL), g_bytes_get_size(blob), endian);
}
/**
* fu_common_reverse_uint8:
* @value: integer

View File

@ -441,43 +441,9 @@ fu_common_get_esp_default(GError **error) G_GNUC_WARN_UNUSED_RESULT;
gboolean
fu_common_check_full_disk_encryption(GError **error);
guint8
fu_common_crc8(const guint8 *buf, gsize bufsz);
guint8
fu_common_crc8_full(const guint8 *buf, gsize bufsz, guint8 crc_init, guint8 polynomial);
guint16
fu_common_crc16(const guint8 *buf, gsize bufsz);
guint16
fu_common_crc16_full(const guint8 *buf, gsize bufsz, guint16 crc, guint16 polynomial);
guint32
fu_common_crc32(const guint8 *buf, gsize bufsz);
guint32
fu_common_crc32_full(const guint8 *buf, gsize bufsz, guint32 crc, guint32 polynomial);
guint8
fu_common_reverse_uint8(guint8 value);
guint8
fu_common_sum8(const guint8 *buf, gsize bufsz);
guint8
fu_common_sum8_bytes(GBytes *blob);
guint16
fu_common_sum16(const guint8 *buf, gsize bufsz);
guint16
fu_common_sum16_bytes(GBytes *blob);
guint16
fu_common_sum16w(const guint8 *buf, gsize bufsz, FuEndianType endian);
guint16
fu_common_sum16w_bytes(GBytes *blob, FuEndianType endian);
guint32
fu_common_sum32(const guint8 *buf, gsize bufsz);
guint32
fu_common_sum32_bytes(GBytes *blob);
guint32
fu_common_sum32w(const guint8 *buf, gsize bufsz, FuEndianType endian);
guint32
fu_common_sum32w_bytes(GBytes *blob, FuEndianType endian);
gchar *
fu_common_uri_get_scheme(const gchar *uri);
gsize

146
libfwupdplugin/fu-crc.c Normal file
View File

@ -0,0 +1,146 @@
/*
* Copyright (C) 2017 Richard Hughes <richard@hughsie.com>
*
* SPDX-License-Identifier: LGPL-2.1+
*/
#define G_LOG_DOMAIN "FuCommon"
#include "config.h"
#include "fu-crc.h"
/**
* fu_crc8_full:
* @buf: memory buffer
* @bufsz: size of @buf
* @crc_init: initial CRC value, typically 0x00
* @polynomial: CRC polynomial, e.g. 0x07 for CCITT
*
* Returns the cyclic redundancy check value for the given memory buffer.
*
* Returns: CRC value
*
* Since: 1.8.2
**/
guint8
fu_crc8_full(const guint8 *buf, gsize bufsz, guint8 crc_init, guint8 polynomial)
{
guint32 crc = crc_init;
for (gsize j = bufsz; j > 0; j--) {
crc ^= (*(buf++) << 8);
for (guint32 i = 8; i; i--) {
if (crc & 0x8000)
crc ^= ((polynomial | 0x100) << 7);
crc <<= 1;
}
}
return ~((guint8)(crc >> 8));
}
/**
* fu_crc8:
* @buf: memory buffer
* @bufsz: size of @buf
*
* Returns the cyclic redundancy check value for the given memory buffer.
*
* Returns: CRC value
*
* Since: 1.8.2
**/
guint8
fu_crc8(const guint8 *buf, gsize bufsz)
{
return fu_crc8_full(buf, bufsz, 0x00, 0x07);
}
/**
* fu_crc16_full:
* @buf: memory buffer
* @bufsz: size of @buf
* @crc: initial CRC value, typically 0xFFFF
* @polynomial: CRC polynomial, typically 0xA001 for IBM or 0x1021 for CCITT
*
* Returns the cyclic redundancy check value for the given memory buffer.
*
* Returns: CRC value
*
* Since: 1.8.2
**/
guint16
fu_crc16_full(const guint8 *buf, gsize bufsz, guint16 crc, guint16 polynomial)
{
for (gsize len = bufsz; len > 0; len--) {
crc = (guint16)(crc ^ (*buf++));
for (guint8 i = 0; i < 8; i++) {
if (crc & 0x1) {
crc = (crc >> 1) ^ polynomial;
} else {
crc >>= 1;
}
}
}
return ~crc;
}
/**
* fu_crc16:
* @buf: memory buffer
* @bufsz: size of @buf
*
* Returns the CRC-16-IBM cyclic redundancy value for the given memory buffer.
*
* Returns: CRC value
*
* Since: 1.8.2
**/
guint16
fu_crc16(const guint8 *buf, gsize bufsz)
{
return fu_crc16_full(buf, bufsz, 0xFFFF, 0xA001);
}
/**
* fu_crc32_full:
* @buf: memory buffer
* @bufsz: size of @buf
* @crc: initial CRC value, typically 0xFFFFFFFF
* @polynomial: CRC polynomial, typically 0xEDB88320
*
* Returns the cyclic redundancy check value for the given memory buffer.
*
* Returns: CRC value
*
* Since: 1.8.2
**/
guint32
fu_crc32_full(const guint8 *buf, gsize bufsz, guint32 crc, guint32 polynomial)
{
for (guint32 idx = 0; idx < bufsz; idx++) {
guint8 data = *buf++;
crc = crc ^ data;
for (guint32 bit = 0; bit < 8; bit++) {
guint32 mask = -(crc & 1);
crc = (crc >> 1) ^ (polynomial & mask);
}
}
return ~crc;
}
/**
* fu_crc32:
* @buf: memory buffer
* @bufsz: size of @buf
*
* Returns the cyclic redundancy check value for the given memory buffer.
*
* Returns: CRC value
*
* Since: 1.8.2
**/
guint32
fu_crc32(const guint8 *buf, gsize bufsz)
{
return fu_crc32_full(buf, bufsz, 0xFFFFFFFF, 0xEDB88320);
}

22
libfwupdplugin/fu-crc.h Normal file
View File

@ -0,0 +1,22 @@
/*
* Copyright (C) 2017 Richard Hughes <richard@hughsie.com>
*
* SPDX-License-Identifier: LGPL-2.1+
*/
#pragma once
#include "fu-common.h"
guint8
fu_crc8(const guint8 *buf, gsize bufsz);
guint8
fu_crc8_full(const guint8 *buf, gsize bufsz, guint8 crc_init, guint8 polynomial);
guint16
fu_crc16(const guint8 *buf, gsize bufsz);
guint16
fu_crc16_full(const guint8 *buf, gsize bufsz, guint16 crc, guint16 polynomial);
guint32
fu_crc32(const guint8 *buf, gsize bufsz);
guint32
fu_crc32_full(const guint8 *buf, gsize bufsz, guint32 crc, guint32 polynomial);

View File

@ -11,6 +11,7 @@
#include <string.h>
#include "fu-common.h"
#include "fu-crc.h"
#include "fu-dfu-firmware-private.h"
/**
@ -245,7 +246,7 @@ fu_dfu_firmware_parse_footer(FuDfuFirmware *self,
return FALSE;
crc = GUINT32_FROM_LE(ftr.crc);
if ((flags & FWUPD_INSTALL_FLAG_IGNORE_CHECKSUM) == 0) {
crc_new = ~fu_common_crc32(data, len - 4);
crc_new = ~fu_crc32(data, len - 4);
if (crc != crc_new) {
g_set_error(error,
FWUPD_ERROR,
@ -323,7 +324,7 @@ fu_dfu_firmware_append_footer(FuDfuFirmware *self, GBytes *contents, GError **er
fu_byte_array_append_uint16(buf, priv->dfu_version, G_LITTLE_ENDIAN);
g_byte_array_append(buf, (const guint8 *)"UFD", 3);
fu_byte_array_append_uint8(buf, sizeof(FuDfuFirmwareFooter));
fu_byte_array_append_uint32(buf, ~fu_common_crc32(buf->data, buf->len), G_LITTLE_ENDIAN);
fu_byte_array_append_uint32(buf, ~fu_crc32(buf->data, buf->len), G_LITTLE_ENDIAN);
return g_byte_array_free_to_bytes(buf);
}

View File

@ -12,6 +12,7 @@
#include "fu-efi-firmware-common.h"
#include "fu-efi-firmware-file.h"
#include "fu-efi-firmware-section.h"
#include "fu-sum.h"
typedef struct {
guint8 type;
@ -254,7 +255,7 @@ fu_efi_firmware_file_parse(FuFirmware *firmware,
/* verify data checksum */
if ((priv->attrib & FU_EFI_FIRMWARE_FILE_ATTRIB_CHECKSUM) > 0 &&
(flags & FWUPD_INSTALL_FLAG_IGNORE_CHECKSUM) == 0) {
guint8 data_checksum_verify = 0x100 - fu_common_sum8_bytes(blob);
guint8 data_checksum_verify = 0x100 - fu_sum8_bytes(blob);
if (data_checksum_verify != data_checksum) {
g_set_error(error,
FWUPD_ERROR,
@ -333,7 +334,7 @@ fu_efi_firmware_file_write(FuFirmware *firmware, GError **error)
return NULL;
g_byte_array_append(buf, (guint8 *)&guid, sizeof(guid));
fu_byte_array_append_uint8(buf, 0x0); /* hdr_checksum */
fu_byte_array_append_uint8(buf, 0x100 - fu_common_sum8_bytes(blob));
fu_byte_array_append_uint8(buf, 0x100 - fu_sum8_bytes(blob));
fu_byte_array_append_uint8(buf, priv->type); /* data_checksum */
fu_byte_array_append_uint8(buf, priv->attrib); /* data_checksum */
fu_byte_array_append_uint32(buf,

View File

@ -180,9 +180,9 @@ static void
fu_common_crc_func(void)
{
guint8 buf[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09};
g_assert_cmpint(fu_common_crc8(buf, sizeof(buf)), ==, 0x7A);
g_assert_cmpint(fu_common_crc16(buf, sizeof(buf)), ==, 0x4DF1);
g_assert_cmpint(fu_common_crc32(buf, sizeof(buf)), ==, 0x40EFAB9E);
g_assert_cmpint(fu_crc8(buf, sizeof(buf)), ==, 0x7A);
g_assert_cmpint(fu_crc16(buf, sizeof(buf)), ==, 0x4DF1);
g_assert_cmpint(fu_crc32(buf, sizeof(buf)), ==, 0x40EFAB9E);
}
static void

214
libfwupdplugin/fu-sum.c Normal file
View File

@ -0,0 +1,214 @@
/*
* Copyright (C) 2017 Richard Hughes <richard@hughsie.com>
*
* SPDX-License-Identifier: LGPL-2.1+
*/
#define G_LOG_DOMAIN "FuCommon"
#include "config.h"
#include "fu-common.h"
#include "fu-sum.h"
/**
* fu_sum8:
* @buf: memory buffer
* @bufsz: size of @buf
*
* Returns the arithmetic sum of all bytes in @buf.
*
* Returns: sum value
*
* Since: 1.8.2
**/
guint8
fu_sum8(const guint8 *buf, gsize bufsz)
{
guint8 checksum = 0;
g_return_val_if_fail(buf != NULL, G_MAXUINT8);
for (gsize i = 0; i < bufsz; i++)
checksum += buf[i];
return checksum;
}
/**
* fu_sum8_bytes:
* @blob: a #GBytes
*
* Returns the arithmetic sum of all bytes in @blob.
*
* Returns: sum value
*
* Since: 1.8.2
**/
guint8
fu_sum8_bytes(GBytes *blob)
{
g_return_val_if_fail(blob != NULL, G_MAXUINT8);
if (g_bytes_get_size(blob) == 0)
return 0;
return fu_sum8(g_bytes_get_data(blob, NULL), g_bytes_get_size(blob));
}
/**
* fu_sum16:
* @buf: memory buffer
* @bufsz: size of @buf
*
* Returns the arithmetic sum of all bytes in @buf, adding them one byte at a time.
*
* Returns: sum value
*
* Since: 1.8.2
**/
guint16
fu_sum16(const guint8 *buf, gsize bufsz)
{
guint16 checksum = 0;
g_return_val_if_fail(buf != NULL, G_MAXUINT16);
for (gsize i = 0; i < bufsz; i++)
checksum += buf[i];
return checksum;
}
/**
* fu_sum16_bytes:
* @blob: a #GBytes
*
* Returns the arithmetic sum of all bytes in @blob, adding them one byte at a time.
*
* Returns: sum value
*
* Since: 1.8.2
**/
guint16
fu_sum16_bytes(GBytes *blob)
{
g_return_val_if_fail(blob != NULL, G_MAXUINT16);
return fu_sum16(g_bytes_get_data(blob, NULL), g_bytes_get_size(blob));
}
/**
* fu_sum16w:
* @buf: memory buffer
* @bufsz: size of @buf
* @endian: an endian type, e.g. %G_LITTLE_ENDIAN
*
* Returns the arithmetic sum of all bytes in @buf, adding them one word at a time.
* The caller must ensure that @bufsz is a multiple of 2.
*
* Returns: sum value
*
* Since: 1.8.2
**/
guint16
fu_sum16w(const guint8 *buf, gsize bufsz, FuEndianType endian)
{
guint16 checksum = 0;
g_return_val_if_fail(buf != NULL, G_MAXUINT16);
g_return_val_if_fail(bufsz % 2 == 0, G_MAXUINT16);
for (gsize i = 0; i < bufsz; i += 2)
checksum += fu_common_read_uint16(&buf[i], endian);
return checksum;
}
/**
* fu_sum16w_bytes:
* @blob: a #GBytes
* @endian: an endian type, e.g. %G_LITTLE_ENDIAN
*
* Returns the arithmetic sum of all bytes in @blob, adding them one word at a time.
* The caller must ensure that the size of @blob is a multiple of 2.
*
* Returns: sum value
*
* Since: 1.8.2
**/
guint16
fu_sum16w_bytes(GBytes *blob, FuEndianType endian)
{
g_return_val_if_fail(blob != NULL, G_MAXUINT16);
return fu_sum16w(g_bytes_get_data(blob, NULL), g_bytes_get_size(blob), endian);
}
/**
* fu_sum32:
* @buf: memory buffer
* @bufsz: size of @buf
*
* Returns the arithmetic sum of all bytes in @buf, adding them one byte at a time.
*
* Returns: sum value
*
* Since: 1.8.2
**/
guint32
fu_sum32(const guint8 *buf, gsize bufsz)
{
guint32 checksum = 0;
g_return_val_if_fail(buf != NULL, G_MAXUINT32);
for (gsize i = 0; i < bufsz; i++)
checksum += buf[i];
return checksum;
}
/**
* fu_sum32_bytes:
* @blob: a #GBytes
*
* Returns the arithmetic sum of all bytes in @blob, adding them one byte at a time.
*
* Returns: sum value
*
* Since: 1.8.2
**/
guint32
fu_sum32_bytes(GBytes *blob)
{
g_return_val_if_fail(blob != NULL, G_MAXUINT32);
return fu_sum32(g_bytes_get_data(blob, NULL), g_bytes_get_size(blob));
}
/**
* fu_sum32w:
* @buf: memory buffer
* @bufsz: size of @buf
* @endian: an endian type, e.g. %G_LITTLE_ENDIAN
*
* Returns the arithmetic sum of all bytes in @buf, adding them one dword at a time.
* The caller must ensure that @bufsz is a multiple of 4.
*
* Returns: sum value
*
* Since: 1.8.2
**/
guint32
fu_sum32w(const guint8 *buf, gsize bufsz, FuEndianType endian)
{
guint32 checksum = 0;
g_return_val_if_fail(buf != NULL, G_MAXUINT32);
g_return_val_if_fail(bufsz % 4 == 0, G_MAXUINT32);
for (gsize i = 0; i < bufsz; i += 4)
checksum += fu_common_read_uint32(&buf[i], endian);
return checksum;
}
/**
* fu_sum32w_bytes:
* @blob: a #GBytes
* @endian: an endian type, e.g. %G_LITTLE_ENDIAN
*
* Returns the arithmetic sum of all bytes in @blob, adding them one dword at a time.
* The caller must ensure that the size of @blob is a multiple of 4.
*
* Returns: sum value
*
* Since: 1.8.2
**/
guint32
fu_sum32w_bytes(GBytes *blob, FuEndianType endian)
{
g_return_val_if_fail(blob != NULL, G_MAXUINT32);
return fu_sum32w(g_bytes_get_data(blob, NULL), g_bytes_get_size(blob), endian);
}

30
libfwupdplugin/fu-sum.h Normal file
View File

@ -0,0 +1,30 @@
/*
* Copyright (C) 2017 Richard Hughes <richard@hughsie.com>
*
* SPDX-License-Identifier: LGPL-2.1+
*/
#pragma once
#include "fu-common.h"
guint8
fu_sum8(const guint8 *buf, gsize bufsz);
guint8
fu_sum8_bytes(GBytes *blob);
guint16
fu_sum16(const guint8 *buf, gsize bufsz);
guint16
fu_sum16_bytes(GBytes *blob);
guint16
fu_sum16w(const guint8 *buf, gsize bufsz, FuEndianType endian);
guint16
fu_sum16w_bytes(GBytes *blob, FuEndianType endian);
guint32
fu_sum32(const guint8 *buf, gsize bufsz);
guint32
fu_sum32_bytes(GBytes *blob);
guint32
fu_sum32w(const guint8 *buf, gsize bufsz, FuEndianType endian);
guint32
fu_sum32w_bytes(GBytes *blob, FuEndianType endian);

View File

@ -22,6 +22,7 @@
#include <libfwupdplugin/fu-common-version.h>
#include <libfwupdplugin/fu-common.h>
#include <libfwupdplugin/fu-context.h>
#include <libfwupdplugin/fu-crc.h>
#include <libfwupdplugin/fu-device-locker.h>
#include <libfwupdplugin/fu-device-metadata.h>
#include <libfwupdplugin/fu-device.h>
@ -44,6 +45,7 @@
#include <libfwupdplugin/fu-progress.h>
#include <libfwupdplugin/fu-security-attrs.h>
#include <libfwupdplugin/fu-srec-firmware.h>
#include <libfwupdplugin/fu-sum.h>
#include <libfwupdplugin/fu-udev-device.h>
#include <libfwupdplugin/fu-usb-device.h>
#include <libfwupdplugin/fu-volume.h>

View File

@ -523,10 +523,6 @@ LIBFWUPDPLUGIN_1.5.0 {
global:
fu_byte_array_set_size;
fu_common_cpuid;
fu_common_crc16;
fu_common_crc32;
fu_common_crc32_full;
fu_common_crc8;
fu_common_filename_glob;
fu_device_bind_driver;
fu_device_dump_firmware;
@ -791,7 +787,6 @@ LIBFWUPDPLUGIN_1.6.1 {
LIBFWUPDPLUGIN_1.6.2 {
global:
fu_common_check_kernel_version;
fu_common_crc16_full;
fu_common_get_firmware_search_path;
fu_common_reset_firmware_search_path;
fu_common_set_firmware_search_path;
@ -919,7 +914,6 @@ LIBFWUPDPLUGIN_1.7.1 {
fu_cfi_device_set_flash_id;
fu_cfi_device_set_size;
fu_common_check_full_disk_encryption;
fu_common_crc8_full;
fu_common_mkdir;
fu_device_add_string;
fu_device_get_internal_flags;
@ -950,16 +944,6 @@ LIBFWUPDPLUGIN_1.7.3 {
fu_cfi_device_set_page_size;
fu_cfi_device_set_sector_size;
fu_common_strtoull_full;
fu_common_sum16;
fu_common_sum16_bytes;
fu_common_sum16w;
fu_common_sum16w_bytes;
fu_common_sum32;
fu_common_sum32_bytes;
fu_common_sum32w;
fu_common_sum32w_bytes;
fu_common_sum8;
fu_common_sum8_bytes;
local: *;
} LIBFWUPDPLUGIN_1.7.2;
@ -1041,11 +1025,27 @@ LIBFWUPDPLUGIN_1.8.1 {
LIBFWUPDPLUGIN_1.8.2 {
global:
fu_crc16;
fu_crc16_full;
fu_crc32;
fu_crc32_full;
fu_crc8;
fu_crc8_full;
fu_device_new;
fu_efivar_secure_boot_enabled;
fu_progress_add_step;
fu_progress_get_name;
fu_progress_set_name;
fu_sum16;
fu_sum16_bytes;
fu_sum16w;
fu_sum16w_bytes;
fu_sum32;
fu_sum32_bytes;
fu_sum32w;
fu_sum32w_bytes;
fu_sum8;
fu_sum8_bytes;
fu_udev_device_ioctl;
fu_udev_device_new;
fu_udev_device_pread;

View File

@ -15,6 +15,8 @@ fwupdplugin_src = [
'fu-cabinet.c',
'fu-chunk.c', # fuzzing
'fu-common.c', # fuzzing
'fu-sum.c', # fuzzing
'fu-crc.c', # fuzzing
'fu-common-cab.c',
'fu-common-guid.c',
'fu-common-version.c', # fuzzing
@ -87,6 +89,8 @@ fwupdplugin_headers = [
'fu-cabinet.h',
'fu-chunk.h',
'fu-common.h',
'fu-sum.h',
'fu-crc.h',
'fu-common-cab.h',
'fu-common-guid.h',
'fu-common-version.h',

View File

@ -163,7 +163,7 @@ fu_acpi_phat_parse(FuFirmware *firmware,
/* verify checksum */
if ((flags & FWUPD_INSTALL_FLAG_IGNORE_CHECKSUM) == 0) {
guint8 checksum = fu_common_sum8(buf, length);
guint8 checksum = fu_sum8(buf, length);
if (checksum != 0x00) {
g_set_error(error,
G_IO_ERROR,
@ -273,7 +273,7 @@ fu_acpi_phat_write(FuFirmware *firmware, GError **error)
g_byte_array_append(buf, buf2->data, buf2->len);
/* fixup checksum */
buf->data[9] = 0xFF - fu_common_sum8(buf->data, buf->len);
buf->data[9] = 0xFF - fu_sum8(buf->data, buf->len);
/* success */
return g_byte_array_free_to_bytes(g_steal_pointer(&buf));

View File

@ -16,7 +16,7 @@
guint32
fu_bcm57xx_nvram_crc(const guint8 *buf, gsize bufsz)
{
return fu_common_crc32(buf, bufsz);
return fu_crc32(buf, bufsz);
}
gboolean

View File

@ -227,7 +227,7 @@ fu_ccgx_firmware_parse_md_block(FuCcgxFirmware *self, FwupdInstallFlags flags, G
}
for (guint i = 0; i < self->records->len - 1; i++) {
rcd = g_ptr_array_index(self->records, i);
checksum_calc += fu_common_sum8_bytes(rcd->data);
checksum_calc += fu_sum8_bytes(rcd->data);
fw_size += g_bytes_get_size(rcd->data);
}
if (fw_size != metadata.fw_size) {

View File

@ -347,9 +347,8 @@ fu_elantp_hid_device_write_firmware(FuDevice *device,
chunks = fu_chunk_array_new(buf + iap_addr, bufsz - iap_addr, 0x0, 0x0, self->fw_page_size);
for (guint i = 0; i < chunks->len; i++) {
FuChunk *chk = g_ptr_array_index(chunks, i);
guint16 csum_tmp = fu_common_sum16w(fu_chunk_get_data(chk),
fu_chunk_get_data_sz(chk),
G_LITTLE_ENDIAN);
guint16 csum_tmp =
fu_sum16w(fu_chunk_get_data(chk), fu_chunk_get_data_sz(chk), G_LITTLE_ENDIAN);
gsize blksz = self->fw_page_size + 3;
g_autofree guint8 *blk = g_malloc0(blksz);

View File

@ -409,9 +409,8 @@ fu_elantp_i2c_device_write_firmware(FuDevice *device,
chunks = fu_chunk_array_new(buf + iap_addr, bufsz - iap_addr, 0x0, 0x0, self->fw_page_size);
for (guint i = 0; i < chunks->len; i++) {
FuChunk *chk = g_ptr_array_index(chunks, i);
guint16 csum_tmp = fu_common_sum16w(fu_chunk_get_data(chk),
fu_chunk_get_data_sz(chk),
G_LITTLE_ENDIAN);
guint16 csum_tmp =
fu_sum16w(fu_chunk_get_data(chk), fu_chunk_get_data_sz(chk), G_LITTLE_ENDIAN);
gsize blksz = self->fw_page_size + 4;
g_autofree guint8 *blk = g_malloc0(blksz);

View File

@ -94,7 +94,7 @@ fu_genesys_usbhub_firmware_verify(const guint8 *buf, gsize bufsz, guint16 code_s
return FALSE;
/* calculate checksum */
checksum = fu_common_sum16(buf, code_size - sizeof(checksum));
checksum = fu_sum16(buf, code_size - sizeof(checksum));
if (checksum != fw_checksum) {
g_set_error(error,
FWUPD_ERROR,
@ -266,7 +266,7 @@ fu_genesys_usbhub_firmware_write(FuFirmware *firmware, GError **error)
return NULL;
/* checksum */
checksum = fu_common_sum16(buf->data, code_size - sizeof(checksum));
checksum = fu_sum16(buf->data, code_size - sizeof(checksum));
if (!fu_common_write_uint16_safe(buf->data,
buf->len,
code_size - sizeof(guint16),

View File

@ -47,11 +47,11 @@ goodixmoc_device_cmd_send(FuGoodixMocDevice *self,
fu_byte_array_append_uint8(buf, type); /* pkg_flag */
fu_byte_array_append_uint8(buf, self->dummy_seq++); /* reserved */
fu_byte_array_append_uint16(buf, req->len + GX_SIZE_CRC32, G_LITTLE_ENDIAN);
crc_hdr = fu_common_crc8(buf->data, buf->len);
crc_hdr = fu_crc8(buf->data, buf->len);
fu_byte_array_append_uint8(buf, crc_hdr);
fu_byte_array_append_uint8(buf, ~crc_hdr);
g_byte_array_append(buf, req->data, req->len);
crc_all = fu_common_crc32(buf->data, buf->len);
crc_all = fu_crc32(buf->data, buf->len);
fu_byte_array_append_uint32(buf, crc_all, G_LITTLE_ENDIAN);
/* send zero length package */
@ -154,7 +154,7 @@ goodixmoc_device_cmd_recv(FuGoodixMocDevice *self,
error))
return FALSE;
offset = sizeof(GxfpPkgHeader) + header_len - GX_SIZE_CRC32;
crc_actual = fu_common_crc32(reply->data, offset);
crc_actual = fu_crc32(reply->data, offset);
if (!fu_common_read_uint32_safe(reply->data,
reply->len,
offset,

View File

@ -44,10 +44,10 @@ static guint32
fu_nordic_hid_firmware_crc32(const guint8 *buf, gsize bufsz)
{
guint crc32 = 0x01;
/* maybe skipped "^" step in fu_common_crc32_full()?
/* maybe skipped "^" step in fu_crc32_full()?
* according https://github.com/madler/zlib/blob/master/crc32.c#L225 */
crc32 ^= 0xFFFFFFFFUL;
return fu_common_crc32_full(buf, bufsz, crc32, 0xEDB88320);
return fu_crc32_full(buf, bufsz, crc32, 0xEDB88320);
}
static gboolean

View File

@ -324,7 +324,7 @@ fu_pxi_ble_device_check_support_resume(FuPxiBleDevice *self,
/* calculate device current checksum */
for (guint i = 0; i < self->fwstate.offset; i++) {
FuChunk *chk = g_ptr_array_index(chunks, i);
checksum_tmp += fu_common_sum16(fu_chunk_get_data(chk), fu_chunk_get_data_sz(chk));
checksum_tmp += fu_sum16(fu_chunk_get_data(chk), fu_chunk_get_data_sz(chk));
}
/* check current file is different with previous fw bin or not */
@ -496,7 +496,7 @@ fu_pxi_ble_device_write_chunk(FuPxiBleDevice *self, FuChunk *chk, GError **error
}
/* the last chunk */
checksum = fu_common_sum16(fu_chunk_get_data(chk), fu_chunk_get_data_sz(chk));
checksum = fu_sum16(fu_chunk_get_data(chk), fu_chunk_get_data_sz(chk));
self->fwstate.checksum += checksum;
if (checksum_device != self->fwstate.checksum) {
g_set_error(error,
@ -598,7 +598,7 @@ fu_pxi_ble_device_fw_upgrade(FuPxiBleDevice *self,
fw = fu_firmware_get_bytes(firmware, error);
if (fw == NULL)
return FALSE;
checksum = fu_common_sum16_bytes(fw);
checksum = fu_sum16_bytes(fw);
fu_byte_array_append_uint8(req, PXI_HID_DEV_OTA_FEATURE_REPORT_ID);
fu_byte_array_append_uint8(req, FU_PXI_DEVICE_CMD_FW_UPGRADE);
fu_byte_array_append_uint32(req, g_bytes_get_size(fw), G_LITTLE_ENDIAN);

View File

@ -154,7 +154,7 @@ fu_pxi_composite_receiver_cmd(guint8 opcode,
g_byte_array_prepend(wireless_mod_cmd, &rf_cmd_code, 0x01); /* command code */
/* prepend checksum */
checksum = fu_common_sum8(wireless_mod_cmd->data, wireless_mod_cmd->len);
checksum = fu_sum8(wireless_mod_cmd->data, wireless_mod_cmd->len);
g_byte_array_prepend(wireless_mod_cmd, &checksum, 0x01);
/* prepend feature report id */

View File

@ -392,7 +392,7 @@ fu_pxi_receiver_device_write_chunk(FuDevice *device, FuChunk *chk, GError **erro
self->fwstate.mtu_size);
/* the checksum of chunk */
checksum = fu_common_sum16(fu_chunk_get_data(chk), fu_chunk_get_data_sz(chk));
checksum = fu_sum16(fu_chunk_get_data(chk), fu_chunk_get_data_sz(chk));
self->fwstate.checksum += checksum;
for (guint i = 0; i < chunks->len; i++) {
FuChunk *chk2 = g_ptr_array_index(chunks, i);
@ -447,7 +447,7 @@ fu_pxi_receiver_device_fw_upgrade(FuDevice *device,
g_bytes_get_size(fw),
G_LITTLE_ENDIAN); /* ota fw upgrade command fw size */
fu_byte_array_append_uint16(ota_cmd,
fu_common_sum16_bytes(fw),
fu_sum16_bytes(fw),
G_LITTLE_ENDIAN); /* ota fw upgrade command checksum */
version = fu_firmware_get_version(firmware);

View File

@ -340,7 +340,7 @@ fu_pxi_wireless_device_write_chunk(FuDevice *device, FuChunk *chk, GError **erro
self->fwstate.mtu_size);
/* calculate checksum of chunk */
checksum = fu_common_sum16(fu_chunk_get_data(chk), fu_chunk_get_data_sz(chk));
checksum = fu_sum16(fu_chunk_get_data(chk), fu_chunk_get_data_sz(chk));
self->fwstate.checksum += checksum;
for (guint i = 0; i < chunks->len; i++) {
@ -496,7 +496,7 @@ fu_pxi_wireless_device_fw_upgrade(FuDevice *device,
g_bytes_get_size(fw),
G_LITTLE_ENDIAN); /* ota fw upgrade command fw size */
fu_byte_array_append_uint16(ota_cmd,
fu_common_sum16_bytes(fw),
fu_sum16_bytes(fw),
G_LITTLE_ENDIAN); /* ota fw upgrade command checksum */
version = fu_firmware_get_version(firmware);

View File

@ -36,8 +36,8 @@ fu_steelseries_firmware_parse(FuFirmware *firmware,
G_LITTLE_ENDIAN,
error))
return FALSE;
checksum_tmp = fu_common_crc32(g_bytes_get_data(fw, NULL),
g_bytes_get_size(fw) - sizeof(checksum_tmp));
checksum_tmp =
fu_crc32(g_bytes_get_data(fw, NULL), g_bytes_get_size(fw) - sizeof(checksum_tmp));
if (checksum_tmp != checksum) {
if ((flags & FWUPD_INSTALL_FLAG_IGNORE_CHECKSUM) == 0) {
g_set_error(error,

View File

@ -165,7 +165,7 @@ fu_steelseries_gamepad_write_firmware_chunks(FuDevice *device,
/* block checksum */
/* probably not necessary */
chunk_checksum = fu_common_sum16(data + 3, STEELSERIES_BUFFER_TRANSFER_SIZE);
chunk_checksum = fu_sum16(data + 3, STEELSERIES_BUFFER_TRANSFER_SIZE);
if (!fu_common_write_uint16_safe(data,
STEELSERIES_BUFFER_CONTROL_SIZE,
0x03 + STEELSERIES_BUFFER_TRANSFER_SIZE,

View File

@ -983,8 +983,8 @@ fu_steelseries_sonic_parse_firmware(FuFirmware *firmware, FwupdInstallFlags flag
G_LITTLE_ENDIAN,
error))
return FALSE;
checksum_tmp = fu_common_crc32(g_bytes_get_data(blob, NULL),
g_bytes_get_size(blob) - sizeof(checksum_tmp));
checksum_tmp =
fu_crc32(g_bytes_get_data(blob, NULL), g_bytes_get_size(blob) - sizeof(checksum_tmp));
checksum_tmp = ~checksum_tmp;
if (checksum_tmp != checksum) {
if ((flags & FWUPD_INSTALL_FLAG_IGNORE_CHECKSUM) == 0) {

View File

@ -319,7 +319,7 @@ fu_synaptics_mst_device_update_esm(FuSynapticsMstDevice *self,
}
/* ESM checksum same */
checksum = fu_common_sum32(payload_data + EEPROM_ESM_OFFSET, esm_sz);
checksum = fu_sum32(payload_data + EEPROM_ESM_OFFSET, esm_sz);
if (checksum == flash_checksum) {
g_debug("ESM checksum already matches");
return TRUE;
@ -469,7 +469,7 @@ fu_synaptics_mst_device_update_tesla_leaf_firmware(FuSynapticsMstDevice *self,
&flash_checksum,
error))
return FALSE;
checksum = fu_common_sum32(payload_data, payload_len);
checksum = fu_sum32(payload_data, payload_len);
if (checksum == flash_checksum)
break;
g_debug("attempt %u: checksum %x didn't match %x",

View File

@ -304,9 +304,9 @@ fu_plugin_uefi_capsule_write_splash_data(FuPlugin *plugin,
};
/* header, payload and image has to add to zero */
csum += fu_common_sum8((guint8 *)&capsule_header, sizeof(capsule_header));
csum += fu_common_sum8((guint8 *)&header, sizeof(header));
csum += fu_common_sum8_bytes(blob);
csum += fu_sum8((guint8 *)&capsule_header, sizeof(capsule_header));
csum += fu_sum8((guint8 *)&header, sizeof(header));
csum += fu_sum8_bytes(blob);
header.checksum = 0x100 - csum;
/* write capsule file */

View File

@ -524,7 +524,7 @@ fu_vli_pd_device_write_dual_firmware(FuVliPdDevice *self,
g_prefix_error(error, "failed to read file CRC: ");
return FALSE;
}
crc_actual = fu_common_crc16(sbuf, sbufsz - 2);
crc_actual = fu_crc16(sbuf, sbufsz - 2);
fu_progress_step_done(progress);
/* update fw2 first if fw1 correct */

View File

@ -156,7 +156,7 @@ fu_vli_pd_firmware_parse(FuFirmware *firmware,
g_prefix_error(error, "failed to read file CRC: ");
return FALSE;
}
crc_actual = fu_common_crc16(buf, bufsz - 2);
crc_actual = fu_crc16(buf, bufsz - 2);
if (crc_actual != crc_file) {
g_set_error(error,
FWUPD_ERROR,

View File

@ -12,7 +12,7 @@
guint8
fu_vli_usbhub_header_crc8(FuVliUsbhubHeader *hdr)
{
return ~fu_common_crc8((const guint8 *)hdr, sizeof(*hdr) - 1);
return ~fu_crc8((const guint8 *)hdr, sizeof(*hdr) - 1);
}
void

View File

@ -58,7 +58,7 @@ fu_wacom_emr_device_setup(FuDevice *device, GError **error)
static guint8
fu_wacom_emr_device_calc_checksum(guint8 init1, const guint8 *buf, gsize bufsz)
{
return init1 + ~(fu_common_sum8(buf, bufsz)) + 1;
return init1 + ~(fu_sum8(buf, bufsz)) + 1;
}
static gboolean

View File

@ -592,7 +592,7 @@ fu_wac_device_write_firmware(FuDevice *device,
}
/* calculate expected checksum and save to device RAM */
csum_local[i] = GUINT32_TO_LE(fu_common_sum32w_bytes(blob_block, G_LITTLE_ENDIAN));
csum_local[i] = GUINT32_TO_LE(fu_sum32w_bytes(blob_block, G_LITTLE_ENDIAN));
if (g_getenv("FWUPD_WACOM_USB_VERBOSE") != NULL)
g_debug("block checksum %02u: 0x%08x", i, csum_local[i]);
if (!fu_wac_device_set_checksum_of_block(self, i, csum_local[i], error))

View File

@ -315,7 +315,7 @@ fu_wac_firmware_parse(FuFirmware *firmware,
static guint8
fu_wac_firmware_calc_checksum(GByteArray *buf)
{
return fu_common_sum8(buf->data, buf->len) ^ 0xFF;
return fu_sum8(buf->data, buf->len) ^ 0xFF;
}
static GBytes *

View File

@ -47,8 +47,7 @@ fu_wac_module_bluetooth_id6_reverse_bits(guint8 value)
static guint8
fu_wac_module_bluetooth_id6_calculate_crc(const guint8 *data, gsize sz)
{
guint8 crc =
~fu_common_crc8_full(data, sz, 0x00, FU_WAC_MODULE_BLUETOOTH_ID6_CRC8_POLYNOMIAL);
guint8 crc = ~fu_crc8_full(data, sz, 0x00, FU_WAC_MODULE_BLUETOOTH_ID6_CRC8_POLYNOMIAL);
return fu_wac_module_bluetooth_id6_reverse_bits(crc);
}