Skip to content

Commit

Permalink
Remove dependence on zlib
Browse files Browse the repository at this point in the history
Introduce env/env_api_crc32.c to support computation of CRC32
so that there is no longer a dependence on zlib.

Signed-off-by: Earl Chew <[email protected]>
[Jan: rebased, re-indented]
Signed-off-by: Jan Kiszka <[email protected]>
  • Loading branch information
earlchew authored and jan-kiszka committed Aug 24, 2023
1 parent 63ad072 commit 3d79ddb
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coverity.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends \
autoconf-archive gcc-multilib gnu-efi libz-dev libpci-dev check
autoconf-archive gcc-multilib gnu-efi libpci-dev check
- name: Install Coverity
run: |
wget https://scan.coverity.com/download/cxx/linux64 \
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install --no-install-recommends \
autoconf-archive gcc-multilib gnu-efi libz-dev libpci-dev check \
autoconf-archive gcc-multilib gnu-efi libpci-dev check \
bats libarchive-zip-perl
- name: Install i386 dependencies
if: ${{ matrix.target == 'i386' }}
Expand All @@ -52,7 +52,7 @@ jobs:
sudo rm -f /etc/apt/sources.list.d/ubuntu-toolchain-r-ubuntu-test-jammy.list
sudo apt-get update
sudo apt-get install --no-install-recommends \
autoconf-archive gcc-multilib gnu-efi libz-dev:i386 \
autoconf-archive gcc-multilib gnu-efi \
libpci-dev:i386 check:i386
- name: Install arm64 dependencies
if: ${{ matrix.target == 'arm64' }}
Expand All @@ -70,7 +70,7 @@ jobs:
sudo apt-get update
sudo apt-get install --no-install-recommends \
autoconf-archive gcc-aarch64-linux-gnu libc6-dev-arm64-cross \
gnu-efi:arm64 libz-dev:arm64 libpci-dev:arm64 check:arm64 \
gnu-efi:arm64 libpci-dev:arm64 check:arm64 \
qemu-user-static
- name: Install arm dependencies
if: ${{ matrix.target == 'arm' }}
Expand All @@ -88,7 +88,7 @@ jobs:
sudo apt-get update
sudo apt-get install --no-install-recommends \
autoconf-archive gcc-arm-linux-gnueabihf libc6-dev-armhf-cross \
gnu-efi:armhf libz-dev:armhf libpci-dev:armhf check:armhf \
gnu-efi:armhf libpci-dev:armhf check:armhf \
qemu-user-static
- name: Install riscv64 dependencies
if: ${{ matrix.target == 'riscv64' }}
Expand All @@ -106,7 +106,7 @@ jobs:
sudo apt-get update
sudo apt-get install --no-install-recommends \
autoconf-archive gcc-riscv64-linux-gnu libc6-dev-riscv64-cross \
gnu-efi:riscv64 libz-dev:riscv64 libpci-dev:riscv64 check:riscv64 \
gnu-efi:riscv64 libpci-dev:riscv64 check:riscv64 \
qemu-user-static
- name: Install cppcheck
if: ${{ matrix.target == 'cppcheck' }}
Expand Down
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ lib_LIBRARIES = libebgenv.a
libebgenv_a_SOURCES = \
env/@[email protected] \
env/env_api.c \
env/env_api_crc32.c \
env/env_config_file.c \
env/env_config_partitions.c \
env/env_disk_utils.c \
Expand Down Expand Up @@ -138,8 +139,7 @@ bg_setenv_LDFLAGS = -Wl,--no-wchar-size-warning
endif

bg_setenv_LDADD = \
$(top_builddir)/libebgenv.a \
-lz
$(top_builddir)/libebgenv.a

