--- lib/libcryptsetup.h
+++ lib/libcryptsetup.h
@@ -1190,6 +1190,8 @@
  */
 void crypt_set_debug_level(int level);
 
+void *aligned_malloc(void **base, int size, int alignment);
+
 /** @} */
 
 #ifdef __cplusplus
--- lib/tcrypt/tcrypt.c
+++ lib/tcrypt/tcrypt.c
@@ -477,7 +477,7 @@
 	unsigned int i, skipped = 0;
 	int r = -EINVAL, legacy_modes;
 
-	if (posix_memalign((void*)&key, crypt_getpagesize(), TCRYPT_HDR_KEY_LEN))
+	if (!aligned_malloc((void*)&key, TCRYPT_HDR_KEY_LEN, crypt_getpagesize()))
 		return -ENOMEM;
 
 	if (params->keyfiles_count)
--- lib/utils_benchmark.c
+++ lib/utils_benchmark.c
@@ -24,6 +24,7 @@
 #include <sys/time.h>
 #include <sys/resource.h>
 
+#include "libcryptsetup.h"
 #include "internal.h"
 
 /*
@@ -131,7 +132,7 @@
 	int repeat_enc, repeat_dec;
 	void *buf = NULL;
 
-	if (posix_memalign(&buf, crypt_getpagesize(), cp->buffer_size))
+	if (!aligned_malloc(&buf, cp->buffer_size, crypt_getpagesize()))
 		return -ENOMEM;
 
 	ms_enc = 0;
--- lib/utils.c
+++ lib/utils.c
@@ -48,7 +48,7 @@
 	return alignment;
 }
 
-static void *aligned_malloc(void **base, int size, int alignment)
+void *aligned_malloc(void **base, int size, int alignment)
 {
 #ifdef HAVE_POSIX_MEMALIGN
 	return posix_memalign(base, alignment, size) ? NULL : *base;
--- src/cryptsetup_reencrypt.c
+++ src/cryptsetup_reencrypt.c
@@ -146,7 +146,7 @@
 		goto out;
 	}
 
-	if (posix_memalign((void *)&buf, alignment(devfd), SECTOR_SIZE)) {
+	if (!aligned_malloc((void *)&buf, SECTOR_SIZE, alignment(devfd))) {
 		log_err(_("Allocation of aligned memory failed.\n"));
 		r = -ENOMEM;
 		goto out;
@@ -363,7 +363,7 @@
 	if (rc->log_fd == -1)
 		return -EINVAL;
 
-	if (posix_memalign((void *)&rc->log_buf, alignment(rc->log_fd), SECTOR_SIZE)) {
+	if (!aligned_malloc((void *)&rc->log_buf, SECTOR_SIZE, alignment(rc->log_fd))) {
 		log_err(_("Allocation of aligned memory failed.\n"));
 		close_log(rc);
 		return -ENOMEM;
@@ -782,7 +782,7 @@
 
 	rc->device_size = opt_device_size ?: rc->device_size_real;
 
-	if (posix_memalign((void *)&buf, alignment(fd_new), block_size)) {
+	if (!aligned_malloc((void *)&buf, block_size, alignment(fd_new))) {
 		log_err(_("Allocation of aligned memory failed.\n"));
 		r = -ENOMEM;
 		goto out;
