xref: /netbsd-src/external/bsd/libfido2/dist/openbsd-compat/openbsd-compat.h (revision 181254a7b1bdde6873432bffef2d2decc4b5c22f)
1 /*
2  * Copyright (c) 2018 Yubico AB. All rights reserved.
3  * Use of this source code is governed by a BSD-style
4  * license that can be found in the LICENSE file.
5  */
6 
7 #ifndef _OPENBSD_COMPAT_H
8 #define _OPENBSD_COMPAT_H
9 
10 #if defined(_MSC_VER)
11 #include "types.h"
12 #endif
13 
14 #if defined(HAVE_ENDIAN_H)
15 #include <endian.h>
16 #endif
17 
18 #if defined(__APPLE__) && !defined(HAVE_ENDIAN_H)
19 #include <libkern/OSByteOrder.h>
20 #define be16toh(x) OSSwapBigToHostInt16((x))
21 #define htobe16(x) OSSwapHostToBigInt16((x))
22 #define be32toh(x) OSSwapBigToHostInt32((x))
23 #endif /* __APPLE__ && !HAVE_ENDIAN_H */
24 
25 #if defined(_WIN32) && !defined(HAVE_ENDIAN_H)
26 #include <winsock2.h>
27 #if !defined(_MSC_VER)
28 #include <sys/param.h>
29 #endif
30 #define be16toh(x) ntohs((x))
31 #define htobe16(x) htons((x))
32 #define be32toh(x) ntohl((x))
33 #endif /* _WIN32 && !HAVE_ENDIAN_H */
34 
35 #if defined(__FreeBSD__) && !defined(HAVE_ENDIAN_H)
36 #include <sys/endian.h>
37 #endif
38 
39 #include <stdlib.h>
40 
41 #if !defined(HAVE_STRLCAT)
42 size_t strlcat(char *, const char *, size_t);
43 #endif
44 
45 #if !defined(HAVE_STRLCPY)
46 size_t strlcpy(char *, const char *, size_t);
47 #endif
48 
49 #if !defined(HAVE_RECALLOCARRAY)
50 void *recallocarray(void *, size_t, size_t, size_t);
51 #endif
52 
53 #if !defined(HAVE_EXPLICIT_BZERO)
54 void explicit_bzero(void *, size_t);
55 #endif
56 
57 #if !defined(HAVE_GETPAGESIZE)
58 int getpagesize(void);
59 #endif
60 
61 #if !defined(HAVE_TIMINGSAFE_BCMP)
62 int timingsafe_bcmp(const void *, const void *, size_t);
63 #endif
64 
65 #if !defined(HAVE_READPASSPHRASE)
66 #include "readpassphrase.h"
67 #else
68 #include <readpassphrase.h>
69 #endif
70 
71 #if OPENSSL_VERSION_NUMBER < 0x10100000L
72 #define EVP_PKEY_get0_EC_KEY(x) ((x)->pkey.ec)
73 #define EVP_PKEY_get0_RSA(x) ((x)->pkey.rsa)
74 #endif
75 
76 #if !defined(HAVE_ERR_H)
77 #include "err.h"
78 #else
79 #include <err.h>
80 #endif
81 
82 #if !defined(HAVE_GETOPT)
83 #include "getopt.h"
84 #else
85 #include <unistd.h>
86 #endif
87 
88 #if !defined(HAVE_GETLINE)
89 #include <stdio.h>
90 ssize_t getline(char **, size_t *, FILE *);
91 #endif
92 
93 #endif /* !_OPENBSD_COMPAT_H */
94