The FreeRADIUS server $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Loading...
Searching...
No Matches
common.h
Go to the documentation of this file.
1#pragma once
2/*
3 * This program is is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or (at
6 * your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
16 */
17
18/**
19 * $Id: ea94dada9a1ce28ff5486c6f1f11a5a7fa7fb241 $
20 * @file lib/sim/common.h
21 * @brief Common code used by multiple SIM algorithms
22 *
23 * @copyright 2019 The FreeRADIUS server project
24 * @copyright 2019 Arran Cudbard-Bell <a.cudbardb@freeradius.org>
25 */
26
27/** Copy a 48bit value from a 64bit integer into a uint8_t buff in big endian byte order
28 *
29 * There may be fast ways of doing this, but this is the *correct*
30 * way, and does not make assumptions about how integers are laid
31 * out in memory.
32 *
33 * @param[out] out 6 byte butter to store value.
34 * @param[in] i integer value.
35 * @return pointer to out.
36 */
37static inline uint8_t *uint48_to_buff(uint8_t out[static 6], uint64_t i)
38{
39 out[0] = (i & 0xff0000000000) >> 40;
40 out[1] = (i & 0x00ff00000000) >> 32;
41 out[2] = (i & 0x0000ff000000) >> 24;
42 out[3] = (i & 0x000000ff0000) >> 16;
43 out[4] = (i & 0x00000000ff00) >> 8;
44 out[5] = (i & 0x0000000000ff);
45
46 return out;
47}
48
49/** Convert a 48bit big endian value into a unsigned 64bit integer
50 *
51 */
52static inline uint64_t uint48_from_buff(uint8_t const in[6])
53{
54 uint64_t i = 0;
55
56 i |= ((uint64_t)in[0]) << 40;
57 i |= ((uint64_t)in[1]) << 32;
58 i |= ((uint32_t)in[2]) << 24;
59 i |= ((uint32_t)in[3]) << 16;
60 i |= ((uint16_t)in[4]) << 8;
61 i |= in[5];
62
63 return i;
64}
static uint8_t * uint48_to_buff(uint8_t out[static 6], uint64_t i)
Copy a 48bit value from a 64bit integer into a uint8_t buff in big endian byte order.
Definition common.h:37
static uint64_t uint48_from_buff(uint8_t const in[6])
Convert a 48bit big endian value into a unsigned 64bit integer.
Definition common.h:52
static fr_slen_t in
Definition dict.h:824
unsigned short uint16_t
unsigned int uint32_t
unsigned char uint8_t
static size_t char ** out
Definition value.h:997