xref: /openbsd-src/sbin/unwind/libunbound/util/rfc_1982.h (revision d500c338f73eadbc8ea62778504d2ca76933e0f6)
1*d500c338Sflorian /*
2*d500c338Sflorian  * util/rfc_1982.h - RFC 1982 Serial Number Arithmetic
3*d500c338Sflorian  *
4*d500c338Sflorian  * Copyright (c) 2023, NLnet Labs. All rights reserved.
5*d500c338Sflorian  *
6*d500c338Sflorian  * This software is open source.
7*d500c338Sflorian  *
8*d500c338Sflorian  * Redistribution and use in source and binary forms, with or without
9*d500c338Sflorian  * modification, are permitted provided that the following conditions
10*d500c338Sflorian  * are met:
11*d500c338Sflorian  *
12*d500c338Sflorian  * Redistributions of source code must retain the above copyright notice,
13*d500c338Sflorian  * this list of conditions and the following disclaimer.
14*d500c338Sflorian  *
15*d500c338Sflorian  * Redistributions in binary form must reproduce the above copyright notice,
16*d500c338Sflorian  * this list of conditions and the following disclaimer in the documentation
17*d500c338Sflorian  * and/or other materials provided with the distribution.
18*d500c338Sflorian  *
19*d500c338Sflorian  * Neither the name of the NLNET LABS nor the names of its contributors may
20*d500c338Sflorian  * be used to endorse or promote products derived from this software without
21*d500c338Sflorian  * specific prior written permission.
22*d500c338Sflorian  *
23*d500c338Sflorian  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24*d500c338Sflorian  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25*d500c338Sflorian  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26*d500c338Sflorian  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27*d500c338Sflorian  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28*d500c338Sflorian  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29*d500c338Sflorian  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30*d500c338Sflorian  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31*d500c338Sflorian  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32*d500c338Sflorian  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33*d500c338Sflorian  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34*d500c338Sflorian  */
35*d500c338Sflorian 
36*d500c338Sflorian /**
37*d500c338Sflorian  * \file
38*d500c338Sflorian  *
39*d500c338Sflorian  * This file contains functions for RFC 1982 serial number arithmetic.
40*d500c338Sflorian  */
41*d500c338Sflorian #ifndef RFC_1982_H
42*d500c338Sflorian #define RFC_1982_H
43*d500c338Sflorian 
44*d500c338Sflorian /**
45*d500c338Sflorian  * RFC 1982 comparison, uses unsigned integers, and tries to avoid
46*d500c338Sflorian  * compiler optimization (eg. by avoiding a-b<0 comparisons).
47*d500c338Sflorian  * @param a: value to compare.
48*d500c338Sflorian  * @param b: value to compare.
49*d500c338Sflorian  * @return 0 if equal, 1 if a > b, else -1.
50*d500c338Sflorian  */
51*d500c338Sflorian int compare_1982(uint32_t a, uint32_t b);
52*d500c338Sflorian 
53*d500c338Sflorian /**
54*d500c338Sflorian  * RFC 1982 subtraction, uses unsigned integers, and tries to avoid
55*d500c338Sflorian  * compiler optimization (eg. by avoiding a-b<0 comparisons).
56*d500c338Sflorian  * @param a: value to subtract from.
57*d500c338Sflorian  * @param b: value to subtract.
58*d500c338Sflorian  * @return the difference between them if we know that b is larger than a,
59*d500c338Sflorian  *	that is the distance between them in serial number arithmetic.
60*d500c338Sflorian  */
61*d500c338Sflorian uint32_t subtract_1982(uint32_t a, uint32_t b);
62*d500c338Sflorian 
63*d500c338Sflorian #endif /* RFC_1982_H */
64