diff --git a/ACME_Lib/6502/rc4.a b/ACME_Lib/6502/rc4.a index 1a73150..9d62811 100644 --- a/ACME_Lib/6502/rc4.a +++ b/ACME_Lib/6502/rc4.a @@ -1,22 +1,22 @@ ;ACME 0.97 ; this is an implementation of the stream cipher algorithm known as RC4. -; UNFINISHED - DO NOT USE! ; you need to define these symbols in your code: ; rc4_length a single byte to hold key/chunk lengths -; rc4_count a single byte (iteration counter) +; rc4_count a single byte (tmp var for iteration counter) ; rc4_ii a single byte to hold state ; rc4_jj a single byte to hold state ; rc4_state a full page of memory (256 bytes) +; rc4_key key buffer ; rc4_in input buffer ; rc4_out output buffer ; the size of the buffers limits how much data you can pass to the functions. -; the two buffer addresses may be identical, in that case the output will -; overwrite the input. +; all three buffer addresses may be identical, in that case the output will +; overwrite the input (and/or the key). ; functions you can then call: ; rc4_init initialise state -; rc4_key_X use key (in input buffer, length in X) to change state +; rc4_usekey_X use key (in key buffer, length in X) to change state ; rc4_reset reset ii and jj (call between keying and processing) ; rc4_process_X de/encrypt a chunk of data buffer-to-buffer (length in X) @@ -27,6 +27,7 @@ .ii = rc4_ii .jj = rc4_jj .state = rc4_state + .keybuf = rc4_key .inbuf = rc4_in .outbuf = rc4_out @@ -44,8 +45,9 @@ rc4_reset ldx #0 stx .jj rts -; use key (in input buffer, length in X) to change permutation in state array -rc4_key_X +; use key (in key buffer, length in X) to change permutation in state array +; X==0 means 256! +rc4_usekey_X ; X holds .ii (but we count from 0 to 255 and so do not use the real .ii at all) ; Y holds .jj or .count (.jj is then in A) stx .length @@ -61,7 +63,7 @@ rc4_key_X adc .state, x ldy .count clc - adc .inbuf, y + adc .keybuf, y ;sta .jj ;if (++count == length) ; count = 0;