From 9a5b474ad2d1741dd9e3b10c02ea5848b71856be Mon Sep 17 00:00:00 2001 From: d0p1 Date: Sun, 24 Mar 2024 09:44:14 +0100 Subject: [PATCH] chore: lib/ cleanup --- lib/Makefile | 4 ++-- lib/crypto/Makefile | 16 ++++++++++++++-- lib/crypto/hash/keccak.s | 3 --- lib/crypto/hash/{sha256.s => sha256.asm} | 23 ++++++++++++----------- lib/crypto/sign/ecdsa.s | 2 -- lib/csu/Makefile | 13 +++++++++++++ lib/csu/crt0.asm | 18 ++++++++++++++++++ lib/pls/runtime/crt0.s | 10 ---------- lib/pls/std/error.pls | 5 ----- lib/pls/std/io/file.pls | 3 --- 10 files changed, 59 insertions(+), 38 deletions(-) delete mode 100644 lib/crypto/hash/keccak.s rename lib/crypto/hash/{sha256.s => sha256.asm} (90%) delete mode 100644 lib/crypto/sign/ecdsa.s create mode 100644 lib/csu/Makefile create mode 100644 lib/csu/crt0.asm delete mode 100644 lib/pls/runtime/crt0.s delete mode 100644 lib/pls/std/error.pls delete mode 100644 lib/pls/std/io/file.pls diff --git a/lib/Makefile b/lib/Makefile index b315fda..be2e97e 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -1,11 +1,11 @@ -SUBDIRS = crypto +SUBDIRS = csu crypto TOPGOALS = all clean install .PHONY: $(SUBDIRS) $(SUBDIRS): @echo "📁 lib/$@" - @DESTDIR=$(DESTDIR)/lib $(MAKE) -C $@ $(MAKECMDGOALS) + @DESTDIR=$(DESTDIR)/usr/lib $(MAKE) -C $@ $(MAKECMDGOALS) .PHONY: $(TOPGOALS) $(TOPGOALS): $(SUBDIRS) diff --git a/lib/crypto/Makefile b/lib/crypto/Makefile index 8d1fed2..a78ea7f 100644 --- a/lib/crypto/Makefile +++ b/lib/crypto/Makefile @@ -1,5 +1,17 @@ -all: +TARGET = libcrypto.a +OBJS = hash/sha256.o + +all: $(TARGET) + +$(TARGET): $(OBJS) + $(AR) rcs $@ $^ + +%.o: %.asm + $(AS) $< $@ clean: + $(RM) $(TARGET) $(OBJS) -install: +install: $(TARGET) + @ mkdir -p $(DESTDIR) + install $(TARGET) $(DESTDIR) diff --git a/lib/crypto/hash/keccak.s b/lib/crypto/hash/keccak.s deleted file mode 100644 index 82e9af4..0000000 --- a/lib/crypto/hash/keccak.s +++ /dev/null @@ -1,3 +0,0 @@ -; file: keccak.s -; Keccak 256 cryptographic hash - diff --git a/lib/crypto/hash/sha256.s b/lib/crypto/hash/sha256.asm similarity index 90% rename from lib/crypto/hash/sha256.s rename to lib/crypto/hash/sha256.asm index 2dd75bc..c0a3b5c 100644 --- a/lib/crypto/hash/sha256.s +++ b/lib/crypto/hash/sha256.asm @@ -5,22 +5,23 @@ ; ; About: CPU compatibility ; /!\ Only work on *486+* due to bswap for now. -[BITS 32] + format COFF + use32 -section .rodata + section '.data' data ; Constant: K ; SHA-256 round constants K: - dd 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, - dd 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, - dd 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, - dd 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, - dd 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, - dd 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, - dd 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, + dd 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5 + dd 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174 + dd 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da + dd 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967 + dd 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85 + dd 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070 + dd 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3 dd 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 -section .text +section '.text' code ; Function: sha256_compute_block sha256_compute_block: @@ -89,7 +90,7 @@ sha256_internal: ; out: ; none ; -global sha256 + public sha256 sha256: push ebp mov ebp, esp diff --git a/lib/crypto/sign/ecdsa.s b/lib/crypto/sign/ecdsa.s deleted file mode 100644 index e05a20d..0000000 --- a/lib/crypto/sign/ecdsa.s +++ /dev/null @@ -1,2 +0,0 @@ -; file: ecdsa.s -; Elliptic Curve Digital Signature Algorithm (ECDSA) diff --git a/lib/csu/Makefile b/lib/csu/Makefile new file mode 100644 index 0000000..0eb9f6d --- /dev/null +++ b/lib/csu/Makefile @@ -0,0 +1,13 @@ +TARGET = crt0.o + +all: $(TARGET) + +%.o: %.asm + $(AS) $< $@ + +clean: + $(RM) $(TARGET) + +install: $(TARGET) + @ mkdir -p $(DESTDIR) + install $(TARGET) $(DESTDIR) diff --git a/lib/csu/crt0.asm b/lib/csu/crt0.asm new file mode 100644 index 0000000..e67da86 --- /dev/null +++ b/lib/csu/crt0.asm @@ -0,0 +1,18 @@ + format COFF + use32 + + public _start + + extrn main + extrn exit + + section '.text' code + + public _start +_start: + + xor ebp, ebp + call main + + call exit + diff --git a/lib/pls/runtime/crt0.s b/lib/pls/runtime/crt0.s deleted file mode 100644 index 52d3550..0000000 --- a/lib/pls/runtime/crt0.s +++ /dev/null @@ -1,10 +0,0 @@ -; file: crt0.s -; -[BITS 32] - -section .text - -.global _start -_start: - xor ebp, ebp - \ No newline at end of file diff --git a/lib/pls/std/error.pls b/lib/pls/std/error.pls deleted file mode 100644 index 35bec1b..0000000 --- a/lib/pls/std/error.pls +++ /dev/null @@ -1,5 +0,0 @@ -CLASS Error; - -MESSAGE - -END; diff --git a/lib/pls/std/io/file.pls b/lib/pls/std/io/file.pls deleted file mode 100644 index f05306e..0000000 --- a/lib/pls/std/io/file.pls +++ /dev/null @@ -1,3 +0,0 @@ -CLASS File; - -END;