Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

Namespaces | Macros
threefish_avx2.cpp File Reference
`#include <botan/threefish.h>`
`#include <immintrin.h>`

Go to the source code of this file.

## Namespaces
| Botan

## Macros
#define | THREEFISH_DEC_2_8_ROUNDS(X0, X1, X2, X3, R, K1, K2, K3, T0, T1, T2)
#define | THREEFISH_DEC_8_ROUNDS(X0, X1, R, K1, K2, K3, T0, T1, T2)
#define | THREEFISH_ENC_2_8_ROUNDS(X0, X1, X2, X3, R, K0, K1, K2, T0, T1, T2)
#define | THREEFISH_ENC_8_ROUNDS(X0, X1, R, K0, K1, K2, T0, T1, T2)
#define | THREEFISH_INJECT_KEY(X0, X1, R, K0, K1, T0I, T1I)
#define | THREEFISH_INJECT_KEY_2(X0, X1, X2, X3, R, K0, K1, T0I, T1I)
#define | THREEFISH_ROUND(X0, X1, SHL)
#define | THREEFISH_ROUND(X0, X1, SHR)
#define | THREEFISH_ROUND_2(X0, X1, X2, X3, SHL)
#define | THREEFISH_ROUND_2(X0, X1, X2, X3, SHR)

## Macro Definition Documentation

#define THREEFISH_DEC_2_8_ROUNDS | ( |  | X0,
|  |  | X1,
|  |  | X2,
|  |  | X3,
|  |  | R,
|  |  | K1,
|  |  | K2,
|  |  | K3,
|  |  | T0,
|  |  | T1,
|  |  | T2
| ) |  |

Value:
do { \
THREEFISH_INJECT_KEY_2(X0, X1, X2, X3, R+1, K2, K3, T2, T0); \
THREEFISH_ROUND_2(X0, X1, X2, X3, ROTATE_8); \
THREEFISH_ROUND_2(X0, X1, X2, X3, ROTATE_7); \
THREEFISH_ROUND_2(X0, X1, X2, X3, ROTATE_6); \
THREEFISH_ROUND_2(X0, X1, X2, X3, ROTATE_5); \
\
THREEFISH_INJECT_KEY_2(X0, X1, X2, X3, R, K1, K2, T0, T1); \
THREEFISH_ROUND_2(X0, X1, X2, X3, ROTATE_4); \
THREEFISH_ROUND_2(X0, X1, X2, X3, ROTATE_3); \
THREEFISH_ROUND_2(X0, X1, X2, X3, ROTATE_2); \
THREEFISH_ROUND_2(X0, X1, X2, X3, ROTATE_1); \
} while(0)
THREEFISH_ROUND_2
#define THREEFISH_ROUND_2(X0, X1, X2, X3, SHL)
THREEFISH_INJECT_KEY_2
#define THREEFISH_INJECT_KEY_2(X0, X1, X2, X3, R, K0, K1, T0I, T1I)

#define THREEFISH_DEC_8_ROUNDS | ( |  | X0,
|  |  | X1,
|  |  | R,
|  |  | K1,
|  |  | K2,
|  |  | K3,
|  |  | T0,
|  |  | T1,
|  |  | T2
| ) |  |

Value:
do { \
THREEFISH_INJECT_KEY(X0, X1, R+1, K2, K3, T2, T0); \
THREEFISH_ROUND(X0, X1, ROTATE_8); \
THREEFISH_ROUND(X0, X1, ROTATE_7); \
THREEFISH_ROUND(X0, X1, ROTATE_6); \
THREEFISH_ROUND(X0, X1, ROTATE_5); \
\
THREEFISH_INJECT_KEY(X0, X1, R, K1, K2, T0, T1); \
THREEFISH_ROUND(X0, X1, ROTATE_4); \
THREEFISH_ROUND(X0, X1, ROTATE_3); \
THREEFISH_ROUND(X0, X1, ROTATE_2); \
THREEFISH_ROUND(X0, X1, ROTATE_1); \
} while(0)
THREEFISH_INJECT_KEY
#define THREEFISH_INJECT_KEY(X0, X1, R, K0, K1, T0I, T1I)
THREEFISH_ROUND
#define THREEFISH_ROUND(X0, X1, SHL)

#define THREEFISH_ENC_2_8_ROUNDS | ( |  | X0,
|  |  | X1,
|  |  | X2,
|  |  | X3,
|  |  | R,
|  |  | K0,
|  |  | K1,
|  |  | K2,
|  |  | T0,
|  |  | T1,
|  |  | T2
| ) |  |

