Skip to content

Commit

Permalink
doc: add moar docs
Browse files Browse the repository at this point in the history
  • Loading branch information
d0p1s4m4 committed Jul 20, 2024
1 parent 9078742 commit f42539c
Show file tree
Hide file tree
Showing 12 changed files with 234 additions and 48 deletions.
25 changes: 13 additions & 12 deletions docs/config/Menu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Timestamp: Updated yyyy/mm/dd
# These are indexes you deleted, so Natural Docs will not add them again
# unless you remove them from this line.

Don't Index: Classes, Macros, Variables
Don't Index: Classes, Variables, Macros


# --------------------------------------------------------------------------
Expand All @@ -43,12 +43,8 @@ Don't Index: Classes, Macros, Variables
# --------------------------------------------------------------------------


File: Introduction (docs/intro.txt)
Link: Source Code (https://git.cute.engineering/d0p1/StupidOS)
File: Coding Style (docs/coding-style.txt)
File: FAQ (docs/faq.txt)
Link: StupidFS (https://stupidfs.d0p1.eu/)
File: Common Object File Format &lparen;COFF&rparen; (docs/COFF.txt)

Group: BootLoader {

Expand Down Expand Up @@ -153,11 +149,6 @@ Group: Lib {

File: rc4.asm (no auto-title, lib/crypto/rc4/rc4.asm)

Group: chacha20 {

File: chacha20.asm (lib/crypto/chacha20/chacha20.asm)
} # Group: chacha20

Group: Dilithium {

File: ntt.asm (lib/crypto/dilithium/ntt.asm)
Expand All @@ -168,13 +159,23 @@ Group: Lib {
File: sha256.asm (lib/crypto/sha2/sha256.asm)
} # Group: SHA2

File: xchacha.asm (lib/crypto/xchacha/xchacha.asm)
File: chacha.asm (lib/crypto/chacha/chacha.asm)
File: hchacha.asm (lib/crypto/hchacha/hchacha.asm)
} # Group: Crypto

File: ctype (no auto-title, lib/c/ctype.asm)
} # Group: Lib

File: Propaganda (docs/propaganda.txt)
File: Webring (docs/webring.txt)
Group: Docs {

File: Introduction (docs/intro.txt)
File: Coding Style (docs/coding-style.txt)
File: FAQ (docs/faq.txt)
File: Common Object File Format &lparen;COFF&rparen; (docs/COFF.txt)
File: Propaganda (docs/propaganda.txt)
File: Webring (docs/webring.txt)
} # Group: Docs

Group: Index {

Expand Down
73 changes: 49 additions & 24 deletions kernel/fs/stpdfs.inc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
;; File: stpdfs.inc
;; Section: Stupid Filesystem
;;
;; > ┌──────────┬───────────┬──────┬───┬──────┬────┬───┬────┐
;; > │Boot block│Super block│Inodes│...│Inodes│Data│...│Data│
Expand All @@ -15,12 +17,16 @@ STPDFS_SB_REV = 1
STPDFS_BSIZE = 512
;; Constant: STPDFS_BADINO
;; StupidFS bad inode
STPDBOOT_BADINO = 0
STPDFS_BADINO = 0
;; Constant: STPDFS_ROOTINO
;; StupidFS root inode
;; StupidFS root inode number
STPDFS_ROOTINO = 1
;; Constant: STPDFS_NDIRECT
;; Number of direct block (7)
STPDFS_NDIRECT = 7
;; Constant: STPDFS_INDIRECT_PER_BLOCK
STPDFS_INDIRECT_PER_BLOCK = STPDFS_BSIZE / 4

;; Constant: STPDFS_NAME_MAX
;; Max file name length (28)
STPDFS_NAME_MAX = 28
Expand All @@ -33,8 +39,28 @@ STPDFS_CLEANLY_UNMOUNTED = 0
STPDFS_ERROR = 1
STPDFS_DIRTY = 1

;; Enum: StupidFS i-node flags
;; STPDFS_INO_FLAG_ALOC - I-node is allocated
;; STPDFS_INO_FLAG_LZP - I-node data is compressed using LZP algorithm (see <lzp.asm>)
;; STPDFS_INO_FLAG_ENC - I-node data is encrypted with XChaCha12 (see <xchacha.asm>)
STPDFS_INO_FLAG_ALOC = 0x8000
STPDFS_INO_FLAG_LZP = 0x0001
STPDFS_INO_FLAG_ENC = 0x0002

;; Constant: STPDFS_INODE_PER_BLOCK
;; I-node per block
STPDFS_INODE_PER_BLOCK = sizeof.StpdFS_Inode / STPDFS_BSIZE

;; Constant: STPDFS_DIRENT_PER_BLOCK
;; Directory entry per block
STPDFS_DIRENT_PER_BLOCK = sizeof.StpdFS_Dirent / STPDFS_BSIZE


;; Struc: StpdFS_FreeList
;;
;; .free - List of free block (0-99), index 0 point to next freelist
;; .nfree - Index
;;
;; > ┌──────────┐
;; > │ block 99 │
;; > ├──────────┤
Expand Down Expand Up @@ -84,15 +110,15 @@ DEFN StpdFS_Sb
;; Struc: StpdFS_Inode
;; StupidFS on disk i-node
;;
;; .mode - TODO
;; .nlink - TODO
;; .uid - TODO
;; .gid - TODO
;; .flags - TODO
;; .size - Date size in byte
;; .zone - TODO
;; .actime - TODO
;; .modtime - TODO
;; .mode - File mode
;; .nlink - Links count
;; .uid - Owner Uid
;; .gid - Group Id
;; .flags - File flags, see <StupidFS i-node flags>
;; .size - Data size in byte
;; .zone - See bellow
;; .actime - Access time (64-bit UNIX timestamp)
;; .modtime - Modification time (64-bit UNIX timestamp)
;;
;;
;; Zone 0-6 are direct, zone 7 indirect, zone 8 double indirect, zone 9 triple indirect
Expand All @@ -110,17 +136,17 @@ DEFN StpdFS_Sb
;; > │zone 7├─────────►│ │ │ │
;; > ├──────┤ └────────┘ └────────┘
;; > │zone 8├───────┐
;; > ├──────┤ │Double indirect┌────────┐ ┌────────┐ ┌────────┐
;; > │zone 9│ └──────────────►│ ├───►│ ├───►│
;; > └──┬───┘ │ │ │ │ │ Data
;; > │ │ │ │ │ │
;; > │ └────────┘ └────────┘ └────────┘
;; > ├──────┤ │Double indirect┌────────┐ ┌────────┐ ┌────────┐
;; > │zone 9│ └──────────────►│ ├───►│ ├───►│ │
;; > └──┬───┘ │ │ │ │ │ Data │
;; > │ │ │ │ │ │ │
;; > │ └────────┘ └────────┘ └────────┘
;; > │ Triple indirect ┌────────┐
;; > └────────────────►│ │ ┌──────────┐ ┌────────┐ ┌──────────┐
;; > │ ├───►│ │ │ │ │
;; > │ │ │ ├─────►│ ├─────►│ Data
;; > └────────┘ │ │ │ │ │
;; > └──────────┘ └────────┘ └──────────┘
;; > └────────────────►│ │ ┌────────┐ ┌────────┐ ┌────────┐
;; > │ ├───►│ │ │ │ │ │
;; > │ │ │ ├─────►│ ├─────►│ Data │
;; > └────────┘ │ │ │ │ │ │
;; > └────────┘ └────────┘ └────────┘
struc StpdFS_Inode {
.mode dw ?
.nlink dw ?
Expand All @@ -134,8 +160,9 @@ struc StpdFS_Inode {
}
DEFN StpdFS_Inode


;; Struc: StpdFS_Dirent
;; StupidFS dir entry
;; StupidFS directory entry
;;
;; .inode - address of i-node
;; .name - null terminated file name (see <STPDFS_NAME_MAX>)
Expand All @@ -145,8 +172,6 @@ struc StpdFS_Dirent {
}
DEFN StpdFS_Dirent

STPDFS_DIRENT_PER_BLOCK = sizeof.StpdFS_Dirent / STPDFS_BSIZE

; ------------------------------------------------------------------------

;; Section: Implementation
Expand Down
34 changes: 31 additions & 3 deletions kernel/fs/xv6fs.inc
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
;; File: xv6fs.inc
;;
;; Usefull links:
;; - <https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/fs.h>
;; - <xv6 book at https://pdos.csail.mit.edu/6.1810/2023/xv6/book-riscv-rev3.pdf>
;;
;; Section: xv6 Filesystem
;;
;; > ┌──────────┬───────────┬───┬───┬───┬──────┬───┬──────┬──────┬───┬──────┬────┬───┬────┐
;; > │Boot block│Super block│Log│...│Log│Inodes│...│Inodes│Bitmap│...│Bitmap│Data│...│Data│
;; > └──────────┴───────────┴───┴───┴───┴──────┴───┴──────┴──────┴───┴──────┴────┴───┴────┘
;;
;; Usefull links:
;; - <https://github.com/mit-pdos/xv6-riscv/blob/riscv/kernel/fs.h>
;; - <xv6 book at https://pdos.csail.mit.edu/6.1810/2023/xv6/book-riscv-rev3.pdf>

;; Constant: XV6FS_BSIZE
;; xv6 Filesystem block size (1024)
XV6FS_BSIZE = 1024
;; Constant: XV6FS_ROOTINO
;; root inode number
XV6FS_ROOTINO = 1
;; Constant: XV6FS_MAGIC
;; Superblock magic number, MUST BE `0x10203040`
XV6FS_MAGIC = 0x10203040
;; Constant: XV6FS_NDIRECT
;; Number of direct block (12)
XV6FS_NDIRECT = 12
XV6FS_NINDIRECT = (XV6FS_BSIZE / 4)
XV6FS_MAXFILE = (XV6FS_NDIRECT + XV6FS_NINDIRECT)
XV6FS_IPB = (XV6FS_BSIZE / 64)
XV6FS_DIRSIZE = 14

;; Struc: Xv6FS_Sb
;; xv6FS superblock
;;
;; .magic - See <XV6FS_MAGIC>
;; .size - TODO
;; .nblock - TODO
;; .ninodes - TODO
;; .nlog - TODO
;; .nlogstart - TODO
;; .inodestart - TODO
;; .bmapstart - TODO
struc Xv6FS_Sb {
.magic dd ?
.size dd ?
Expand All @@ -33,6 +52,14 @@ struc Xv6FS_Sb {
DEFN Xv6FS_Sb

;; Struc: Xv6FS_Inode
;; xv6FS on disk i-node
;;
;; .type - TODO
;; .major - TODO
;; .minor - TODO
;; .nlink - TODO
;; .size - TODO
;; .addrs - TODO
struc Xv6FS_Inode {
.type dw ?
.major dw ?
Expand All @@ -44,6 +71,7 @@ struc Xv6FS_Inode {
DEFN Xv6FS_Inode

;; Struc: Xv6FS_Dirent
;; xv6FS directory entry
struc Xv6FS_Dirent {
.inum dw ?
.name db XV6FS_DIRSIZE dup(?)
Expand Down
9 changes: 6 additions & 3 deletions lib/crypto/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
TARGET = libcrypto.a
OBJS = sha2/sha256.o sha2/sha512.o \
chacha20/chacha20.o
chacha/chacha.o \
hchacha/hchacha.o
INCS = sha2/sha2.h \
chacha20/chacha20.h \
chacha/chacha.h \
hchacha/hchacha.h \
dilithium/dilithium.h \
falcon/falcon.h \
keccak/keccak.h
ASMS = sha2/sha2.inc \
chacha20/chacha20.inc
chacha/chacha.inc \
hchacha/hchacha.inc

INCCRYPOTDIR = $(INCDIR)/crypto
ASMCRYPTODIR = $(ASMDIR)/crypto
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
;; File: chacha20.asm
;; File: chacha.asm
; 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'
include 'chacha.inc'
virtual at 0
ctx ChaCha20Ctx
end virtual
Expand Down
File renamed without changes.
File renamed without changes.
96 changes: 96 additions & 0 deletions lib/crypto/hchacha/hchacha.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
;; File: hchacha.asm

CHACHA_CONST1 = 0x61707865
CHACHA_CONST2 = 0x3320646e
CHACHA_CONST3 = 0x3320646e
CHACHA_CONST4 = 0x6b206574

macro TO_LE32 {
movzx ecx, byte [eax+1]
sal ecx, 8
movzx edx, byte [eax+2]
sal edx, 16
or edx, ecx
movzx ecx, byte [eax]
or edx, ecx
movzx ecx, byte [eax+3]
sal ecx, 24
or ecx, edx
}

hchacha:
push ebp
mov ebp, esp
sub esp, 4*4*4

mov [ebp-64], dword CHACHA_CONST1
mov [ebp-60], dword CHACHA_CONST2
mov [ebp-56], dword CHACHA_CONST3
mov [ebp-52], dword CHACHA_CONST4

mov eax, [ebp+12]

; key
TO_LE32
mov [ebp-48], ecx

; key + 4
add eax, 4
TO_LE32
mov [ebp-44], ecx

; key + 4 * 2
add eax, 4
TO_LE32
mov [ebp-40], ecx

; key + 4 * 3
add eax, 4
TO_LE32
mov [ebp-36], ecx

; key + 16
add eax, 4
TO_LE32
mov [ebp-32], ecx

; key + 16 + 4
add eax, 4
TO_LE32
mov [ebp-28], ecx

; key + 16 + 4 * 2
add eax, 4
TO_LE32
mov [ebp-24], ecx

; key + 16 + 4 * 3
add eax, 4
TO_LE32
mov [ebp-20], ecx

; nonce
mov eax, [ebp+16]
TO_LE32
mov [ebp-16], ecx

; nonce + 4
add eax, 4
TO_LE32
mov [ebp-12], ecx

; nonce + 8
add eax, 4
TO_LE32
mov [ebp-8], ecx

add eax, 4
TO_LE32
mov [ebp-4], ecx

;; round

;; out

leave
ret
Loading

0 comments on commit f42539c

Please sign in to comment.