xref: /openbsd-src/lib/libcrypto/hidden/crypto_namespace.h (revision 3374c67d44f9b75b98444cbf63020f777792342e)
1 /*	$OpenBSD: crypto_namespace.h,v 1.1 2022/11/11 11:25:18 beck Exp $	*/
2 /*
3  * Copyright (c) 2016 Philip Guenther <guenther@openbsd.org>
4  *
5  * Permission to use, copy, modify, and distribute this software for any
6  * purpose with or without fee is hereby granted, provided that the above
7  * copyright notice and this permission notice appear in all copies.
8  *
9  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16  */
17 
18 #ifndef _LIBCRYPTO_CRYPTO_NAMESPACE_H_
19 #define _LIBCRYPTO_CRYPTO_NAMESPACE_H_
20 
21 /*
22  * If marked as 'used', then internal calls use the name with prefix "_lcry_"
23  * and we alias that to the normal name *and* the name with prefix "_libre_";
24  * external calls use the latter name.
25  */
26 
27 #ifdef LIBRESSL_NAMESPACE
28 # define LCRYPTO_UNUSED(x)		typeof(x) x __attribute__((deprecated))
29 #ifdef LIBRESSL_CRYPTO_NAMESPACE
30 #  define LCRYPTO_USED(x)		__attribute__((visibility("hidden")))	\
31 				typeof(x) x asm("_lcry_"#x)
32 #  define LCRYPTO_ALIAS1(pre,x)	asm(".global "#pre#x"; "#pre#x" = _lcry_"#x)
33 #  define LCRYPTO_ALIAS(x)	LCRYPTO_ALIAS1(,x); LCRYPTO_ALIAS1(_libre_,x);
34 #else
35 #  define LCRYPTO_USED(x)          typeof(x) x asm("_libre_"#x)
36 #endif
37 #else
38 # define LCRYPTO_UNUSED(x)
39 # define LCRYPTO_USED(x)
40 # define LCRYPTO_ALIAS1(pre,x)
41 # define LCRYPTO_ALIAS(x)
42 #endif
43 
44 #endif	/* _LIBCRYPTO_CRYPTO_NAMESPACE_H_ */
45