Value:
do { \
rotate_keys(K1, K2, K0); \
THREEFISH_ROUND_2(X0, X1, X2, X3, ROTATE_1); \
THREEFISH_ROUND_2(X0, X1, X2, X3, ROTATE_2); \
THREEFISH_ROUND_2(X0, X1, X2, X3, ROTATE_3); \
THREEFISH_ROUND_2(X0, X1, X2, X3, ROTATE_4); \
THREEFISH_INJECT_KEY_2(X0, X1, X2, X3, R, K0, K1, T0, T1); \
\
THREEFISH_ROUND_2(X0, X1, X2, X3, ROTATE_5); \
THREEFISH_ROUND_2(X0, X1, X2, X3, ROTATE_6); \
THREEFISH_ROUND_2(X0, X1, X2, X3, ROTATE_7); \
THREEFISH_ROUND_2(X0, X1, X2, X3, ROTATE_8); \
THREEFISH_INJECT_KEY_2(X0, X1, X2, X3, R+1, K1, K2, T2, T0); \
} while(0)
THREEFISH_ROUND_2
#define THREEFISH_ROUND_2(X0, X1, X2, X3, SHL)
THREEFISH_INJECT_KEY_2
#define THREEFISH_INJECT_KEY_2(X0, X1, X2, X3, R, K0, K1, T0I, T1I)

#define THREEFISH_ENC_8_ROUNDS | ( |  | X0,
|  |  | X1,
|  |  | R,
|  |  | K0,
|  |  | K1,
|  |  | K2,
|  |  | T0,
|  |  | T1,
|  |  | T2
| ) |  |

Value:
do { \
rotate_keys(K1, K2, K0); \
THREEFISH_ROUND(X0, X1, ROTATE_1); \
THREEFISH_ROUND(X0, X1, ROTATE_2); \
THREEFISH_ROUND(X0, X1, ROTATE_3); \
THREEFISH_ROUND(X0, X1, ROTATE_4); \
THREEFISH_INJECT_KEY(X0, X1, R, K0, K1, T0, T1); \
\
THREEFISH_ROUND(X0, X1, ROTATE_5); \
THREEFISH_ROUND(X0, X1, ROTATE_6); \
THREEFISH_ROUND(X0, X1, ROTATE_7); \
THREEFISH_ROUND(X0, X1, ROTATE_8); \
THREEFISH_INJECT_KEY(X0, X1, R+1, K1, K2, T2, T0); \
} while(0)
THREEFISH_INJECT_KEY
#define THREEFISH_INJECT_KEY(X0, X1, R, K0, K1, T0I, T1I)
THREEFISH_ROUND
#define THREEFISH_ROUND(X0, X1, SHL)

#define THREEFISH_INJECT_KEY | ( |  | X0,
|  |  | X1,
|  |  | R,
|  |  | K0,
|  |  | K1,
|  |  | T0I,
|  |  | T1I
| ) |  |

Value:
do { \
const __m256i T0 = _mm256_permute4x64_epi64(T, _MM_SHUFFLE(T0I, 0, 0, 0)); \
const __m256i T1 = _mm256_permute4x64_epi64(T, _MM_SHUFFLE(0, T1I, 0, 0)); \
X0 = _mm256_add_epi64(X0, K0); \
X1 = _mm256_add_epi64(X1, K1); \
X1 = _mm256_add_epi64(X1, _mm256_set_epi64x(R,0,0,0)); \
X0 = _mm256_add_epi64(X0, T0); \
X1 = _mm256_add_epi64(X1, T1); \
} while(0)

#define THREEFISH_INJECT_KEY | ( |  | X0,
|  |  | X1,
|  |  | R,
|  |  | K0,
|  |  | K1,
|  |  | T0I,
|  |  | T1I
| ) |  |

Value:
do { \
const __m256i T0 = _mm256_permute4x64_epi64(T, _MM_SHUFFLE(T0I, 0, 0, 0)); \
const __m256i T1 = _mm256_permute4x64_epi64(T, _MM_SHUFFLE(0, T1I, 0, 0)); \
X0 = _mm256_sub_epi64(X0, K0); \
X1 = _mm256_sub_epi64(X1, K1); \
X1 = _mm256_sub_epi64(X1, _mm256_set_epi64x(R, 0, 0, 0)); \
X0 = _mm256_sub_epi64(X0, T0); \
X1 = _mm256_sub_epi64(X1, T1); \
} while(0)

#define THREEFISH_INJECT_KEY_2 | ( |  | X0,
|  |  | X1,
|  |  | X2,
|  |  | X3,
|  |  | R,
|  |  | K0,
|  |  | K1,
|  |  | T0I,
|  |  | T1I
| ) |  |

Value:
do { \
const __m256i T0 = _mm256_permute4x64_epi64(T, _MM_SHUFFLE(T0I, 0, 0, 0)); \
__m256i T1 = _mm256_permute4x64_epi64(T, _MM_SHUFFLE(0, T1I, 0, 0)); \
X0 = _mm256_add_epi64(X0, K0); \
X2 = _mm256_add_epi64(X2, K0); \
X1 = _mm256_add_epi64(X1, K1); \
X3 = _mm256_add_epi64(X3, K1); \
T1 = _mm256_add_epi64(T1, _mm256_set_epi64x(R,0,0,0)); \
X0 = _mm256_add_epi64(X0, T0); \
X2 = _mm256_add_epi64(X2, T0); \
X1 = _mm256_add_epi64(X1, T1); \
X3 = _mm256_add_epi64(X3, T1); \
} while(0)

#define THREEFISH_INJECT_KEY_2 | ( |  | X0,
|  |  | X1,
|  |  | X2,
|  |  | X3,
|  |  | R,
|  |  | K0,
|  |  | K1,
|  |  | T0I,
|  |  | T1I
| ) |  |

