Crypto++  6.1
Free C++ class library of cryptographic schemes
Typedefs | Functions
ppc-simd.h File Reference

Support functions for PowerPC and vector operations. More...

Go to the source code of this file.

Typedefs

typedef __vector unsigned char uint8x16_p
 
typedef __vector unsigned short uint16x8_p
 
typedef __vector unsigned int uint32x4_p
 

Functions

void ReverseByteArrayLE (byte src[16])
 Reverse a 16-byte array. More...
 
template<class T >
Reverse (const T &src)
 Reverse a vector. More...
 
uint32x4_p VectorLoadBE (const uint8_t src[16])
 Loads a vector from a byte array. More...
 
uint32x4_p VectorLoadBE (int off, const uint8_t src[16])
 Loads a vector from a byte array. More...
 
uint32x4_p VectorLoad (const byte src[16])
 Loads a vector from a byte array. More...
 
uint32x4_p VectorLoad (int off, const byte src[16])
 Loads a vector from a byte array. More...
 
uint32x4_p VectorLoadKey (const byte src[16])
 Loads a vector from a byte array. More...
 
uint32x4_p VectorLoadKey (const word32 src[4])
 Loads a vector from a 32-bit word array. More...
 
uint32x4_p VectorLoadKey (int off, const byte src[16])
 Loads a vector from a byte array. More...
 
template<class T >
void VectorStoreBE (const T &src, uint8_t dest[16])
 Stores a vector to a byte array. More...
 
template<class T >
void VectorStoreBE (const T &src, int off, uint8_t dest[16])
 Stores a vector to a byte array. More...
 
template<class T >
void VectorStore (const T &src, byte dest[16])
 Stores a vector to a byte array. More...
 
template<class T >
void VectorStore (const T &src, int off, byte dest[16])
 Stores a vector to a byte array. More...
 
template<class T1 , class T2 >
T1 VectorPermute (const T1 &vec1, const T1 &vec2, const T2 &mask)
 Permutes two vectors. More...
 
template<class T1 , class T2 >
T1 VectorXor (const T1 &vec1, const T2 &vec2)
 XOR two vectors. More...
 
template<class T1 , class T2 >
T1 VectorAdd (const T1 &vec1, const T2 &vec2)
 Add two vector. More...
 
template<unsigned int C, class T1 , class T2 >
T1 VectorShiftLeft (const T1 &vec1, const T2 &vec2)
 Shift two vectors left. More...
 
template<class T1 , class T2 >
T1 VectorEncrypt (const T1 &state, const T2 &key)
 One round of AES encryption. More...
 
template<class T1 , class T2 >
T1 VectorEncryptLast (const T1 &state, const T2 &key)
 Final round of AES encryption. More...
 
template<class T1 , class T2 >
T1 VectorDecrypt (const T1 &state, const T2 &key)
 One round of AES decryption. More...
 
template<class T1 , class T2 >
T1 VectorDecryptLast (const T1 &state, const T2 &key)
 Final round of AES decryption. More...
 
template<int func, int subfunc, class T >
VectorSHA256 (const T &vec)
 SHA256 Sigma functions. More...
 
template<int func, int subfunc, class T >
VectorSHA512 (const T &vec)
 SHA512 Sigma functions. More...
 

Detailed Description

Support functions for PowerPC and vector operations.

This header provides an agnostic interface into GCC and IBM XL C/C++ compilers modulo their different built-in functions for accessing vector intructions.

The abstractions are necesssary to support back to GCC 4.8. GCC 4.8 and 4.9 are still popular, and they are the default compiler for GCC112, GCC118 and others on the compile farm. Older IBM XL C/C++ compilers also experience it due to lack of vec_xl_be support on some platforms. Modern compilers provide best support and don't need many of the little hacks below.

Since
Crypto++ 6.0

Definition in file ppc-simd.h.

Function Documentation

◆ ReverseByteArrayLE()

void ReverseByteArrayLE ( byte  src[16])
inline

Reverse a 16-byte array.

Parameters
srcthe byte array

ReverseByteArrayLE reverses a 16-byte array on a little endian system. It does nothing on a big endian system.

Since
Crypto++ 6.0

Definition at line 116 of file ppc-simd.h.

◆ Reverse()

template<class T >
T Reverse ( const T &  src)
inline

Reverse a vector.

Template Parameters
Tvector type
Parameters
srcthe vector

Reverse() endian swaps the bytes in a vector

See also
Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey()
Since
Crypto++ 6.0

Definition at line 134 of file ppc-simd.h.

◆ VectorLoadBE() [1/2]

uint32x4_p VectorLoadBE ( const uint8_t  src[16])
inline

Loads a vector from a byte array.

