1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
+
-
-
+
+
-
-
-
+
+
+
+
+
+
-
+
+
+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
|
#! /usr/bin/env tclsh
lappend auto_path [file join [file dirname [info script]] .. ..]
package require nano
proc test1 {} {
# Detached signature
set data [binary decode hex 0000000000000000000000000000000000000000000000000000000000000000]
set key [binary decode hex C4D214F19E706E9C7487CEF00DE8059200C32414F0ED82E5E33B523AEDF719BA]
set signed [string toupper [binary encode hex [::nano::internal::signDetached $data $key]]]
set signed_expected 1C2DE9B8A71215F949A11BBEA7EFA4ECD67A8C2B5A9AD98AE6B1AB7F7A3D2CFD715F570309148C7B39C346FB9B91B321D7E75BD598F271AF31AB60A99D086709
set sig [string toupper [binary encode hex [::nano::internal::signDetached $data $key]]]
set sig_expected 1C2DE9B8A71215F949A11BBEA7EFA4ECD67A8C2B5A9AD98AE6B1AB7F7A3D2CFD715F570309148C7B39C346FB9B91B321D7E75BD598F271AF31AB60A99D086709
if {$signed ne $signed_expected} {
puts "\[FAIL\] Got: $signed"
puts "\[FAIL\] Exp: $signed_expected"
if {$sig ne $sig_expected} {
puts "\[FAIL\] Got: $sig"
puts "\[FAIL\] Exp: $sig_expected"
return false
}
# Public key generation
set pubKey_expected "FE1934767B26FA05A1526E40101E899959AB088FA1C4219865F33669E8EB99B6"
set pubKey [::nano::internal::publicKey $key]
set pubKey [binary encode hex $pubKey]
set pubKey [string toupper [binary encode hex $pubKey]]
if {$pubKey ne $pubKey_expected} {
puts "\[FAIL\] Got: $pubKey"
puts "\[FAIL\] Exp: $pubKey_expected"
return false
}
puts "Pub: $pubKey"
# Detached signature verification
## Positive
set data [binary decode hex 0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF]
set key [binary decode hex C4D214F19E706E9C7487CEF00DE8059200C32414F0ED82E5E33B523AEDF719BA]
set pubKey [::nano::internal::publicKey $key]
set sig [::nano::internal::signDetached $data $key]
set verified [::nano::internal::verifyDetached $data $sig $pubKey]
if {!$verified} {
puts "\[FAIL\] Got: $verified"
puts "\[FAIL\] Exp: true"
return false
}
## Negative
set pubKey [binary decode hex "7E0008FAD05BD9E22A8DEBA963CE3C9C769BC01B00974226D264C9078A7A98A8"]
set verified [::nano::internal::verifyDetached $data $sig $pubKey]
if {$verified} {
puts "\[FAIL\] Got: $verified"
puts "\[FAIL\] Exp: false"
return false
}
}
test1
|