@@ -15,50 +15,50 @@ suite "basics":
15
15
16
16
test " zeroed" :
17
17
let s = zeroed 20
18
- assert s == repeat ('\0 ' , 20 )
18
+ check s == repeat ('\0 ' , 20 )
19
19
20
20
test " memcmp" :
21
- assert memcmp (" hello" , " hello" )
22
- assert memcmp (" hello" , " hello2" ) == false
23
- assert memcmp (" hello2" , " hello" ) == false
24
- assert memcmp (" hello" , " hallo" ) == false
21
+ check memcmp (" hello" , " hello" )
22
+ check memcmp (" hello" , " hello2" ) == false
23
+ check memcmp (" hello2" , " hello" ) == false
24
+ check memcmp (" hello" , " hallo" ) == false
25
25
26
26
test " is zero" :
27
- assert is_zero (" " )
28
- assert is_zero (" \0\0\0 " )
29
- assert is_zero (" \0\0\1 " ) == false
30
- assert zeroed (20 ).is_zero ()
27
+ check is_zero (" " )
28
+ check is_zero (" \0\0\0 " )
29
+ check is_zero (" \0\0\1 " ) == false
30
+ check zeroed (20 ).is_zero ()
31
31
32
32
test " bin2hex" :
33
- assert bin2hex (" " ) == " "
34
- assert bin2hex (" \0\255 " ) == " 00ff"
35
- assert bin2hex (" \255\0 " ) == " ff00"
36
- assert bin2hex (" \0\1\2\3\4\5\6\7\8\9 " ) == " 00010203040506070809"
33
+ check bin2hex (" " ) == " "
34
+ check bin2hex (" \0\255 " ) == " 00ff"
35
+ check bin2hex (" \255\0 " ) == " ff00"
36
+ check bin2hex (" \0\1\2\3\4\5\6\7\8\9 " ) == " 00010203040506070809"
37
37
38
38
test " hex2bin" :
39
- assert hex2bin (" " ) == " "
40
- assert hex2bin (" 00ff" ) == " \0\255 "
41
- assert hex2bin (" ff00" ) == " \255\0 "
42
- assert hex2bin (" ff:aa:bb:cc" , ignore= " :" ) == " \xFF\xAA\xBB\xCC\0 "
39
+ check hex2bin (" " ) == " "
40
+ check hex2bin (" 00ff" ) == " \0\255 "
41
+ check hex2bin (" ff00" ) == " \255\0 "
42
+ check hex2bin (" ff:aa:bb:cc" , ignore= " :" ) == " \xFF\xAA\xBB\xCC\0 "
43
43
# FIXME
44
- # assert hex2bin("ff:aa:bb:cc", ignore=":").len == 4
45
- # assert hex2bin("00010203040506070809") == "\0\x01\x02\x03\x04\x05\x06\x07\x08\x09"
44
+ # check hex2bin("ff:aa:bb:cc", ignore=":").len == 4
45
+ # check hex2bin("00010203040506070809") == "\0\x01\x02\x03\x04\x05\x06\x07\x08\x09"
46
46
47
47
test " random" :
48
48
var r = randombytes (8 )
49
- assert r.len == 8
49
+ check r.len == 8
50
50
51
51
test " auth" :
52
52
let
53
53
key = repeat ('k' , crypto_auth_KEYBYTES ())
54
54
mac = crypto_auth (" hello" , key)
55
- assert mac.len == crypto_auth_BYTES ()
56
- assert crypto_auth_verify (mac, " hello" , key)
57
- assert crypto_auth_verify (mac, " hallo" , key) == false
55
+ check mac.len == crypto_auth_BYTES ()
56
+ check crypto_auth_verify (mac, " hello" , key)
57
+ check crypto_auth_verify (mac, " hallo" , key) == false
58
58
let mac_bogus = zeroed crypto_auth_BYTES ()
59
- assert crypto_auth_verify (mac_bogus, " hello" , key) == false
59
+ check crypto_auth_verify (mac_bogus, " hello" , key) == false
60
60
let key_bogus = repeat ('b' , crypto_auth_KEYBYTES ())
61
- assert crypto_auth_verify (mac, " hello" , key_bogus) == false
61
+ check crypto_auth_verify (mac, " hello" , key_bogus) == false
62
62
63
63
64
64
test " hex2bin" :
@@ -72,7 +72,7 @@ suite "authenticated encryption":
72
72
msg = " hello there"
73
73
ciphertext = crypto_secretbox_easy (key, msg)
74
74
decrypted = crypto_secretbox_open_easy (key, ciphertext)
75
- assert msg == decrypted
75
+ check msg == decrypted
76
76
77
77
78
78
# Public-key authenticated encryption
@@ -84,12 +84,12 @@ suite "crypto_box":
84
84
(pk, sk) = crypto_box_keypair ()
85
85
nonce = randombytes (crypto_box_NONCEBYTES ())
86
86
ciphertext = crypto_box_easy (msg, nonce, pk, sk)
87
- assert ciphertext.len == msg.len + crypto_box_MACBYTES ()
87
+ check ciphertext.len == msg.len + crypto_box_MACBYTES ()
88
88
89
89
let orig = crypto_box_open_easy (ciphertext, nonce, pk, sk)
90
- assert orig == msg
90
+ check orig == msg
91
91
# FIXME let sig = sign(sk, "hello")
92
- # assert sig.len == 64
92
+ # check sig.len == 64
93
93
94
94
95
95
suite " public-key signatures" :
@@ -98,23 +98,23 @@ suite "public-key signatures":
98
98
let
99
99
seed = repeat ('s' , crypto_sign_SEEDBYTES ())
100
100
(pk, sk) = crypto_sign_seed_keypair (seed)
101
- assert pk.len == crypto_sign_PUBLICKEYBYTES ()
102
- assert sk.len == crypto_sign_SECRETKEYBYTES ()
101
+ check pk.len == crypto_sign_PUBLICKEYBYTES ()
102
+ check sk.len == crypto_sign_SECRETKEYBYTES ()
103
103
104
104
test " real keypair" :
105
105
let (real_pk, real_sk) = crypto_sign_keypair ()
106
- assert real_pk.len == crypto_sign_PUBLICKEYBYTES ()
107
- assert real_sk.len == crypto_sign_SECRETKEYBYTES ()
106
+ check real_pk.len == crypto_sign_PUBLICKEYBYTES ()
107
+ check real_sk.len == crypto_sign_SECRETKEYBYTES ()
108
108
109
109
test " extract seed from secret key" :
110
- assert crypto_sign_ed25519_sk_to_seed (sk) == seed
110
+ check crypto_sign_ed25519_sk_to_seed (sk) == seed
111
111
112
112
test " generate public key from secret key" :
113
- assert crypto_sign_ed25519_sk_to_pk (sk) == pk
113
+ check crypto_sign_ed25519_sk_to_pk (sk) == pk
114
114
115
115
test " sign" :
116
116
let sig = crypto_sign_detached (sk, " hello" )
117
- assert sig.len == crypto_sign_BYTES ()
117
+ check sig.len == crypto_sign_BYTES ()
118
118
119
119
test " verify" :
120
120
let signature = crypto_sign_detached (sk, " hello" )
@@ -130,43 +130,43 @@ suite "public-key signatures":
130
130
let
131
131
msg = " 4242424242424242424242"
132
132
sealed = crypto_box_seal (msg, pk)
133
- assert sealed.len == msg.len + crypto_box_SEALBYTES ()
133
+ check sealed.len == msg.len + crypto_box_SEALBYTES ()
134
134
135
135
test " crypto_box_seal_open" :
136
136
checkpoint " seal"
137
137
let
138
138
msg = " 123456789"
139
139
sealed = crypto_box_seal (msg, pk)
140
- assert sealed.len == msg.len + crypto_box_SEALBYTES ()
140
+ check sealed.len == msg.len + crypto_box_SEALBYTES ()
141
141
checkpoint " open"
142
142
# FIXME
143
143
# let opened = crypto_box_seal_open(sealed, pk, sk)
144
- # assert msg == opened
144
+ # check msg == opened
145
145
146
146
147
147
suite " hashing" :
148
148
149
149
test " generic hashing" :
150
150
let h = crypto_generichash (" hello" )
151
- assert h.len == crypto_generichash_BYTES ()
151
+ check h.len == crypto_generichash_BYTES ()
152
152
153
153
test " generic multipart hashing" :
154
154
let ha = new_generic_hash (repeat ('k' , crypto_generichash_KEYBYTES ()))
155
155
skip ()
156
156
# for x in 0..100:
157
157
# let ha_old = ha
158
158
# ha.update("hello")
159
- # assert ha != ha_old
159
+ # check ha != ha_old
160
160
# let h = ha.finalize()
161
- # assert bin2hex(h) == "3d76eda4eaf33f6bf73ab54a37e86e1a87a" &
161
+ # check bin2hex(h) == "3d76eda4eaf33f6bf73ab54a37e86e1a87a" &
162
162
# "fbe5fb803e727cbcb33c082f32035"
163
163
164
164
test " generic multipart hashing key = nil" :
165
165
let ha = new_generic_hash (nil , 33 )
166
166
ha.update (" hello" )
167
167
skip ()
168
168
# let h = ha.finalize()
169
- # assert bin2hex(h) == "1fc1d1cb09e15737e79c9a3a687bc751e07" &
169
+ # check bin2hex(h) == "1fc1d1cb09e15737e79c9a3a687bc751e07" &
170
170
# "d151c2da09ecb65ea8b8b38c89b03af"
171
171
172
172
test " generic multipart hashing bad sizes" :
@@ -186,20 +186,20 @@ suite "hashing":
186
186
h = crypto_shorthash (" hello" , k)
187
187
h2 = crypto_shorthash (" hello" , k)
188
188
h_using_k2 = crypto_shorthash (" hello" , k2)
189
- assert k.len == crypto_shorthash_KEYBYTES ()
190
- assert k2.len == crypto_shorthash_KEYBYTES ()
191
- assert k != k2
192
- assert h.len == crypto_shorthash_BYTES ()
193
- assert h == h2
194
- assert h != h_using_k2
189
+ check k.len == crypto_shorthash_KEYBYTES ()
190
+ check k2.len == crypto_shorthash_KEYBYTES ()
191
+ check k != k2
192
+ check h.len == crypto_shorthash_BYTES ()
193
+ check h == h2
194
+ check h != h_using_k2
195
195
196
196
test " Diffie-Hellman function" :
197
197
198
198
test " scalarmult base" :
199
199
let
200
200
secret_key = repeat ('k' , crypto_scalarmult_SCALARBYTES ())
201
201
public_key = crypto_scalarmult_base (secret_key)
202
- assert public_key == hex2bin " 8462fb3f0798f9fe2c39f3823bb41cd3effe70bb5c81735be46a143135c58454"
202
+ check public_key == hex2bin " 8462fb3f0798f9fe2c39f3823bb41cd3effe70bb5c81735be46a143135c58454"
203
203
204
204
test " scalarmult" :
205
205
let
@@ -209,24 +209,24 @@ test "Diffie-Hellman function":
209
209
public_key2 = crypto_scalarmult_base (secret_key2)
210
210
shared_secret12 = crypto_scalarmult (secret_key1, public_key2)
211
211
shared_secret21 = crypto_scalarmult (secret_key2, public_key1)
212
- assert shared_secret12.bin2hex () == " 806b0dffd3436ce81b12c4283db697bcfaab98571910ad33d3f385ec5409c009"
213
- assert shared_secret12 == shared_secret21
212
+ check shared_secret12.bin2hex () == " 806b0dffd3436ce81b12c4283db697bcfaab98571910ad33d3f385ec5409c009"
213
+ check shared_secret12 == shared_secret21
214
214
215
215
test " poly1305 onetimeauth" :
216
216
let
217
217
msg = repeat ('m' , 33 )
218
218
key = repeat ('k' , crypto_onetimeauth_KEYBYTES ())
219
219
tok = crypto_onetimeauth (msg, key)
220
220
ok = crypto_onetimeauth_verify (tok, msg, key)
221
- assert ok
222
- assert tok.len == crypto_onetimeauth_BYTES ()
221
+ check ok
222
+ check tok.len == crypto_onetimeauth_BYTES ()
223
223
224
224
let bogus_msg = repeat ('m' , 32 )
225
- assert crypto_onetimeauth_verify (tok, bogus_msg, key) == false
225
+ check crypto_onetimeauth_verify (tok, bogus_msg, key) == false
226
226
let bogus_tok = repeat ('z' , crypto_onetimeauth_BYTES ())
227
- assert crypto_onetimeauth_verify (bogus_tok, msg, key) == false
227
+ check crypto_onetimeauth_verify (bogus_tok, msg, key) == false
228
228
let bogus_key = repeat ('x' , crypto_onetimeauth_KEYBYTES ())
229
- assert crypto_onetimeauth_verify (tok, msg, bogus_key) == false
229
+ check crypto_onetimeauth_verify (tok, msg, bogus_key) == false
230
230
231
231
232
232
suite " HMAC" :
0 commit comments