| 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> | 10 #include <stdint.h> |
| 11 | 11 |
| 12 #include "poly1305.h" | 12 #include "poly1305.h" |
| 13 | 13 |
| 14 #if defined(NSS_X86) || defined(NSS_X64) | 14 #if defined(NSS_X86) || defined(NSS_X64) |
| 15 /* We can assume little-endian. */ | 15 /* We can assume little-endian. */ |
| 16 static uint32_t U8TO32_LE(const unsigned char *m) { | 16 static uint32_t U8TO32_LE(const unsigned char *m) { |
| 17 uint32_t r; | 17 uint32_t r; |
| 18 memcpy(&r, m, sizeof(r)); | 18 memcpy(&r, m, sizeof(r)); |
| 19 return r; | 19 return r; |
| 20 } | 20 } |
| 21 | 21 |
| 22 static void U32TO8_LE(unsigned char *m, uint32_t v) { | 22 static void U32TO8_LE(unsigned char *m, uint32_t v) { |
| 23 memcpy(m, &v, sizeof(v)); | 23 memcpy(m, &v, sizeof(v)); |
| 24 } | 24 } |
| 25 #else | 25 #else |
| 26 static void U8TO32_LE(const unsigned char *m) { | 26 static uint32_t U8TO32_LE(const unsigned char *m) { |
| 27 return (uint32_t)m[0] | | 27 return (uint32_t)m[0] | |
| 28 (uint32_t)m[1] << 8 | | 28 (uint32_t)m[1] << 8 | |
| 29 (uint32_t)m[2] << 16 | | 29 (uint32_t)m[2] << 16 | |
| 30 (uint32_t)m[3] << 24; | 30 (uint32_t)m[3] << 24; |
| 31 } | 31 } |
| 32 | 32 |
| 33 static void U32TO8_LE(unsigned char *m, uint32_t v) { | 33 static void U32TO8_LE(unsigned char *m, uint32_t v) { |
| 34 m[0] = v; | 34 m[0] = v; |
| 35 m[1] = v >> 8; | 35 m[1] = v >> 8; |
| 36 m[2] = v >> 16; | 36 m[2] = v >> 16; |
| (...skipping 208 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]); | 245 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]); | 246 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]); | 247 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]); | 248 f3 = ((state->h3 >> 18) | (state->h4 << 8)) + (uint64_t)U8TO32_LE(&stat
e->key[12]); |
| 249 | 249 |
| 250 U32TO8_LE(&mac[ 0], f0); f1 += (f0 >> 32); | 250 U32TO8_LE(&mac[ 0], f0); f1 += (f0 >> 32); |
| 251 U32TO8_LE(&mac[ 4], f1); f2 += (f1 >> 32); | 251 U32TO8_LE(&mac[ 4], f1); f2 += (f1 >> 32); |
| 252 U32TO8_LE(&mac[ 8], f2); f3 += (f2 >> 32); | 252 U32TO8_LE(&mac[ 8], f2); f3 += (f2 >> 32); |
| 253 U32TO8_LE(&mac[12], f3); | 253 U32TO8_LE(&mac[12], f3); |
| 254 } | 254 } |
| OLD | NEW |