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