summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--blake2.cpp20
-rw-r--r--donna_32.cpp33
-rw-r--r--donna_64.cpp33
-rw-r--r--salsa.cpp15
4 files changed, 76 insertions, 25 deletions
diff --git a/blake2.cpp b/blake2.cpp
index f8872619..622603c3 100644
--- a/blake2.cpp
+++ b/blake2.cpp
@@ -43,19 +43,31 @@
# undef CRYPTOPP_ALTIVEC_AVAILABLE
#endif
+#if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64)
+const unsigned int ALIGN_SPEC32=16;
+const unsigned int ALIGN_SPEC64=16;
+#elif (CRYPTOPP_CXX11_ALIGNOF)
+const unsigned int ALIGN_SPEC32=alignof(CryptoPP::word32);
+const unsigned int ALIGN_SPEC64=alignof(CryptoPP::word64);
+#else
+// Can't use GetAlignmentOf<word64>() because of C++11 constexpr
+const unsigned int ALIGN_SPEC32=4;
+const unsigned int ALIGN_SPEC64=8;
+#endif
+
NAMESPACE_BEGIN(CryptoPP)
// Export the tables to the SIMD files
extern const word32 BLAKE2S_IV[8];
extern const word64 BLAKE2B_IV[8];
-CRYPTOPP_ALIGN_DATA(16)
+CRYPTOPP_ALIGN_DATA(ALIGN_SPEC32)
const word32 BLAKE2S_IV[8] = {
0x6A09E667UL, 0xBB67AE85UL, 0x3C6EF372UL, 0xA54FF53AUL,
0x510E527FUL, 0x9B05688CUL, 0x1F83D9ABUL, 0x5BE0CD19UL
};
-CRYPTOPP_ALIGN_DATA(16)
+CRYPTOPP_ALIGN_DATA(ALIGN_SPEC64)
const word64 BLAKE2B_IV[8] = {
W64LIT(0x6a09e667f3bcc908), W64LIT(0xbb67ae8584caa73b),
W64LIT(0x3c6ef372fe94f82b), W64LIT(0xa54ff53a5f1d36f1),
@@ -72,7 +84,7 @@ using CryptoPP::word32;
using CryptoPP::word64;
using CryptoPP::rotrConstant;
-CRYPTOPP_ALIGN_DATA(16)
+CRYPTOPP_ALIGN_DATA(ALIGN_SPEC32)
const byte BLAKE2S_SIGMA[10][16] = {
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
@@ -86,7 +98,7 @@ const byte BLAKE2S_SIGMA[10][16] = {
{ 10, 2, 8, 4, 7, 6, 1, 5, 15, 11, 9, 14, 3, 12, 13 , 0 },
};
-CRYPTOPP_ALIGN_DATA(16)
+CRYPTOPP_ALIGN_DATA(ALIGN_SPEC32)
const byte BLAKE2B_SIGMA[12][16] = {
{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 },
{ 14, 10, 4, 8, 9, 15, 13, 6, 1, 12, 0, 2, 11, 7, 5, 3 },
diff --git a/donna_32.cpp b/donna_32.cpp
index 25227ff7..2fc72e9a 100644
--- a/donna_32.cpp
+++ b/donna_32.cpp
@@ -37,6 +37,19 @@
// Squash MS LNK4221 and libtool warnings
extern const char DONNA32_FNAME[] = __FILE__;
+ANONYMOUS_NAMESPACE_BEGIN
+
+#if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64)
+const unsigned int ALIGN_SPEC=16;
+#elif (CRYPTOPP_CXX11_ALIGNOF)
+const unsigned int ALIGN_SPEC=alignof(CryptoPP::word32);
+#else
+// Can't use GetAlignmentOf<word32>() because of C++11 constexpr
+const unsigned int ALIGN_SPEC=4;
+#endif
+
+ANONYMOUS_NAMESPACE_END
+
#if defined(CRYPTOPP_CURVE25519_32BIT)
#include "donna_32.h"
@@ -431,7 +444,7 @@ curve25519_swap_conditional(bignum25519 x, bignum25519 qpx, word32 iswap) {
*/
void
curve25519_pow_two5mtwo0_two250mtwo0(bignum25519 b) {
- ALIGN(16) bignum25519 t0,c;
+ ALIGN(ALIGN_SPEC) bignum25519 t0,c;
/* 2^5 - 2^0 */ /* b */
/* 2^10 - 2^5 */ curve25519_square_times(t0, b, 5);
@@ -455,7 +468,7 @@ curve25519_pow_two5mtwo0_two250mtwo0(bignum25519 b) {
*/
void
curve25519_recip(bignum25519 out, const bignum25519 z) {
- ALIGN(16) bignum25519 a, t0, b;
+ ALIGN(ALIGN_SPEC) bignum25519 a, t0, b;
/* 2 */ curve25519_square(a, z); /* a = 2 */
/* 8 */ curve25519_square_times(t0, a, 2);
@@ -967,7 +980,7 @@ curve25519_swap_conditional(bignum25519 a, bignum25519 b, word32 iswap) {
*/
void
curve25519_pow_two5mtwo0_two250mtwo0(bignum25519 b) {
- ALIGN(16) bignum25519 t0,c;
+ ALIGN(ALIGN_SPEC) bignum25519 t0,c;
/* 2^5 - 2^0 */ /* b */
/* 2^10 - 2^5 */ curve25519_square_times(t0, b, 5);
@@ -991,7 +1004,7 @@ curve25519_pow_two5mtwo0_two250mtwo0(bignum25519 b) {
*/
void
curve25519_recip(bignum25519 out, const bignum25519 z) {
- ALIGN(16) bignum25519 a,t0,b;
+ ALIGN(ALIGN_SPEC) bignum25519 a,t0,b;
/* 2 */ curve25519_square_times(a, z, 1); /* a = 2 */
/* 8 */ curve25519_square_times(t0, a, 2);
@@ -1009,7 +1022,7 @@ curve25519_recip(bignum25519 out, const bignum25519 z) {
*/
void
curve25519_pow_two252m3(bignum25519 two252m3, const bignum25519 z) {
- ALIGN(16) bignum25519 b,c,t0;
+ ALIGN(ALIGN_SPEC) bignum25519 b,c,t0;
/* 2 */ curve25519_square_times(c, z, 1); /* c = 2 */
/* 8 */ curve25519_square_times(t0, c, 2); /* t0 = 8 */
@@ -1865,7 +1878,7 @@ ed25519_publickey_CXX(byte publicKey[32], const byte secretKey[32])
using namespace CryptoPP::Donna::Ed25519;
bignum256modm a;
- ALIGN(16) ge25519 A;
+ ALIGN(ALIGN_SPEC) ge25519 A;
hash_512bits extsk;
/* A = aB */
@@ -1889,7 +1902,7 @@ ed25519_sign_CXX(std::istream& stream, const byte sk[32], const byte pk[32], byt
using namespace CryptoPP::Donna::Ed25519;
bignum256modm r, S, a;
- ALIGN(16) ge25519 R;
+ ALIGN(ALIGN_SPEC) ge25519 R;
hash_512bits extsk, hashr, hram;
// Unfortunately we need to read the stream twice. The fisrt time calculates
@@ -1938,7 +1951,7 @@ ed25519_sign_CXX(const byte *m, size_t mlen, const byte sk[32], const byte pk[32
using namespace CryptoPP::Donna::Ed25519;
bignum256modm r, S, a;
- ALIGN(16) ge25519 R;
+ ALIGN(ALIGN_SPEC) ge25519 R;
hash_512bits extsk, hashr, hram;
ed25519_extsk(extsk, sk);
@@ -1990,7 +2003,7 @@ ed25519_sign_open_CXX(std::istream& stream, const byte pk[32], const byte RS[64]
using namespace CryptoPP::Donna::Ed25519;
- ALIGN(16) ge25519 R, A;
+ ALIGN(ALIGN_SPEC) ge25519 R, A;
hash_512bits hash;
bignum256modm hram, S;
byte checkR[32];
@@ -2018,7 +2031,7 @@ ed25519_sign_open_CXX(const byte *m, size_t mlen, const byte pk[32], const byte
using namespace CryptoPP::Donna::Ed25519;
- ALIGN(16) ge25519 R, A;
+ ALIGN(ALIGN_SPEC) ge25519 R, A;
hash_512bits hash;
bignum256modm hram, S;
byte checkR[32];
diff --git a/donna_64.cpp b/donna_64.cpp
index 5319c636..77ffe9c3 100644
--- a/donna_64.cpp
+++ b/donna_64.cpp
@@ -37,6 +37,19 @@
// Squash MS LNK4221 and libtool warnings
extern const char DONNA64_FNAME[] = __FILE__;
+ANONYMOUS_NAMESPACE_BEGIN
+
+#if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64)
+const unsigned int ALIGN_SPEC=16;
+#elif (CRYPTOPP_CXX11_ALIGNOF)
+const unsigned int ALIGN_SPEC=alignof(CryptoPP::word64);
+#else
+// Can't use GetAlignmentOf<word64>() because of C++11 constexpr
+const unsigned int ALIGN_SPEC=8;
+#endif
+
+ANONYMOUS_NAMESPACE_END
+
#if defined(CRYPTOPP_CURVE25519_64BIT)
#include "donna_64.h"
@@ -359,7 +372,7 @@ curve25519_swap_conditional(bignum25519 x, bignum25519 qpx, word64 iswap) {
*/
void
curve25519_pow_two5mtwo0_two250mtwo0(bignum25519 b) {
- ALIGN(16) bignum25519 t0,c;
+ ALIGN(ALIGN_SPEC) bignum25519 t0,c;
/* 2^5 - 2^0 */ /* b */
/* 2^10 - 2^5 */ curve25519_square_times(t0, b, 5);
@@ -383,7 +396,7 @@ curve25519_pow_two5mtwo0_two250mtwo0(bignum25519 b) {
*/
void
curve25519_recip(bignum25519 out, const bignum25519 z) {
- ALIGN(16) bignum25519 a, t0, b;
+ ALIGN(ALIGN_SPEC) bignum25519 a, t0, b;
/* 2 */ curve25519_square(a, z); /* a = 2 */
/* 8 */ curve25519_square_times(t0, a, 2);
@@ -1065,7 +1078,7 @@ contract256_slidingwindow_modm(signed char r[256], const bignum256modm s, int wi
*/
void
curve25519_pow_two5mtwo0_two250mtwo0(bignum25519 b) {
- ALIGN(16) bignum25519 t0,c;
+ ALIGN(ALIGN_SPEC) bignum25519 t0,c;
/* 2^5 - 2^0 */ /* b */
/* 2^10 - 2^5 */ curve25519_square_times(t0, b, 5);
@@ -1089,7 +1102,7 @@ curve25519_pow_two5mtwo0_two250mtwo0(bignum25519 b) {
*/
void
curve25519_recip(bignum25519 out, const bignum25519 z) {
- ALIGN(16) bignum25519 a,t0,b;
+ ALIGN(ALIGN_SPEC) bignum25519 a,t0,b;
/* 2 */ curve25519_square_times(a, z, 1); /* a = 2 */
/* 8 */ curve25519_square_times(t0, a, 2);
@@ -1107,7 +1120,7 @@ curve25519_recip(bignum25519 out, const bignum25519 z) {
*/
void
curve25519_pow_two252m3(bignum25519 two252m3, const bignum25519 z) {
- ALIGN(16) bignum25519 b,c,t0;
+ ALIGN(ALIGN_SPEC) bignum25519 b,c,t0;
/* 2 */ curve25519_square_times(c, z, 1); /* c = 2 */
/* 8 */ curve25519_square_times(t0, c, 2); /* t0 = 8 */
@@ -1580,7 +1593,7 @@ ed25519_publickey_CXX(byte publicKey[32], const byte secretKey[32])
using namespace CryptoPP::Donna::Ed25519;
bignum256modm a;
- ALIGN(16) ge25519 A;
+ ALIGN(ALIGN_SPEC) ge25519 A;
hash_512bits extsk;
/* A = aB */
@@ -1604,7 +1617,7 @@ ed25519_sign_CXX(std::istream& stream, const byte sk[32], const byte pk[32], byt
using namespace CryptoPP::Donna::Ed25519;
bignum256modm r, S, a;
- ALIGN(16) ge25519 R;
+ ALIGN(ALIGN_SPEC) ge25519 R;
hash_512bits extsk, hashr, hram;
// Unfortunately we need to read the stream twice. The fisrt time calculates
@@ -1652,7 +1665,7 @@ ed25519_sign_CXX(const byte *m, size_t mlen, const byte sk[32], const byte pk[32
using namespace CryptoPP::Donna::Ed25519;
bignum256modm r, S, a;
- ALIGN(16) ge25519 R;
+ ALIGN(ALIGN_SPEC) ge25519 R;
hash_512bits extsk, hashr, hram;
ed25519_extsk(extsk, sk);
@@ -1703,7 +1716,7 @@ ed25519_sign_open_CXX(const byte *m, size_t mlen, const byte pk[32], const byte
using namespace CryptoPP::Donna::Ed25519;
- ALIGN(16) ge25519 R, A;
+ ALIGN(ALIGN_SPEC) ge25519 R, A;
hash_512bits hash;
bignum256modm hram, S;
byte checkR[32];
@@ -1731,7 +1744,7 @@ ed25519_sign_open_CXX(std::istream& stream, const byte pk[32], const byte RS[64]
using namespace CryptoPP::Donna::Ed25519;
- ALIGN(16) ge25519 R, A;
+ ALIGN(ALIGN_SPEC) ge25519 R, A;
hash_512bits hash;
bignum256modm hram, S;
byte checkR[32];
diff --git a/salsa.cpp b/salsa.cpp
index 942d17ee..01c57d22 100644
--- a/salsa.cpp
+++ b/salsa.cpp
@@ -26,6 +26,19 @@
# undef CRYPTOPP_SSSE3_ASM_AVAILABLE
#endif
+ANONYMOUS_NAMESPACE_BEGIN
+
+#if (CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X32 || CRYPTOPP_BOOL_X64)
+const unsigned int ALIGN_SPEC=16;
+#elif (CRYPTOPP_CXX11_ALIGNOF)
+const unsigned int ALIGN_SPEC=alignof(CryptoPP::word32);
+#else
+// Can't use GetAlignmentOf<word32>() because of C++11 constexpr
+const unsigned int ALIGN_SPEC=4;
+#endif
+
+ANONYMOUS_NAMESPACE_END
+
NAMESPACE_BEGIN(CryptoPP)
#if defined(CRYPTOPP_DEBUG) && !defined(CRYPTOPP_DOXYGEN_PROCESSING)
@@ -41,7 +54,7 @@ void Salsa20_Core(word32* data, unsigned int rounds)
CRYPTOPP_ASSERT(data != NULLPTR);
CRYPTOPP_ASSERT(rounds % 2 == 0);
- CRYPTOPP_ALIGN_DATA(16) word32 x[16];
+ CRYPTOPP_ALIGN_DATA(ALIGN_SPEC) word32 x[16];
for (size_t i = 0; i < 16; ++i)
x[i] = data[i];