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 /* Adopted from the public domain code in NaCl by djb. */ | 5 /* Adopted from the public domain code in NaCl by djb. */ |
6 | 6 |
7 #include <string.h> | 7 #include <string.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 | 9 |
10 #include "prtypes.h" | 10 #include "prtypes.h" |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 input[8] = U8TO32_LITTLE(key + 16); | 71 input[8] = U8TO32_LITTLE(key + 16); |
72 input[9] = U8TO32_LITTLE(key + 20); | 72 input[9] = U8TO32_LITTLE(key + 20); |
73 input[10] = U8TO32_LITTLE(key + 24); | 73 input[10] = U8TO32_LITTLE(key + 24); |
74 input[11] = U8TO32_LITTLE(key + 28); | 74 input[11] = U8TO32_LITTLE(key + 28); |
75 | 75 |
76 input[0] = U8TO32_LITTLE(sigma + 0); | 76 input[0] = U8TO32_LITTLE(sigma + 0); |
77 input[1] = U8TO32_LITTLE(sigma + 4); | 77 input[1] = U8TO32_LITTLE(sigma + 4); |
78 input[2] = U8TO32_LITTLE(sigma + 8); | 78 input[2] = U8TO32_LITTLE(sigma + 8); |
79 input[3] = U8TO32_LITTLE(sigma + 12); | 79 input[3] = U8TO32_LITTLE(sigma + 12); |
80 | 80 |
81 input[12] = counter; | 81 input[12] = (PRUint32)counter; |
82 input[13] = counter >> 32; | 82 input[13] = (PRUint32)(counter >> 32); |
83 input[14] = U8TO32_LITTLE(nonce + 0); | 83 input[14] = U8TO32_LITTLE(nonce + 0); |
84 input[15] = U8TO32_LITTLE(nonce + 4); | 84 input[15] = U8TO32_LITTLE(nonce + 4); |
85 | 85 |
86 while (inLen >= 64) { | 86 while (inLen >= 64) { |
87 ChaChaCore(block, input, 20); | 87 ChaChaCore(block, input, 20); |
88 for (i = 0; i < 64; i++) { | 88 for (i = 0; i < 64; i++) { |
89 out[i] = in[i] ^ block[i]; | 89 out[i] = in[i] ^ block[i]; |
90 } | 90 } |
91 | 91 |
92 input[12]++; | 92 input[12]++; |
93 if (input[12] == 0) { | 93 if (input[12] == 0) { |
94 input[13]++; | 94 input[13]++; |
95 } | 95 } |
96 | 96 |
97 inLen -= 64; | 97 inLen -= 64; |
98 in += 64; | 98 in += 64; |
99 out += 64; | 99 out += 64; |
100 } | 100 } |
101 | 101 |
102 if (inLen > 0) { | 102 if (inLen > 0) { |
103 ChaChaCore(block, input, 20); | 103 ChaChaCore(block, input, 20); |
104 for (i = 0; i < inLen; i++) { | 104 for (i = 0; i < inLen; i++) { |
105 out[i] = in[i] ^ block[i]; | 105 out[i] = in[i] ^ block[i]; |
106 } | 106 } |
107 } | 107 } |
108 } | 108 } |
OLD | NEW |