From: SATOH Fumiyasu Date: Thu, 3 Aug 2017 07:59:02 +0000 (+0900) Subject: ITS#8709 contrib/slapd-modules/passwd/totp: OpenSSL 1.1.0 compatibility X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=2c36a37f908cd2e7297b1bd5621fea2f0d32451a;p=openldap ITS#8709 contrib/slapd-modules/passwd/totp: OpenSSL 1.1.0 compatibility --- diff --git a/contrib/slapd-modules/passwd/totp/slapd-totp.c b/contrib/slapd-modules/passwd/totp/slapd-totp.c index c77753ded1..5896b33b0b 100644 --- a/contrib/slapd-modules/passwd/totp/slapd-totp.c +++ b/contrib/slapd-modules/passwd/totp/slapd-totp.c @@ -41,11 +41,34 @@ #define TOTP_SHA1 EVP_sha1() #define TOTP_SHA256 EVP_sha256() #define TOTP_SHA512 EVP_sha512() -#define TOTP_HMAC_CTX HMAC_CTX +#define TOTP_HMAC_CTX HMAC_CTX * -#define HMAC_setup(ctx, key, len, hash) HMAC_CTX_init(&ctx); HMAC_Init_ex(&ctx, key, len, hash, 0) -#define HMAC_crunch(ctx, buf, len) HMAC_Update(&ctx, buf, len) -#define HMAC_finish(ctx, dig, dlen) HMAC_Final(&ctx, dig, &dlen); HMAC_CTX_cleanup(&ctx) +#if OPENSSL_VERSION_NUMBER < 0x10100000L +static HMAC_CTX *HMAC_CTX_new(void) +{ + HMAC_CTX *ctx = OPENSSL_malloc(sizeof(*ctx)); + if (ctx != NULL) { + HMAC_CTX_init(ctx); + } + return ctx; +} + +static void HMAC_CTX_free(HMAC_CTX *ctx) +{ + if (ctx != NULL) { + HMAC_CTX_cleanup(ctx); + OPENSSL_free(ctx); + } +} +#endif /* OPENSSL_VERSION_NUMBER < 0x10100000L */ + +#define HMAC_setup(ctx, key, len, hash) \ + ctx = HMAC_CTX_new(); \ + HMAC_Init_ex(ctx, key, len, hash, 0) +#define HMAC_crunch(ctx, buf, len) HMAC_Update(ctx, buf, len) +#define HMAC_finish(ctx, dig, dlen) \ + HMAC_Final(ctx, dig, &dlen); \ + HMAC_CTX_free(ctx) #elif HAVE_GNUTLS #include