diff --git a/aesopt.h b/aesopt.h
index 9919f6c50edd3de8c521214b8e396e6a49947006..571b7c45290556c95543130b88574c0cac373fb3 100755
--- a/aesopt.h
+++ b/aesopt.h
@@ -154,7 +154,7 @@
 #elif defined( __FreeBSD__ )
 #  include <sys/types.h>
 #  include <sys/endian.h>
-#elif defined( BSD ) && ( BSD >= 199103 )
+#elif defined( BSD ) && ( BSD >= 199103 ) || defined(__APPLE__)
 #  include <machine/endian.h>
 #elif defined( __GNUC__ ) || defined( __GNU_LIBRARY__ )
 #  include <endian.h>
diff --git a/md5.c b/md5.c
index abb277ac01e7ef03c934da68df23ee1561ff657c..9388a820e49a849a9b7c48b3c1dd85ef37bb76ae 100755
--- a/md5.c
+++ b/md5.c
@@ -6,7 +6,7 @@
 #elif defined( __FreeBSD__ )
 #  include <sys/types.h>
 #  include <sys/endian.h>
-#elif defined( BSD ) && ( BSD >= 199103 )
+#elif defined( BSD ) && ( BSD >= 199103 ) || defined(__APPLE__)
 #  include <machine/endian.h>
 #else
 #  include <endian.h>