]>
git.ipfire.org Git - thirdparty/bird.git/blob - lib/checksum_test.c
2 * BIRD Library -- IP One-Complement Checksum Tests
4 * (c) 2015 CZ.NIC z.s.p.o.
6 * Can be freely distributed and used under the terms of the GNU GPL.
11 #include "test/birdtest.h"
13 #include "lib/checksum.h"
18 ipsum_calculate_expected(u32
*a
)
23 for(i
= 0; i
< MAX_NUM
; i
++)
26 bt_debug("low) \t0x%08X \n", sum
);
29 bt_debug("high) \t0x%08X \n", sum
);
31 u16 carry
= sum
>> 16;
32 sum
= (sum
& 0xffff) + carry
;
33 bt_debug("carry) \t0x%08X \n\n", sum
);
35 bt_debug("sum) \t0x%08X \n", sum
);
38 bt_debug("~sum) \t0x%08X \n", sum
);
49 for (i
= 0; i
< MAX_NUM
; i
++)
52 u16 sum_calculated
= ipsum_calculate(a
, sizeof(a
), NULL
);
53 u16 sum_calculated_2
= ipsum_calculate(&a
[0], sizeof(u32
)*(MAX_NUM
/2), &a
[MAX_NUM
/2], sizeof(u32
)*(MAX_NUM
- MAX_NUM
/2), NULL
);
54 bt_assert(sum_calculated
== sum_calculated_2
);
56 u16 sum_expected
= ipsum_calculate_expected(a
);
58 bt_debug("sum_calculated: %08X \n", sum_calculated
);
59 bt_debug("sum_expected: %08X \n", sum_expected
);
61 bt_assert(sum_calculated
== sum_expected
);
72 for (i
= 0; i
< MAX_NUM
; i
++)
75 u16 sum
= ipsum_calculate_expected(a
);
79 bt_assert(ipsum_verify(a
, sizeof(a
), NULL
));
86 main(int argc
, char *argv
[])
90 bt_test_suite(t_calculate
, "Checksum of pseudo-random data");
91 bt_test_suite(t_verify
, "Verification of pseudo-random data.");
93 return bt_exit_value();