1ff825849SDag-Erling Smørgrav /* arc4_lock.c - global lock for arc4random 2ff825849SDag-Erling Smørgrav * 3ff825849SDag-Erling Smørgrav * Copyright (c) 2014, NLnet Labs. All rights reserved. 4ff825849SDag-Erling Smørgrav * 5ff825849SDag-Erling Smørgrav * This software is open source. 6ff825849SDag-Erling Smørgrav * 7ff825849SDag-Erling Smørgrav * Redistribution and use in source and binary forms, with or without 8ff825849SDag-Erling Smørgrav * modification, are permitted provided that the following conditions 9ff825849SDag-Erling Smørgrav * are met: 10ff825849SDag-Erling Smørgrav * 11ff825849SDag-Erling Smørgrav * Redistributions of source code must retain the above copyright notice, 12ff825849SDag-Erling Smørgrav * this list of conditions and the following disclaimer. 13ff825849SDag-Erling Smørgrav * 14ff825849SDag-Erling Smørgrav * Redistributions in binary form must reproduce the above copyright notice, 15ff825849SDag-Erling Smørgrav * this list of conditions and the following disclaimer in the documentation 16ff825849SDag-Erling Smørgrav * and/or other materials provided with the distribution. 17ff825849SDag-Erling Smørgrav * 18ff825849SDag-Erling Smørgrav * Neither the name of the NLNET LABS nor the names of its contributors may 19ff825849SDag-Erling Smørgrav * be used to endorse or promote products derived from this software without 20ff825849SDag-Erling Smørgrav * specific prior written permission. 21ff825849SDag-Erling Smørgrav * 22ff825849SDag-Erling Smørgrav * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23ff825849SDag-Erling Smørgrav * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24ff825849SDag-Erling Smørgrav * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 25ff825849SDag-Erling Smørgrav * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 26ff825849SDag-Erling Smørgrav * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 27ff825849SDag-Erling Smørgrav * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 28ff825849SDag-Erling Smørgrav * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29ff825849SDag-Erling Smørgrav * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30ff825849SDag-Erling Smørgrav * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31ff825849SDag-Erling Smørgrav * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32ff825849SDag-Erling Smørgrav * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33ff825849SDag-Erling Smørgrav */ 34ff825849SDag-Erling Smørgrav #include "config.h" 35ff825849SDag-Erling Smørgrav #define LOCKRET(func) func 36ff825849SDag-Erling Smørgrav #include "util/locks.h" 37ff825849SDag-Erling Smørgrav 38ff825849SDag-Erling Smørgrav void _ARC4_LOCK(void); 39ff825849SDag-Erling Smørgrav void _ARC4_UNLOCK(void); 40ff825849SDag-Erling Smørgrav 41ff825849SDag-Erling Smørgrav #ifdef THREADS_DISABLED 42ff825849SDag-Erling Smørgrav void _ARC4_LOCK(void) 43ff825849SDag-Erling Smørgrav { 44ff825849SDag-Erling Smørgrav } 45ff825849SDag-Erling Smørgrav 46ff825849SDag-Erling Smørgrav void _ARC4_UNLOCK(void) 47ff825849SDag-Erling Smørgrav { 48ff825849SDag-Erling Smørgrav } 49ff825849SDag-Erling Smørgrav #else /* !THREADS_DISABLED */ 50ff825849SDag-Erling Smørgrav 51*3005e0a3SDag-Erling Smørgrav static lock_quick_type arc4lock; 52ff825849SDag-Erling Smørgrav static int arc4lockinit = 0; 53ff825849SDag-Erling Smørgrav 54ff825849SDag-Erling Smørgrav void _ARC4_LOCK(void) 55ff825849SDag-Erling Smørgrav { 56ff825849SDag-Erling Smørgrav if(!arc4lockinit) { 57ff825849SDag-Erling Smørgrav arc4lockinit = 1; 58ff825849SDag-Erling Smørgrav lock_quick_init(&arc4lock); 59ff825849SDag-Erling Smørgrav } 60ff825849SDag-Erling Smørgrav lock_quick_lock(&arc4lock); 61ff825849SDag-Erling Smørgrav } 62ff825849SDag-Erling Smørgrav 63ff825849SDag-Erling Smørgrav void _ARC4_UNLOCK(void) 64ff825849SDag-Erling Smørgrav { 65ff825849SDag-Erling Smørgrav lock_quick_unlock(&arc4lock); 66ff825849SDag-Erling Smørgrav } 67ff825849SDag-Erling Smørgrav #endif /* THREADS_DISABLED */ 68