OLD | NEW |
1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
5 /* This implementation of poly1305 is by Andrew Moon | 5 /* This implementation of poly1305 is by Andrew Moon |
6 * (https://github.com/floodyberry/poly1305-donna) and released as public | 6 * (https://github.com/floodyberry/poly1305-donna) and released as public |
7 * domain. */ | 7 * domain. */ |
8 | 8 |
9 #include <string.h> | 9 #include <string.h> |
10 #include <stdint.h> | |
11 | 10 |
12 #include "poly1305.h" | 11 #include "poly1305.h" |
13 | 12 |
| 13 #if defined(_MSC_VER) && _MSC_VER < 1600 |
| 14 #include "prtypes.h" |
| 15 typedef PRUint32 uint32_t; |
| 16 typedef PRUint64 uint64_t; |
| 17 #else |
| 18 #include <stdint.h> |
| 19 #endif |
| 20 |
14 #if defined(NSS_X86) || defined(NSS_X64) | 21 #if defined(NSS_X86) || defined(NSS_X64) |
15 /* We can assume little-endian. */ | 22 /* We can assume little-endian. */ |
16 static uint32_t U8TO32_LE(const unsigned char *m) { | 23 static uint32_t U8TO32_LE(const unsigned char *m) { |
17 uint32_t r; | 24 uint32_t r; |
18 memcpy(&r, m, sizeof(r)); | 25 memcpy(&r, m, sizeof(r)); |
19 return r; | 26 return r; |
20 } | 27 } |
21 | 28 |
22 static void U32TO8_LE(unsigned char *m, uint32_t v) { | 29 static void U32TO8_LE(unsigned char *m, uint32_t v) { |
23 memcpy(m, &v, sizeof(v)); | 30 memcpy(m, &v, sizeof(v)); |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 f0 = ((state->h0 ) | (state->h1 << 26)) + (uint64_t)U8TO32_LE(&stat
e->key[0]); | 252 f0 = ((state->h0 ) | (state->h1 << 26)) + (uint64_t)U8TO32_LE(&stat
e->key[0]); |
246 f1 = ((state->h1 >> 6) | (state->h2 << 20)) + (uint64_t)U8TO32_LE(&stat
e->key[4]); | 253 f1 = ((state->h1 >> 6) | (state->h2 << 20)) + (uint64_t)U8TO32_LE(&stat
e->key[4]); |
247 f2 = ((state->h2 >> 12) | (state->h3 << 14)) + (uint64_t)U8TO32_LE(&stat
e->key[8]); | 254 f2 = ((state->h2 >> 12) | (state->h3 << 14)) + (uint64_t)U8TO32_LE(&stat
e->key[8]); |
248 f3 = ((state->h3 >> 18) | (state->h4 << 8)) + (uint64_t)U8TO32_LE(&stat
e->key[12]); | 255 f3 = ((state->h3 >> 18) | (state->h4 << 8)) + (uint64_t)U8TO32_LE(&stat
e->key[12]); |
249 | 256 |
250 U32TO8_LE(&mac[ 0], (uint32_t)f0); f1 += (f0 >> 32); | 257 U32TO8_LE(&mac[ 0], (uint32_t)f0); f1 += (f0 >> 32); |
251 U32TO8_LE(&mac[ 4], (uint32_t)f1); f2 += (f1 >> 32); | 258 U32TO8_LE(&mac[ 4], (uint32_t)f1); f2 += (f1 >> 32); |
252 U32TO8_LE(&mac[ 8], (uint32_t)f2); f3 += (f2 >> 32); | 259 U32TO8_LE(&mac[ 8], (uint32_t)f2); f3 += (f2 >> 32); |
253 U32TO8_LE(&mac[12], (uint32_t)f3); | 260 U32TO8_LE(&mac[12], (uint32_t)f3); |
254 } | 261 } |
OLD | NEW |