Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Made libraries compliant with loader spec. Updated docs.

  • Loading branch information...
commit 5db07b550d6e5228ca026d63bae024e5b5776f68 1 parent f5f7e2f
Devin Akman authored
View
4 docs/Specs/LibCrypto_README.txt
@@ -82,7 +82,7 @@ How to Use:
parties should agree on the highest number above 20 that still allows for
reasonable calculation time.
-6. Call JSR lib_crypto_wrapper.
+6. Call lib_crypto_wrapper from the library's Public API.
7. The data will now have been overwritten with its encrypted/unencrypted
version. Nothing else outside the space taken up by the library should
@@ -93,7 +93,7 @@ How to Use:
9. If you're done with the library, go to step 10. Otherwise, go to step 2.
10. Once you're completely finished with all cryptographic operations, call
- JSR lib_crypto_cleanup. This prevents information about the state from
+ lib_crypto_cleanup. This prevents information about the state from
leaking into the hands of adversaries. Also delete the key from RAM when it
is no longer needed. However, keep it stored elsewhere to be used when it
is required again.
View
2  docs/Specs/LibRNG_README.txt
@@ -9,4 +9,4 @@ the fact that the system clock has good enough time resolution for our
purposes, the data generated will certainly be good enough for in game usage.
Use is very simple. Set the A register to where you want the first out of 16
-words of data to be written, then call JSR lib_rng_wrapper.
+words of data to be written, then call lib_rng_wrapper.
View
78 src/Libraries/LibCrypto.dasm
@@ -21,7 +21,9 @@
SET PUSH, X ; instead of 1.
SET PUSH, Y
SET PUSH, Z
- JSR lib_crypto_apply
+ .longform
+:lib_crypto_RELOC1 JSR lib_crypto_apply
+ .shortform
SET Z, POP
SET Y, POP
SET X, POP
@@ -35,7 +37,9 @@
:lib_crypto_cleanup
SET PUSH, I
SET PUSH, J
- JSR lib_crypto_init
+ .longform
+:lib_crypto_RELOC2 JSR lib_crypto_init
+ .shortform
SET A, 0
SET B, 0
SET C, 0
@@ -49,26 +53,34 @@
; Initializes the state array.
:lib_crypto_init
- SET I, lib_crypto_state
+ .longform
+:lib_crypto_RELOC3 SET I, lib_crypto_state
+ .shortform
SET J, 0
:lib_crypto_initloop
STI [I], J
- IFN I, lib_crypto_end
- SET PC, lib_crypto_initloop
- SET [lib_crypto_firstrun_flag], 1
- SET PC, POP
+ .longform
+:lib_crypto_RELOC4 IFN I, lib_crypto_end
+:lib_crypto_RELOC5 SET PC, lib_crypto_initloop
+:lib_crypto_RELOC6 SET [lib_crypto_firstrun_flag], 1 ; [label] comes after 1
+ .shortform ; when assembled in
+ SET PC, POP ; longform.
; Sets up the state based on the key.
; A is the number of iterations and B is the location of the key in memory.
:lib_crypto_shufflestate
- SET [lib_crypto_firstrun_flag], 0
+ .longform
+:lib_crypto_RELOC7 SET [lib_crypto_firstrun_flag], 0 ; Same as above.
+ .shortform
SET J, 0
:lib_crypto_shuffleloop_outer
SET I, 0 ; Inner loop counter.
:lib_crypto_shuffleloop
SET C, B ; Key pointer.
- SET Y, lib_crypto_state ; State array pointer.
+ .longform
+:lib_crypto_RELOC8 SET Y, lib_crypto_state ; State array pointer.
+ .shortform
SET Z, Y ; Set Y and Z (array pointer) to beginning of array.
ADD Y, I ; Move Y to ith position.
ADD J, [Y]
@@ -81,10 +93,14 @@
SET [Z], X ; Swap complete.
ADD I, 1
IFN I, 256
- SET PC, lib_crypto_shuffleloop
+ .longform
+:lib_crypto_RELOC9 SET PC, lib_crypto_shuffleloop
+ .shortform
SUB A, 1
IFN A, 0
- SET PC, lib_crypto_shuffleloop_outer
+ .longform
+:lib_crypto_RELOC10 SET PC, lib_crypto_shuffleloop_outer
+ .shortform
SET PC, POP
; Applies the algorithm with arguments passed from the wrapper subroutine.
@@ -94,8 +110,10 @@
SET PUSH, B
SET PUSH, C
SET PUSH, I ; Store values on stack.
- IFN [lib_crypto_firstrun_flag], 1
- JSR lib_crypto_init
+ .longform
+:lib_crypto_RELOC11 IFN [lib_crypto_firstrun_flag], 1 ; Same as RELOC6.
+:lib_crypto_RELOC12 JSR lib_crypto_init
+ .shortform
SET A, POP ; Set A to iterations.
SET B, PICK 2 ; Set B to key location.
JSR lib_crypto_shufflestate
@@ -107,7 +125,9 @@
:lib_crypto_applyloop
IFG B, C
SET PC, POP ; Exits here.
- SET Y, lib_crypto_state ; State array pointer.
+ .longform
+:lib_crypto_RELOC13 SET Y, lib_crypto_state ; State array pointer.
+ .shortform
SET Z, Y ; Ditto.
ADD I, 1
AND I, 0xff ; Fewer cycles than MOD I, 256.
@@ -121,7 +141,9 @@
AND X, 0xff ; Fewer cycles than MOD X, 256.
XOR [B], X
ADD B, 1
- SET PC, lib_crypto_applyloop
+ .longform
+:lib_crypto_RELOC14 SET PC, lib_crypto_applyloop
+ .shortform
:lib_crypto_firstrun_flag
DAT 0x01
@@ -143,4 +165,28 @@ DAT 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC
DAT 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF
DAT 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF
DAT 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA, 0xFB, 0xFC, 0xFD, 0xFE, 0xFF
-:lib_crypto_end
+:lib_crypto_end
+
+; Begin Library Header.
+DAT lib_crypto_wrapper
+DAT lib_crypto_cleanup
+; Begin Relocation Table.
+DAT lib_crypto_RELOC1+1
+DAT lib_crypto_RELOC2+1
+DAT lib_crypto_RELOC3+1
+DAT lib_crypto_RELOC4+1
+DAT lib_crypto_RELOC5+1
+DAT lib_crypto_RELOC6+2
+DAT lib_crypto_RELOC7+2
+DAT lib_crypto_RELOC8+1
+DAT lib_crypto_RELOC9+1
+DAT lib_crypto_RELOC10+1
+DAT lib_crypto_RELOC11+2
+DAT lib_crypto_RELOC12+1
+DAT lib_crypto_RELOC13+1
+DAT lib_crypto_RELOC14+1
+; End Relocation Table.
+DAT 14 ; Relocation table length
+DAT 1 ; Header version number.
+DAT 19 ; Library Header length.
+; End Library Header.
View
178 src/Libraries/LibRNG.dasm
@@ -16,7 +16,9 @@
SET PUSH, X
SET PUSH, Y
SET PUSH, Z
- JSR lib_rng_generate
+ .longform
+:lib_rng_RELOC1 JSR lib_rng_generate
+ .shortform
SET Z, POP
SET Y, POP
SET X, POP
@@ -24,31 +26,45 @@
SET I, POP
SET PC, POP
-; MD2 Stuff. Don't call from your code. Bad dog.
; -----------------------------------------------------------------------------
+
:lib_rng_init
- SET I, lib_rng_padding
+ .longform
+:lib_rng_RELOC2 SET I, lib_rng_padding
+ .shortform
:lib_rng_initloop
STI [I], 12
- IFN I, lib_rng_checksum
- SET PC, lib_rng_initloop
+ .longform
+:lib_rng_RELOC3 IFN I, lib_rng_checksum
+:lib_rng_RELOC4 SET PC, lib_rng_initloop
+ .shortform
:lib_rng_initloop2
STI [I], 0
- IFN I, lib_rng_s_table
- SET PC, lib_rng_initloop2
- SET [lib_rng_firstrun_flag], 1
+ .longform
+:lib_rng_RELOC5 IFN I, lib_rng_s_table
+:lib_rng_RELOC6 SET PC, lib_rng_initloop2
+:lib_rng_RELOC7 SET [lib_rng_firstrun_flag], 1 ; RELOC7+2
+ .shortform
SET PC, POP
:lib_rng_generate_checksum
- SET [lib_rng_firstrun_flag], 0
+ .longform
+:lib_rng_RELOC8 SET [lib_rng_firstrun_flag], 0 ; Same as RELOC7.
+ .shortform
SET I, 0 ; I := L
SET J, 0 ; Checksum inner loop counter.
:lib_rng_checksumloop
- SET X, lib_rng_checksum
+ .longform
+:lib_rng_RELOC9 SET X, lib_rng_checksum
+ .shortform
ADD X, J ; [X] := C[j]
- SET Y, lib_rng_seed_firstbyte
+ .longform
+:lib_rng_RELOC10 SET Y, lib_rng_seed_firstbyte
+ .shortform
ADD Y, J ; [Y] := M[i*16 + j] where i = 0.
- SET Z, lib_rng_s_table
+ .longform
+:lib_rng_RELOC11 SET Z, lib_rng_s_table
+ .shortform
SET C, [Y]
XOR C, I ; C := c xor L
ADD Z, C ; [Z] := S[c xor L]
@@ -56,30 +72,38 @@
SET I, [X]
ADD J, 1
IFN J, 16
- SET PC, lib_rng_checksumloop
+ .longform
+:lib_rng_RELOC12 SET PC, lib_rng_checksumloop
+ .shortform
SET PC, POP
:lib_rng_generate ; A is location where random number should be written to.
SET PUSH, A
JSR [cd_get_sys_time]
- SET [lib_rng_seed_firstbyte], B
- SHR [lib_rng_seed_firstbyte], 8
- SET [lib_rng_seed_secondbyte], B
- AND [lib_rng_seed_secondbyte], 0xff
- SET [lib_rng_seed_thirdbyte], A
- SHR [lib_rng_seed_thirdbyte], 8
- SET [lib_rng_seed_fourthbyte], A
- AND [lib_rng_seed_fourthbyte], 0xff
- IFN [lib_rng_firstrun_flag], 1
- JSR lib_rng_init
- JSR lib_rng_generate_checksum
+ .longform ; All of these except for the last 2 need to be +2.
+:lib_rng_RELOC13 SET [lib_rng_seed_firstbyte], B
+:lib_rng_RELOC14 SHR [lib_rng_seed_firstbyte], 8
+:lib_rng_RELOC15 SET [lib_rng_seed_secondbyte], B
+:lib_rng_RELOC16 AND [lib_rng_seed_secondbyte], 0xff
+:lib_rng_RELOC17 SET [lib_rng_seed_thirdbyte], A
+:lib_rng_RELOC18 SHR [lib_rng_seed_thirdbyte], 8
+:lib_rng_RELOC19 SET [lib_rng_seed_fourthbyte], A
+:lib_rng_RELOC20 AND [lib_rng_seed_fourthbyte], 0xff
+:lib_rng_RELOC21 IFN [lib_rng_firstrun_flag], 1
+:lib_rng_RELOC22 JSR lib_rng_init
+:lib_rng_RELOC23 JSR lib_rng_generate_checksum
+ .shortform
SET J, 0
:lib_rng_generateloop1 ; First iteration, i = 0
- SET X, lib_rng_buffer
+ .longform
+:lib_rng_RELOC24 SET X, lib_rng_buffer
+ .shortform
ADD X, J
SET C, [X] ; C := X[j], will use this value later.
ADD X, 16 ; [X] := X[16 + j]
- SET Y, lib_rng_seed_firstbyte
+ .longform
+:lib_rng_RELOC25 SET Y, lib_rng_seed_firstbyte
+ .shortform
ADD Y, J ; [Y] := M[i*16 + j] where i = 0.
SET [X], [Y]
SET Z, [X] ; Z := X[16 + j], will use this value later too.
@@ -88,33 +112,45 @@
SET [X], Z
ADD J, 1
IFN J, 16
- SET PC, lib_rng_generateloop1
+ .longform
+:lib_rng_RELOC26 SET PC, lib_rng_generateloop1
+ .shortform
SET J, 0
SET A, 0 ; A := t
:lib_rng_generateloop15
SET Z, 0 ; Z := k
:lib_rng_generateloop15_inner
- SET X, lib_rng_buffer
+ .longform
+:lib_rng_RELOC27 SET X, lib_rng_buffer
ADD X, Z
- SET I, lib_rng_s_table
+:lib_rng_RELOC28 SET I, lib_rng_s_table
+ .shortform
ADD I, A
XOR [X], [I]
SET A, [X]
ADD Z, 1
IFN Z, 0x30
- SET PC, lib_rng_generateloop15_inner
+ .longform
+:lib_rng_RELOC29 SET PC, lib_rng_generateloop15_inner
+ .shortform
ADD A, J
AND A, 0xff ; Fewer cycles than MOD A, 256
ADD J, 1
IFN J, 18
- SET PC, lib_rng_generateloop15
+ .longform
+:lib_rng_RELOC30 SET PC, lib_rng_generateloop15
+ .shortform
SET J, 0
:lib_rng_generateloop2 ; Second iteration of unrolled loop. i = 1.
- SET X, lib_rng_buffer
+ .longform
+:lib_rng_RELOC31 SET X, lib_rng_buffer
+ .shortform
ADD X, J
SET C, [X]
ADD X, 16
- SET Y, lib_rng_seed_firstbyte
+ .longform
+:lib_rng_RELOC32 SET Y, lib_rng_seed_firstbyte
+ .shortform
ADD Y, 16
ADD Y, J ; [Y] := M[i*16 + j] where i = 1.
SET [X], [Y]
@@ -124,36 +160,48 @@
SET [X], Z
ADD J, 1
IFN J, 16
- SET PC, lib_rng_generateloop2
+ .longform
+:lib_rng_RELOC33 SET PC, lib_rng_generateloop2
+ .shortform
SET J, 0
SET A, 0 ; A := t
:lib_rng_generateloop25
SET Z, 0 ; Z := k
:lib_rng_generateloop25_inner
- SET X, lib_rng_buffer
+ .longform
+:lib_rng_RELOC34 SET X, lib_rng_buffer
ADD X, Z
- SET I, lib_rng_s_table
+:lib_rng_RELOC35 SET I, lib_rng_s_table
+ .shortform
ADD I, A
XOR [X], [I]
SET A, [X]
ADD Z, 1
IFN Z, 0x30
- SET PC, lib_rng_generateloop25_inner
+ .longform
+:lib_rng_RELOC36 SET PC, lib_rng_generateloop25_inner
+ .shortform
ADD A, J
AND A, 0xff ; Fewer cycles than MOD A, 256
ADD J, 1
IFN J, 18
- SET PC, lib_rng_generateloop25
+ .longform
+:lib_rng_RELOC37 SET PC, lib_rng_generateloop25
+ .shortform
SET I, 0
SET A, POP
:lib_rng_generate_writeloop
- SET X, lib_rng_buffer
+ .longform
+:lib_rng_RELOC38 SET X, lib_rng_buffer
+ .shortform
ADD X, I
SET C, A
ADD C, I
STI [C], [X]
IFN I, 16
- SET PC, lib_rng_generate_writeloop
+ .longform
+:lib_rng_RELOC39 SET PC, lib_rng_generate_writeloop
+ .shortform
SET PC, POP
:lib_rng_firstrun_flag
@@ -207,4 +255,52 @@ DAT 0x6A, 0xDC, 0x37, 0xC8, 0x6C, 0xC1, 0xAB, 0xFA, 0x24, 0xE1, 0x7B, 0x08, 0x0C
DAT 0x78, 0x88, 0x95, 0x8B, 0xE3, 0x63, 0xE8, 0x6D, 0xE9, 0xCB, 0xD5, 0xFE, 0x3B, 0x00, 0x1D, 0x39
DAT 0xF2, 0xEF, 0xB7, 0x0E, 0x66, 0x58, 0xD0, 0xE4, 0xA6, 0x77, 0x72, 0xF8, 0xEB, 0x75, 0x4B, 0x0A
DAT 0x31, 0x44, 0x50, 0xB4, 0x8F, 0xED, 0x1F, 0x1A, 0xDB, 0x99, 0x8D, 0x33, 0x9F, 0x11, 0x83, 0x14
-:lib_rng_end
+:lib_rng_end
+
+; Begin Library Header.
+DAT lib_rng_wrapper
+; Begin Relocation Table.
+DAT lib_rng_RELOC1+1
+DAT lib_rng_RELOC2+1
+DAT lib_rng_RELOC3+1
+DAT lib_rng_RELOC4+1
+DAT lib_rng_RELOC5+1
+DAT lib_rng_RELOC6+1
+DAT lib_rng_RELOC7+2
+DAT lib_rng_RELOC8+1
+DAT lib_rng_RELOC9+1
+DAT lib_rng_RELOC10+1
+DAT lib_rng_RELOC11+1
+DAT lib_rng_RELOC12+1
+DAT lib_rng_RELOC13+2
+DAT lib_rng_RELOC14+2
+DAT lib_rng_RELOC15+2
+DAT lib_rng_RELOC16+2
+DAT lib_rng_RELOC17+2
+DAT lib_rng_RELOC18+2
+DAT lib_rng_RELOC19+2
+DAT lib_rng_RELOC20+2
+DAT lib_rng_RELOC21+2
+DAT lib_rng_RELOC22+1
+DAT lib_rng_RELOC23+1
+DAT lib_rng_RELOC24+1
+DAT lib_rng_RELOC25+1
+DAT lib_rng_RELOC26+1
+DAT lib_rng_RELOC27+1
+DAT lib_rng_RELOC28+1
+DAT lib_rng_RELOC29+1
+DAT lib_rng_RELOC30+1
+DAT lib_rng_RELOC31+1
+DAT lib_rng_RELOC32+1
+DAT lib_rng_RELOC33+1
+DAT lib_rng_RELOC34+1
+DAT lib_rng_RELOC35+1
+DAT lib_rng_RELOC36+1
+DAT lib_rng_RELOC37+1
+DAT lib_rng_RELOC38+1
+DAT lib_rng_RELOC39+1
+; End Relocation Table.
+DAT 38 ; Relocation table length.
+DAT 1 ; Header version number.
+DAT 43 ; Library Header length.
+; End Library Header.
Please sign in to comment.
Something went wrong with that request. Please try again.