summaryrefslogtreecommitdiff
path: root/node/Poly1305.cpp
diff options
context:
space:
mode:
authorAdam Ierymenko <adam.ierymenko@zerotier.com>2018-04-25 06:39:02 -0700
committerGitHub <noreply@github.com>2018-04-25 06:39:02 -0700
commit42ec780a6f6eedef4d8b1d8218bd72fc6ed75cc0 (patch)
tree7bf86c4d92d6a0f77eced79bfc33313c62c7b6dd /node/Poly1305.cpp
parent18c9dc8a0649c866eff9f299f20fa5b19c502e52 (diff)
parent4608880fb06700822d01e9e5d6729fcdeb82b64b (diff)
downloadinfinitytier-42ec780a6f6eedef4d8b1d8218bd72fc6ed75cc0.tar.gz
infinitytier-42ec780a6f6eedef4d8b1d8218bd72fc6ed75cc0.zip
Merge branch 'dev' into netbsd-support
Diffstat (limited to 'node/Poly1305.cpp')
-rw-r--r--node/Poly1305.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/node/Poly1305.cpp b/node/Poly1305.cpp
index b78071f6..eceb57b3 100644
--- a/node/Poly1305.cpp
+++ b/node/Poly1305.cpp
@@ -121,7 +121,6 @@ static inline int crypto_onetimeauth(unsigned char *out,const unsigned char *in,
}
void Poly1305::compute(void *auth,const void *data,unsigned int len,const void *key)
- throw()
{
crypto_onetimeauth((unsigned char *)auth,(const unsigned char *)data,len,(const unsigned char *)key);
}
@@ -135,7 +134,7 @@ typedef struct poly1305_context {
unsigned char opaque[136];
} poly1305_context;
-#if (defined(_MSC_VER) || defined(__GNUC__)) && (defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || defined(__AMD64) || defined(__AMD64__))
+#if (defined(_MSC_VER) || defined(__GNUC__)) && (defined(__amd64) || defined(__amd64__) || defined(__x86_64) || defined(__x86_64__) || defined(__AMD64) || defined(__AMD64__) || defined(_M_X64))
//////////////////////////////////////////////////////////////////////////////
// 128-bit implementation for MSC and GCC from Poly1305-donna
@@ -183,9 +182,9 @@ typedef struct poly1305_state_internal_t {
unsigned char final;
} poly1305_state_internal_t;
-/* interpret eight 8 bit unsigned integers as a 64 bit unsigned integer in little endian */
-static inline unsigned long long
-U8TO64(const unsigned char *p) {
+#if defined(ZT_NO_TYPE_PUNNING) || (__BYTE_ORDER != __LITTLE_ENDIAN)
+static inline unsigned long long U8TO64(const unsigned char *p)
+{
return
(((unsigned long long)(p[0] & 0xff) ) |
((unsigned long long)(p[1] & 0xff) << 8) |
@@ -196,10 +195,13 @@ U8TO64(const unsigned char *p) {
((unsigned long long)(p[6] & 0xff) << 48) |
((unsigned long long)(p[7] & 0xff) << 56));
}
+#else
+#define U8TO64(p) (*reinterpret_cast<const unsigned long long *>(p))
+#endif
-/* store a 64 bit unsigned integer as eight 8 bit unsigned integers in little endian */
-static inline void
-U64TO8(unsigned char *p, unsigned long long v) {
+#if defined(ZT_NO_TYPE_PUNNING) || (__BYTE_ORDER != __LITTLE_ENDIAN)
+static inline void U64TO8(unsigned char *p, unsigned long long v)
+{
p[0] = (v ) & 0xff;
p[1] = (v >> 8) & 0xff;
p[2] = (v >> 16) & 0xff;
@@ -209,6 +211,9 @@ U64TO8(unsigned char *p, unsigned long long v) {
p[6] = (v >> 48) & 0xff;
p[7] = (v >> 56) & 0xff;
}
+#else
+#define U64TO8(p,v) ((*reinterpret_cast<unsigned long long *>(p)) = (v))
+#endif
static inline void
poly1305_init(poly1305_context *ctx, const unsigned char key[32]) {
@@ -617,7 +622,6 @@ poly1305_update(poly1305_context *ctx, const unsigned char *m, size_t bytes) {
} // anonymous namespace
void Poly1305::compute(void *auth,const void *data,unsigned int len,const void *key)
- throw()
{
poly1305_context ctx;
poly1305_init(&ctx,reinterpret_cast<const unsigned char *>(key));