@@ -81,118 +81,59 @@ C79E915C3277361FBFA587C6DC06FEDE0B7E57FEC0B68F96B3AD651D54264357
81
81
82
82
83
83
===start-group=== "Elliptic-curve Diffie-Hellman key exchange"
84
+ curves: [secp256k1 secp256r1 secp224r1 secp192r1 secp160r1]
85
+ foreach ecurve curves [
86
+ --test-- rejoin ["ECDH (" ecurve ") keys usage" ]
87
+
88
+ ;- Boban and Alice both init key with same curve
89
+ --assert handle? k-Alice: ecdh/init none ecurve
90
+ --assert handle? k-Boban: ecdh/init none ecurve
91
+ --assert ecurve = ecdh/curve k-Alice
92
+ --assert ecurve = ecdh/curve k-Boban
93
+ ;- ... exports and exchange public parts of it
94
+ --assert binary? pub-Alice: ecdh/public k-Alice
95
+ --assert binary? pub-Boban: ecdh/public k-Boban
96
+ ;- ... and use them to compute shared secret.
97
+ --assert binary? secret-Alice: ecdh/secret k-Alice pub-Boban
98
+ --assert binary? secret-Boban: ecdh/secret k-Boban pub-Alice
99
+ ;- These keys should be same on both sides
100
+ --assert secret-Alice = secret-Boban
101
+ ;- Once done with the exchange, the ECDH key must be released!
102
+ --assert handle? ecdh/release k-Alice
103
+ --assert none? ecdh/public k-Alice
104
+
105
+ ;- re-initialization...
106
+ --assert handle? ecdh/init k-Alice ecurve ;- using existing key for a new init
107
+ --assert binary? pub-Alice: ecdh/public k-Alice
108
+ ;- /release may be used with /secret
109
+ --assert binary? secret-Alice: ecdh/secret/release k-Alice pub-Boban
110
+ --assert binary? secret-Boban: ecdh/secret/release k-Boban pub-Alice
111
+ --assert secret-Alice = secret-Boban
112
+
113
+ --test-- rejoin ["ECDSA (" ecurve ") signing" ]
114
+
115
+ ;- Alice generates her key-pair
116
+ k-Alice: ecdh/init none ecurve
117
+ ;- wants to sign some data:
118
+ data: {Ladies and Gentlemen of the class of '99: If I could offer you only one tip for the future, sunscreen would be it.}
119
+ ;- computes its hash:
120
+ hash: checksum /method data 'sha256
121
+ ;- and use ECDSA to sign it using her private key
122
+ signature: ecdsa/sign k-Alice hash
123
+ --assert binary? signature
124
+ --assert 64 = length? signature
125
+ ;- can verify if it really works:
126
+ --assert ecdsa/verify k-Alice hash signature
127
+
128
+ ;- than Alice may send the data with signature, used curve and public key to Boban
129
+ pub-Alice: ecdh/public k-Alice
130
+ ;- Boban can verify, that the data are really from Alice
131
+ --assert ecdsa/verify/curve pub-Alice hash signature ecurve
132
+
133
+ ]
134
+
135
+
84
136
85
- --test-- "ECDH (secp256k1) keys usage"
86
-
87
- ecurve: 'secp256k1
88
- ;- Boban and Alice both init key with same curve
89
- --assert handle? k-Alice: ecdh/init none ecurve
90
- --assert handle? k-Boban: ecdh/init none ecurve
91
- --assert ecurve = ecdh/curve k-Alice
92
- --assert ecurve = ecdh/curve k-Boban
93
- ;- ... exports and exchange public parts of it
94
- --assert binary? pub-Alice: ecdh/public k-Alice
95
- --assert binary? pub-Boban: ecdh/public k-Boban
96
- ;- ... and use them to compute shared secret.
97
- --assert binary? secret-Alice: ecdh/secret k-Alice pub-Boban
98
- --assert binary? secret-Boban: ecdh/secret k-Boban pub-Alice
99
- ;- These keys should be same on both sides
100
- --assert secret-Alice = secret-Boban
101
- ;- Once done with the exchange, the ECDH key must be released!
102
- --assert handle? ecdh/release k-Alice
103
- --assert handle? ecdh/release k-Boban
104
- --assert none? ecdh/public k-Alice
105
-
106
- --test-- "ECDH (secp256r1) keys usage"
107
-
108
- ecurve: 'secp256r1
109
- ;- Boban and Alice both init key with same curve
110
- --assert handle? k-Alice: ecdh/init none ecurve
111
- --assert handle? k-Boban: ecdh/init none ecurve
112
- --assert ecurve = ecdh/curve k-Alice
113
- --assert ecurve = ecdh/curve k-Boban
114
- ;- ... exports and exchange public parts of it
115
- --assert binary? pub-Alice: ecdh/public k-Alice
116
- --assert binary? pub-Boban: ecdh/public k-Boban
117
- ;- ... and use them to compute shared secret.
118
- --assert binary? secret-Alice: ecdh/secret k-Alice pub-Boban
119
- --assert binary? secret-Boban: ecdh/secret k-Boban pub-Alice
120
- ;- These keys should be same on both sides
121
- --assert secret-Alice = secret-Boban
122
- ;- Once done with the exchange, the ECDH key must be released!
123
- --assert handle? ecdh/release k-Alice
124
- --assert handle? ecdh/release k-Boban
125
- --assert none? ecdh/public k-Alice
126
-
127
- --test-- "ECDH (secp224r1) keys usage"
128
-
129
- ecurve: 'secp224r1
130
- ;- Boban and Alice both init key with same curve
131
- --assert handle? k-Alice: ecdh/init none ecurve
132
- --assert handle? k-Boban: ecdh/init none ecurve
133
- --assert ecurve = ecdh/curve k-Alice
134
- --assert ecurve = ecdh/curve k-Boban
135
- ;- ... exports and exchange public parts of it
136
- --assert binary? pub-Alice: ecdh/public k-Alice
137
- --assert binary? pub-Boban: ecdh/public k-Boban
138
- ;- ... and use them to compute shared secret.
139
- --assert binary? secret-Alice: ecdh/secret k-Alice pub-Boban
140
- --assert binary? secret-Boban: ecdh/secret k-Boban pub-Alice
141
- ;- These keys should be same on both sides
142
- --assert secret-Alice = secret-Boban
143
- ;- Once done with the exchange, the ECDH key must be released!
144
- --assert handle? ecdh/release k-Alice
145
- --assert handle? ecdh/release k-Boban
146
- --assert none? ecdh/public k-Alice
147
-
148
- --test-- "ECDH (secp192r1) keys usage"
149
-
150
- ecurve: 'secp192r1
151
- ;- Boban and Alice both init key with same curve
152
- --assert handle? k-Alice: ecdh/init none ecurve
153
- --assert handle? k-Boban: ecdh/init none ecurve
154
- --assert ecurve = ecdh/curve k-Alice
155
- --assert ecurve = ecdh/curve k-Boban
156
- ;- ... exports and exchange public parts of it
157
- --assert binary? pub-Alice: ecdh/public k-Alice
158
- --assert binary? pub-Boban: ecdh/public k-Boban
159
- ;- ... and use them to compute shared secret.
160
- --assert binary? secret-Alice: ecdh/secret k-Alice pub-Boban
161
- --assert binary? secret-Boban: ecdh/secret k-Boban pub-Alice
162
- ;- These keys should be same on both sides
163
- --assert secret-Alice = secret-Boban
164
- ;- Once done with the exchange, the ECDH key must be released!
165
- --assert handle? ecdh/release k-Alice
166
- --assert handle? ecdh/release k-Boban
167
- --assert none? ecdh/public k-Alice
168
-
169
- --test-- "ECDH (secp160r1) keys usage"
170
-
171
- ecurve: 'secp160r1
172
- ;- Boban and Alice both init key with same curve
173
- --assert handle? k-Alice: ecdh/init none ecurve
174
- --assert handle? k-Boban: ecdh/init none ecurve
175
- --assert ecurve = ecdh/curve k-Alice
176
- --assert ecurve = ecdh/curve k-Boban
177
- ;- ... exports and exchange public parts of it
178
- --assert binary? pub-Alice: ecdh/public k-Alice
179
- --assert binary? pub-Boban: ecdh/public k-Boban
180
- ;- ... and use them to compute shared secret.
181
- --assert binary? secret-Alice: ecdh/secret k-Alice pub-Boban
182
- --assert binary? secret-Boban: ecdh/secret k-Boban pub-Alice
183
- ;- These keys should be same on both sides
184
- --assert secret-Alice = secret-Boban
185
- ;- Once done with the exchange, the ECDH key must be released!
186
- --assert handle? ecdh/release k-Alice
187
- --assert none? ecdh/public k-Alice
188
-
189
- --test-- "ECDH key re-initialization"
190
- --assert handle? ecdh/init k-Alice ecurve ;- using existing key for a new init
191
- --assert binary? pub-Alice: ecdh/public k-Alice
192
- ;- /release may be used with /secret
193
- --assert binary? secret-Alice: ecdh/secret/release k-Alice pub-Boban
194
- --assert binary? secret-Boban: ecdh/secret/release k-Boban pub-Alice
195
- --assert secret-Alice = secret-Boban
196
137
197
138
===end-group===
198
139
0 commit comments