Commit 9d841afa authored by bernd's avatar bernd

Coding for stateless packets

parent 8d3b140b
......@@ -47,7 +47,7 @@ $4000 Constant /kregion
ELSE 0 THEN ;
: sec+! ( addr1 u1 addr2 -- )
dup @ 0= IF sec! ELSE sec@ dup >r + swap $40 r> - umin move THEN ;
: sec-off ( addr -- ) >r r@ @ ?dup-IF kfree64 THEN r> off ;
: sec-off ( addr -- ) dup @ dup IF kfree64 off EXIT THEN 2drop ;
: sec+[]! ( addr1 u1 addr2 -- ) >r
0 { w^ sec } sec sec! sec cell r> $+! ;
......
......@@ -395,6 +395,7 @@ Variable throwcount
string-stack $off
object-stack $off
nest-stack $off
tmp-0key sec-off
o to connection
o IF
maxdata code+
......
......@@ -144,7 +144,7 @@ net2o-base
reply-key, gen-punchload gen-punch time-offset! context ]tmpnest
push-cmd ;] IS expect-reply? ;
+net2o: knock ( $:challenge -- ) $> tmp-0key sec! ;
+net2o: knock ( $:key -- ) $> tmp-0key sec! ;
gen-table $freeze
......
......@@ -173,22 +173,30 @@ User last-ivskey
crypt-buf-init inbuf packet-data +cryptsu
inbuf 1+ c@ c:decrypt+auth +enc ;
: set-0key ( 64addr flag keyaddr -- )
: set-0key ( keyaddr -- )
dup @ IF
$@ state# min ivs-assembly swap move
addr>assembly
ivs-assembly >c:key
sec@ state# min
ivs-assembly state# bounds ?DO
2dup I swap move
dup +LOOP 2drop
ELSE
2drop 64drop default-key
THEN ;
ivs-assembly state# erase
THEN
ivs-assembly >c:key ;
: inbuf0-decrypt ( -- flag ) +calc
inbuf addr 64@ inbuf flags w@ my-0key set-0key
: try-0decrypt ( key -- flag ) set-0key
inbuf packet-data +cryptsu
inbuf 1+ c@ c:decrypt+auth +enc ;
: inbuf0-decrypt ( -- flag ) +calc
inbuf addr 64@ inbuf flags w@ addr>assembly
my-0key try-0decrypt dup IF EXIT THEN
contexts BEGIN @ dup WHILE >o
next-context dest-0key try-0decrypt o>
dup IF nip EXIT THEN REPEAT ;
: outbuf0-encrypt ( -- ) +calc
outbuf addr 64@ outbuf flags w@
outbuf addr 64@ outbuf flags w@ addr>assembly
o IF dest-0key ELSE tmp-0key THEN set-0key
outbuf packet-data +cryptsu
outbuf 1+ c@ c:encrypt+auth +enc ;
......
......@@ -811,6 +811,8 @@ current-o
\ job context structure and subclasses
Variable contexts \G contains all command objects
object class
field: token-table
field: parent
......@@ -885,6 +887,7 @@ cmd-class class
field: log-context
field: ack-context
field: msg-context
field: next-context \ link field if needed
field: codebuf#
field: context#
field: wait-task
......@@ -1105,6 +1108,7 @@ UValue connection
: n2o:new-context ( addr -- o )
context-class new >o timeout( ." new context: " o hex. cr )
o contexts !@ next-context !
o to connection \ current connection
context-table @ token-table ! \ copy pointer
init-context# @ context# ! 1 init-context# +!
......@@ -1782,11 +1786,12 @@ User outflag outflag off
: send-code-packet ( -- ) +sendX
\ ." send " outbuf .header
o IF code-map @ outbuf-encrypt ELSE outbuf0-encrypt THEN
outbuf flags 1+ c@ stateless# and IF
outbuf0-encrypt
return-addr
cmd0( .time ." cmd0 to: " dup $10 xtype cr )
ELSE
code-map @ outbuf-encrypt
return-address
THEN packet-to ;
......@@ -2303,6 +2308,11 @@ $10 Constant tmp-crypt-val
\ dispose context
: unlink-ctx ( next hit ptr -- )
next-context @ o contexts
BEGIN 2dup @ <> WHILE @ dup .next-context swap 0= UNTIL
2drop drop EXIT THEN nip ! ;
: n2o:dispose-context ( o:addr -- o:addr )
[: cmd( ." Disposing context... " o hex. cr )
timeout( ." Disposing context... " o hex. ." task: " up@ hex. cr )
......@@ -2315,12 +2325,14 @@ $10 Constant tmp-crypt-val
resend0 $off fstate-off
\ erase crypto keys
crypto-key sec-off
dest-0key sec-off
data-resend $off
dest-pubkey $off
pubkey $off
mpubkey $off
log-context @ .dispose
ack-context @ >o timing-stat $off track-timing $off dispose o>
unlink-ctx
dispose 0 to connection
cmd( ." disposed" cr ) ;] file-sema c-section ;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment