Permalink
Browse files

Made libraries compliant with loader spec. Updated docs.

  • Loading branch information...
Devin Akman
Devin Akman committed Dec 12, 2012
1 parent f5f7e2f commit 5db07b550d6e5228ca026d63bae024e5b5776f68
Showing with 202 additions and 60 deletions.
  1. +2 −2 docs/Specs/LibCrypto_README.txt
  2. +1 −1 docs/Specs/LibRNG_README.txt
  3. +62 −16 src/Libraries/LibCrypto.dasm
  4. +137 −41 src/Libraries/LibRNG.dasm
@@ -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.
@@ -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.
@@ -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.
Oops, something went wrong.

0 comments on commit 5db07b5

Please sign in to comment.