##### DH1080 KeyXchange for tcl BETA
bind notc - "DH1080_INIT *" DH1080_INIT_recv
bind notc - "DH1080_FINISH *" DH1080_FINISH_recv
bind msg - !DH1080 DH1080_KeyXchange

load /home/path/to/DH1080_tcl.so

# I have no clue how to create a 300 bytes string in TCL :)
set mypubkey "1EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE"
set myprivkey "2EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE"



proc DH1080_INIT_recv { nick host handle text dest } {
	global mypubkey myprivkey

        set arg_len [string length $text]
        if { ($arg_len < 192) || ($arg_len > 193) } { return }

        ## IMPORTANT: the 2 variables should be at least 200 bytes each!
        ## You might run into a crash, if they are too small!
	DH1080gen "$myprivkey" "$mypubkey"
        putserv "NOTICE $nick :DH1080_FINISH $mypubkey"

	set hispubkey [lindex $text 1]
	DH1080comp "$myprivkey" "$hispubkey"
        ## $hispubkey now contains the secret key!

# putlog "secret!!: $hispubkey"
# your_setkey_proc $nick $hispubkey

	## Always destroy the secret key after use!
        set hispubkey "4EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE"
}



proc DH1080_FINISH_recv { nick host handle text dest } {
        global mypubkey myprivkey

        set arg_len [string length $text]
        if { ($arg_len < 194) || ($arg_len > 195) } { return }

	set hispubkey [lindex $text 1]
	DH1080comp "$myprivkey" "$hispubkey"
	## $hispubkey now contains the secret key!

# putlog "secret!!: $hispubkey"
# your_setkey_proc $nick $hispubkey

        ## Always destroy the secret key after use!
        set hispubkey "5EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE_EMPTY_SPACE"
}


proc DH1080_KeyXchange { nick uhost hand args } {
        global mypubkey myprivkey

        ## IMPORTANT: the 2 variables should be at least 200 bytes each!
        ## You might run into a crash, if they are too small!
        DH1080gen "$myprivkey" "$mypubkey"

	putserv "NOTICE $nick :DH1080_INIT $mypubkey"
}

