[Tkabber-dev] r2127 - in trunk/tkabber-plugins: . otr otr/tclotr

tkabber-svn at jabber.ru tkabber-svn at jabber.ru
Sun Feb 2 11:14:13 MSK 2014


Author: sergei
Date: 2014-02-02 11:14:13 +0400 (Sun, 02 Feb 2014)
New Revision: 2127

Modified:
   trunk/tkabber-plugins/ChangeLog
   trunk/tkabber-plugins/otr/key.tcl
   trunk/tkabber-plugins/otr/tclotr/key.tcl
Log:
	* otr/key.tcl, otr/tclotr/key.tcl: Moved key generation procedure to
	  the otr::key package.


Modified: trunk/tkabber-plugins/ChangeLog
===================================================================
--- trunk/tkabber-plugins/ChangeLog	2014-01-31 14:54:21 UTC (rev 2126)
+++ trunk/tkabber-plugins/ChangeLog	2014-02-02 07:14:13 UTC (rev 2127)
@@ -1,3 +1,8 @@
+2014-02-02  Sergei Golovan <sgolovan at nes.ru>
+
+	* otr/key.tcl, otr/tclotr/key.tcl: Moved key generation procedure to
+	  the otr::key package.
+
 2014-01-31  Sergei Golovan <sgolovan at nes.ru>
 
 	* otr/otr.tcl: Fixed typo in creating OTR button for normal message

Modified: trunk/tkabber-plugins/otr/key.tcl
===================================================================
--- trunk/tkabber-plugins/otr/key.tcl	2014-01-31 14:54:21 UTC (rev 2126)
+++ trunk/tkabber-plugins/otr/key.tcl	2014-02-02 07:14:13 UTC (rev 2127)
@@ -1,5 +1,8 @@
 # $Id$
 
+package require otr::crypto
+package require otr::key
+
 namespace eval key {
     set ns http://tkabber.jabber.ru/otr
     set otrdir [file join $::configdir otr]
@@ -395,18 +398,6 @@
     return
 }
 
-# ::otr::crypto::GenPrimesIteration --
-#	A dirty hack which overrides ::otr::crypto::genPrimesIteration and
-#	adds a side effect which updates progressbar. This helps not freezing
-#	the GUI during DSA private key generation.
-
-rename ::otr::crypto::GenPrimesIteration ::otr::crypto::GenPrimesIteration:old
-
-proc ::otr::crypto::GenPrimesIteration {L t q p0 pseed pgen_counter} "
-	incr [namespace current]::key::progress
-	update
-	::otr::crypto::GenPrimesIteration:old \$L \$t \$q \$p0 \$pseed \$pgen_counter"
-
 # key::generate_key --
 #
 #	Private procedure which generates and store new DSA private key.
@@ -441,44 +432,33 @@
     $f.gen configure -state disabled
     $f.delete configure -state disabled
 
-    set status 0
-    while {!$status} {
-	# Generate first seed
-	set fstatus 0
-	while {!$fstatus} {
-	    lassign [::otr::crypto::getFirstSeed $N $N] \
-		    fstatus firstseed
-	    incr progress
-	    update
-	}
+    set newkey [::otr::key::generate $L $N]
+    incr progress
 
-	# Generate p and q
-	set status 0
-	while {!$status} {
-	    lassign [::otr::crypto::genPrimes $L $N $firstseed] \
-		    status p q pseed qseed pgen_counter qgen_counter
-	    incr progress
-	    update
-	}
-    }
-
-    # Generate g
-    set g [::otr::crypto::genGenerator $p $q]
-    incr progress
-    update
-    # Generate x y
-    lassign [::otr::crypto::genKeyPair $p $q $g] kstatus x y
-    incr progress
-    update
-    set progress -1
-    set newkey [list $p $q $g $y $x]
     if {![dict exists $Keys $keyjid] || [dict get $Keys $keyjid] ne $newkey} {
 	dict set Keys $keyjid $newkey
 	store $Keys
 	[namespace parent]::clear_all_jid $keyjid
     }
+    set progress -1
     fill_dialog $w
     $w itemconfigure 0 -state normal
     $f.jid configure -state normal
     return
 }
+
+# ::otr::crypto::GenPrimesIteration --
+#	A dirty hack which overrides ::otr::crypto::genPrimesIteration and
+#	adds a side effect which updates progressbar. This helps not freezing
+#	the GUI during DSA private key generation.
+#	[subst] substitutes [namespace current].
+
+rename ::otr::crypto::GenPrimesIteration ::otr::crypto::GenPrimesIteration:old
+
+proc ::otr::crypto::GenPrimesIteration {L t q p0 pseed pgen_counter} \
+    [subst -novariables {
+	incr [namespace current]::key::progress
+	update
+	::otr::crypto::GenPrimesIteration:old $L $t $q $p0 $pseed $pgen_counter
+    }]
+

Modified: trunk/tkabber-plugins/otr/tclotr/key.tcl
===================================================================
--- trunk/tkabber-plugins/otr/tclotr/key.tcl	2014-01-31 14:54:21 UTC (rev 2126)
+++ trunk/tkabber-plugins/otr/tclotr/key.tcl	2014-02-02 07:14:13 UTC (rev 2127)
@@ -14,6 +14,7 @@
 package require base64
 package require asn
 package require math::bignum
+package require otr::crypto
 
 package provide otr::key 0.1
 
@@ -130,4 +131,46 @@
     close $fd
 }
 
+# ::otr::key::generate --
+#
+#       Generate a new DSA private key.
+#
+# Arguments:
+#       L           Length of p in bits.
+#       N           Length of q in bits.
+#
+# Result:
+#       DSA private key {p, q, g, y, x}.
+#
+# Side effects:
+#       Several random numbers are generated, so some entropy is used
+#       by PRNG.
+
+proc ::otr::key::generate {L N} {
+    set status 0
+    while {!$status} {
+	# Generate first seed
+	set fstatus 0
+	while {!$fstatus} {
+	    lassign [::otr::crypto::getFirstSeed $N $N] \
+		    fstatus firstseed
+	}
+
+	# Generate p and q
+	lassign [::otr::crypto::genPrimes $L $N $firstseed] \
+		status p q pseed qseed pgen_counter qgen_counter
+    }
+
+    # Generate g
+    set g [::otr::crypto::genGenerator $p $q]
+
+    # Generate x y
+    set kstatus 0
+    while {!$kstatus} {
+        lassign [::otr::crypto::genKeyPair $p $q $g] kstatus x y
+    }
+
+    list $p $q $g $y $x
+}
+
 # vim:ts=8:sw=4:sts=4:et



More information about the Tkabber-dev mailing list