[endianess] fix some issues on non supported arches
This commit is contained in:
parent
36d5fde149
commit
71fe77da68
@ -24,6 +24,9 @@ module Crypto.Internal.CompatPrim
|
|||||||
) where
|
) where
|
||||||
|
|
||||||
import GHC.Prim
|
import GHC.Prim
|
||||||
|
#if !defined(ARCH_IS_LITTLE_ENDIAN) && !defined(ARCH_IS_BIG_ENDIAN)
|
||||||
|
import Data.Memory.Endian (getSystemEndianness, Endianness(..))
|
||||||
|
#endif
|
||||||
|
|
||||||
-- | byteswap Word# to or from Big Endian
|
-- | byteswap Word# to or from Big Endian
|
||||||
--
|
--
|
||||||
@ -31,8 +34,10 @@ import GHC.Prim
|
|||||||
be32Prim :: Word# -> Word#
|
be32Prim :: Word# -> Word#
|
||||||
#ifdef ARCH_IS_LITTLE_ENDIAN
|
#ifdef ARCH_IS_LITTLE_ENDIAN
|
||||||
be32Prim = byteswap32Prim
|
be32Prim = byteswap32Prim
|
||||||
|
#elif defined(ARCH_IS_BIG_ENDIAN)
|
||||||
|
be32Prim = id
|
||||||
#else
|
#else
|
||||||
be32Prim w = w
|
be32Prim w = if getSystemEndianness == LittleEndian then byteswap32Prim w else w
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
-- | byteswap Word# to or from Little Endian
|
-- | byteswap Word# to or from Little Endian
|
||||||
@ -41,8 +46,10 @@ be32Prim w = w
|
|||||||
le32Prim :: Word# -> Word#
|
le32Prim :: Word# -> Word#
|
||||||
#ifdef ARCH_IS_LITTLE_ENDIAN
|
#ifdef ARCH_IS_LITTLE_ENDIAN
|
||||||
le32Prim w = w
|
le32Prim w = w
|
||||||
#else
|
#elif defined(ARCH_IS_BIG_ENDIAN)
|
||||||
le32Prim = byteswap32Prim
|
le32Prim = byteswap32Prim
|
||||||
|
#else
|
||||||
|
le32Prim w = if getSystemEndianness == LittleEndian then w else byteswap32Prim w
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
-- | Simple compatibility for byteswap the lower 32 bits of a Word#
|
-- | Simple compatibility for byteswap the lower 32 bits of a Word#
|
||||||
@ -69,11 +76,24 @@ convert4To32 a b c d = or# (or# c1 c2) (or# c3 c4)
|
|||||||
!c2 = uncheckedShiftL# b 16#
|
!c2 = uncheckedShiftL# b 16#
|
||||||
!c3 = uncheckedShiftL# c 8#
|
!c3 = uncheckedShiftL# c 8#
|
||||||
!c4 = d
|
!c4 = d
|
||||||
#else
|
#elif defined(ARCH_IS_BIG_ENDIAN)
|
||||||
!c1 = uncheckedShiftL# d 24#
|
!c1 = uncheckedShiftL# d 24#
|
||||||
!c2 = uncheckedShiftL# c 16#
|
!c2 = uncheckedShiftL# c 16#
|
||||||
!c3 = uncheckedShiftL# b 8#
|
!c3 = uncheckedShiftL# b 8#
|
||||||
!c4 = a
|
!c4 = a
|
||||||
|
#else
|
||||||
|
!c1
|
||||||
|
| getSystemEndianness == LittleEndian = uncheckedShiftL# a 24#
|
||||||
|
| otherwise = uncheckedShiftL# d 24#
|
||||||
|
!c2
|
||||||
|
| getSystemEndianness == LittleEndian = uncheckedShiftL# b 16#
|
||||||
|
| otherwise = uncheckedShiftL# c 16#
|
||||||
|
!c3
|
||||||
|
| getSystemEndianness == LittleEndian = uncheckedShiftL# c 8#
|
||||||
|
| otherwise = uncheckedShiftL# b 8#
|
||||||
|
!c4
|
||||||
|
| getSystemEndianness == LittleEndian = d
|
||||||
|
| otherwise = a
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
-- | Simple wrapper to handle pre 7.8 and future, where
|
-- | Simple wrapper to handle pre 7.8 and future, where
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user