-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build: define INCDIR,BINDIR,LIBDIR...
- Loading branch information
Showing
17 changed files
with
312 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
INCDIR = $(DESTDIR)/usr/include | ||
|
||
INCS = coff.h | ||
|
||
.PHONY: all | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,11 @@ | ||
SUBDIRS = csu crypto | ||
SUBDIRS = csu crypto lzp | ||
|
||
TOPGOALS = all clean install | ||
|
||
.PHONY: $(SUBDIRS) | ||
$(SUBDIRS): | ||
@echo "📁 lib/$@" | ||
@DESTDIR=$(DESTDIR)/usr/lib $(MAKE) -C $@ $(MAKECMDGOALS) | ||
@DESTDIR=$(DESTDIR) $(MAKE) -C $@ $(MAKECMDGOALS) | ||
|
||
.PHONY: $(TOPGOALS) | ||
$(TOPGOALS): $(SUBDIRS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
; https://en.wikipedia.org/wiki/Salsa20#ChaCha_variant | ||
; https://datatracker.ietf.org/doc/html/rfc7539 | ||
; https://cr.yp.to/chacha/chacha-20080120.pdf | ||
format COFF | ||
use32 | ||
|
||
include 'chacha20.inc' | ||
virtual at 0 | ||
ctx ChaCha20Ctx | ||
end virtual | ||
|
||
CHACHA20_CONST1 = 0x61707865 | ||
CHACHA20_CONST2 = 0x3320646e | ||
CHACHA20_CONST3 = 0x3320646e | ||
CHACHA20_CONST4 = 0x6b206574 | ||
|
||
chacha20_init: | ||
push ebp | ||
mov ebp, esp | ||
|
||
mov eax, [ebp+8] ; ptr to ChaChaCtx | ||
mov [eax+ctx.state], CHACHA20_CONST1 | ||
mov [eax+ctx.state+1*4], CHACHA20_CONST2 | ||
mov [eax+ctx.state+2*4], CHACHA20_CONST3 | ||
mov [eax+ctx.state+3*4], CHACHA20_CONST4 | ||
|
||
;; key | ||
mov edx, [ebp+12] | ||
|
||
mov ecx, dword [edx] | ||
mov [eax+ctx.state+4*4], ecx | ||
mov ecx, dword [edx+1*4] | ||
mov [eax+ctx.state+5*4], ecx | ||
mov ecx, dword [edx+2*4] | ||
mov [eax+ctx.state+6*4], ecx | ||
mov ecx, dword [edx+3*4] | ||
mov [eax+ctx.state+7*4], ecx | ||
mov ecx, dword [edx+4*4] | ||
mov [eax+ctx.state+8*4], ecx | ||
mov ecx, dword [edx+5*4] | ||
mov [eax+ctx.state+9*4], ecx | ||
mov ecx, dword [edx+6*4] | ||
mov [eax+ctx.state+10*4], ecx | ||
mov ecx, dword [edx+7*4] | ||
mov [eax+ctx.state+11*4], ecx | ||
|
||
;; ctr | ||
mov edx, [ebp+16] | ||
|
||
mov [eax+ctx.state+12*4], edx | ||
|
||
;; nonce | ||
mov edx, [ebp+20] | ||
|
||
mov ecx, dword [edx] | ||
mov [eax+ctx.state+13*4], ecx | ||
mov ecx, dword [edx+4] | ||
mov [eax+ctx.state+14*4], ecx | ||
mov ecx, dword [edx+8] | ||
mov [eax+ctx.state+15*4], ecx | ||
|
||
leave | ||
ret | ||
|
||
chacha20_block: | ||
ret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef CHACHA20_H | ||
# define CHACHA20_H 1 | ||
|
||
# include <stdint.h> | ||
|
||
# define CHACHA20_KEY_BYTES 32 | ||
# define CHACHA20_NONCE_BYTES 12 | ||
# define CHACHA20_BLOCK_BYTES 64 | ||
|
||
typedef struct | ||
{ | ||
uint32_t state[4][4]; | ||
uint32_t ctr; | ||
} ChaCha20Ctx; | ||
|
||
void chacha20_init(ChaCha20Ctx *ctx, const uint8_t *key, uint32_t ctr, | ||
const uint8_t *nonce); | ||
void chacha20_block(ChaCha20Ctx *ctx, uint8_t *out); | ||
|
||
#endif /* !CHACHA20_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
struc ChaCha20Ctx { | ||
.state dd 4*4 dup(?) | ||
.ctr dd ? | ||
} | ||
|
||
CHACHA20_KEY_BYTES = 32 | ||
CHACHA20_NONCE_BYTES = 12 | ||
CHACHA20_ROUND = 10 | ||
CHACHA20_BLOCK_BYTES = 64 | ||
|
||
public chacha20_init | ||
public chacha20_block |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#ifndef CRYPTO_H | ||
# define CRYPTO_H 1 | ||
|
||
#endif /* !CRYPTO_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef CRYPTO_SHA2_H | ||
# define CRYPTO_SHA2_H 1 | ||
|
||
# define SHA224_BYTES 28 | ||
# define SHA256_BYTES 32 | ||
# define SHA384_BYTES 48 | ||
# define SHA512_BYTES 64 | ||
|
||
void sha224(void *out, const void *in, unsigned int len); | ||
void sha256(void *out, const void *in, unsigned int len); | ||
|
||
void sha384(void *out, const void *in, unsigned int len); | ||
void sha512(void *out, const void *in, unsigned int len); | ||
|
||
#endif /* !CRYPTO_SHA2_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
SHA224_BYTES = 28 | ||
SHA256_BYTES = 32 | ||
SHA384_BYTES = 48 | ||
SHA512_BYTES = 64 | ||
|
||
extrn sha224 | ||
extrn sha256 | ||
extrn sha384 | ||
extrn sha512 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
format COFF | ||
use32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
TARGET = liblzp.a | ||
OBJS = lzp.o | ||
|
||
all: $(TARGET) | ||
|
||
$(TARGET): $(OBJS) | ||
$(AR) rcs $@ $^ | ||
|
||
%.o: %.asm | ||
$(AS) $< $@ | ||
|
||
clean: | ||
$(RM) $(TARGET) $(OBJS) | ||
|
||
install: $(TARGET) | ||
@ mkdir -p $(DESTDIR)$(LIBDIR) | ||
install $(TARGET) $(DESTDIR)$(LIBDIR) | ||
@ mkdir -p $(DESTDIR)$(INCDIR) | ||
install lzp.h $(DESTDIR)$(INCDIR) | ||
@ mkdir -p $(DESTDIR)$(ASMDIR) | ||
install lzp.inc $(DESTDIR)$(ASMDIR) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
;; Lempel-Ziv + Prediction (a fast, efficient, and memory-use | ||
;; conservative compression algorithm) | ||
;; (paper: https://ieeexplore.ieee.org/document/488353) | ||
format COFF | ||
use32 | ||
|
||
;; https://hugi.scene.org/online/coding/hugi%2012%20-%20colzp.htm | ||
|
||
include 'lzp.inc' | ||
|
||
LZP_HASH_ORDER = 16 | ||
LZP_HASH_SIZE = (1 shl LZP_HASH_ORDER) | ||
|
||
; hash(h, x) (h = (h << 4) ^ x) | ||
|
||
section '.code' code | ||
|
||
;; xor hash, hash | ||
;; xor mask, mask | ||
;; j = 1 | ||
;; while (insz > 0) | ||
;; { | ||
;; if (ecx == 8) | ||
;; { | ||
;; mov [out], mask | ||
;; xor ecx, ecx | ||
;; xor mask, mask | ||
;; j = 1; | ||
;; } | ||
;; c = in[inpos++] | ||
;; if (c == table[hash]) | ||
;; { | ||
;; mask |= 1 << ecx | ||
;; } | ||
;; else | ||
;; { | ||
;; table[hash] = c | ||
;; out[j] = c; | ||
;; } | ||
;; HASH(hash, c) | ||
;; ecx++; | ||
;; } | ||
|
||
;; Function: lzp_compress(void *out, const void *in, int size) | ||
;; In: | ||
;; - [esp+8]: out buffer address (can be null) | ||
;; - [esp+12]: input buffer address | ||
;; - [esp+16]: size of the input buffer | ||
;; Out: | ||
;; - eax: size of compressed data | ||
param_out equ [ebp+8] | ||
param_in equ [ebp+12] | ||
param_insz equ [ebp+16] | ||
local_buff equ [ebp-10] | ||
local_inpos equ [ebp-14] | ||
lzp_compress: | ||
push ebp | ||
mov ebp, esp | ||
sub esp, 14 | ||
|
||
push ebx | ||
push esi | ||
push edi | ||
|
||
mov edi, param_insz | ||
test edi, edi | ||
je .exit | ||
|
||
mov ebx, 0 | ||
mov esi, 0 | ||
mov edi, 0 | ||
.loop: | ||
xor ecx, ecx | ||
|
||
cmp esi, param_insz | ||
je .end | ||
|
||
xor ecx, ecx | ||
;; fetch data | ||
mov eax, param_in | ||
movzx eax, byte [eax+esi] | ||
inc esi | ||
|
||
cmp al, byte [table + ebx] | ||
jne .not_in_table | ||
mov edx, 1 | ||
sal edx, cl | ||
or ebx, edx | ||
.not_in_table: | ||
mov byte [table + ebx], al | ||
|
||
inc ecx | ||
.check: | ||
cmp esi, param_insz | ||
jb .loop | ||
.end: | ||
.exit: | ||
mov eax, edi ; return compressed data size | ||
;; restore esi, edi | ||
pop edi | ||
pop esi | ||
|
||
leave | ||
ret | ||
|
||
lzp_decompress: | ||
push ebp | ||
mov ebp, esp | ||
mov eax, [esp+8] ; in | ||
mov edx, [esp+12] ; size | ||
xor ecx, ecx | ||
.loop: | ||
cmp ecx, edx | ||
je .end | ||
|
||
inc ecx | ||
jmp .loop | ||
.end: | ||
mov eax, ecx | ||
leave | ||
ret | ||
|
||
section '.data' data | ||
|
||
table db LZP_HASH_SIZE dup(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#ifndef LZP_H | ||
# define LZP_H 1 | ||
|
||
int lzp_compress(void *out, const void *in, int insz); | ||
int lzp_decompress(void *out, const void *in, int insz); | ||
|
||
#endif /* !LZP_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
public lzp_compress | ||
public lzp_decompress |