ae5acb7 |
Jamozed |
2021-01-26 17:31:54 |
0
|
// test_crypt.c |
98e5939 |
Jamozed |
2021-11-27 17:53:46 |
1
|
// Crypt unit test for libutil |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
2
|
// Copyright (C) 2021, Jakob Wakeling |
7f427d9 |
Jamozed |
2022-03-06 12:55:13 |
3
|
// MIT Licence |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
4
|
|
bd9fc8b |
Jamozed |
2021-01-27 14:44:30 |
5
|
#include "../crypt.h" |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
6
|
#include "unit.h" |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
7
|
|
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
8
|
#include <stdint.h> |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
9
|
#include <stdio.h> |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
10
|
|
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
11
|
int main(void) { |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
12
|
{ |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
13
|
ASSERT("G00T00 ROL8 1", |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
14
|
ROL8(0xF0u, 1) == 0xE1u); |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
15
|
ASSERT("G00T01 ROL8 7", |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
16
|
ROL8(0xF0u, 7) == 0x78u); |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
17
|
ASSERT("G00T02 ROL16 1", |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
18
|
ROL16(0xF000u, 1) == 0xE001u); |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
19
|
ASSERT("G00T03 ROL16 15", |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
20
|
ROL16(0xF000u, 15) == 0x7800u); |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
21
|
ASSERT("G00T04 ROL32 1", |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
22
|
ROL32(0xF0000000uL, 1) == 0xE0000001uL); |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
23
|
ASSERT("G00T05 ROL32 31", |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
24
|
ROL32(0xF0000000uL, 31) == 0x78000000uL); |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
25
|
ASSERT("G00T06 ROL64 1", |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
26
|
ROL64(0xF000000000000000uLL, 1) == 0xE000000000000001uLL); |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
27
|
ASSERT("G00T07 ROL64 63", |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
28
|
ROL64(0xF000000000000000uLL, 63) == 0x7800000000000000uLL); |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
29
|
} |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
30
|
|
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
31
|
{ |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
32
|
ASSERT("G01T00 ROR8 1", |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
33
|
ROR8(0x0Fu, 1) == 0x87u); |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
34
|
ASSERT("G01T01 ROR8 7", |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
35
|
ROR8(0x0Fu, 7) == 0x1Eu); |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
36
|
ASSERT("G01T02 ROR16 1", |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
37
|
ROR16(0x000Fu, 1) == 0x8007u); |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
38
|
ASSERT("G01T03 ROR16 15", |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
39
|
ROR16(0x000Fu, 15) == 0x001Eu); |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
40
|
ASSERT("G01T04 ROR32 1", |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
41
|
ROR32(0x0000000FuL, 1) == 0x80000007uL); |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
42
|
ASSERT("G01T05 ROR32 31", |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
43
|
ROR32(0x0000000FuL, 31) == 0x0000001EuL); |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
44
|
ASSERT("G01T06 ROR64 1", |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
45
|
ROR64(0x000000000000000FuLL, 1) == 0x8000000000000007uLL); |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
46
|
ASSERT("G01T07 ROR64 63", |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
47
|
ROR64(0x000000000000000FuLL, 63) == 0x000000000000001EuLL); |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
48
|
} |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
49
|
|
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
50
|
printf("%d of %d tests passed\n", testspassed, testsrun); |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
51
|
return testsfailed; |
e4b2536 |
Jamozed |
2021-01-26 14:06:02 |
52
|
} |
|
|
|
53
|
|