xref: /netbsd-src/external/bsd/ntp/dist/include/ntp_md5.h (revision eabc0478de71e4e011a5b4e0392741e01d491794)
1 /*	$NetBSD: ntp_md5.h,v 1.10 2024/08/18 20:46:50 christos Exp $	*/
2 
3 /*
4  * ntp_md5.h: deal with md5.h headers
5  *
6  * Use the system MD5 if available, otherwise libisc's.
7  */
8 #ifndef NTP_MD5_H
9 #define NTP_MD5_H
10 
11 /* Use the system MD5 or fall back on libisc's */
12 # if defined HAVE_MD5_H && defined HAVE_MD5INIT
13 #  include <md5.h>
14 # else
15 #  include "isc/md5.h"
16    typedef isc_md5_t		MD5_CTX;
17 #  define MD5_DIGEST_LENGTH	ISC_MD5_DIGESTLENGTH
18 #  define MD5Init(c)		isc_md5_init(c)
19 #  define MD5Update(c, p, s)	isc_md5_update(c, (const void *)p, s)
20 #  define MD5Final(d, c)	isc_md5_final((c), (d))	/* swapped */
21 # endif
22 
23 # define KEY_TYPE_MD5			NID_md5
24 
25 #ifdef OPENSSL
26 # include <openssl/evp.h>
27 # include "libssl_compat.h"
28 # ifdef HAVE_OPENSSL_CMAC_H
29 #  include <openssl/cmac.h>
30 #  define CMAC                  "AES128CMAC"
31 #  define AES_128_KEY_SIZE      16
32 # endif /*HAVE_OPENSSL_CMAC_H*/
33 #else	/* !OPENSSL follows */
34 /*
35  * Provide OpenSSL-alike MD5 API if we're not using OpenSSL
36  */
37 
38   typedef MD5_CTX			EVP_MD_CTX;
39 
40 # define NID_md5			4	/* from openssl/objects.h */
41 # define EVP_MAX_MD_SIZE		MD5_DIGEST_LENGTH
42 # define EVP_MD_CTX_free(c)		free(c)
43 # define EVP_MD_CTX_new()		calloc(1, sizeof(MD5_CTX))
44 # define EVP_get_digestbynid(t)		NULL
45 # define EVP_md5()			NULL
46 # define EVP_MD_CTX_init(c)
47 # define EVP_MD_CTX_set_flags(c, f)
48 # define EVP_DigestInit(c, dt)		(MD5Init(c), (dt ? 1 : 1))
49 # define EVP_DigestInit_ex(c, dt, i)	(MD5Init(c), (dt ? 1 : 1))
50 # define EVP_DigestUpdate(c, p, s)	MD5Update(c, (const void *)(p), \
51 						  s)
52 # define EVP_DigestFinal(c, d, pdl)	\
53 	do {				\
54 		MD5Final((d), (c));	\
55 		*(pdl) = MD5_LENGTH;	\
56 	} while (0)
57 # endif	/* !OPENSSL */
58 #endif	/* NTP_MD5_H */
59