Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/crypto/krb5/src/util/support/t_unal.c
34889 views
1
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
#undef NDEBUG
3
#include "k5-platform.h"
4
5
int
6
main(void)
7
{
8
/* Test some low-level assumptions the Kerberos code depends
9
on. */
10
11
union {
12
uint64_t n64;
13
uint32_t n32;
14
uint16_t n16;
15
unsigned char b[9];
16
} u;
17
static unsigned char buf[9] = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };
18
19
assert(load_64_be(buf+1) == 0x0102030405060708LL);
20
assert(load_64_le(buf+1) == 0x0807060504030201LL);
21
assert(load_32_le(buf+2) == 0x05040302);
22
assert(load_32_be(buf+2) == 0x02030405);
23
assert(load_16_be(buf+3) == 0x0304);
24
assert(load_16_le(buf+3) == 0x0403);
25
u.b[0] = 0;
26
assert((store_64_be(0x0102030405060708LL, u.b+1), !memcmp(buf, u.b, 9)));
27
u.b[1] = 9;
28
assert((store_64_le(0x0807060504030201LL, u.b+1), !memcmp(buf, u.b, 9)));
29
u.b[2] = 10;
30
assert((store_32_be(0x02030405, u.b+2), !memcmp(buf, u.b, 9)));
31
u.b[3] = 11;
32
assert((store_32_le(0x05040302, u.b+2), !memcmp(buf, u.b, 9)));
33
u.b[4] = 12;
34
assert((store_16_be(0x0304, u.b+3), !memcmp(buf, u.b, 9)));
35
u.b[4] = 13;
36
assert((store_16_le(0x0403, u.b+3), !memcmp(buf, u.b, 9)));
37
/* Verify that load_*_n properly does native format. Assume
38
the unaligned thing is okay. */
39
u.n64 = 0x090a0b0c0d0e0f00LL;
40
assert(load_64_n((unsigned char *) &u.n64) == 0x090a0b0c0d0e0f00LL);
41
u.n32 = 0x06070809;
42
assert(load_32_n((unsigned char *) &u.n32) == 0x06070809);
43
u.n16 = 0x0a0b;
44
assert(load_16_n((unsigned char *) &u.n16) == 0x0a0b);
45
46
return 0;
47
}
48
49