Value:
do { \
const __m256i T0 = _mm256_permute4x64_epi64(T, _MM_SHUFFLE(T0I, 0, 0, 0)); \
__m256i T1 = _mm256_permute4x64_epi64(T, _MM_SHUFFLE(0, T1I, 0, 0)); \
X0 = _mm256_sub_epi64(X0, K0); \
X2 = _mm256_sub_epi64(X2, K0); \
X1 = _mm256_sub_epi64(X1, K1); \
X3 = _mm256_sub_epi64(X3, K1); \
T1 = _mm256_add_epi64(T1, _mm256_set_epi64x(R,0,0,0)); \
X0 = _mm256_sub_epi64(X0, T0); \
X2 = _mm256_sub_epi64(X2, T0); \
X1 = _mm256_sub_epi64(X1, T1); \
X3 = _mm256_sub_epi64(X3, T1); \
} while(0)

#define THREEFISH_ROUND | ( |  | X0,
|  |  | X1,
|  |  | SHL
| ) |  |

Value:
do { \
const __m256i SHR = _mm256_sub_epi64(_mm256_set1_epi64x(64), SHL); \
X0 = _mm256_add_epi64(X0, X1); \
X1 = _mm256_or_si256(_mm256_sllv_epi64(X1, SHL), _mm256_srlv_epi64(X1, SHR)); \
X1 = _mm256_xor_si256(X1, X0); \
X0 = _mm256_permute4x64_epi64(X0, _MM_SHUFFLE(0, 3, 2, 1)); \
X1 = _mm256_permute4x64_epi64(X1, _MM_SHUFFLE(1, 2, 3, 0)); \
} while(0)

#define THREEFISH_ROUND | ( |  | X0,
|  |  | X1,
|  |  | SHR
| ) |  |

Value:
do { \
const __m256i SHL = _mm256_sub_epi64(_mm256_set1_epi64x(64), SHR); \
X0 = _mm256_permute4x64_epi64(X0, _MM_SHUFFLE(2, 1, 0, 3)); \
X1 = _mm256_permute4x64_epi64(X1, _MM_SHUFFLE(1, 2, 3, 0)); \
X1 = _mm256_xor_si256(X1, X0); \
X1 = _mm256_or_si256(_mm256_sllv_epi64(X1, SHL), _mm256_srlv_epi64(X1, SHR)); \
X0 = _mm256_sub_epi64(X0, X1); \
} while(0)

#define THREEFISH_ROUND_2 | ( |  | X0,
|  |  | X1,
|  |  | X2,
|  |  | X3,
|  |  | SHL
| ) |  |

Value:
do { \
const __m256i SHR = _mm256_sub_epi64(_mm256_set1_epi64x(64), SHL); \
X0 = _mm256_add_epi64(X0, X1); \
X2 = _mm256_add_epi64(X2, X3); \
X1 = _mm256_or_si256(_mm256_sllv_epi64(X1, SHL), _mm256_srlv_epi64(X1, SHR)); \
X3 = _mm256_or_si256(_mm256_sllv_epi64(X3, SHL), _mm256_srlv_epi64(X3, SHR)); \
X1 = _mm256_xor_si256(X1, X0); \
X3 = _mm256_xor_si256(X3, X2); \
X0 = _mm256_permute4x64_epi64(X0, _MM_SHUFFLE(0, 3, 2, 1)); \
X2 = _mm256_permute4x64_epi64(X2, _MM_SHUFFLE(0, 3, 2, 1)); \
X1 = _mm256_permute4x64_epi64(X1, _MM_SHUFFLE(1, 2, 3, 0)); \
X3 = _mm256_permute4x64_epi64(X3, _MM_SHUFFLE(1, 2, 3, 0)); \
} while(0)

#define THREEFISH_ROUND_2 | ( |  | X0,
|  |  | X1,
|  |  | X2,
|  |  | X3,
|  |  | SHR
| ) |  |

Value:
do { \
const __m256i SHL = _mm256_sub_epi64(_mm256_set1_epi64x(64), SHR); \
X0 = _mm256_permute4x64_epi64(X0, _MM_SHUFFLE(2, 1, 0, 3)); \
X2 = _mm256_permute4x64_epi64(X2, _MM_SHUFFLE(2, 1, 0, 3)); \
X1 = _mm256_permute4x64_epi64(X1, _MM_SHUFFLE(1, 2, 3, 0)); \
X3 = _mm256_permute4x64_epi64(X3, _MM_SHUFFLE(1, 2, 3, 0)); \
X1 = _mm256_xor_si256(X1, X0); \
X3 = _mm256_xor_si256(X3, X2); \
X1 = _mm256_or_si256(_mm256_sllv_epi64(X1, SHL), _mm256_srlv_epi64(X1, SHR)); \
X3 = _mm256_or_si256(_mm256_sllv_epi64(X3, SHL), _mm256_srlv_epi64(X3, SHR)); \
X0 = _mm256_sub_epi64(X0, X1); \
X2 = _mm256_sub_epi64(X2, X3); \
} while(0)