Parameters
srcthe byte array

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.
See also
Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey()
Since
Crypto++ 6.0

Definition at line 147 of file ppc-simd.h.

◆ VectorLoadBE() [2/2]

uint32x4_p VectorLoadBE ( int  off,
const uint8_t  src[16] 
)
inline

Loads a vector from a byte array.

Parameters
srcthe byte array
offoffset into the src byte array

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.
See also
Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey()
Since
Crypto++ 6.0

Definition at line 168 of file ppc-simd.h.

◆ VectorLoad() [1/2]

uint32x4_p VectorLoad ( const byte  src[16])
inline

Loads a vector from a byte array.

Parameters
srcthe byte array

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.
See also
Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey()
Since
Crypto++ 6.0

Definition at line 188 of file ppc-simd.h.

◆ VectorLoad() [2/2]

uint32x4_p VectorLoad ( int  off,
const byte  src[16] 
)
inline

Loads a vector from a byte array.

Parameters
srcthe byte array
offoffset into the src byte array

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.
See also
Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey()
Since
Crypto++ 6.0

Definition at line 201 of file ppc-simd.h.

◆ VectorLoadKey() [1/3]

uint32x4_p VectorLoadKey ( const byte  src[16])
inline

Loads a vector from a byte array.

Parameters
srcthe byte array

Loads a vector from a byte array. VectorLoadKey does not swap endianess on little endian systems.

Note
VectorLoadKey does not require an aligned array.
See also
Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey()
Since
Crypto++ 6.0

Definition at line 213 of file ppc-simd.h.

◆ VectorLoadKey() [2/3]

uint32x4_p VectorLoadKey ( const word32  src[4])
inline

Loads a vector from a 32-bit word array.

Parameters
srcthe 32-bit word array

Loads a vector from a 32-bit word array. VectorLoadKey does not swap endianess on little endian systems.

Note
VectorLoadKey does not require an aligned array.
See also
Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey()
Since
Crypto++ 6.0

Definition at line 229 of file ppc-simd.h.

◆ VectorLoadKey() [3/3]

uint32x4_p VectorLoadKey ( int  off,
const byte  src[16] 
)
inline

Loads a vector from a byte array.

Parameters
srcthe byte array
offoffset into the src byte array

Loads a vector from a byte array. VectorLoadKey does not swap endianess on little endian systems.

Note
VectorLoadKey does not require an aligned array.
See also
Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey()
Since
Crypto++ 6.0

Definition at line 246 of file ppc-simd.h.

◆ VectorStoreBE() [1/2]

template<class T >
void VectorStoreBE ( const T &  src,
uint8_t  dest[16] 
)
inline

Stores a vector to a byte array.

Template Parameters
Tvector type
Parameters
srcthe vector
destthe byte array

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.
See also
Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey()
Since
Crypto++ 6.0

Definition at line 265 of file ppc-simd.h.

◆ VectorStoreBE() [2/2]

template<class T >
void VectorStoreBE ( const T &  src,
int  off,
uint8_t  dest[16] 
)
inline

Stores a vector to a byte array.

Template Parameters
Tvector type
Parameters
srcthe vector
offoffset into the dest byte array
destthe byte array

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.
See also
Reverse(), VectorLoadBE(), VectorLoad(), VectorLoadKey()
Since
Crypto++ 6.0

Definition at line 288 of file ppc-simd.h.

◆ VectorStore() [1/2]

template<class T >
void VectorStore ( const T &  src,
byte  dest[16] 
)
inline

Stores a vector to a byte array.

Template Parameters
Tvector type
Parameters
srcthe vector
destthe byte array

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

Definition at line 310 of file ppc-simd.h.

◆ VectorStore() [2/2]

template<class T >
void VectorStore ( const T &  src,
int  off,
byte  dest[16] 
)
inline

Stores a vector to a byte array.

Template Parameters
Tvector type
Parameters
srcthe vector
offoffset into the dest byte array
destthe byte array

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

Definition at line 334 of file ppc-simd.h.

◆ VectorPermute()

template<class T1 , class T2 >
T1 VectorPermute ( const T1 &  vec1,
const T1 &  vec2,
const T2 &  mask 
)
inline

Permutes two vectors.

Template Parameters
T1vector type
T2vector type
Parameters
vec1the first vector
vec2the second vector
maskvector mask

VectorPermute returns a new vector from vec1 and vec2 based on mask. mask is an uint8x16_p type vector. The return vector is the same type as vec1.

Since
Crypto++ 6.0

Definition at line 359 of file ppc-simd.h.

◆ VectorXor()

template<class T1 , class T2 >
T1 VectorXor ( const T1 &  vec1,
const T2 &  vec2 
)
inline

XOR two vectors.

