added file to library (unfinished, do not use!)

git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@311 4df02467-bbd4-4a76-a152-e7ce94205b78
This commit is contained in:
marcobaye 2020-12-26 23:13:11 +00:00
parent 8dc1b0ca0f
commit 65e258488a
2 changed files with 125 additions and 2 deletions

123
ACME_Lib/6502/rc4.a Normal file
View File

@ -0,0 +1,123 @@
;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_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_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.
; functions you can then call:
; rc4_init initialise state
; rc4_key_X use key (in input 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)
!zone rc4 {
; create shorter names
.length = rc4_length
.count = rc4_count
.ii = rc4_ii
.jj = rc4_jj
.state = rc4_state
.inbuf = rc4_in
.outbuf = rc4_out
; fill state vector with initial values (00..ff) and init both counters
rc4_init
ldx #0
- txa
sta .state, x
inx
bne -
;FALLTHROUGH
; reset state counters to zero (actually, only really needed for jj)
rc4_reset ldx #0
stx .ii
stx .jj
rts
; use key (in input buffer, length in X) to change permutation in state array
rc4_key_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
ldx #0
stx .count
; do 256 mixing operations
;.ii = 0
;ldx #0 ;do {
ldy .jj
--- ;jj += state[ii] + key[count];
tya;lda .jj
clc
adc .state, x
ldy .count
clc
adc .inbuf, y
;sta .jj
;if (++count == length)
; count = 0;
iny
cpy .length
bne +
ldy #0
+ sty .count
tay ; now Y holds .jj
lda .state, x ;tmp = state[ii]
pha
lda .state, y ;state[ii] = state[jj]
sta .state, x
pla ;state[jj] = tmp
sta .state, y
inx ;} while (++ii);
bne ---
sty .jj ; writeback
rts
; de/encrypt first X bytes of input buffer to output buffer
; X==0 means 256!
rc4_process_X
stx .limit
ldx #0
stx .offset
- ; ++ii
inc .ii
; jj += state[ii]
ldx .ii
lda .jj
clc
adc .state, x
sta .jj
tay
; tmp = state[ii];
; state[ii] = state[jj];
; state[jj] = tmp;
lda .state, x
pha
lda .state, y
sta .state, x
pla
sta .state, y
; nn = state[ii] + state[jj];
clc
adc .state, x
; buf[aktueller_offset] ^= state[nn]
tax
lda .state, x
ldx #MODIFIED8 : .offset = * - 1
eor .inbuf, x
sta .outbuf, x
; all done?
inx
cpx #MODIFIED8 : .limit = * - 1
bne -
rts
}

View File

@ -260,8 +260,8 @@ lib_cbm_c128_zeropage_a = 1
;z_frekzp = $fa ; ROM does not use this, but it does get swapped out when screen changes! ;z_frekzp = $fa ; ROM does not use this, but it does get swapped out when screen changes!
;} ;}
; $fb/$fc/$fd/$fe are unused ; $fb/$fc/$fd/$fe are unused
z_lofbuf = $ff z_lofbuf = $ff ; overwritten when outputting line numbers or ti$
z_fbuffr = $0100 z_fbuffr = $0100 ; buffer for number strings
z_xcnt = $0110 z_xcnt = $0110
z_dosf1l = $0111 z_dosf1l = $0111
z_dosds1 = $0112 z_dosds1 = $0112