xref: /freebsd/contrib/ntp/include/ntp_md5.h (revision af23369a6deaaeb612ab266eb88b8bb8d560c322)
1 /*
2  * ntp_md5.h: deal with md5.h headers
3  *
4  * Use the system MD5 if available, otherwise libisc's.
5  */
6 #ifndef NTP_MD5_H
7 #define NTP_MD5_H
8 
9 #ifdef OPENSSL
10 # include <openssl/evp.h>
11 # include "libssl_compat.h"
12 # ifdef HAVE_OPENSSL_CMAC_H
13 #  include <openssl/cmac.h>
14 #  define CMAC                  "AES128CMAC"
15 #  define AES_128_KEY_SIZE      16
16 # endif /*HAVE_OPENSSL_CMAC_H*/
17 #else	/* !OPENSSL follows */
18 /*
19  * Provide OpenSSL-alike MD5 API if we're not using OpenSSL
20  */
21 # if defined HAVE_MD5_H && defined HAVE_MD5INIT
22 #  include <md5.h>
23 # else
24 #  include "isc/md5.h"
25    typedef isc_md5_t		MD5_CTX;
26 #  define MD5Init(c)		isc_md5_init(c)
27 #  define MD5Update(c, p, s)	isc_md5_update(c, p, s)
28 #  define MD5Final(d, c)	isc_md5_final((c), (d))	/* swapped */
29 # endif
30 
31   typedef MD5_CTX			EVP_MD_CTX;
32 
33 # define EVP_MD_CTX_free(c)		free(c)
34 # define EVP_MD_CTX_new()		calloc(1, sizeof(MD5_CTX))
35 # define EVP_get_digestbynid(t)		NULL
36 # define EVP_md5()			NULL
37 # define EVP_MD_CTX_init(c)
38 # define EVP_MD_CTX_set_flags(c, f)
39 # define EVP_DigestInit(c, dt)		(MD5Init(c), 1)
40 # define EVP_DigestInit_ex(c, dt, i)	(MD5Init(c), 1)
41 # define EVP_DigestUpdate(c, p, s)	MD5Update(c, (const void *)(p), \
42 						  s)
43 # define EVP_DigestFinal(c, d, pdl)	\
44 	do {				\
45 		MD5Final((d), (c));	\
46 		*(pdl) = 16;		\
47 	} while (0)
48 # endif	/* !OPENSSL */
49 #endif	/* NTP_MD5_H */
50