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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
-- Test siphash routines
context("Siphash check functions", function()
local ffi = require("ffi")
ffi.cdef[[
void rspamd_cryptobox_init (void);
size_t siphash24_test(bool generic, size_t niters, size_t len);
bool siphash24_fuzz (size_t cycles);
double rspamd_get_ticks (void);
]]
ffi.C.rspamd_cryptobox_init()
local speed_iters = 1000
test("Siphash test reference vectors (1KB)", function()
local t1 = ffi.C.rspamd_get_ticks()
local res = ffi.C.siphash24_test(true, speed_iters, 1024)
local t2 = ffi.C.rspamd_get_ticks()
print("Reference siphash (1KB): " .. tostring(t2 - t1) .. " sec")
assert_not_equal(res, 0)
end)
test("Siphash test optimized vectors (1KB)", function()
local t1 = ffi.C.rspamd_get_ticks()
local res = ffi.C.siphash24_test(false, speed_iters, 1024)
local t2 = ffi.C.rspamd_get_ticks()
print("Optimized siphash (1KB): " .. tostring(t2 - t1) .. " sec")
assert_not_equal(res, 0)
end)
test("Siphash test reference vectors (5B)", function()
local t1 = ffi.C.rspamd_get_ticks()
local res = ffi.C.siphash24_test(true, speed_iters, 5)
local t2 = ffi.C.rspamd_get_ticks()
print("Reference siphash (5B): " .. tostring(t2 - t1) .. " sec")
assert_not_equal(res, 0)
end)
test("Siphash test optimized vectors (5B)", function()
local t1 = ffi.C.rspamd_get_ticks()
local res = ffi.C.siphash24_test(false, speed_iters, 5)
local t2 = ffi.C.rspamd_get_ticks()
print("Optimized siphash (5B): " .. tostring(t2 - t1) .. " sec")
assert_not_equal(res, 0)
end)
test("Siphash test reference vectors (50B)", function()
local t1 = ffi.C.rspamd_get_ticks()
local res = ffi.C.siphash24_test(true, speed_iters, 50)
local t2 = ffi.C.rspamd_get_ticks()
print("Reference siphash (50B): " .. tostring(t2 - t1) .. " sec")
assert_not_equal(res, 0)
end)
test("Siphash test optimized vectors (50B)", function()
local t1 = ffi.C.rspamd_get_ticks()
local res = ffi.C.siphash24_test(false, speed_iters, 50)
local t2 = ffi.C.rspamd_get_ticks()
print("Optimized siphash (50B): " .. tostring(t2 - t1) .. " sec")
assert_not_equal(res, 0)
end)
test("Siphash fuzz test (1000 iters)", function()
local res = ffi.C.siphash24_fuzz(1000)
assert_not_equal(res, 0)
end)
test("Siphash fuzz test (10000 iters)", function()
local res = ffi.C.siphash24_fuzz(10000)
assert_not_equal(res, 0)
end)
end)
|