Template Parameters
T1vector type
T2vector type
Parameters
vec1the first vector
vec2the second vector

VectorXor returns a new vector from vec1 and vec2. The return vector is the same type as vec1.

Since
Crypto++ 6.0

Definition at line 373 of file ppc-simd.h.

◆ VectorAdd()

template<class T1 , class T2 >
T1 VectorAdd ( const T1 &  vec1,
const T2 &  vec2 
)
inline

Add two vector.

Template Parameters
T1vector type
T2vector type
Parameters
vec1the first vector
vec2the second vector

VectorAdd returns a new vector from vec1 and vec2. vec2 is cast to the same type as vec1. The return vector is the same type as vec1.

Since
Crypto++ 6.0

Definition at line 388 of file ppc-simd.h.

◆ VectorShiftLeft()

template<unsigned int C, class T1 , class T2 >
T1 VectorShiftLeft ( const T1 &  vec1,
const T2 &  vec2 
)
inline

Shift two vectors left.

Template Parameters
Cshift byte count
T1vector type
T2vector type
Parameters
vec1the first vector
vec2the second vector

VectorShiftLeft() concatenates vec1 and vec2 and returns a new vector after shifting the concatenation by the specified number of bytes. Both vec1 and vec2 are cast to uint8x16_p. The return vector is the same type as vec1.

On big endian machines VectorShiftLeft() is vec_sld(a, b, c). On little endian machines VectorShiftLeft() is translated to vec_sld(b, a, 16-c). You should always call the function as if on a big endian machine as shown below.

   uint8x16_p r0 = {0};
   uint8x16_p r1 = VectorLoad(ptr);
   uint8x16_p r5 = VectorShiftLeft<12>(r0, r1);
See also
Is vec_sld endian sensitive? on Stack Overflow
Since
Crypto++ 6.0

Definition at line 416 of file ppc-simd.h.

◆ VectorEncrypt()

template<class T1 , class T2 >
T1 VectorEncrypt ( const T1 &  state,
const T2 &  key 
)
inline

One round of AES encryption.

Template Parameters
T1vector type
T2vector type
Parameters
statethe state vector
keythe subkey vector

VectorEncrypt performs one round of AES encryption of state using subkey key. The return vector is the same type as vec1.

Since
Crypto++ 6.0

Definition at line 438 of file ppc-simd.h.

◆ VectorEncryptLast()

template<class T1 , class T2 >
T1 VectorEncryptLast ( const T1 &  state,
const T2 &  key 
)
inline

Final round of AES encryption.

Template Parameters
T1vector type
T2vector type
Parameters
statethe state vector
keythe subkey vector

VectorEncryptLast performs the final round of AES encryption of state using subkey key. The return vector is the same type as vec1.

Since
Crypto++ 6.0

Definition at line 458 of file ppc-simd.h.

◆ VectorDecrypt()

template<class T1 , class T2 >
T1 VectorDecrypt ( const T1 &  state,
const T2 &  key 
)
inline

One round of AES decryption.

Template Parameters
T1vector type
T2vector type
Parameters
statethe state vector
keythe subkey vector

VectorDecrypt performs one round of AES decryption of state using subkey key. The return vector is the same type as vec1.

Since
Crypto++ 6.0

Definition at line 478 of file ppc-simd.h.

◆ VectorDecryptLast()

template<class T1 , class T2 >
T1 VectorDecryptLast ( const T1 &  state,
const T2 &  key 
)
inline

Final round of AES decryption.

Template Parameters
T1vector type
T2vector type
Parameters
statethe state vector
keythe subkey vector

VectorDecryptLast performs the final round of AES decryption of state using subkey key. The return vector is the same type as vec1.

Since
Crypto++ 6.0

Definition at line 498 of file ppc-simd.h.

◆ VectorSHA256()

template<int func, int subfunc, class T >
T VectorSHA256 ( const T &  vec)
inline

SHA256 Sigma functions.

Template Parameters
funcfunction
subfuncsub-function
Tvector type
Parameters
vecthe block to transform

VectorSHA256 selects sigma0, sigma1, Sigma0, Sigma1 based on func and subfunc. The return vector is the same type as vec.

Since
Crypto++ 6.0

Definition at line 518 of file ppc-simd.h.

◆ VectorSHA512()

template<int func, int subfunc, class T >
T VectorSHA512 ( const T &  vec)
inline

SHA512 Sigma functions.

Template Parameters
funcfunction
subfuncsub-function
Tvector type
Parameters
vecthe block to transform

VectorSHA512 selects sigma0, sigma1, Sigma0, Sigma1 based on func and subfunc. The return vector is the same type as vec.

Since
Crypto++ 6.0

Definition at line 538 of file ppc-simd.h.