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