install-exec-hook:
$(AM_V_at)$(LN_S) -f bg_setenv$(EXEEXT) \
Expand Down
2 changes: 0 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ AC_CHECK_HEADERS([sys/mount.h])
AC_CHECK_HEADERS([unistd.h])
AC_CHECK_HEADERS([wchar.h])
AC_CHECK_HEADER_STDBOOL
AC_CHECK_HEADERS([zlib.h])
AC_CHECK_LIB([z], [crc32], [], [AC_MSG_ERROR([need crc32 implementation from libz])])
AC_FUNC_GETMNTENT
AC_PROG_CXX
AC_TYPE_INT32_T
Expand Down
6 changes: 3 additions & 3 deletions env/env_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ int ebg_env_setglobalstate(ebgenv_t *e, uint16_t ustate)
}
if (env->data->ustate != ustate) {
env->data->ustate = ustate;
env->data->crc32 = crc32(0, (Bytef *)env->data,
env->data->crc32 = bgenv_crc32(0, env->data,
sizeof(BG_ENVDATA) - sizeof(env->data->crc32));
if (!bgenv_write(env)) {
bgenv_close(env);
Expand All @@ -228,8 +228,8 @@ int ebg_env_close(ebgenv_t *e)

/* recalculate checksum */
env_current->data->crc32 =
crc32(0, (Bytef *)env_current->data,
sizeof(BG_ENVDATA) - sizeof(env_current->data->crc32));
bgenv_crc32(0, env_current->data,
sizeof(BG_ENVDATA) - sizeof(env_current->data->crc32));
/* save */
if (!bgenv_write(env_current)) {
res = EIO;
Expand Down
8 changes: 4 additions & 4 deletions env/env_api_fat.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ void bgenv_be_verbose(bool v)
static void clear_envdata(BG_ENVDATA *data)
{
memset(data, 0, sizeof(BG_ENVDATA));
data->crc32 = crc32(0, (Bytef *)data,
sizeof(BG_ENVDATA) - sizeof(data->crc32));
data->crc32 = bgenv_crc32(0, data,
sizeof(BG_ENVDATA) - sizeof(data->crc32));
}

bool validate_envdata(BG_ENVDATA *data)
{
uint32_t sum = crc32(0, (Bytef *)data,
sizeof(BG_ENVDATA) - sizeof(data->crc32));
uint32_t sum = bgenv_crc32(0, data,
sizeof(BG_ENVDATA) - sizeof(data->crc32));

if (data->crc32 != sum) {
VERBOSE(stderr, "Invalid CRC32!\n");
Expand Down
3 changes: 2 additions & 1 deletion include/env_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <sys/file.h>
#include <sys/mount.h>
#include "config.h"
#include <zlib.h>
#include "envdata.h"
#include "ebgenv.h"
#include <uchar.h>
Expand Down Expand Up @@ -80,6 +79,8 @@ extern void bgenv_be_verbose(bool v);
extern char *str16to8(char *buffer, const char16_t *src);
extern char16_t *str8to16(char16_t *buffer, const char *src);

extern uint32_t bgenv_crc32(uint32_t, const void *, size_t);

extern bool bgenv_init(void);
extern void bgenv_finalize(void);
extern BGENV *bgenv_open_by_index(uint32_t index);
Expand Down
1 change: 0 additions & 1 deletion libebgenv.pc.in
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ Name: libebgenv
URL: https://github.com/siemens/efibootguard
Description: Library to access the EFI Boot Guard environment
Version: @LIBEBGENV_VERSION@
Requires.private: zlib
Libs: -L${libdir} -lebgenv
Cflags: -I${includedir}
5 changes: 3 additions & 2 deletions tools/bg_setenv.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,9 @@ static void update_environment(BGENV *env, bool verbosity)
journal_free_action(action);
}

env->data->crc32 = crc32(0, (const Bytef *)env->data,
sizeof(BG_ENVDATA) - sizeof(env->data->crc32));
env->data->crc32 =
bgenv_crc32(0, env->data,
sizeof(BG_ENVDATA) - sizeof(env->data->crc32));

}

Expand Down
1 change: 1 addition & 0 deletions tools/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ endif
libtest_env_api_fat_a_SRC = \
../../env/env_api.c \
../../env/env_api_fat.c \
../../env/env_api_crc32.c \
../../tools/ebgpart.c \
../../env/env_config_file.c \
../../env/env_config_partitions.c \
Expand Down

0 comments on commit 3d79ddb

Please sign in to comment.