From d5c12191b3037d2bc1a2e27885f868729b4f0783 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Fri, 22 Sep 2017 18:31:59 -0400 Subject: [PATCH] Update documentation --- ppc-crypto.h | 94 ++++++++++++++++++++++++++++++++++++---------------- ppc-simd.cpp | 6 ++-- 2 files changed, 70 insertions(+), 30 deletions(-) diff --git a/ppc-crypto.h b/ppc-crypto.h index 7735b774..cd9f3bba 100644 --- a/ppc-crypto.h +++ b/ppc-crypto.h @@ -86,7 +86,7 @@ inline VectorType VectorLoadBE(const uint8_t src[16]) //! \brief Loads a vector from a byte array //! \param src the byte array -//! \param off offset into the byte array +//! \param off offset into the src byte array //! \details Loads a vector in big endian format from a byte array. //! VectorLoadBE will swap endianess on little endian systems. //! \note VectorLoadBE does not require an aligned array. @@ -105,29 +105,6 @@ inline VectorType VectorLoadBE(int off, const uint8_t src[16]) #endif } -//! \brief Stores a vector to a byte array -//! \tparam T a vector type -//! \param src the vector -//! \param dest the byte array -//! \details Stores a vector in big endian format to a byte array. -//! VectorStoreBE will swap endianess on little endian systems. -//! \note VectorStoreBE does not require an aligned array. -//! \sa Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey() -//! \since Crypto++ 6.0 -template -inline void VectorStoreBE(const T& src, uint8_t dest[16]) -{ -#if defined(CRYPTOPP_XLC_VERSION) - vec_xst_be((uint8x16_p8)src, 0, (uint8_t*)dest); -#else -# if defined(IS_LITTLE_ENDIAN) - vec_vsx_st(Reverse((uint8x16_p8)src), 0, (uint8_t*)dest); -# else - vec_vsx_st((uint8x16_p8)src, 0, (uint8_t*)dest); -# endif -#endif -} - ////////////////////////////////////////////////////////////////// //! \brief Loads a vector from a byte array @@ -144,7 +121,7 @@ inline VectorType VectorLoad(const byte src[16]) //! \brief Loads a vector from a byte array //! \param src the byte array -//! \param off offset into the byte array +//! \param off offset into the src byte array //! \details Loads a vector in big endian format from a byte array. //! VectorLoad will swap endianess on little endian systems. //! \note VectorLoad does not require an aligned array. @@ -189,7 +166,7 @@ inline VectorType VectorLoadKey(const word32 src[4]) //! \brief Loads a vector from a byte array //! \param src the byte array -//! \param off offset into the byte array +//! \param off offset into the src byte array //! \details Loads a vector from a byte array. //! VectorLoadKey does not swap endianess on little endian systems. //! \note VectorLoadKey does not require an aligned array. @@ -209,13 +186,74 @@ inline VectorType VectorLoadKey(int off, const byte src[16]) //! \param src the vector //! \param dest the byte array //! \details Stores a vector in big endian format to a byte array. -//! VectorStore will swap endianess on little endian systems. +//! VectorStoreBE will swap endianess on little endian systems. //! \note VectorStoreBE does not require an aligned array. +//! \sa Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey() +//! \since Crypto++ 6.0 +template +inline void VectorStoreBE(const T& src, uint8_t dest[16]) +{ +#if defined(CRYPTOPP_XLC_VERSION) + vec_xst_be((uint8x16_p8)src, 0, (uint8_t*)dest); +#else +# if defined(IS_LITTLE_ENDIAN) + vec_vsx_st(Reverse((uint8x16_p8)src), 0, (uint8_t*)dest); +# else + vec_vsx_st((uint8x16_p8)src, 0, (uint8_t*)dest); +# endif +#endif +} +//! \brief Stores a vector to a byte array +//! \tparam T a vector type +//! \param src the vector +//! \param off offset into the dest byte array +//! \param dest the byte array +//! \details Stores a vector in big endian format to a byte array. +//! VectorStoreBE will swap endianess on little endian systems. +//! \note VectorStoreBE does not require an aligned array. +//! \sa Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey() +//! \since Crypto++ 6.0 +template +inline void VectorStoreBE(const T& src, int off, uint8_t dest[16]) +{ +#if defined(CRYPTOPP_XLC_VERSION) + vec_xst_be((uint8x16_p8)src, off, (uint8_t*)dest); +#else +# if defined(IS_LITTLE_ENDIAN) + vec_vsx_st(Reverse((uint8x16_p8)src), off, (uint8_t*)dest); +# else + vec_vsx_st((uint8x16_p8)src, off, (uint8_t*)dest); +# endif +#endif +} + +//! \brief Stores a vector to a byte array +//! \tparam T a vector type +//! \param src the vector +//! \param dest the byte array +//! \details Stores a vector in big endian format to a byte array. +//! VectorStore will swap endianess on little endian systems. +//! \note VectorStore does not require an aligned array. //! \since Crypto++ 6.0 template inline void VectorStore(const T& src, byte dest[16]) { - return VectorStoreBE(src, (uint8_t*)dest); + VectorStoreBE((uint8x16_p8)src, (uint8_t*)dest); +} + +//! \brief Stores a vector to a byte array +//! \tparam T a vector type +//! \param src the vector +//! \param off offset into the dest byte array +//! \param dest the byte array +//! \details Stores a vector in big endian format to a byte array. +//! VectorStore will swap endianess on little endian systems. +//! \note VectorStore does not require an aligned array. +//! \since Crypto++ 6.0 +template +inline void VectorStore(const T& src, int off, byte dest[16]) +{ + VectorStoreBE((uint8x16_p8)src, off, (uint8_t*)dest); } //! \brief Permutes two vectors diff --git a/ppc-simd.cpp b/ppc-simd.cpp index 652c18cb..6a5e74de 100644 --- a/ppc-simd.cpp +++ b/ppc-simd.cpp @@ -195,8 +195,10 @@ bool CPU_ProbeAES() result = false; else { - byte key[16] = {0xA0, 0xFA, 0xFE, 0x17, 0x88, 0x54, 0x2c, 0xb1, 0x23, 0xa3, 0x39, 0x39, 0x2a, 0x6c, 0x76, 0x05}; - byte state[16] = {0x19, 0x3d, 0xe3, 0xb3, 0xa0, 0xf4, 0xe2, 0x2b, 0x9a, 0xc6, 0x8d, 0x2a, 0xe9, 0xf8, 0x48, 0x08}; + byte key[16] = {0xA0, 0xFA, 0xFE, 0x17, 0x88, 0x54, 0x2c, 0xb1, + 0x23, 0xa3, 0x39, 0x39, 0x2a, 0x6c, 0x76, 0x05}; + byte state[16] = {0x19, 0x3d, 0xe3, 0xb3, 0xa0, 0xf4, 0xe2, 0x2b, + 0x9a, 0xc6, 0x8d, 0x2a, 0xe9, 0xf8, 0x48, 0x08}; byte r[16] = {255}, z[16] = {}; uint8x16_p8 k = (uint8x16_p8)VectorLoad(0, key);