]> git.sur5r.net Git - openldap/blobdiff - contrib/slapd-modules/passwd/totp/slapd-totp.c
Happy New Year
[openldap] / contrib / slapd-modules / passwd / totp / slapd-totp.c
index 4a0d40a0c0a9fab6ef9a813fa71f0de0ef6bc7db..8d52fdda72ff7677361ad4022f3bd37023ff52b3 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2015 The OpenLDAP Foundation.
+ * Copyright 2015-2018 The OpenLDAP Foundation.
  * Portions Copyright 2015 by Howard Chu, Symas Corp.
  * All rights reserved.
  *
 #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 <nettle/hmac.h>