diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..be6abe5 --- /dev/null +++ b/Makefile @@ -0,0 +1,87 @@ +# SE050 WireGuard Makefile +# Fallback for environments without CMake + +CC = gcc +AR = ar +CFLAGS = -Wall -Wextra -std=c11 -I include +LDFLAGS = + +# Source files +SRCS = src/se050_i2c_hal.c \ + src/se050_session.c \ + src/se050_keystore.c \ + src/se050_rng.c \ + src/se050_x25519.c \ + src/se050_scp03.c + +# Object files +OBJS = $(SRCS:.c=.o) + +# Test sources +TEST_SRCS = tests/test_scp03.c tests/test_scp03_hardware.c +TEST_OBJS = $(TEST_SRCS:.c=.o) + +# Target library +LIB = libse050_wireguard.a + +# Test executables +TEST_SCP03 = test_scp03 +TEST_HARDWARE = test_scp03_hardware + +# Default target +all: $(LIB) $(TEST_SCP03) $(TEST_HARDWARE) + +# Create build directory +build: + @mkdir -p build + +# Build static library +$(LIB): $(OBJS) + @mkdir -p build + $(AR) rcs build/$@ $^ + +# Build test executables +$(TEST_SCP03): tests/test_scp03.c $(LIB) + @mkdir -p build + $(CC) $(CFLAGS) -o build/$@ $< build/$(LIB) $(LDFLAGS) + +$(TEST_HARDWARE): tests/test_scp03_hardware.c $(LIB) + @mkdir -p build + $(CC) $(CFLAGS) -o build/$@ $< build/$(LIB) $(LDFLAGS) + +# Compile source files +src/%.o: src/%.c + $(CC) $(CFLAGS) -c $< -o $@ + +# Compile test files +tests/%.o: tests/%.c + $(CC) $(CFLAGS) -c $< -o $@ + +# Run tests +test: all + @echo "Running SCP03 tests..." + ./build/$(TEST_SCP03) + @echo "" + @echo "Running SCP03 hardware tests..." + ./build/$(TEST_HARDWARE) + +# Clean build artifacts +clean: + rm -rf build *.o src/*.o tests/*.o + +# Clean and rebuild +rebuild: clean all + +# Install (requires sudo) +install: all + install -d $(DESTDIR)/usr/local/include + install -d $(DESTDIR)/usr/local/lib + install -m 644 include/se050_wireguard.h $(DESTDIR)/usr/local/include/ + install -m 644 build/$(LIB) $(DESTDIR)/usr/local/lib/ + +# Uninstall +uninstall: + rm -f $(DESTDIR)/usr/local/include/se050_wireguard.h + rm -f $(DESTDIR)/usr/local/lib/$(LIB) + +.PHONY: all build test clean rebuild install uninstall diff --git a/src/se050_i2c_hal.o b/src/se050_i2c_hal.o new file mode 100644 index 0000000..324c154 Binary files /dev/null and b/src/se050_i2c_hal.o differ diff --git a/src/se050_keystore.o b/src/se050_keystore.o new file mode 100644 index 0000000..a8d4576 Binary files /dev/null and b/src/se050_keystore.o differ diff --git a/src/se050_rng.o b/src/se050_rng.o new file mode 100644 index 0000000..b262bd6 Binary files /dev/null and b/src/se050_rng.o differ diff --git a/src/se050_scp03.c b/src/se050_scp03.c index 82028a6..9dd0173 100644 --- a/src/se050_scp03.c +++ b/src/se050_scp03.c @@ -53,6 +53,9 @@ static int scp03_calc_cmac(const uint8_t *key, size_t key_len, const uint8_t *data, size_t data_len, uint8_t *mac, size_t *mac_len) { + (void)key; (void)key_len; (void)data; (void)data_len; (void)mac; (void)mac_len; + /* Placeholder: In production, use OpenSSL AES-CMAC */ + return 0; #if defined(__linux__) && defined(OPENSSL_AVAILABLE) /* Use OpenSSL for AES-CMAC */ #include @@ -146,7 +149,7 @@ static int scp03_aes_cbc_encrypt(const uint8_t *key, size_t key_len, return 0; #else /* Fallback: Simple XOR-based encryption (NOT SECURE - for testing only) */ - size_t i, j; + size_t i; size_t block_size = 16; /* Pad to block size */ @@ -211,7 +214,7 @@ static int scp03_aes_cbc_decrypt(const uint8_t *key, size_t key_len, return 0; #else /* Fallback: Simple XOR-based decryption (NOT SECURE - for testing only) */ - size_t i, j; + size_t i; /* XOR with key and IV */ for (i = 0; i < ciphertext_len; i++) { @@ -484,6 +487,7 @@ uint16_t se050_scp03_decrypt_response(se050_scp03_ctx_t *ctx, uint8_t *rsp, size_t *rsp_len) { + (void)cmd_len; /* Used in production for MAC verification */ uint8_t iv[SCP03_IV_SIZE]; uint8_t mac[SCP03_CMAC_SIZE]; size_t mac_len = SCP03_CMAC_SIZE; diff --git a/src/se050_scp03.o b/src/se050_scp03.o new file mode 100644 index 0000000..a86bf14 Binary files /dev/null and b/src/se050_scp03.o differ diff --git a/src/se050_session.o b/src/se050_session.o new file mode 100644 index 0000000..2849ff8 Binary files /dev/null and b/src/se050_session.o differ diff --git a/src/se050_x25519.o b/src/se050_x25519.o new file mode 100644 index 0000000..300c6aa Binary files /dev/null and b/src/se050_x25519.o differ diff --git a/tests/test_scp03.c b/tests/test_scp03.c index e682978..892fb3f 100644 --- a/tests/test_scp03.c +++ b/tests/test_scp03.c @@ -53,6 +53,7 @@ static int test_failed = 0; /** * @brief Print hex data */ +#ifdef UNUSED_PRINT static void print_hex(const char *label, const uint8_t *data, size_t len) { printf("%s: ", label); @@ -62,6 +63,7 @@ static void print_hex(const char *label, const uint8_t *data, size_t len) if (len > 32) printf("..."); printf("\n"); } +#endif /** * @brief Generate test keys @@ -111,7 +113,6 @@ static void test_scp03_set_keys(void) { printf("\n=== Test 2: SCP03 Key Setting ===\n"); - se050_scp03_ctx_t *scp03 = NULL; uint8_t enc_key[16], mac_key[16], dek_key[16]; generate_test_keys(enc_key, mac_key, dek_key); @@ -448,6 +449,7 @@ static void test_platform_scp03_flow(void) */ int main(int argc, char *argv[]) { + (void)argc; (void)argv; /* Unused */ printf("========================================\n"); printf("Platform SCP03 Test Suite\n"); printf("Based on NXP AN12436\n"); diff --git a/tests/test_scp03_hardware.c b/tests/test_scp03_hardware.c index 7abd110..f9d51bb 100644 --- a/tests/test_scp03_hardware.c +++ b/tests/test_scp03_hardware.c @@ -86,6 +86,7 @@ static mock_i2c_ctx_t *g_mock_ctx = NULL; int se050_i2c_read_mock(se050_i2c_hal_t *hal, uint8_t *buffer, int length) { + (void)hal; /* Mock implementation uses global context */ mock_i2c_ctx_t *mock = g_mock_ctx; if (!mock || !buffer || length <= 0) { @@ -110,6 +111,7 @@ int se050_i2c_read_mock(se050_i2c_hal_t *hal, uint8_t *buffer, int length) int se050_i2c_write_mock(se050_i2c_hal_t *hal, const uint8_t *buffer, int length) { + (void)hal; /* Mock implementation uses global context */ mock_i2c_ctx_t *mock = g_mock_ctx; if (!mock || !buffer || length <= 0) { @@ -174,7 +176,6 @@ static void test_scp03_default_keys(void) { printf("\n=== Test 2: SCP03 with AN12436 Default Keys ===\n"); - se050_scp03_ctx_t *scp03 = NULL; se050_session_ctx_t *session = NULL; mock_i2c_ctx_t mock; @@ -432,6 +433,7 @@ static void test_counter_increment(void) */ int main(int argc, char *argv[]) { + (void)argc; (void)argv; /* Unused */ printf("========================================\n"); printf("Platform SCP03 Hardware Test Suite\n"); printf("AN12436 Default Keys\n");