19c2daa00SOllivier Robert /* 29c2daa00SOllivier Robert * ntp_md5.h: deal with md5.h headers 32b15cb3dSCy Schubert * 42b15cb3dSCy Schubert * Use the system MD5 if available, otherwise libisc's. 59c2daa00SOllivier Robert */ 62b15cb3dSCy Schubert #ifndef NTP_MD5_H 72b15cb3dSCy Schubert #define NTP_MD5_H 89c2daa00SOllivier Robert 9*f5f40dd6SCy Schubert /* Use the system MD5 or fall back on libisc's */ 10*f5f40dd6SCy Schubert # if defined HAVE_MD5_H && defined HAVE_MD5INIT 11*f5f40dd6SCy Schubert # include <md5.h> 12*f5f40dd6SCy Schubert # else 13*f5f40dd6SCy Schubert # include "isc/md5.h" 14*f5f40dd6SCy Schubert typedef isc_md5_t MD5_CTX; 15*f5f40dd6SCy Schubert # define MD5_DIGEST_LENGTH ISC_MD5_DIGESTLENGTH 16*f5f40dd6SCy Schubert # define MD5Init(c) isc_md5_init(c) 17*f5f40dd6SCy Schubert # define MD5Update(c, p, s) isc_md5_update(c, (const void *)p, s) 18*f5f40dd6SCy Schubert # define MD5Final(d, c) isc_md5_final((c), (d)) /* swapped */ 19*f5f40dd6SCy Schubert # endif 20*f5f40dd6SCy Schubert 21e6bfd18dSCy Schubert # define KEY_TYPE_MD5 NID_md5 22e6bfd18dSCy Schubert 232b15cb3dSCy Schubert #ifdef OPENSSL 244e1ef62aSXin LI # include <openssl/evp.h> 25f0574f5cSXin LI # include "libssl_compat.h" 264e1ef62aSXin LI # ifdef HAVE_OPENSSL_CMAC_H 274e1ef62aSXin LI # include <openssl/cmac.h> 284e1ef62aSXin LI # define CMAC "AES128CMAC" 294e1ef62aSXin LI # define AES_128_KEY_SIZE 16 304e1ef62aSXin LI # endif /*HAVE_OPENSSL_CMAC_H*/ 312b15cb3dSCy Schubert #else /* !OPENSSL follows */ 322b15cb3dSCy Schubert /* 332b15cb3dSCy Schubert * Provide OpenSSL-alike MD5 API if we're not using OpenSSL 342b15cb3dSCy Schubert */ 352b15cb3dSCy Schubert 362b15cb3dSCy Schubert typedef MD5_CTX EVP_MD_CTX; 37f0574f5cSXin LI 38e6bfd18dSCy Schubert # define NID_md5 4 /* from openssl/objects.h */ 39*f5f40dd6SCy Schubert # define EVP_MAX_MD_SIZE MD5_DIGEST_LENGTH 40f0574f5cSXin LI # define EVP_MD_CTX_free(c) free(c) 41f0574f5cSXin LI # define EVP_MD_CTX_new() calloc(1, sizeof(MD5_CTX)) 422b15cb3dSCy Schubert # define EVP_get_digestbynid(t) NULL 43a25439b6SCy Schubert # define EVP_md5() NULL 442b15cb3dSCy Schubert # define EVP_MD_CTX_init(c) 452b15cb3dSCy Schubert # define EVP_MD_CTX_set_flags(c, f) 462b15cb3dSCy Schubert # define EVP_DigestInit(c, dt) (MD5Init(c), 1) 472b15cb3dSCy Schubert # define EVP_DigestInit_ex(c, dt, i) (MD5Init(c), 1) 482b15cb3dSCy Schubert # define EVP_DigestUpdate(c, p, s) MD5Update(c, (const void *)(p), \ 492b15cb3dSCy Schubert s) 502b15cb3dSCy Schubert # define EVP_DigestFinal(c, d, pdl) \ 512b15cb3dSCy Schubert do { \ 522b15cb3dSCy Schubert MD5Final((d), (c)); \ 53*f5f40dd6SCy Schubert *(pdl) = MD5_LENGTH; \ 542b15cb3dSCy Schubert } while (0) 552b15cb3dSCy Schubert # endif /* !OPENSSL */ 562b15cb3dSCy Schubert #endif /* NTP_MD5_H */ 57