1 | 4 patches for repository http://tahoe-lafs.org/source/pycryptopp/trunk: |
---|
2 | |
---|
3 | Sat Jul 3 10:21:28 Öйú±ê׼ʱ¼ä 2010 xueyu7452@gmail.com |
---|
4 | * part1.dpatch |
---|
5 | |
---|
6 | Sun Jul 4 12:11:06 Öйú±ê׼ʱ¼ä 2010 xueyu7452@gmail.com |
---|
7 | * xsalsa20.dpatch |
---|
8 | |
---|
9 | Sun Jul 4 12:30:39 Öйú±ê׼ʱ¼ä 2010 xueyu7452@gmail.com |
---|
10 | * hmac.dpatch |
---|
11 | |
---|
12 | Sun Jul 4 12:35:22 Öйú±ê׼ʱ¼ä 2010 xueyu7452@gmail.com |
---|
13 | * hkdf.dpatch |
---|
14 | |
---|
15 | New patches: |
---|
16 | |
---|
17 | [part1.dpatch |
---|
18 | xueyu7452@gmail.com**20100703022128 |
---|
19 | Ignore-this: e06eb0269745dc3eaf711891749dcbd0 |
---|
20 | ] { |
---|
21 | hunk ./pycryptopp/_pycryptoppmodule.cpp 8 |
---|
22 | #include "publickey/rsamodule.hpp" |
---|
23 | #include "hash/sha256module.hpp" |
---|
24 | #include "cipher/aesmodule.hpp" |
---|
25 | +#include "cipher/xsalsamodule.hpp" |
---|
26 | |
---|
27 | PyDoc_STRVAR(_pycryptopp__doc__, |
---|
28 | "_pycryptopp -- Python wrappers for a few algorithms from Crypto++\n\ |
---|
29 | hunk ./pycryptopp/_pycryptoppmodule.cpp 18 |
---|
30 | from pycryptopp.publickey import rsa\n\ |
---|
31 | from pycryptopp import cipher\n\ |
---|
32 | from pycryptopp.cipher import aes\n\ |
---|
33 | +from pycryptopp.cipher import xsalsa\n\ |
---|
34 | from pycryptopp import hash\n\ |
---|
35 | from pycryptopp.hash import sha256"); |
---|
36 | |
---|
37 | hunk ./pycryptopp/_pycryptoppmodule.cpp 44 |
---|
38 | init_rsa(module); |
---|
39 | init_sha256(module); |
---|
40 | init_aes(module); |
---|
41 | + init_xsalsa(module); |
---|
42 | } |
---|
43 | |
---|
44 | hunk ./pycryptopp/cipher/__init__.py 2 |
---|
45 | import aes |
---|
46 | +import xsalsa |
---|
47 | +#import ciphercombiner |
---|
48 | |
---|
49 | quiet_pyflakes=[aes] |
---|
50 | } |
---|
51 | [xsalsa20.dpatch |
---|
52 | xueyu7452@gmail.com**20100704041106 |
---|
53 | Ignore-this: bad22988183fb1ef8d387aaf0aecd8e5 |
---|
54 | ] { |
---|
55 | addfile ./cryptopp/salsa.cpp |
---|
56 | hunk ./cryptopp/salsa.cpp 1 |
---|
57 | +// salsa.cpp - written and placed in the public domain by Wei Dai |
---|
58 | + |
---|
59 | +// use "cl /EP /P /DCRYPTOPP_GENERATE_X64_MASM salsa.cpp" to generate MASM code |
---|
60 | + |
---|
61 | +#include "pch.h" |
---|
62 | + |
---|
63 | +#ifndef CRYPTOPP_GENERATE_X64_MASM |
---|
64 | + |
---|
65 | +#include "salsa.h" |
---|
66 | +#include "misc.h" |
---|
67 | +#include "argnames.h" |
---|
68 | +#include "cpu.h" |
---|
69 | + |
---|
70 | +NAMESPACE_BEGIN(CryptoPP) |
---|
71 | + |
---|
72 | +void Salsa20_TestInstantiations() |
---|
73 | +{ |
---|
74 | + Salsa20::Encryption x; |
---|
75 | +} |
---|
76 | + |
---|
77 | +void Salsa20_Policy::CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length) |
---|
78 | +{ |
---|
79 | + m_rounds = params.GetIntValueWithDefault(Name::Rounds(), 20); |
---|
80 | + |
---|
81 | + if (!(m_rounds == 8 || m_rounds == 12 || m_rounds == 20)) |
---|
82 | + throw InvalidRounds(Salsa20::StaticAlgorithmName(), m_rounds); |
---|
83 | + |
---|
84 | + // m_state is reordered for SSE2 |
---|
85 | + GetBlock<word32, LittleEndian> get1(key); |
---|
86 | + get1(m_state[13])(m_state[10])(m_state[7])(m_state[4]); |
---|
87 | + GetBlock<word32, LittleEndian> get2(key + length - 16); |
---|
88 | + get2(m_state[15])(m_state[12])(m_state[9])(m_state[6]); |
---|
89 | + |
---|
90 | + // "expand 16-byte k" or "expand 32-byte k" |
---|
91 | + m_state[0] = 0x61707865; |
---|
92 | + m_state[1] = (length == 16) ? 0x3120646e : 0x3320646e; |
---|
93 | + m_state[2] = (length == 16) ? 0x79622d36 : 0x79622d32; |
---|
94 | + m_state[3] = 0x6b206574; |
---|
95 | +} |
---|
96 | + |
---|
97 | +void Salsa20_Policy::CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length) |
---|
98 | +{ |
---|
99 | + assert(length==8); |
---|
100 | + GetBlock<word32, LittleEndian> get(IV); |
---|
101 | + get(m_state[14])(m_state[11]); |
---|
102 | + m_state[8] = m_state[5] = 0; |
---|
103 | +} |
---|
104 | + |
---|
105 | +void Salsa20_Policy::SeekToIteration(lword iterationCount) |
---|
106 | +{ |
---|
107 | + m_state[8] = (word32)iterationCount; |
---|
108 | + m_state[5] = (word32)SafeRightShift<32>(iterationCount); |
---|
109 | +} |
---|
110 | + |
---|
111 | +#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X64 |
---|
112 | +unsigned int Salsa20_Policy::GetAlignment() const |
---|
113 | +{ |
---|
114 | +#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE |
---|
115 | + if (HasSSE2()) |
---|
116 | + return 16; |
---|
117 | + else |
---|
118 | +#endif |
---|
119 | + return GetAlignmentOf<word32>(); |
---|
120 | +} |
---|
121 | + |
---|
122 | +unsigned int Salsa20_Policy::GetOptimalBlockSize() const |
---|
123 | +{ |
---|
124 | +#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE |
---|
125 | + if (HasSSE2()) |
---|
126 | + return 4*BYTES_PER_ITERATION; |
---|
127 | + else |
---|
128 | +#endif |
---|
129 | + return BYTES_PER_ITERATION; |
---|
130 | +} |
---|
131 | +#endif |
---|
132 | + |
---|
133 | +#ifdef CRYPTOPP_X64_MASM_AVAILABLE |
---|
134 | +extern "C" { |
---|
135 | +void Salsa20_OperateKeystream(byte *output, const byte *input, size_t iterationCount, int rounds, void *state); |
---|
136 | +} |
---|
137 | +#endif |
---|
138 | + |
---|
139 | +#pragma warning(disable: 4731) // frame pointer register 'ebp' modified by inline assembly code |
---|
140 | + |
---|
141 | +void Salsa20_Policy::OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount) |
---|
142 | +{ |
---|
143 | +#endif // #ifdef CRYPTOPP_GENERATE_X64_MASM |
---|
144 | + |
---|
145 | +#ifdef CRYPTOPP_X64_MASM_AVAILABLE |
---|
146 | + Salsa20_OperateKeystream(output, input, iterationCount, m_rounds, m_state.data()); |
---|
147 | + return; |
---|
148 | +#endif |
---|
149 | + |
---|
150 | +#if CRYPTOPP_BOOL_SSE2_ASM_AVAILABLE |
---|
151 | +#ifdef CRYPTOPP_GENERATE_X64_MASM |
---|
152 | + ALIGN 8 |
---|
153 | + Salsa20_OperateKeystream PROC FRAME |
---|
154 | + mov r10, [rsp + 5*8] ; state |
---|
155 | + alloc_stack(10*16 + 32*16 + 8) |
---|
156 | + save_xmm128 xmm6, 0200h |
---|
157 | + save_xmm128 xmm7, 0210h |
---|
158 | + save_xmm128 xmm8, 0220h |
---|
159 | + save_xmm128 xmm9, 0230h |
---|
160 | + save_xmm128 xmm10, 0240h |
---|
161 | + save_xmm128 xmm11, 0250h |
---|
162 | + save_xmm128 xmm12, 0260h |
---|
163 | + save_xmm128 xmm13, 0270h |
---|
164 | + save_xmm128 xmm14, 0280h |
---|
165 | + save_xmm128 xmm15, 0290h |
---|
166 | + .endprolog |
---|
167 | + |
---|
168 | + #define REG_output rcx |
---|
169 | + #define REG_input rdx |
---|
170 | + #define REG_iterationCount r8 |
---|
171 | + #define REG_state r10 |
---|
172 | + #define REG_rounds e9d |
---|
173 | + #define REG_roundsLeft eax |
---|
174 | + #define REG_temp32 r11d |
---|
175 | + #define REG_temp r11 |
---|
176 | + #define SSE2_WORKSPACE rsp |
---|
177 | +#else |
---|
178 | + if (HasSSE2()) |
---|
179 | + { |
---|
180 | + #if CRYPTOPP_BOOL_X64 |
---|
181 | + #define REG_output %4 |
---|
182 | + #define REG_input %1 |
---|
183 | + #define REG_iterationCount %2 |
---|
184 | + #define REG_state %3 |
---|
185 | + #define REG_rounds %0 |
---|
186 | + #define REG_roundsLeft eax |
---|
187 | + #define REG_temp32 edx |
---|
188 | + #define REG_temp rdx |
---|
189 | + #define SSE2_WORKSPACE %5 |
---|
190 | + |
---|
191 | + FixedSizeAlignedSecBlock<byte, 32*16> workspace; |
---|
192 | + #else |
---|
193 | + #define REG_output edi |
---|
194 | + #define REG_input eax |
---|
195 | + #define REG_iterationCount ecx |
---|
196 | + #define REG_state esi |
---|
197 | + #define REG_rounds edx |
---|
198 | + #define REG_roundsLeft ebx |
---|
199 | + #define REG_temp32 ebp |
---|
200 | + #define REG_temp ebp |
---|
201 | + #define SSE2_WORKSPACE esp + WORD_SZ |
---|
202 | + #endif |
---|
203 | + |
---|
204 | + #ifdef __GNUC__ |
---|
205 | + __asm__ __volatile__ |
---|
206 | + ( |
---|
207 | + ".intel_syntax noprefix;" |
---|
208 | + AS_PUSH_IF86( bx) |
---|
209 | + #else |
---|
210 | + void *s = m_state.data(); |
---|
211 | + word32 r = m_rounds; |
---|
212 | + |
---|
213 | + AS2( mov REG_iterationCount, iterationCount) |
---|
214 | + AS2( mov REG_input, input) |
---|
215 | + AS2( mov REG_output, output) |
---|
216 | + AS2( mov REG_state, s) |
---|
217 | + AS2( mov REG_rounds, r) |
---|
218 | + #endif |
---|
219 | +#endif // #ifndef CRYPTOPP_GENERATE_X64_MASM |
---|
220 | + |
---|
221 | + AS_PUSH_IF86( bp) |
---|
222 | + AS2( cmp REG_iterationCount, 4) |
---|
223 | + ASJ( jl, 5, f) |
---|
224 | + |
---|
225 | +#if CRYPTOPP_BOOL_X86 |
---|
226 | + AS2( mov ebx, esp) |
---|
227 | + AS2( and esp, -16) |
---|
228 | + AS2( sub esp, 32*16) |
---|
229 | + AS1( push ebx) |
---|
230 | +#endif |
---|
231 | + |
---|
232 | +#define SSE2_EXPAND_S(i, j) \ |
---|
233 | + ASS( pshufd xmm4, xmm##i, j, j, j, j) \ |
---|
234 | + AS2( movdqa [SSE2_WORKSPACE + (i*4+j)*16 + 256], xmm4) |
---|
235 | + |
---|
236 | + AS2( movdqa xmm0, [REG_state + 0*16]) |
---|
237 | + AS2( movdqa xmm1, [REG_state + 1*16]) |
---|
238 | + AS2( movdqa xmm2, [REG_state + 2*16]) |
---|
239 | + AS2( movdqa xmm3, [REG_state + 3*16]) |
---|
240 | + SSE2_EXPAND_S(0, 0) |
---|
241 | + SSE2_EXPAND_S(0, 1) |
---|
242 | + SSE2_EXPAND_S(0, 2) |
---|
243 | + SSE2_EXPAND_S(0, 3) |
---|
244 | + SSE2_EXPAND_S(1, 0) |
---|
245 | + SSE2_EXPAND_S(1, 2) |
---|
246 | + SSE2_EXPAND_S(1, 3) |
---|
247 | + SSE2_EXPAND_S(2, 1) |
---|
248 | + SSE2_EXPAND_S(2, 2) |
---|
249 | + SSE2_EXPAND_S(2, 3) |
---|
250 | + SSE2_EXPAND_S(3, 0) |
---|
251 | + SSE2_EXPAND_S(3, 1) |
---|
252 | + SSE2_EXPAND_S(3, 2) |
---|
253 | + SSE2_EXPAND_S(3, 3) |
---|
254 | + |
---|
255 | +#define SSE2_EXPAND_S85(i) \ |
---|
256 | + AS2( mov dword ptr [SSE2_WORKSPACE + 8*16 + i*4 + 256], REG_roundsLeft) \ |
---|
257 | + AS2( mov dword ptr [SSE2_WORKSPACE + 5*16 + i*4 + 256], REG_temp32) \ |
---|
258 | + AS2( add REG_roundsLeft, 1) \ |
---|
259 | + AS2( adc REG_temp32, 0) |
---|
260 | + |
---|
261 | + ASL(1) |
---|
262 | + AS2( mov REG_roundsLeft, dword ptr [REG_state + 8*4]) |
---|
263 | + AS2( mov REG_temp32, dword ptr [REG_state + 5*4]) |
---|
264 | + SSE2_EXPAND_S85(0) |
---|
265 | + SSE2_EXPAND_S85(1) |
---|
266 | + SSE2_EXPAND_S85(2) |
---|
267 | + SSE2_EXPAND_S85(3) |
---|
268 | + AS2( mov dword ptr [REG_state + 8*4], REG_roundsLeft) |
---|
269 | + AS2( mov dword ptr [REG_state + 5*4], REG_temp32) |
---|
270 | + |
---|
271 | +#define SSE2_QUARTER_ROUND(a, b, d, i) \ |
---|
272 | + AS2( movdqa xmm4, xmm##d) \ |
---|
273 | + AS2( paddd xmm4, xmm##a) \ |
---|
274 | + AS2( movdqa xmm5, xmm4) \ |
---|
275 | + AS2( pslld xmm4, i) \ |
---|
276 | + AS2( psrld xmm5, 32-i) \ |
---|
277 | + AS2( pxor xmm##b, xmm4) \ |
---|
278 | + AS2( pxor xmm##b, xmm5) |
---|
279 | + |
---|
280 | +#define L01(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##A, [SSE2_WORKSPACE + d*16 + i*256]) /* y3 */ |
---|
281 | +#define L02(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##C, [SSE2_WORKSPACE + a*16 + i*256]) /* y0 */ |
---|
282 | +#define L03(A,B,C,D,a,b,c,d,i) AS2( paddd xmm##A, xmm##C) /* y0+y3 */ |
---|
283 | +#define L04(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##B, xmm##A) |
---|
284 | +#define L05(A,B,C,D,a,b,c,d,i) AS2( pslld xmm##A, 7) |
---|
285 | +#define L06(A,B,C,D,a,b,c,d,i) AS2( psrld xmm##B, 32-7) |
---|
286 | +#define L07(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, [SSE2_WORKSPACE + b*16 + i*256]) |
---|
287 | +#define L08(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, xmm##B) /* z1 */ |
---|
288 | +#define L09(A,B,C,D,a,b,c,d,i) AS2( movdqa [SSE2_WORKSPACE + b*16], xmm##A) |
---|
289 | +#define L10(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##B, xmm##A) |
---|
290 | +#define L11(A,B,C,D,a,b,c,d,i) AS2( paddd xmm##A, xmm##C) /* z1+y0 */ |
---|
291 | +#define L12(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##D, xmm##A) |
---|
292 | +#define L13(A,B,C,D,a,b,c,d,i) AS2( pslld xmm##A, 9) |
---|
293 | +#define L14(A,B,C,D,a,b,c,d,i) AS2( psrld xmm##D, 32-9) |
---|
294 | +#define L15(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, [SSE2_WORKSPACE + c*16 + i*256]) |
---|
295 | +#define L16(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, xmm##D) /* z2 */ |
---|
296 | +#define L17(A,B,C,D,a,b,c,d,i) AS2( movdqa [SSE2_WORKSPACE + c*16], xmm##A) |
---|
297 | +#define L18(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##D, xmm##A) |
---|
298 | +#define L19(A,B,C,D,a,b,c,d,i) AS2( paddd xmm##A, xmm##B) /* z2+z1 */ |
---|
299 | +#define L20(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##B, xmm##A) |
---|
300 | +#define L21(A,B,C,D,a,b,c,d,i) AS2( pslld xmm##A, 13) |
---|
301 | +#define L22(A,B,C,D,a,b,c,d,i) AS2( psrld xmm##B, 32-13) |
---|
302 | +#define L23(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, [SSE2_WORKSPACE + d*16 + i*256]) |
---|
303 | +#define L24(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, xmm##B) /* z3 */ |
---|
304 | +#define L25(A,B,C,D,a,b,c,d,i) AS2( movdqa [SSE2_WORKSPACE + d*16], xmm##A) |
---|
305 | +#define L26(A,B,C,D,a,b,c,d,i) AS2( paddd xmm##A, xmm##D) /* z3+z2 */ |
---|
306 | +#define L27(A,B,C,D,a,b,c,d,i) AS2( movdqa xmm##D, xmm##A) |
---|
307 | +#define L28(A,B,C,D,a,b,c,d,i) AS2( pslld xmm##A, 18) |
---|
308 | +#define L29(A,B,C,D,a,b,c,d,i) AS2( psrld xmm##D, 32-18) |
---|
309 | +#define L30(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, xmm##C) /* xor y0 */ |
---|
310 | +#define L31(A,B,C,D,a,b,c,d,i) AS2( pxor xmm##A, xmm##D) /* z0 */ |
---|
311 | +#define L32(A,B,C,D,a,b,c,d,i) AS2( movdqa [SSE2_WORKSPACE + a*16], xmm##A) |
---|
312 | + |
---|
313 | +#define SSE2_QUARTER_ROUND_X8(i, a, b, c, d, e, f, g, h) \ |
---|
314 | + L01(0,1,2,3, a,b,c,d, i) L01(4,5,6,7, e,f,g,h, i) \ |
---|
315 | + L02(0,1,2,3, a,b,c,d, i) L02(4,5,6,7, e,f,g,h, i) \ |
---|
316 | + L03(0,1,2,3, a,b,c,d, i) L03(4,5,6,7, e,f,g,h, i) \ |
---|
317 | + L04(0,1,2,3, a,b,c,d, i) L04(4,5,6,7, e,f,g,h, i) \ |
---|
318 | + L05(0,1,2,3, a,b,c,d, i) L05(4,5,6,7, e,f,g,h, i) \ |
---|
319 | + L06(0,1,2,3, a,b,c,d, i) L06(4,5,6,7, e,f,g,h, i) \ |
---|
320 | + L07(0,1,2,3, a,b,c,d, i) L07(4,5,6,7, e,f,g,h, i) \ |
---|
321 | + L08(0,1,2,3, a,b,c,d, i) L08(4,5,6,7, e,f,g,h, i) \ |
---|
322 | + L09(0,1,2,3, a,b,c,d, i) L09(4,5,6,7, e,f,g,h, i) \ |
---|
323 | + L10(0,1,2,3, a,b,c,d, i) L10(4,5,6,7, e,f,g,h, i) \ |
---|
324 | + L11(0,1,2,3, a,b,c,d, i) L11(4,5,6,7, e,f,g,h, i) \ |
---|
325 | + L12(0,1,2,3, a,b,c,d, i) L12(4,5,6,7, e,f,g,h, i) \ |
---|
326 | + L13(0,1,2,3, a,b,c,d, i) L13(4,5,6,7, e,f,g,h, i) \ |
---|
327 | + L14(0,1,2,3, a,b,c,d, i) L14(4,5,6,7, e,f,g,h, i) \ |
---|
328 | + L15(0,1,2,3, a,b,c,d, i) L15(4,5,6,7, e,f,g,h, i) \ |
---|
329 | + L16(0,1,2,3, a,b,c,d, i) L16(4,5,6,7, e,f,g,h, i) \ |
---|
330 | + L17(0,1,2,3, a,b,c,d, i) L17(4,5,6,7, e,f,g,h, i) \ |
---|
331 | + L18(0,1,2,3, a,b,c,d, i) L18(4,5,6,7, e,f,g,h, i) \ |
---|
332 | + L19(0,1,2,3, a,b,c,d, i) L19(4,5,6,7, e,f,g,h, i) \ |
---|
333 | + L20(0,1,2,3, a,b,c,d, i) L20(4,5,6,7, e,f,g,h, i) \ |
---|
334 | + L21(0,1,2,3, a,b,c,d, i) L21(4,5,6,7, e,f,g,h, i) \ |
---|
335 | + L22(0,1,2,3, a,b,c,d, i) L22(4,5,6,7, e,f,g,h, i) \ |
---|
336 | + L23(0,1,2,3, a,b,c,d, i) L23(4,5,6,7, e,f,g,h, i) \ |
---|
337 | + L24(0,1,2,3, a,b,c,d, i) L24(4,5,6,7, e,f,g,h, i) \ |
---|
338 | + L25(0,1,2,3, a,b,c,d, i) L25(4,5,6,7, e,f,g,h, i) \ |
---|
339 | + L26(0,1,2,3, a,b,c,d, i) L26(4,5,6,7, e,f,g,h, i) \ |
---|
340 | + L27(0,1,2,3, a,b,c,d, i) L27(4,5,6,7, e,f,g,h, i) \ |
---|
341 | + L28(0,1,2,3, a,b,c,d, i) L28(4,5,6,7, e,f,g,h, i) \ |
---|
342 | + L29(0,1,2,3, a,b,c,d, i) L29(4,5,6,7, e,f,g,h, i) \ |
---|
343 | + L30(0,1,2,3, a,b,c,d, i) L30(4,5,6,7, e,f,g,h, i) \ |
---|
344 | + L31(0,1,2,3, a,b,c,d, i) L31(4,5,6,7, e,f,g,h, i) \ |
---|
345 | + L32(0,1,2,3, a,b,c,d, i) L32(4,5,6,7, e,f,g,h, i) |
---|
346 | + |
---|
347 | +#define SSE2_QUARTER_ROUND_X16(i, a, b, c, d, e, f, g, h, A, B, C, D, E, F, G, H) \ |
---|
348 | + L01(0,1,2,3, a,b,c,d, i) L01(4,5,6,7, e,f,g,h, i) L01(8,9,10,11, A,B,C,D, i) L01(12,13,14,15, E,F,G,H, i) \ |
---|
349 | + L02(0,1,2,3, a,b,c,d, i) L02(4,5,6,7, e,f,g,h, i) L02(8,9,10,11, A,B,C,D, i) L02(12,13,14,15, E,F,G,H, i) \ |
---|
350 | + L03(0,1,2,3, a,b,c,d, i) L03(4,5,6,7, e,f,g,h, i) L03(8,9,10,11, A,B,C,D, i) L03(12,13,14,15, E,F,G,H, i) \ |
---|
351 | + L04(0,1,2,3, a,b,c,d, i) L04(4,5,6,7, e,f,g,h, i) L04(8,9,10,11, A,B,C,D, i) L04(12,13,14,15, E,F,G,H, i) \ |
---|
352 | + L05(0,1,2,3, a,b,c,d, i) L05(4,5,6,7, e,f,g,h, i) L05(8,9,10,11, A,B,C,D, i) L05(12,13,14,15, E,F,G,H, i) \ |
---|
353 | + L06(0,1,2,3, a,b,c,d, i) L06(4,5,6,7, e,f,g,h, i) L06(8,9,10,11, A,B,C,D, i) L06(12,13,14,15, E,F,G,H, i) \ |
---|
354 | + L07(0,1,2,3, a,b,c,d, i) L07(4,5,6,7, e,f,g,h, i) L07(8,9,10,11, A,B,C,D, i) L07(12,13,14,15, E,F,G,H, i) \ |
---|
355 | + L08(0,1,2,3, a,b,c,d, i) L08(4,5,6,7, e,f,g,h, i) L08(8,9,10,11, A,B,C,D, i) L08(12,13,14,15, E,F,G,H, i) \ |
---|
356 | + L09(0,1,2,3, a,b,c,d, i) L09(4,5,6,7, e,f,g,h, i) L09(8,9,10,11, A,B,C,D, i) L09(12,13,14,15, E,F,G,H, i) \ |
---|
357 | + L10(0,1,2,3, a,b,c,d, i) L10(4,5,6,7, e,f,g,h, i) L10(8,9,10,11, A,B,C,D, i) L10(12,13,14,15, E,F,G,H, i) \ |
---|
358 | + L11(0,1,2,3, a,b,c,d, i) L11(4,5,6,7, e,f,g,h, i) L11(8,9,10,11, A,B,C,D, i) L11(12,13,14,15, E,F,G,H, i) \ |
---|
359 | + L12(0,1,2,3, a,b,c,d, i) L12(4,5,6,7, e,f,g,h, i) L12(8,9,10,11, A,B,C,D, i) L12(12,13,14,15, E,F,G,H, i) \ |
---|
360 | + L13(0,1,2,3, a,b,c,d, i) L13(4,5,6,7, e,f,g,h, i) L13(8,9,10,11, A,B,C,D, i) L13(12,13,14,15, E,F,G,H, i) \ |
---|
361 | + L14(0,1,2,3, a,b,c,d, i) L14(4,5,6,7, e,f,g,h, i) L14(8,9,10,11, A,B,C,D, i) L14(12,13,14,15, E,F,G,H, i) \ |
---|
362 | + L15(0,1,2,3, a,b,c,d, i) L15(4,5,6,7, e,f,g,h, i) L15(8,9,10,11, A,B,C,D, i) L15(12,13,14,15, E,F,G,H, i) \ |
---|
363 | + L16(0,1,2,3, a,b,c,d, i) L16(4,5,6,7, e,f,g,h, i) L16(8,9,10,11, A,B,C,D, i) L16(12,13,14,15, E,F,G,H, i) \ |
---|
364 | + L17(0,1,2,3, a,b,c,d, i) L17(4,5,6,7, e,f,g,h, i) L17(8,9,10,11, A,B,C,D, i) L17(12,13,14,15, E,F,G,H, i) \ |
---|
365 | + L18(0,1,2,3, a,b,c,d, i) L18(4,5,6,7, e,f,g,h, i) L18(8,9,10,11, A,B,C,D, i) L18(12,13,14,15, E,F,G,H, i) \ |
---|
366 | + L19(0,1,2,3, a,b,c,d, i) L19(4,5,6,7, e,f,g,h, i) L19(8,9,10,11, A,B,C,D, i) L19(12,13,14,15, E,F,G,H, i) \ |
---|
367 | + L20(0,1,2,3, a,b,c,d, i) L20(4,5,6,7, e,f,g,h, i) L20(8,9,10,11, A,B,C,D, i) L20(12,13,14,15, E,F,G,H, i) \ |
---|
368 | + L21(0,1,2,3, a,b,c,d, i) L21(4,5,6,7, e,f,g,h, i) L21(8,9,10,11, A,B,C,D, i) L21(12,13,14,15, E,F,G,H, i) \ |
---|
369 | + L22(0,1,2,3, a,b,c,d, i) L22(4,5,6,7, e,f,g,h, i) L22(8,9,10,11, A,B,C,D, i) L22(12,13,14,15, E,F,G,H, i) \ |
---|
370 | + L23(0,1,2,3, a,b,c,d, i) L23(4,5,6,7, e,f,g,h, i) L23(8,9,10,11, A,B,C,D, i) L23(12,13,14,15, E,F,G,H, i) \ |
---|
371 | + L24(0,1,2,3, a,b,c,d, i) L24(4,5,6,7, e,f,g,h, i) L24(8,9,10,11, A,B,C,D, i) L24(12,13,14,15, E,F,G,H, i) \ |
---|
372 | + L25(0,1,2,3, a,b,c,d, i) L25(4,5,6,7, e,f,g,h, i) L25(8,9,10,11, A,B,C,D, i) L25(12,13,14,15, E,F,G,H, i) \ |
---|
373 | + L26(0,1,2,3, a,b,c,d, i) L26(4,5,6,7, e,f,g,h, i) L26(8,9,10,11, A,B,C,D, i) L26(12,13,14,15, E,F,G,H, i) \ |
---|
374 | + L27(0,1,2,3, a,b,c,d, i) L27(4,5,6,7, e,f,g,h, i) L27(8,9,10,11, A,B,C,D, i) L27(12,13,14,15, E,F,G,H, i) \ |
---|
375 | + L28(0,1,2,3, a,b,c,d, i) L28(4,5,6,7, e,f,g,h, i) L28(8,9,10,11, A,B,C,D, i) L28(12,13,14,15, E,F,G,H, i) \ |
---|
376 | + L29(0,1,2,3, a,b,c,d, i) L29(4,5,6,7, e,f,g,h, i) L29(8,9,10,11, A,B,C,D, i) L29(12,13,14,15, E,F,G,H, i) \ |
---|
377 | + L30(0,1,2,3, a,b,c,d, i) L30(4,5,6,7, e,f,g,h, i) L30(8,9,10,11, A,B,C,D, i) L30(12,13,14,15, E,F,G,H, i) \ |
---|
378 | + L31(0,1,2,3, a,b,c,d, i) L31(4,5,6,7, e,f,g,h, i) L31(8,9,10,11, A,B,C,D, i) L31(12,13,14,15, E,F,G,H, i) \ |
---|
379 | + L32(0,1,2,3, a,b,c,d, i) L32(4,5,6,7, e,f,g,h, i) L32(8,9,10,11, A,B,C,D, i) L32(12,13,14,15, E,F,G,H, i) |
---|
380 | + |
---|
381 | +#if CRYPTOPP_BOOL_X64 |
---|
382 | + SSE2_QUARTER_ROUND_X16(1, 0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15) |
---|
383 | +#else |
---|
384 | + SSE2_QUARTER_ROUND_X8(1, 2, 6, 10, 14, 3, 7, 11, 15) |
---|
385 | + SSE2_QUARTER_ROUND_X8(1, 0, 4, 8, 12, 1, 5, 9, 13) |
---|
386 | +#endif |
---|
387 | + AS2( mov REG_roundsLeft, REG_rounds) |
---|
388 | + ASJ( jmp, 2, f) |
---|
389 | + |
---|
390 | + ASL(SSE2_Salsa_Output) |
---|
391 | + AS2( movdqa xmm0, xmm4) |
---|
392 | + AS2( punpckldq xmm4, xmm5) |
---|
393 | + AS2( movdqa xmm1, xmm6) |
---|
394 | + AS2( punpckldq xmm6, xmm7) |
---|
395 | + AS2( movdqa xmm2, xmm4) |
---|
396 | + AS2( punpcklqdq xmm4, xmm6) // e |
---|
397 | + AS2( punpckhqdq xmm2, xmm6) // f |
---|
398 | + AS2( punpckhdq xmm0, xmm5) |
---|
399 | + AS2( punpckhdq xmm1, xmm7) |
---|
400 | + AS2( movdqa xmm6, xmm0) |
---|
401 | + AS2( punpcklqdq xmm0, xmm1) // g |
---|
402 | + AS2( punpckhqdq xmm6, xmm1) // h |
---|
403 | + AS_XMM_OUTPUT4(SSE2_Salsa_Output_A, REG_input, REG_output, 4, 2, 0, 6, 1, 0, 4, 8, 12, 1) |
---|
404 | + AS1( ret) |
---|
405 | + |
---|
406 | + ASL(6) |
---|
407 | +#if CRYPTOPP_BOOL_X64 |
---|
408 | + SSE2_QUARTER_ROUND_X16(0, 0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15) |
---|
409 | + ASL(2) |
---|
410 | + SSE2_QUARTER_ROUND_X16(0, 0, 13, 10, 7, 1, 14, 11, 4, 2, 15, 8, 5, 3, 12, 9, 6) |
---|
411 | +#else |
---|
412 | + SSE2_QUARTER_ROUND_X8(0, 2, 6, 10, 14, 3, 7, 11, 15) |
---|
413 | + SSE2_QUARTER_ROUND_X8(0, 0, 4, 8, 12, 1, 5, 9, 13) |
---|
414 | + ASL(2) |
---|
415 | + SSE2_QUARTER_ROUND_X8(0, 2, 15, 8, 5, 3, 12, 9, 6) |
---|
416 | + SSE2_QUARTER_ROUND_X8(0, 0, 13, 10, 7, 1, 14, 11, 4) |
---|
417 | +#endif |
---|
418 | + AS2( sub REG_roundsLeft, 2) |
---|
419 | + ASJ( jnz, 6, b) |
---|
420 | + |
---|
421 | +#define SSE2_OUTPUT_4(a, b, c, d) \ |
---|
422 | + AS2( movdqa xmm4, [SSE2_WORKSPACE + a*16 + 256])\ |
---|
423 | + AS2( paddd xmm4, [SSE2_WORKSPACE + a*16])\ |
---|
424 | + AS2( movdqa xmm5, [SSE2_WORKSPACE + b*16 + 256])\ |
---|
425 | + AS2( paddd xmm5, [SSE2_WORKSPACE + b*16])\ |
---|
426 | + AS2( movdqa xmm6, [SSE2_WORKSPACE + c*16 + 256])\ |
---|
427 | + AS2( paddd xmm6, [SSE2_WORKSPACE + c*16])\ |
---|
428 | + AS2( movdqa xmm7, [SSE2_WORKSPACE + d*16 + 256])\ |
---|
429 | + AS2( paddd xmm7, [SSE2_WORKSPACE + d*16])\ |
---|
430 | + ASC( call, SSE2_Salsa_Output) |
---|
431 | + |
---|
432 | + SSE2_OUTPUT_4(0, 13, 10, 7) |
---|
433 | + SSE2_OUTPUT_4(4, 1, 14, 11) |
---|
434 | + SSE2_OUTPUT_4(8, 5, 2, 15) |
---|
435 | + SSE2_OUTPUT_4(12, 9, 6, 3) |
---|
436 | + AS2( test REG_input, REG_input) |
---|
437 | + ASJ( jz, 9, f) |
---|
438 | + AS2( add REG_input, 12*16) |
---|
439 | + ASL(9) |
---|
440 | + AS2( add REG_output, 12*16) |
---|
441 | + AS2( sub REG_iterationCount, 4) |
---|
442 | + AS2( cmp REG_iterationCount, 4) |
---|
443 | + ASJ( jge, 1, b) |
---|
444 | + AS_POP_IF86( sp) |
---|
445 | + |
---|
446 | + ASL(5) |
---|
447 | + AS2( sub REG_iterationCount, 1) |
---|
448 | + ASJ( jl, 4, f) |
---|
449 | + AS2( movdqa xmm0, [REG_state + 0*16]) |
---|
450 | + AS2( movdqa xmm1, [REG_state + 1*16]) |
---|
451 | + AS2( movdqa xmm2, [REG_state + 2*16]) |
---|
452 | + AS2( movdqa xmm3, [REG_state + 3*16]) |
---|
453 | + AS2( mov REG_roundsLeft, REG_rounds) |
---|
454 | + |
---|
455 | + ASL(0) |
---|
456 | + SSE2_QUARTER_ROUND(0, 1, 3, 7) |
---|
457 | + SSE2_QUARTER_ROUND(1, 2, 0, 9) |
---|
458 | + SSE2_QUARTER_ROUND(2, 3, 1, 13) |
---|
459 | + SSE2_QUARTER_ROUND(3, 0, 2, 18) |
---|
460 | + ASS( pshufd xmm1, xmm1, 2, 1, 0, 3) |
---|
461 | + ASS( pshufd xmm2, xmm2, 1, 0, 3, 2) |
---|
462 | + ASS( pshufd xmm3, xmm3, 0, 3, 2, 1) |
---|
463 | + SSE2_QUARTER_ROUND(0, 3, 1, 7) |
---|
464 | + SSE2_QUARTER_ROUND(3, 2, 0, 9) |
---|
465 | + SSE2_QUARTER_ROUND(2, 1, 3, 13) |
---|
466 | + SSE2_QUARTER_ROUND(1, 0, 2, 18) |
---|
467 | + ASS( pshufd xmm1, xmm1, 0, 3, 2, 1) |
---|
468 | + ASS( pshufd xmm2, xmm2, 1, 0, 3, 2) |
---|
469 | + ASS( pshufd xmm3, xmm3, 2, 1, 0, 3) |
---|
470 | + AS2( sub REG_roundsLeft, 2) |
---|
471 | + ASJ( jnz, 0, b) |
---|
472 | + |
---|
473 | + AS2( paddd xmm0, [REG_state + 0*16]) |
---|
474 | + AS2( paddd xmm1, [REG_state + 1*16]) |
---|
475 | + AS2( paddd xmm2, [REG_state + 2*16]) |
---|
476 | + AS2( paddd xmm3, [REG_state + 3*16]) |
---|
477 | + |
---|
478 | + AS2( add dword ptr [REG_state + 8*4], 1) |
---|
479 | + AS2( adc dword ptr [REG_state + 5*4], 0) |
---|
480 | + |
---|
481 | + AS2( pcmpeqb xmm6, xmm6) // all ones |
---|
482 | + AS2( psrlq xmm6, 32) // lo32 mask |
---|
483 | + ASS( pshufd xmm7, xmm6, 0, 1, 2, 3) // hi32 mask |
---|
484 | + AS2( movdqa xmm4, xmm0) |
---|
485 | + AS2( movdqa xmm5, xmm3) |
---|
486 | + AS2( pand xmm0, xmm7) |
---|
487 | + AS2( pand xmm4, xmm6) |
---|
488 | + AS2( pand xmm3, xmm6) |
---|
489 | + AS2( pand xmm5, xmm7) |
---|
490 | + AS2( por xmm4, xmm5) // 0,13,2,15 |
---|
491 | + AS2( movdqa xmm5, xmm1) |
---|
492 | + AS2( pand xmm1, xmm7) |
---|
493 | + AS2( pand xmm5, xmm6) |
---|
494 | + AS2( por xmm0, xmm5) // 4,1,6,3 |
---|
495 | + AS2( pand xmm6, xmm2) |
---|
496 | + AS2( pand xmm2, xmm7) |
---|
497 | + AS2( por xmm1, xmm6) // 8,5,10,7 |
---|
498 | + AS2( por xmm2, xmm3) // 12,9,14,11 |
---|
499 | + |
---|
500 | + AS2( movdqa xmm5, xmm4) |
---|
501 | + AS2( movdqa xmm6, xmm0) |
---|
502 | + AS3( shufpd xmm4, xmm1, 2) // 0,13,10,7 |
---|
503 | + AS3( shufpd xmm0, xmm2, 2) // 4,1,14,11 |
---|
504 | + AS3( shufpd xmm1, xmm5, 2) // 8,5,2,15 |
---|
505 | + AS3( shufpd xmm2, xmm6, 2) // 12,9,6,3 |
---|
506 | + |
---|
507 | + // output keystream |
---|
508 | + AS_XMM_OUTPUT4(SSE2_Salsa_Output_B, REG_input, REG_output, 4, 0, 1, 2, 3, 0, 1, 2, 3, 4) |
---|
509 | + ASJ( jmp, 5, b) |
---|
510 | + ASL(4) |
---|
511 | + |
---|
512 | + AS_POP_IF86( bp) |
---|
513 | +#ifdef __GNUC__ |
---|
514 | + AS_POP_IF86( bx) |
---|
515 | + ".att_syntax prefix;" |
---|
516 | + : |
---|
517 | + #if CRYPTOPP_BOOL_X64 |
---|
518 | + : "r" (m_rounds), "r" (input), "r" (iterationCount), "r" (m_state.data()), "r" (output), "r" (workspace.m_ptr) |
---|
519 | + : "%eax", "%edx", "memory", "cc", "%xmm0", "%xmm1", "%xmm2", "%xmm3", "%xmm4", "%xmm5", "%xmm6", "%xmm7", "%xmm8", "%xmm9", "%xmm10", "%xmm11", "%xmm12", "%xmm13", "%xmm14", "%xmm15" |
---|
520 | + #else |
---|
521 | + : "d" (m_rounds), "a" (input), "c" (iterationCount), "S" (m_state.data()), "D" (output) |
---|
522 | + : "memory", "cc" |
---|
523 | + #endif |
---|
524 | + ); |
---|
525 | +#endif |
---|
526 | +#ifdef CRYPTOPP_GENERATE_X64_MASM |
---|
527 | + movdqa xmm6, [rsp + 0200h] |
---|
528 | + movdqa xmm7, [rsp + 0210h] |
---|
529 | + movdqa xmm8, [rsp + 0220h] |
---|
530 | + movdqa xmm9, [rsp + 0230h] |
---|
531 | + movdqa xmm10, [rsp + 0240h] |
---|
532 | + movdqa xmm11, [rsp + 0250h] |
---|
533 | + movdqa xmm12, [rsp + 0260h] |
---|
534 | + movdqa xmm13, [rsp + 0270h] |
---|
535 | + movdqa xmm14, [rsp + 0280h] |
---|
536 | + movdqa xmm15, [rsp + 0290h] |
---|
537 | + add rsp, 10*16 + 32*16 + 8 |
---|
538 | + ret |
---|
539 | +Salsa20_OperateKeystream ENDP |
---|
540 | +#else |
---|
541 | + } |
---|
542 | + else |
---|
543 | +#endif |
---|
544 | +#endif |
---|
545 | +#ifndef CRYPTOPP_GENERATE_X64_MASM |
---|
546 | + { |
---|
547 | + word32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15; |
---|
548 | + |
---|
549 | + while (iterationCount--) |
---|
550 | + { |
---|
551 | + x0 = m_state[0]; x1 = m_state[1]; x2 = m_state[2]; x3 = m_state[3]; |
---|
552 | + x4 = m_state[4]; x5 = m_state[5]; x6 = m_state[6]; x7 = m_state[7]; |
---|
553 | + x8 = m_state[8]; x9 = m_state[9]; x10 = m_state[10]; x11 = m_state[11]; |
---|
554 | + x12 = m_state[12]; x13 = m_state[13]; x14 = m_state[14]; x15 = m_state[15]; |
---|
555 | + |
---|
556 | + for (int i=m_rounds; i>0; i-=2) |
---|
557 | + { |
---|
558 | + #define QUARTER_ROUND(a, b, c, d) \ |
---|
559 | + b = b ^ rotlFixed(a + d, 7); \ |
---|
560 | + c = c ^ rotlFixed(b + a, 9); \ |
---|
561 | + d = d ^ rotlFixed(c + b, 13); \ |
---|
562 | + a = a ^ rotlFixed(d + c, 18); |
---|
563 | + |
---|
564 | + QUARTER_ROUND(x0, x4, x8, x12) |
---|
565 | + QUARTER_ROUND(x1, x5, x9, x13) |
---|
566 | + QUARTER_ROUND(x2, x6, x10, x14) |
---|
567 | + QUARTER_ROUND(x3, x7, x11, x15) |
---|
568 | + |
---|
569 | + QUARTER_ROUND(x0, x13, x10, x7) |
---|
570 | + QUARTER_ROUND(x1, x14, x11, x4) |
---|
571 | + QUARTER_ROUND(x2, x15, x8, x5) |
---|
572 | + QUARTER_ROUND(x3, x12, x9, x6) |
---|
573 | + } |
---|
574 | + |
---|
575 | + #define SALSA_OUTPUT(x) {\ |
---|
576 | + CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, LITTLE_ENDIAN_ORDER, 0, x0 + m_state[0]);\ |
---|
577 | + CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, LITTLE_ENDIAN_ORDER, 1, x13 + m_state[13]);\ |
---|
578 | + CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, LITTLE_ENDIAN_ORDER, 2, x10 + m_state[10]);\ |
---|
579 | + CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, LITTLE_ENDIAN_ORDER, 3, x7 + m_state[7]);\ |
---|
580 | + CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, LITTLE_ENDIAN_ORDER, 4, x4 + m_state[4]);\ |
---|
581 | + CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, LITTLE_ENDIAN_ORDER, 5, x1 + m_state[1]);\ |
---|
582 | + CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, LITTLE_ENDIAN_ORDER, 6, x14 + m_state[14]);\ |
---|
583 | + CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, LITTLE_ENDIAN_ORDER, 7, x11 + m_state[11]);\ |
---|
584 | + CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, LITTLE_ENDIAN_ORDER, 8, x8 + m_state[8]);\ |
---|
585 | + CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, LITTLE_ENDIAN_ORDER, 9, x5 + m_state[5]);\ |
---|
586 | + CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, LITTLE_ENDIAN_ORDER, 10, x2 + m_state[2]);\ |
---|
587 | + CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, LITTLE_ENDIAN_ORDER, 11, x15 + m_state[15]);\ |
---|
588 | + CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, LITTLE_ENDIAN_ORDER, 12, x12 + m_state[12]);\ |
---|
589 | + CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, LITTLE_ENDIAN_ORDER, 13, x9 + m_state[9]);\ |
---|
590 | + CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, LITTLE_ENDIAN_ORDER, 14, x6 + m_state[6]);\ |
---|
591 | + CRYPTOPP_KEYSTREAM_OUTPUT_WORD(x, LITTLE_ENDIAN_ORDER, 15, x3 + m_state[3]);} |
---|
592 | + |
---|
593 | +#ifndef CRYPTOPP_DOXYGEN_PROCESSING |
---|
594 | + CRYPTOPP_KEYSTREAM_OUTPUT_SWITCH(SALSA_OUTPUT, BYTES_PER_ITERATION); |
---|
595 | +#endif |
---|
596 | + |
---|
597 | + if (++m_state[8] == 0) |
---|
598 | + ++m_state[5]; |
---|
599 | + } |
---|
600 | + } |
---|
601 | +} // see comment above if an internal compiler error occurs here |
---|
602 | + |
---|
603 | +void XSalsa20_Policy::CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length) |
---|
604 | +{ |
---|
605 | + m_rounds = params.GetIntValueWithDefault(Name::Rounds(), 20); |
---|
606 | + |
---|
607 | + if (!(m_rounds == 8 || m_rounds == 12 || m_rounds == 20)) |
---|
608 | + throw InvalidRounds(XSalsa20::StaticAlgorithmName(), m_rounds); |
---|
609 | + |
---|
610 | + GetUserKey(LITTLE_ENDIAN_ORDER, m_key.begin(), m_key.size(), key, length); |
---|
611 | + if (length == 16) |
---|
612 | + memcpy(m_key.begin()+4, m_key.begin(), 16); |
---|
613 | + |
---|
614 | + // "expand 32-byte k" |
---|
615 | + m_state[0] = 0x61707865; |
---|
616 | + m_state[1] = 0x3320646e; |
---|
617 | + m_state[2] = 0x79622d32; |
---|
618 | + m_state[3] = 0x6b206574; |
---|
619 | +} |
---|
620 | + |
---|
621 | +void XSalsa20_Policy::CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length) |
---|
622 | +{ |
---|
623 | + assert(length==24); |
---|
624 | + |
---|
625 | + word32 x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15; |
---|
626 | + |
---|
627 | + GetBlock<word32, LittleEndian> get(IV); |
---|
628 | + get(x14)(x11)(x8)(x5)(m_state[14])(m_state[11]); |
---|
629 | + |
---|
630 | + x13 = m_key[0]; x10 = m_key[1]; x7 = m_key[2]; x4 = m_key[3]; |
---|
631 | + x15 = m_key[4]; x12 = m_key[5]; x9 = m_key[6]; x6 = m_key[7]; |
---|
632 | + x0 = m_state[0]; x1 = m_state[1]; x2 = m_state[2]; x3 = m_state[3]; |
---|
633 | + |
---|
634 | + for (int i=m_rounds; i>0; i-=2) |
---|
635 | + { |
---|
636 | + QUARTER_ROUND(x0, x4, x8, x12) |
---|
637 | + QUARTER_ROUND(x1, x5, x9, x13) |
---|
638 | + QUARTER_ROUND(x2, x6, x10, x14) |
---|
639 | + QUARTER_ROUND(x3, x7, x11, x15) |
---|
640 | + |
---|
641 | + QUARTER_ROUND(x0, x13, x10, x7) |
---|
642 | + QUARTER_ROUND(x1, x14, x11, x4) |
---|
643 | + QUARTER_ROUND(x2, x15, x8, x5) |
---|
644 | + QUARTER_ROUND(x3, x12, x9, x6) |
---|
645 | + } |
---|
646 | + |
---|
647 | + m_state[13] = x0; m_state[10] = x1; m_state[7] = x2; m_state[4] = x3; |
---|
648 | + m_state[15] = x14; m_state[12] = x11; m_state[9] = x8; m_state[6] = x5; |
---|
649 | + m_state[8] = m_state[5] = 0; |
---|
650 | +} |
---|
651 | + |
---|
652 | +NAMESPACE_END |
---|
653 | + |
---|
654 | +#endif // #ifndef CRYPTOPP_GENERATE_X64_MASM |
---|
655 | addfile ./cryptopp/salsa.h |
---|
656 | hunk ./cryptopp/salsa.h 1 |
---|
657 | +// salsa.h - written and placed in the public domain by Wei Dai |
---|
658 | + |
---|
659 | +#ifndef CRYPTOPP_SALSA_H |
---|
660 | +#define CRYPTOPP_SALSA_H |
---|
661 | + |
---|
662 | +#include "strciphr.h" |
---|
663 | + |
---|
664 | +NAMESPACE_BEGIN(CryptoPP) |
---|
665 | + |
---|
666 | +//! _ |
---|
667 | +struct Salsa20_Info : public VariableKeyLength<32, 16, 32, 16, SimpleKeyingInterface::UNIQUE_IV, 8> |
---|
668 | +{ |
---|
669 | + static const char *StaticAlgorithmName() {return "Salsa20";} |
---|
670 | +}; |
---|
671 | + |
---|
672 | +class CRYPTOPP_NO_VTABLE Salsa20_Policy : public AdditiveCipherConcretePolicy<word32, 16> |
---|
673 | +{ |
---|
674 | +protected: |
---|
675 | + void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length); |
---|
676 | + void OperateKeystream(KeystreamOperation operation, byte *output, const byte *input, size_t iterationCount); |
---|
677 | + void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length); |
---|
678 | + bool CipherIsRandomAccess() const {return true;} |
---|
679 | + void SeekToIteration(lword iterationCount); |
---|
680 | +#if CRYPTOPP_BOOL_X86 || CRYPTOPP_BOOL_X64 |
---|
681 | + unsigned int GetAlignment() const; |
---|
682 | + unsigned int GetOptimalBlockSize() const; |
---|
683 | +#endif |
---|
684 | + |
---|
685 | + FixedSizeAlignedSecBlock<word32, 16> m_state; |
---|
686 | + int m_rounds; |
---|
687 | +}; |
---|
688 | + |
---|
689 | +/// <a href="http://www.cryptolounge.org/wiki/Salsa20">Salsa20</a>, variable rounds: 8, 12 or 20 (default 20) |
---|
690 | +struct Salsa20 : public Salsa20_Info, public SymmetricCipherDocumentation |
---|
691 | +{ |
---|
692 | + typedef SymmetricCipherFinal<ConcretePolicyHolder<Salsa20_Policy, AdditiveCipherTemplate<> >, Salsa20_Info> Encryption; |
---|
693 | + typedef Encryption Decryption; |
---|
694 | +}; |
---|
695 | + |
---|
696 | +//! _ |
---|
697 | +struct XSalsa20_Info : public FixedKeyLength<32, SimpleKeyingInterface::UNIQUE_IV, 24> |
---|
698 | +{ |
---|
699 | + static const char *StaticAlgorithmName() {return "XSalsa20";} |
---|
700 | +}; |
---|
701 | + |
---|
702 | +class CRYPTOPP_NO_VTABLE XSalsa20_Policy : public Salsa20_Policy |
---|
703 | +{ |
---|
704 | +public: |
---|
705 | + void CipherSetKey(const NameValuePairs ¶ms, const byte *key, size_t length); |
---|
706 | + void CipherResynchronize(byte *keystreamBuffer, const byte *IV, size_t length); |
---|
707 | + |
---|
708 | +protected: |
---|
709 | + FixedSizeSecBlock<word32, 8> m_key; |
---|
710 | +}; |
---|
711 | + |
---|
712 | +/// <a href="http://www.cryptolounge.org/wiki/XSalsa20">XSalsa20</a>, variable rounds: 8, 12 or 20 (default 20) |
---|
713 | +struct XSalsa20 : public XSalsa20_Info, public SymmetricCipherDocumentation |
---|
714 | +{ |
---|
715 | + typedef SymmetricCipherFinal<ConcretePolicyHolder<XSalsa20_Policy, AdditiveCipherTemplate<> >, XSalsa20_Info> Encryption; |
---|
716 | + typedef Encryption Decryption; |
---|
717 | +}; |
---|
718 | + |
---|
719 | +NAMESPACE_END |
---|
720 | + |
---|
721 | +#endif |
---|
722 | addfile ./pycryptopp/cipher/xsalsa.py |
---|
723 | hunk ./pycryptopp/cipher/xsalsa.py 1 |
---|
724 | +#!/usr/bin/env python |
---|
725 | +from pycryptopp import _import_my_names |
---|
726 | + |
---|
727 | +_import_my_names(globals(), "xsalsa_") |
---|
728 | + |
---|
729 | +del _import_my_names |
---|
730 | + |
---|
731 | addfile ./pycryptopp/cipher/xsalsamodule.cpp |
---|
732 | hunk ./pycryptopp/cipher/xsalsamodule.cpp 1 |
---|
733 | +/** |
---|
734 | + * xsalsamodule.cpp -- Python wrappers around Crypto++'s salsa |
---|
735 | + */ |
---|
736 | + |
---|
737 | +#define PY_SSIZE_T_CLEAN |
---|
738 | +#include <Python.h> |
---|
739 | +#if (PY_VERSION_HEX < 0x02050000) |
---|
740 | +typedef int Py_ssize_t; |
---|
741 | +#endif |
---|
742 | + |
---|
743 | +#include "xsalsamodule.hpp" |
---|
744 | + |
---|
745 | +#ifdef USE_NAME_CRYPTO_PLUS_PLUS |
---|
746 | +//#include <crypto++/modes.h> |
---|
747 | +#include <crypto++/salsa.h> |
---|
748 | +#else |
---|
749 | +//#include <cryptopp/modes.h> |
---|
750 | +#include <cryptopp/salsa.h> |
---|
751 | +#endif |
---|
752 | + |
---|
753 | +static const char* const xsalsa__doc__ = "_xsalsa cipher"; |
---|
754 | + |
---|
755 | +static PyObject *xsalsa_error; |
---|
756 | + |
---|
757 | +typedef struct { |
---|
758 | + PyObject_HEAD |
---|
759 | + |
---|
760 | + /* internal */ |
---|
761 | +// CryptoPP::CTR_Mode<CryptoPP::XSalsa20>::Encryption *e; |
---|
762 | + CryptoPP::XSalsa20::Encryption *e; |
---|
763 | +} XSalsa; |
---|
764 | + |
---|
765 | +PyDoc_STRVAR(XSalsa__doc__, |
---|
766 | +"An XSalsa20 cipher object.\n\ |
---|
767 | +\n\ |
---|
768 | +This object encrypts/decrypts in CTR mode, using a counter that is initialized\n\ |
---|
769 | +to zero when you instantiate the object. Successive calls to .process() will \n\ |
---|
770 | +use the current counter and increment it.\n\ |
---|
771 | +\n\ |
---|
772 | +"); |
---|
773 | + |
---|
774 | +static PyObject *XSalsa_process(XSalsa* self, PyObject* msgobj) { |
---|
775 | + if(!PyString_CheckExact(msgobj)) { |
---|
776 | + PyStringObject* typerepr = reinterpret_cast<PyStringObject*>(PyObject_Repr(reinterpret_cast<PyObject*>(msgobj->ob_type))); |
---|
777 | + if (typerepr) { |
---|
778 | + PyErr_Format(xsalsa_error, "Precondition violation: you are required to pass a Python string object (not a unicode, a subclass of string, or anything else), but you passed %s.", PyString_AS_STRING(reinterpret_cast<PyObject*>(typerepr))); |
---|
779 | + Py_DECREF(typerepr); |
---|
780 | + } else |
---|
781 | + PyErr_Format(xsalsa_error, "Precondition violation: you are required to pass a Python string object (not a unicode, a subclass of string, or anything else)."); |
---|
782 | + return NULL; |
---|
783 | + } |
---|
784 | + |
---|
785 | + const char* msg; |
---|
786 | + Py_ssize_t msgsize; |
---|
787 | + if (PyString_AsStringAndSize(msgobj, const_cast<char**>(&msg), &msgsize)) |
---|
788 | + return NULL; |
---|
789 | + assert (msgsize >= 0); |
---|
790 | + |
---|
791 | + PyStringObject* result = reinterpret_cast<PyStringObject*>(PyString_FromStringAndSize(NULL, msgsize)); |
---|
792 | + if (!result) |
---|
793 | + return NULL; |
---|
794 | + |
---|
795 | + self->e->ProcessString(reinterpret_cast<byte*>(PyString_AS_STRING(result)), reinterpret_cast<const byte*>(msg), msgsize); |
---|
796 | + return reinterpret_cast<PyObject*>(result); |
---|
797 | +} |
---|
798 | + |
---|
799 | +PyDoc_STRVAR(XSalsa_process__doc__, |
---|
800 | +"Encrypt or decrypt the next bytes, returning the result."); |
---|
801 | + |
---|
802 | +static PyMethodDef XSalsa_methods[] = { |
---|
803 | + {"process", reinterpret_cast<PyCFunction>(XSalsa_process), METH_O, XSalsa_process__doc__}, |
---|
804 | + {NULL}, |
---|
805 | +}; |
---|
806 | + |
---|
807 | +static PyObject* XSalsa_new(PyTypeObject* type, PyObject *args, PyObject *kwdict) { |
---|
808 | + XSalsa* self = reinterpret_cast<XSalsa*>(type->tp_alloc(type, 0)); |
---|
809 | + if (!self) |
---|
810 | + return NULL; |
---|
811 | + self->e = NULL; |
---|
812 | + return reinterpret_cast<PyObject*>(self); |
---|
813 | +} |
---|
814 | + |
---|
815 | +static void XSalsa_dealloc(PyObject* self) { |
---|
816 | + if (reinterpret_cast<XSalsa*>(self)->e) |
---|
817 | + delete reinterpret_cast<XSalsa*>(self)->e; |
---|
818 | + self->ob_type->tp_free(self); |
---|
819 | +} |
---|
820 | + |
---|
821 | +static int XSalsa_init(PyObject* self, PyObject *args, PyObject *kwdict) { |
---|
822 | + static const char *kwlist[] = { "key", "iv", NULL}; |
---|
823 | + const char *key = NULL; |
---|
824 | + Py_ssize_t keysize = 0; |
---|
825 | + const char *iv = NULL; |
---|
826 | + const char defaultiv[24] = {0}; |
---|
827 | + Py_ssize_t ivsize = 0; |
---|
828 | + if (!PyArg_ParseTupleAndKeywords(args, kwdict, "t#|t#:XSalsa.__init__", const_cast<char**>(kwlist), &key, &keysize, &iv, &ivsize)) |
---|
829 | + return -1; |
---|
830 | + assert (keysize >= 0); |
---|
831 | + assert (ivsize >= 0); |
---|
832 | + |
---|
833 | + if(!iv) |
---|
834 | + iv = defaultiv; |
---|
835 | + try { |
---|
836 | + reinterpret_cast<XSalsa*>(self)->e = new CryptoPP::XSalsa20::Encryption(reinterpret_cast<const byte*>(key), keysize, reinterpret_cast<const byte*>(iv)); |
---|
837 | + } |
---|
838 | + catch (CryptoPP::InvalidKeyLength le) |
---|
839 | + { |
---|
840 | + PyErr_Format(xsalsa_error, "Precondition violation: you are required to pass a valid key size. Crypto++ gave this exception: %s", le.what()); |
---|
841 | + return -1; |
---|
842 | + } |
---|
843 | + if (!reinterpret_cast<XSalsa*>(self)->e) |
---|
844 | + { |
---|
845 | + PyErr_NoMemory(); |
---|
846 | + return -1; |
---|
847 | + } |
---|
848 | + return 0; |
---|
849 | +} |
---|
850 | + |
---|
851 | + |
---|
852 | +static PyTypeObject XSalsa_type = { |
---|
853 | + PyObject_HEAD_INIT(NULL) |
---|
854 | + 0, /*ob_size*/ |
---|
855 | + "_xsalsa.XSalsa", /*tp_name*/ |
---|
856 | + sizeof(XSalsa), /*tp_basicsize*/ |
---|
857 | + 0, /*tp_itemsize*/ |
---|
858 | + XSalsa_dealloc, /*tp_dealloc*/ |
---|
859 | + 0, /*tp_print*/ |
---|
860 | + 0, /*tp_getattr*/ |
---|
861 | + 0, /*tp_setattr*/ |
---|
862 | + 0, /*tp_compare*/ |
---|
863 | + 0, /*tp_repr*/ |
---|
864 | + 0, /*tp_as_number*/ |
---|
865 | + 0, /*tp_as_sequence*/ |
---|
866 | + 0, /*tp_as_mapping*/ |
---|
867 | + 0, /*tp_hash*/ |
---|
868 | + 0, /*tp_call*/ |
---|
869 | + 0, /*tp_str*/ |
---|
870 | + 0, /*tp_getattro*/ |
---|
871 | + 0, /*tp_setattro*/ |
---|
872 | + 0, /*tp_as_buffer*/ |
---|
873 | + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ |
---|
874 | + XSalsa__doc__, /*tp_doc*/ |
---|
875 | + 0, /*tp_traverse*/ |
---|
876 | + 0, /*tp_clear*/ |
---|
877 | + 0, /*tp_richcompare*/ |
---|
878 | + 0, /*tp_weaklistoffset*/ |
---|
879 | + 0, /*tp_iter*/ |
---|
880 | + 0, /*tp_iternext*/ |
---|
881 | + XSalsa_methods, /*tp_methods*/ |
---|
882 | + 0, /*tp_members*/ |
---|
883 | + 0, /*tp_getset*/ |
---|
884 | + 0, /*tp_base*/ |
---|
885 | + 0, /*tp_dict*/ |
---|
886 | + 0, /*tp_descr_get*/ |
---|
887 | + 0, /*tp_descr_set*/ |
---|
888 | + 0, /*tp_dictoffset*/ |
---|
889 | + XSalsa_init, /*tp_init*/ |
---|
890 | + 0, /*tp_alloc*/ |
---|
891 | + XSalsa_new, /*tp_new*/ |
---|
892 | +}; |
---|
893 | + |
---|
894 | +void init_xsalsa(PyObject*const module) |
---|
895 | +{ |
---|
896 | + if (PyType_Ready(&XSalsa_type) < 0) |
---|
897 | + return; |
---|
898 | + Py_INCREF(&XSalsa_type); |
---|
899 | + PyModule_AddObject(module, "xsalsa_XSalsa", (PyObject *)&XSalsa_type); |
---|
900 | + |
---|
901 | + xsalsa_error = PyErr_NewException(const_cast<char*>("_xsalsa.Error"), NULL, NULL); |
---|
902 | + PyModule_AddObject(module, "xsalsa_Error", xsalsa_error); |
---|
903 | + |
---|
904 | + PyModule_AddStringConstant(module, "xsalsa__doc__", const_cast<char*>(xsalsa__doc__)); |
---|
905 | +} |
---|
906 | addfile ./pycryptopp/cipher/xsalsamodule.hpp |
---|
907 | hunk ./pycryptopp/cipher/xsalsamodule.hpp 1 |
---|
908 | +#ifndef __INCL_XSALSAMODULE_HPP |
---|
909 | +#define __INCL_XSALSAMODULE_HPP |
---|
910 | + |
---|
911 | +extern void init_xsalsa(PyObject* module); |
---|
912 | + |
---|
913 | +#endif; /*#ifndef __INCL_XSALSAMODULE_HPP*/ |
---|
914 | addfile ./pycryptopp/test/test_xsalsa.py |
---|
915 | hunk ./pycryptopp/test/test_xsalsa.py 1 |
---|
916 | +#!/usr/bin/env python |
---|
917 | + |
---|
918 | +import random, re |
---|
919 | +import unittest |
---|
920 | + |
---|
921 | +from binascii import a2b_hex, b2a_hex |
---|
922 | +from pkg_resources import resource_string |
---|
923 | + |
---|
924 | +from pycryptopp.cipher import xsalsa |
---|
925 | +TEST_XSALSA_RE=re.compile("\nCOUNT=([0-9]+)\nKEY=([0-9a-f]+)\nIV=([0-9a-f]+)\nPLAINTEXT=([0-9a-f]+)\nCIPHERTEXT=([0-9a-f]+)") |
---|
926 | + |
---|
927 | +class XSalsaTest(unittest.TestCase): |
---|
928 | + |
---|
929 | + enc0="eea6a7251c1e72916d11c2cb214d3c252539121d8e234e652d651fa4c8cff880309e645a74e9e0a60d8243acd9177ab51a1beb8d5a2f5d700c093c5e5585579625337bd3ab619d615760d8c5b224a85b1d0efe0eb8a7ee163abb0376529fcc09bab506c618e13ce777d82c3ae9d1a6f972d4160287cbfe60bf2130fc0a6ff6049d0a5c8a82f429231f0080" |
---|
930 | + |
---|
931 | + def test_zero_XSalsa(self): |
---|
932 | + key="1b27556473e985d462cd51197a9a46c76009549eac6474f206c4ee0844f68389" |
---|
933 | + iv="69696ee955b62b73cd62bda875fc73d68219e0036b7a0b37" |
---|
934 | + computedcipher=xsalsa.XSalsa(a2b_hex(key),a2b_hex(iv)).process('\x00'*139) |
---|
935 | + self.failUnlessEqual(a2b_hex(self.enc0), computedcipher, "enc0: %s, computedciper: %s" % (self.enc0, b2a_hex(computedcipher))) |
---|
936 | + |
---|
937 | + cryptor=xsalsa.XSalsa(a2b_hex(key),a2b_hex(iv)) |
---|
938 | + |
---|
939 | + computedcipher1=cryptor.process('\x00'*69) |
---|
940 | + computedcipher2=cryptor.process('\x00'*69) |
---|
941 | + computedcipher3=cryptor.process('\x00') |
---|
942 | + computedcipher12=b2a_hex(computedcipher1)+b2a_hex(computedcipher2)+b2a_hex(computedcipher3) |
---|
943 | + self.failUnlessEqual(self.enc0, computedcipher12) |
---|
944 | + |
---|
945 | + def test_XSalsa(self): |
---|
946 | + curfile = open( '../testvectors/testx1.txt', 'r') |
---|
947 | + s = curfile.read() |
---|
948 | + print s,"\n" |
---|
949 | + return self._test_XSalsa(s) |
---|
950 | + |
---|
951 | + def _test_XSalsa(self, vects_str): |
---|
952 | + for mo in TEST_XSALSA_RE.finditer(vects_str): |
---|
953 | + count = int(mo.group(1)) |
---|
954 | + key = a2b_hex(mo.group(2)) |
---|
955 | + iv = a2b_hex(mo.group(3)) |
---|
956 | +# plaintext = a2b_hex(mo.group(4)) |
---|
957 | +# ciphertext= a2b_hex(mo.group(5)) |
---|
958 | + plaintext = mo.group(4) |
---|
959 | + ciphertext = mo.group(5) |
---|
960 | + computedcipher=xsalsa.XSalsa(key,iv).process(a2b_hex(plaintext)) |
---|
961 | +# print "ciphertext", b2a_hex(computedcipher), '\n' |
---|
962 | +# print "computedtext", ciphertext, '\n' |
---|
963 | +# print count, ": \n" |
---|
964 | + self.failUnlessEqual(computedcipher,a2b_hex(ciphertext),"computedcipher: %s, ciphertext: %s" % (b2a_hex(computedcipher), ciphertext)) |
---|
965 | + |
---|
966 | + #the random decomposing |
---|
967 | + plaintext1 = "" |
---|
968 | + plaintext2 = "" |
---|
969 | + length = len(plaintext) |
---|
970 | + rccipher = "" |
---|
971 | + cryptor = xsalsa.XSalsa(key,iv) |
---|
972 | + if length > 2: |
---|
973 | + point = random.randint(0,length-3) |
---|
974 | + if (point%2) !=0: |
---|
975 | + point -= 1 |
---|
976 | + plaintext1 += plaintext[:point+2] |
---|
977 | + plaintext2 += plaintext[point+2:] |
---|
978 | + rccipher += b2a_hex(cryptor.process(a2b_hex(plaintext1))) |
---|
979 | + rccipher += b2a_hex(cryptor.process(a2b_hex(plaintext2))) |
---|
980 | + self.failUnlessEqual(rccipher, ciphertext, "random computed cipher: %s, ciphertext: %s" % (rccipher, ciphertext)) |
---|
981 | + |
---|
982 | + #every byte encrypted |
---|
983 | + cryptor = xsalsa.XSalsa(key,iv) |
---|
984 | + eccipher="" |
---|
985 | + l = 0 |
---|
986 | + while l<=(length-2): |
---|
987 | + eccipher += b2a_hex(cryptor.process(a2b_hex(plaintext[l:l+2]))) |
---|
988 | + l += 2 |
---|
989 | + self.failUnlessEqual(eccipher, ciphertext, "every byte computed cipher: %s, ciphertext: %s" % (eccipher, ciphertext)) |
---|
990 | + |
---|
991 | + |
---|
992 | + def test_init_type_check(self): |
---|
993 | + self.failUnlessRaises(TypeError, xsalsa.XSalsa, None) |
---|
994 | + self.failUnlessRaises(xsalsa.Error, xsalsa.XSalsa, "a"*1) |
---|
995 | + self.failUnlessRaises(xsalsa.Error, xsalsa.XSalsa, "a"*17) |
---|
996 | + self.failUnlessRaises(xsalsa.Error, xsalsa.XSalsa, "a"*18) |
---|
997 | +# self.failUnlessRaises(xsalsa.Error, xsalsa.XSalsa, "a"*32) |
---|
998 | + |
---|
999 | +if __name__ == "__main__": |
---|
1000 | + unittest.main() |
---|
1001 | addfile ./pycryptopp/testvectors/testx1.txt |
---|
1002 | hunk ./pycryptopp/testvectors/testx1.txt 1 |
---|
1003 | + |
---|
1004 | +COUNT=1 |
---|
1005 | +KEY=a6a7251c1e72916d11c2cb214d3c252539121d8e234e652d651fa4c8cff88030 |
---|
1006 | +IV=9e645a74e9e0a60d8243acd9177ab51a1beb8d5a2f5d700c |
---|
1007 | +PLAINTEXT=093c5e5585579625337bd3ab619d615760d8c5b224a85b1d0efe0eb8a7ee163abb0376529fcc09bab506c618e13ce777d82c3ae9d1a6f972d4160287cbfe60bf2130fc0a6ff6049d0a5c8a82f429231f008082e845d7e189d37f9ed2b464e6b919e6523a8c1210bd52a02a4c3fe406d3085f5068d1909eeeca6369abc981a42e87fe665583f0ab85ae71f6f84f528e6b397af86f6917d9754b7320dbdc2fea81496f2732f532ac78c4e9c6cfb18f8e9bdf74622eb126141416776971a84f94d156beaf67aecbf2ad412e76e66e8fad7633f5b6d7f3d64b5c6c69ce29003c6024465ae3b89be78e915d88b4b5621d |
---|
1008 | +CIPHERTEXT=b2af688e7d8fc4b508c05cc39dd583d6714322c64d7f3e63147aede2d9534934b04ff6f337b031815cd094bdbc6d7a92077dce709412286822ef0737ee47f6b7ffa22f9d53f11dd2b0a3bb9fc01d9a88f9d53c26e9365c2c3c063bc4840bfc812e4b80463e69d179530b25c158f543191cff993106511aa036043bbc75866ab7e34afc57e2cce4934a5faae6eabe4f221770183dd060467827c27a354159a081275a291f69d946d6fe28ed0b9ce08206cf484925a51b9498dbde178ddd3ae91a8581b91682d860f840782f6eea49dbb9bd721501d2c67122dea3b7283848c5f13e0c0de876bd227a856e4de593a3 |
---|
1009 | + |
---|
1010 | +COUNT=2 |
---|
1011 | +KEY=9e1da239d155f52ad37f75c7368a536668b051952923ad44f57e75ab588e475a |
---|
1012 | +IV=af06f17859dffa799891c4288f6635b5c5a45eee9017fd72 |
---|
1013 | +PLAINTEXT=feac9d54fc8c115ae247d9a7e919dd76cfcbc72d32cae4944860817cbdfb8c04e6b1df76a16517cd33ccf1acda9206389e9e318f5966c093cfb3ec2d9ee2de856437ed581f552f26ac2907609df8c613b9e33d44bfc21ff79153e9ef81a9d66cc317857f752cc175fd8891fefebb7d041e6517c3162d197e2112837d3bc4104312ad35b75ea686e7c70d4ec04746b52ff09c421451459fb59f |
---|
1014 | +CIPHERTEXT=2c261a2f4e61a62e1b27689916bf03453fcbc97bb2af6f329391ef063b5a219bf984d07d70f602d85f6db61474e9d9f5a2deecb4fcd90184d16f3b5b5e168ee03ea8c93f3933a22bc3d1a5ae8c2d8b02757c87c073409052a2a8a41e7f487e041f9a49a0997b540e18621cad3a24f0a56d9b19227929057ab3ba950f6274b121f193e32e06e5388781a1cb57317c0ba6305e910961d01002f0 |
---|
1015 | + |
---|
1016 | +COUNT=3 |
---|
1017 | +KEY=d5c7f6797b7e7e9c1d7fd2610b2abf2bc5a7885fb3ff78092fb3abe8986d35e2 |
---|
1018 | +IV=744e17312b27969d826444640e9c4a378ae334f185369c95 |
---|
1019 | +PLAINTEXT=7758298c628eb3a4b6963c5445ef66971222be5d1a4ad839715d1188071739b77cc6e05d5410f963a64167629757 |
---|
1020 | +CIPHERTEXT=27b8cfe81416a76301fd1eec6a4d99675069b2da2776c360db1bdfea7c0aa613913e10f7a60fec04d11e65f2d64e |
---|
1021 | + |
---|
1022 | +COUNT=4 |
---|
1023 | +KEY=737d7811ce96472efed12258b78122f11deaec8759ccbd71eac6bbefa627785c |
---|
1024 | +IV=6fb2ee3dda6dbd12f1274f126701ec75c35c86607adb3edd |
---|
1025 | +PLAINTEXT=501325fb2645264864df11faa17bbd58312b77cad3d94ac8fb8542f0eb653ad73d7fce932bb874cb89ac39fc47f8267cf0f0c209f204b2d8578a3bdf461cb6a271a468bebaccd9685014ccbc9a73618c6a5e778a21cc8416c60ad24ddc417a130d53eda6dfbfe47d09170a7be1a708b7b5f3ad464310be36d9a2a95dc39e83d38667e842eb6411e8a23712297b165f690c2d7ca1b1346e3c1fccf5cafd4f8be0 |
---|
1026 | +CIPHERTEXT=6724c372d2e9074da5e27a6c54b2d703dc1d4c9b1f8d90f00c122e692ace7700eadca942544507f1375b6581d5a8fb39981c1c0e6e1ff2140b082e9ec016fce141d5199647d43b0b68bfd0fea5e00f468962c7384dd6129aea6a3fdfe75abb210ed5607cef8fa0e152833d5ac37d52e557b91098a322e76a45bbbcf4899e790618aa3f4c2e5e0fc3de93269a577d77a5502e8ea02f717b1dd2df1ec69d8b61ca |
---|
1027 | + |
---|
1028 | +COUNT=5 |
---|
1029 | +KEY=760158da09f89bbab2c99e6997f9523a95fcef10239bcca2573b7105f6898d34 |
---|
1030 | +IV=43636b2cc346fc8b7c85a19bf507bdc3dafe953b88c69dba |
---|
1031 | +PLAINTEXT=d30a6d42dff49f0ed039a306bae9dec8d9e88366cc19e8c3642fd58fa0794ebf8029d949730339b0823a51f0f49f0d2c71f1051c1e0e2c86941f172789cdb1b0107413e70f982ff9761877bb526ef1c3eb1106a948d60ef21bd35d32cfd64f89b79ed63ecc5cca56246af736766f285d8e6b0da9cb1cd21020223ffacc5a32 |
---|
1032 | +CIPHERTEXT=c815b6b79b64f9369aec8dce8c753df8a50f2bc97c70ce2f014db33a65ac5816bac9e30ac08bdded308c65cb87e28e2e71b677dc25c5a6499c1553555daf1f55270a56959dffa0c66f24e0af00951ec4bb59ccc3a6c5f52e0981647e53e439313a52c40fa7004c855b6e6eb25b212a138e843a9ba46edb2a039ee82a263abe |
---|
1033 | + |
---|
1034 | +COUNT=6 |
---|
1035 | +KEY=27ba7e81e7edd4e71be53c07ce8e633138f287e155c7fa9e84c4ad804b7fa1b9 |
---|
1036 | +IV=ea05f4ebcd2fb6b000da0612861ba54ff5c176fb601391aa |
---|
1037 | +PLAINTEXT=e09ff5d2cb050d69b2d42494bde5825238c756d6991d99d7a20d1ef0b83c371c89872690b2fc11d5369f4fc4971b6d3d6c078aef9b0f05c0e61ab89c025168054defeb03fef633858700c58b1262ce011300012673e893e44901dc18eee3105699c44c805897bdaf776af1833162a21a |
---|
1038 | +CIPHERTEXT=a23e7ef93c5d0667c96d9e404dcbe6be62026fa98f7a3ff9ba5d458643a16a1cef7272dc6097a9b52f35983557c77a11b314b4f7d5dc2cca15ee47616f861873cbfed1d32372171a61e38e447f3cf362b3abbb2ed4170d89dcb28187b7bfd206a3e026f084a7e0ed63d319de6bc9afc0 |
---|
1039 | + |
---|
1040 | +COUNT=7 |
---|
1041 | +KEY=6799d76e5ffb5b4920bc2768bafd3f8c16554e65efcf9a16f4683a7a06927c11 |
---|
1042 | +IV=61ab951921e54ff06d9b77f313a4e49df7a057d5fd627989 |
---|
1043 | +PLAINTEXT=472766 |
---|
1044 | +CIPHERTEXT=8fd7df |
---|
1045 | + |
---|
1046 | +COUNT=8 |
---|
1047 | +KEY=f68238c08365bb293d26980a606488d09c2f109edafa0bbae9937b5cc219a49c |
---|
1048 | +IV=5190b51e9b708624820b5abdf4e40fad1fb950ad1adc2d26 |
---|
1049 | +PLAINTEXT=47ec6b1f73c4b7ff5274a0bfd7f45f864812c85a12fbcb3c2cf8a3e90cf66ccf2eacb521e748363c77f52eb426ae57a0c6c78f75af71284569e79d1a92f949a9d69c4efc0b69902f1e36d7562765543e2d3942d9f6ff5948d8a312cff72c1afd9ea3088aff7640bfd265f7a9946e606abc77bcedae6bddc75a0dba0bd917d73e3bd1268f727e0096345da1ed25cf553ea7a98fea6b6f285732de37431561ee1b3064887fbcbd71935e02 |
---|
1050 | +CIPHERTEXT=36160e88d3500529ba4edba17bc24d8cfaca9a0680b3b1fc97cf03f3675b7ac301c883a68c071bc54acdd3b63af4a2d72f985e51f9d60a4c7fd481af10b2fc75e252fdee7ea6b6453190617dcc6e2fe1cd56585fc2f0b0e97c5c3f8ad7eb4f31bc4890c03882aac24cc53acc1982296526690a220271c2f6e326750d3fbda5d5b63512c831f67830f59ac49aae330b3e0e02c9ea0091d19841f1b0e13d69c9fbfe8a12d6f30bb734d9d2 |
---|
1051 | + |
---|
1052 | +COUNT=9 |
---|
1053 | +KEY=45b2bd0de4ed9293ec3e26c4840faaf64b7d619d51e9d7a2c7e36c83d584c3df |
---|
1054 | +IV=546c8c5d6be8f90952cab3f36d7c1957baaa7a59abe3d7e5 |
---|
1055 | +PLAINTEXT=5007c8cd5b3c40e17d7fe423a87ae0ced86bec1c39dc07a25772f3e96dabd56cd3fd7319f6c9654925f2d87087a700e1b130da796895d1c9b9acd62b266144067d373ed51e787498b03c52faad16bb3826fa511b0ed2a19a8663f5ba2d6ea7c38e7212e9697d91486c49d8a000b9a1935d6a7ff7ef23e720a45855481440463b4ac8c4f6e7062adc1f1e1e25d3d65a31812f58a71160 |
---|
1056 | +CIPHERTEXT=8eacfba568898b10c0957a7d44100685e8763a71a69a8d16bc7b3f88085bb9a2f09642e4d09a9f0ad09d0aad66b22610c8bd02ff6679bb92c2c026a216bf425c6be35fb8dae7ff0c72b0efd6a18037c70eed0ca90062a49a3c97fdc90a8f9c2ea536bfdc41918a7582c9927fae47efaa3dc87967b7887dee1bf071734c7665901d9105dae2fdf66b4918e51d8f4a48c60d19fbfbbcba |
---|
1057 | + |
---|
1058 | +COUNT=10 |
---|
1059 | +KEY=fe559c9a282beb40814d016d6bfcb2c0c0d8bf077b1110b8703a3ce39d70e0e1 |
---|
1060 | +IV=b076200cc7011259805e18b304092754002723ebec5d6200 |
---|
1061 | +PLAINTEXT=6db65b9ec8b114a944137c821fd606be75478d928366d5284096cdef782fcff7e8f59cb8ffcda979757902c5ffa6bc477ceaa4cb5d5ea76f94d91e833f823a6bc78f1055dfa6a97bea8965c1cde67a668e001257334a585727d9e0f7c1a06e88d3d25a4e6d9096c968bf138e116a3ebeffd4bb4808adb1fd698164ba0a35c709a47f16f1f4435a2345a9194a00b95abd51851d505809a6077da9baca5831afff31578c487ee68f2767974a98a7e803aac788da98319c4ea8eaa3d394855651f484cef543f537e35158ee29 |
---|
1062 | +CIPHERTEXT=4dce9c8f97a028051b0727f34e1b9ef21f06f0760f36e71713204027902090ba2bb6b13436ee778d9f50530efbd7a32b0d41443f58ccaee781c7b716d3a96fdec0e3764ed7959f34c3941278591ea033b5cbadc0f1916032e9bebbd1a8395b83fb63b1454bd775bd20b3a2a96f951246ac14daf68166ba62f6cbff8bd121ac9498ff8852fd2be975df52b5daef3829d18eda42e715022dcbf930d0a789ee6a146c2c7088c35773c63c06b4af4559856ac199ced86863e4294707825337c5857970eb7fddeb263781309011 |
---|
1063 | + |
---|
1064 | +COUNT=11 |
---|
1065 | +KEY=0ae10012d7e56614b03dcc89b14bae9242ffe630f3d7e35ce8bbb97bbc2c92c3 |
---|
1066 | +IV=f96b025d6cf46a8a12ac2af1e2aef1fb83590adadaa5c5ea |
---|
1067 | +PLAINTEXT=ea0f354e96f12bc72bbaa3d12b4a8ed879b042f0689878f46b651cc4116d6f78409b11430b3aaa30b2076891e8e1fa528f2fd169ed93dc9f84e24409eec2101daf4d057be2492d11de640cbd7b355ad29fb70400fffd7cd6d425abeeb732a0eaa4330af4c656252c4173deab653eb85c58462d7ab0f35fd12b613d29d473d330310dc323d3c66348bbdbb68a326324657cae7b77a9e34358f2cec50c85609e73056856796e3be8d62b6e2fe9f953 |
---|
1068 | +CIPHERTEXT=e8abd48924b54e5b80866be7d4ebe5cf4274cafff08b39cb2d40a8f0b472398aedc776e0793812fbf1f60078635d2ed86b15efcdba60411ee23b07233592a44ec31b1013ce8964236675f8f183aef885e864f2a72edf4215b5338fa2b54653dfa1a8c55ce5d95cc605b9b311527f2e3463ffbec78a9d1d65dabad2f338769c9f43f133a791a11c7eca9af0b771a4ac32963dc8f631a2c11217ac6e1b9430c1aae1ceebe22703f429998a8fb8c641 |
---|
1069 | + |
---|
1070 | +COUNT=12 |
---|
1071 | +KEY=082c539bc5b20f97d767cd3f229eda80b2adc4fe49c86329b5cd6250a9877450 |
---|
1072 | +IV=845543502e8b64912d8f2c8d9fffb3c69365686587c08d0c |
---|
1073 | +PLAINTEXT=a96bb7e910281a6dfad7c8a9c370674f0ceec1ad8d4f0de32f9ae4a23ed329e3d6bc708f876640a229153ac0e7281a8188dd77695138f01cda5f41d5215fd5c6bdd46d982cb73b1efe2997970a9fdbdb1e768d7e5db712068d8ba1af6067b5753495e23e6e1963af012f9c7ce450bf2de619d3d59542fb55f3 |
---|
1074 | +CIPHERTEXT=835da74fc6de08cbda277a7966a07c8dcd627e7b17adde6d930b6581e3124b8baad096f693991fedb1572930601fc7709541839b8e3ffd5f033d2060d999c6c6e3048276613e648000acb5212cc632a916afce290e20ebdf612d08a6aa4c79a74b070d3f872a861f8dc6bb07614db515d363349d3a8e3336a3 |
---|
1075 | + |
---|
1076 | +COUNT=13 |
---|
1077 | +KEY=3d02bff3375d403027356b94f514203737ee9a85d2052db3e4e5a217c259d18a |
---|
1078 | +IV=74216c95031895f48c1dba651555ebfa3ca326a755237025 |
---|
1079 | +PLAINTEXT=0d4b0f54fd09ae39baa5fa4baccf2e6682e61b257e01f42b8f |
---|
1080 | +CIPHERTEXT=16c4006c28365190411eb1593814cf15e74c22238f210afc3d |
---|
1081 | + |
---|
1082 | +COUNT=14 |
---|
1083 | +KEY=ad1a5c47688874e6663a0f3fa16fa7efb7ecadc175c468e5432914bdb480ffc6 |
---|
1084 | +IV=e489eed440f1aae1fac8fb7a9825635454f8f8f1f52e2fcc |
---|
1085 | +PLAINTEXT=aa6c1e53580f03a9abb73bfdadedfecada4c6b0ebe020ef10db745e54ba861caf65f0e40dfc520203bb54d29e0a8f78f16b3f1aa525d6bfa33c54726e59988cfbec78056 |
---|
1086 | +CIPHERTEXT=02fe84ce81e178e7aabdd3ba925a766c3c24756eefae33942af75e8b464556b5997e616f3f2dfc7fce91848afd79912d9fb55201b5813a5a074d2c0d4292c1fd441807c5 |
---|
1087 | + |
---|
1088 | +COUNT=15 |
---|
1089 | +KEY=053a02bedd6368c1fb8afc7a1b199f7f7ea2220c9a4b642a6850091c9d20ab9c |
---|
1090 | +IV=c713eea5c26dad75ad3f52451e003a9cb0d649f917c89dde |
---|
1091 | +PLAINTEXT=8f0a8a164760426567e388840276de3f95cb5e3fadc6ed3f3e4fe8bc169d9388804dcb94b6587dbb66cb0bd5f87b8e98b52af37ba290629b858e0e2aa7378047a26602 |
---|
1092 | +CIPHERTEXT=516710e59843e6fbd4f25d0d8ca0ec0d47d39d125e9dad987e0518d49107014cb0ae405e30c2eb3794750bca142ce95e290cf95abe15e822823e2e7d3ab21bc8fbd445 |
---|
1093 | + |
---|
1094 | +COUNT=16 |
---|
1095 | +KEY=5b14ab0fbed4c58952548a6cb1e0000cf4481421f41288ea0aa84add9f7deb96 |
---|
1096 | +IV=54bf52b911231b952ba1a6af8e45b1c5a29d97e2abad7c83 |
---|
1097 | +PLAINTEXT=37fb44a675978b560ff9a4a87011d6f3ad2d37a2c3815b45a3c0e6d1b1d8b1784cd468927c2ee39e1dccd4765e1c3d676a335be1ccd6900a45f5d41a317648315d8a8c24adc64eb285f6aeba05b9029586353d303f17a807658b9ff790474e1737bd5fdc604aeff8dfcaf1427dcc3aacbb0256badcd183ed75a2dc52452f87d3c1ed2aa583472b0ab91cda20614e9b6fdbda3b49b098c95823cc72d8e5b717f2314b0324e9ce |
---|
1098 | +CIPHERTEXT=ae6deb5d6ce43d4b09d0e6b1c0e9f46157bcd8ab50eaa3197ff9fa2bf7af649eb52c68544fd3adfe6b1eb316f1f23538d470c30dbfec7e57b60cbcd096c782e7736b669199c8253e70214cf2a098fda8eac5da79a9496a3aae754d03b17c6d70d1027f42bf7f95ce3d1d9c338854e158fcc803e4d6262fb639521e47116ef78a7a437ca9427ba645cd646832feab822a208278e45e93e118d780b988d65397eddfd7a819526e |
---|
1099 | + |
---|
1100 | +COUNT=17 |
---|
1101 | +KEY=d74636e3413a88d85f322ca80fb0bd650bd0bf0134e2329160b69609cd58a4b0 |
---|
1102 | +IV=efb606aa1d9d9f0f465eaa7f8165f1ac09f5cb46fecf2a57 |
---|
1103 | +PLAINTEXT=f85471b75f6ec81abac2799ec09e98e280b2ffd64ca285e5a0109cfb31ffab2d617b2c2952a2a8a788fc0da2af7f530758f74f1ab56391ab5ff2adbcc5be2d6c7f49fbe8118104c6ff9a23c6dfe52f57954e6a69dcee5db06f514f4a0a572a9a8525d961dae72269b987189d465df6107119c7fa790853e063cba0fab7800ca932e258880fd74c33c784675bedad0e7c09e9cc4d63dd5e9713d5d4a0196e6b562226ac31b4f57c04f90a181973737ddc7e80f364112a9fbb435ebdbcabf7d490ce52 |
---|
1104 | +CIPHERTEXT=b2b795fe6c1d4c83c1327e015a67d4465fd8e32813575cbab263e20ef05864d2dc17e0e4eb81436adfe9f638dcc1c8d78f6b0306baf938e5d2ab0b3e05e735cc6fff2d6e02e3d60484bea7c7a8e13e23197fea7b04d47d48f4a4e5944174539492800d3ef51e2ee5e4c8a0bdf050c2dd3dd74fce5e7e5c37364f7547a11480a3063b9a0a157b15b10a5a954de2731ced055aa2e2767f0891d4329c426f3808ee867bed0dc75b5922b7cfb895700fda016105a4c7b7f0bb90f029f6bbcb04ac36ac16 |
---|
1105 | } |
---|
1106 | [hmac.dpatch |
---|
1107 | xueyu7452@gmail.com**20100704043039 |
---|
1108 | Ignore-this: a39c389df18c12fd0ab09948535a9376 |
---|
1109 | ] { |
---|
1110 | addfile ./pycryptopp/hash/hmac.py |
---|
1111 | hunk ./pycryptopp/hash/hmac.py 1 |
---|
1112 | +#!/usr/bin/env python |
---|
1113 | + |
---|
1114 | +#from pycryptopp import sha256 |
---|
1115 | +import sha256 |
---|
1116 | + |
---|
1117 | +digest_size = None |
---|
1118 | + |
---|
1119 | +class HMAC(object): |
---|
1120 | + """RFC2104 HMAC class |
---|
1121 | + """ |
---|
1122 | + |
---|
1123 | + blocksize = 64 |
---|
1124 | + def __init__(self, key, msg=None, digestmod = None): |
---|
1125 | + """Create a new HMAC object |
---|
1126 | + |
---|
1127 | + key: key for the keyed hash object. |
---|
1128 | + msg: Initial input for the hash, if provided. |
---|
1129 | + digestmod: A module from pycrptopp hash package |
---|
1130 | + """ |
---|
1131 | + |
---|
1132 | + if digestmod is None: |
---|
1133 | + digestmod = sha256.SHA256 |
---|
1134 | + |
---|
1135 | + if callable(digestmod): |
---|
1136 | + self.digest_cons = digestmod |
---|
1137 | + else: |
---|
1138 | + self.digest_cons = lambda d='':digestmod.new(d) |
---|
1139 | + |
---|
1140 | + self.outer = self.digest_cons() |
---|
1141 | + self.inner = self.digest_cons() |
---|
1142 | + self.digest_size = len(self.digest_cons().digest()) |
---|
1143 | + |
---|
1144 | + blocksize = self.blocksize |
---|
1145 | + if len(key) > blocksize: |
---|
1146 | + key = self.digest_cons(key).digest() |
---|
1147 | + |
---|
1148 | + key = key + chr(0)*(blocksize - len(key)) |
---|
1149 | +# ikey = key ^ (imask*blocksize) |
---|
1150 | +# okey = key ^ (omask*blocksize) |
---|
1151 | + |
---|
1152 | + ikey = "".join(chr(ord(key[i])^0x5c) for i in xrange(blocksize)) |
---|
1153 | + okey = "".join(chr(ord(key[i])^0x36) for i in xrange(blocksize)) |
---|
1154 | + self.outer.update(ikey) |
---|
1155 | + self.inner.update(okey) |
---|
1156 | + if msg is not None: |
---|
1157 | + self.inner.update(msg) |
---|
1158 | + |
---|
1159 | + def digest(self): |
---|
1160 | + """Return the hash value of this hashing object |
---|
1161 | + """ |
---|
1162 | + self.outer.update(self.inner.digest()) |
---|
1163 | +# print "hi,xueyu coming\n" |
---|
1164 | + return self.outer.digest() |
---|
1165 | + |
---|
1166 | + def hexdigest(self): |
---|
1167 | + """Like digest(), but returns a string of hexadecimal digits instead. |
---|
1168 | + """ |
---|
1169 | + self.outer.update(self.inner.digest()) |
---|
1170 | + return self.outer.hexdigest() |
---|
1171 | + |
---|
1172 | + |
---|
1173 | +def new(key, msg = None, digestmod = None): |
---|
1174 | + """Create a new hashing object and return it. |
---|
1175 | + |
---|
1176 | + key: The starting key for the hash |
---|
1177 | + msg: if available, will immediately be hashed into the object's starting |
---|
1178 | + state. |
---|
1179 | + """ |
---|
1180 | + return HMAC(key, msg, digestmod) |
---|
1181 | + |
---|
1182 | + |
---|
1183 | + |
---|
1184 | + |
---|
1185 | + |
---|
1186 | + |
---|
1187 | + |
---|
1188 | + |
---|
1189 | + |
---|
1190 | addfile ./pycryptopp/test/hmac_bench.py |
---|
1191 | hunk ./pycryptopp/test/hmac_bench.py 1 |
---|
1192 | +#!/usr/bin/env python |
---|
1193 | + |
---|
1194 | +import random, re, time |
---|
1195 | +import unittest |
---|
1196 | + |
---|
1197 | +from binascii import a2b_hex, b2a_hex |
---|
1198 | +from pycryptopp.hash import hmac, sha256 |
---|
1199 | + |
---|
1200 | +def randstr(n): |
---|
1201 | + return ''.join(map(chr, map(random.randrange, [0]*n, [256]*n))) |
---|
1202 | + |
---|
1203 | +#multiple times hmac using different key and different messages |
---|
1204 | +def HMAC_Bench1(): |
---|
1205 | + print "HMAC_Bench1 starting\n" |
---|
1206 | + start_time = time.clock() |
---|
1207 | +# i=1 |
---|
1208 | + for keylen in xrange(100): |
---|
1209 | + for msglen in xrange(100): |
---|
1210 | +# for times in xrange(10): |
---|
1211 | +# print i, '\n' |
---|
1212 | +# i+=1 |
---|
1213 | + key = randstr(keylen) |
---|
1214 | + msg = randstr(msglen) |
---|
1215 | + h = hmac.new(key, msg, sha256.SHA256) |
---|
1216 | + h.digest() |
---|
1217 | + |
---|
1218 | + stop_time = time.clock() |
---|
1219 | + print "multiple times hmac using different random key and different random messages, 100 random keys * 100 messages with lenth from 0 to 99, Bench1: ", stop_time-start_time,'sec \nHMAC_Bench1 ending\n' |
---|
1220 | + |
---|
1221 | +#using a key hmac a short message |
---|
1222 | +def HMAC_Bench2(): |
---|
1223 | + print "HMAC_Bench2 starting\n" |
---|
1224 | + start_time = time.clock() |
---|
1225 | + key = randstr(100) |
---|
1226 | + msg = randstr(10) |
---|
1227 | + h = hmac.new(key, msg, sha256.SHA256) |
---|
1228 | + h.digest() |
---|
1229 | + stop_time = time.clock() |
---|
1230 | + print "using a key hmac a short message, Bench2: ", stop_time-start_time,"sec \n" |
---|
1231 | + print "HMAC_Bench2 ending\n\n\n" |
---|
1232 | + |
---|
1233 | +def HMAC_Bench3(): |
---|
1234 | + print "hmac bench3 starting\n" |
---|
1235 | + start_time = time.clock() |
---|
1236 | + k1 = "k"*100 |
---|
1237 | + m1 = "a"*10000000 |
---|
1238 | + h1 = hmac.new(k1, m1, sha256.SHA256) |
---|
1239 | + h1.digest() |
---|
1240 | + stop_time = time.clock() |
---|
1241 | + print "using a fixed 100 bytes key hmac a 10^7 bytes long fixed long message:\n", stop_time-start_time, 'sec \n' |
---|
1242 | + print "another one using a random string" |
---|
1243 | + start_time = time.clock() |
---|
1244 | + k2=randstr(100) |
---|
1245 | + m2=randstr(10000000) |
---|
1246 | + h2 = hmac.new(k2, m2, sha256.SHA256) |
---|
1247 | + h2.digest() |
---|
1248 | + stop_time = time.clock() |
---|
1249 | + print "using a random 100 bytes key hmac a 10^7 bytes long random message, Bench3: ", stop_time-start_time,"sec \n" |
---|
1250 | + print "As we can see, most of time is spent on random string generation \nhmac bench3 ending\n\n\n" |
---|
1251 | + |
---|
1252 | +def HMAC_Bench4(): |
---|
1253 | + print "hmac bench4 starting\n" |
---|
1254 | + k = "k"*100 |
---|
1255 | + m = "b"*10000000 |
---|
1256 | + start_time = time.clock() |
---|
1257 | + for times in xrange(1000): |
---|
1258 | + h = hmac.new(k, m , sha256.SHA256) |
---|
1259 | + h.digest() |
---|
1260 | + stop_time = time.clock() |
---|
1261 | + print "hmac a 10^7 bytes long message 1000 times, Bench4: ", stop_time-start_time, "sec \n" |
---|
1262 | + print "hmac bench4 ending\n\n\n" |
---|
1263 | + |
---|
1264 | + |
---|
1265 | +def main(): |
---|
1266 | + HMAC_Bench4() |
---|
1267 | + HMAC_Bench3() |
---|
1268 | + HMAC_Bench2() |
---|
1269 | + HMAC_Bench1() |
---|
1270 | + |
---|
1271 | +if __name__=="__main__": |
---|
1272 | + main() |
---|
1273 | + |
---|
1274 | addfile ./pycryptopp/test/test_hmac.py |
---|
1275 | hunk ./pycryptopp/test/test_hmac.py 1 |
---|
1276 | +#!/usr/bin/env python |
---|
1277 | + |
---|
1278 | +import random, re |
---|
1279 | +import unittest |
---|
1280 | + |
---|
1281 | +from binascii import a2b_hex, b2a_hex |
---|
1282 | +from pkg_resources import resource_string |
---|
1283 | + |
---|
1284 | +from pycryptopp.hash import hmac, sha256 |
---|
1285 | +TEST_HMAC_RE=re.compile("\nCOUNT=([0-9]+)\nKEY=([0-9a-f]+)\nDATA=([0-9a-f]+)\nHMAC-SHA256=([0-9a-f]+)") |
---|
1286 | + |
---|
1287 | +class HMACTest(unittest.TestCase): |
---|
1288 | + def test_HMAC(self): |
---|
1289 | + curfile = open('../testvectors/HMACMsg.txt', 'r') |
---|
1290 | + s = curfile.read() |
---|
1291 | + print s,"\n" |
---|
1292 | + return self._test_HMAC(s) |
---|
1293 | + |
---|
1294 | + def _test_HMAC(self, vects_str): |
---|
1295 | + for mo in TEST_HMAC_RE.finditer(vects_str): |
---|
1296 | + count = int(mo.group(1)) |
---|
1297 | +# print "hello", count, "\n" |
---|
1298 | + key = a2b_hex(mo.group(2)) |
---|
1299 | + data = a2b_hex(mo.group(3)) |
---|
1300 | + hmacvalue = mo.group(4) |
---|
1301 | + |
---|
1302 | + length = len(hmacvalue) |
---|
1303 | + h = hmac.new(key,data,sha256.SHA256) |
---|
1304 | + computedhmacvalue = b2a_hex(h.digest()) |
---|
1305 | + self.failUnlessEqual(computedhmacvalue[:length],hmacvalue,"computedhmac: %s, hmac: %s" % (computedhmacvalue, hmacvalue)) |
---|
1306 | + |
---|
1307 | +if __name__ == "__main__": |
---|
1308 | + unittest.main() |
---|
1309 | addfile ./pycryptopp/testvectors/HMACMsg.txt |
---|
1310 | hunk ./pycryptopp/testvectors/HMACMsg.txt 1 |
---|
1311 | + |
---|
1312 | +COUNT=1 |
---|
1313 | +KEY=0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b |
---|
1314 | +DATA=4869205468657265 |
---|
1315 | +HMAC-SHA256=b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7 |
---|
1316 | + |
---|
1317 | +COUNT=2 |
---|
1318 | +KEY=4a656665 |
---|
1319 | +DATA=7768617420646f2079612077616e7420666f72206e6f7468696e673f |
---|
1320 | +HMAC-SHA256=5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843 |
---|
1321 | + |
---|
1322 | +COUNT=3 |
---|
1323 | +KEY=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
---|
1324 | +DATA=dddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd |
---|
1325 | +HMAC-SHA256=773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe |
---|
1326 | + |
---|
1327 | +COUNT=4 |
---|
1328 | +KEY=0102030405060708090a0b0c0d0e0f10111213141516171819 |
---|
1329 | +DATA=cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd |
---|
1330 | +HMAC-SHA256=82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b |
---|
1331 | + |
---|
1332 | +COUNT=5 |
---|
1333 | +KEY=0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c |
---|
1334 | +DATA=546573742057697468205472756e636174696f6e |
---|
1335 | +HMAC-SHA256=a3b6167473100ee06e0c796c2955552b |
---|
1336 | + |
---|
1337 | +COUNT=6 |
---|
1338 | +KEY=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
---|
1339 | +DATA=54657374205573696e67204c6172676572205468616e20426c6f636b2d53697a65204b6579202d2048617368204b6579204669727374 |
---|
1340 | +HMAC-SHA256=60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54 |
---|
1341 | + |
---|
1342 | +COUNT=7 |
---|
1343 | +KEY=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa |
---|
1344 | +DATA=5468697320697320612074657374207573696e672061206c6172676572207468616e20626c6f636b2d73697a65206b657920616e642061206c6172676572207468616e20626c6f636b2d73697a6520646174612e20546865206b6579206e6565647320746f20626520686173686564206265666f7265206265696e6720757365642062792074686520484d414320616c676f726974686d2e |
---|
1345 | +HMAC-SHA256=9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f51535c3a35e2 |
---|
1346 | + |
---|
1347 | } |
---|
1348 | [hkdf.dpatch |
---|
1349 | xueyu7452@gmail.com**20100704043522 |
---|
1350 | Ignore-this: f6facaf1aae1d2a4fe94faebea7cec33 |
---|
1351 | ] { |
---|
1352 | addfile ./pycryptopp/hash/hkdf.py |
---|
1353 | hunk ./pycryptopp/hash/hkdf.py 1 |
---|
1354 | +#!/usr/bin/env python |
---|
1355 | +import sha256, hmac |
---|
1356 | +import math |
---|
1357 | +from binascii import a2b_hex, b2a_hex |
---|
1358 | + |
---|
1359 | +class HKDF(object): |
---|
1360 | + def __init__(self, ikm, L, salt=None, info="", digestmod = None): |
---|
1361 | + self.ikm = ikm |
---|
1362 | + self.keylen = L |
---|
1363 | + |
---|
1364 | + if digestmod is None: |
---|
1365 | + digestmod = sha256.SHA256 |
---|
1366 | + |
---|
1367 | + if callable(digestmod): |
---|
1368 | + self.digest_cons = digestmod |
---|
1369 | + else: |
---|
1370 | + self.digest_cons = lambda d='':digestmod.new(d) |
---|
1371 | + self.hashlen = len(self.digest_cons().digest()) |
---|
1372 | + |
---|
1373 | + if salt is None: |
---|
1374 | + self.salt = chr(0)*(self.hashlen) |
---|
1375 | + else: |
---|
1376 | + self.salt = salt |
---|
1377 | + |
---|
1378 | + self.info = info |
---|
1379 | + |
---|
1380 | + #extract PRK |
---|
1381 | + def extract(self): |
---|
1382 | + h = hmac.new(self.salt, self.ikm, self.digest_cons) |
---|
1383 | + self.prk = h.digest() |
---|
1384 | + return self.prk |
---|
1385 | + |
---|
1386 | + #expand PRK |
---|
1387 | + def expand(self): |
---|
1388 | + N = math.ceil(float(self.keylen)/self.hashlen) |
---|
1389 | + T = "" |
---|
1390 | + temp = "" |
---|
1391 | + i=0x01 |
---|
1392 | + '''while len(T)<2*self.keylen : |
---|
1393 | + msg = temp |
---|
1394 | + msg += self.info |
---|
1395 | + msg += b2a_hex(chr(i)) |
---|
1396 | + h = hmac.new(self.prk, a2b_hex(msg), self.digest_cons) |
---|
1397 | + temp = b2a_hex(h.digest()) |
---|
1398 | + i += 1 |
---|
1399 | + T += temp |
---|
1400 | + ''' |
---|
1401 | + while len(T)<self.keylen : |
---|
1402 | + msg = temp |
---|
1403 | + msg += self.info |
---|
1404 | + msg += chr(i) |
---|
1405 | + h = hmac.new(self.prk, msg, self.digest_cons) |
---|
1406 | + temp = h.digest() |
---|
1407 | + i += 1 |
---|
1408 | + T += temp |
---|
1409 | + |
---|
1410 | + self.okm = T[0:self.keylen] |
---|
1411 | + return self.okm |
---|
1412 | + |
---|
1413 | +def new(ikm, L, salt=None, info="", digestmod = None): |
---|
1414 | + return HKDF(ikm, L,salt,info,digestmod) |
---|
1415 | + |
---|
1416 | + |
---|
1417 | addfile ./pycryptopp/test/hkdf_bench.py |
---|
1418 | hunk ./pycryptopp/test/hkdf_bench.py 1 |
---|
1419 | +#!/usr/bin/env python |
---|
1420 | + |
---|
1421 | +import random, re, time |
---|
1422 | +import unittest |
---|
1423 | +import hashlib |
---|
1424 | + |
---|
1425 | +from binascii import a2b_hex, b2a_hex |
---|
1426 | +from pycryptopp.hash import hkdf, sha256 |
---|
1427 | + |
---|
1428 | +def randstr(n): |
---|
1429 | + return ''.join(map(chr, map(random.randrange, [0]*n, [256]*n))) |
---|
1430 | + |
---|
1431 | +def HKDF_Bench1(): |
---|
1432 | + print "HKDF_Bench1 starting\n" |
---|
1433 | + ctxinfo = "hkdf bench test" |
---|
1434 | + salt = "" |
---|
1435 | + hash = sha256.SHA256 |
---|
1436 | + l = 20 |
---|
1437 | +# hk = hkdf.new(ikm, l, salt, ctxinfo, hash) |
---|
1438 | + start_time = time.clock() |
---|
1439 | + for times in xrange(1000): |
---|
1440 | + ikm = randstr(100) |
---|
1441 | + hk = hkdf.new(ikm, l, salt, ctxinfo, hash) |
---|
1442 | + prk = hk.extract() |
---|
1443 | + okm = hk.expand() |
---|
1444 | + |
---|
1445 | + stop_time = time.clock() |
---|
1446 | + print "hkdf using a 100 bytes ikm without salt, test 1000 times, Bench1: ", stop_time-start_time, "sec \n" |
---|
1447 | + print "HKDF_Bench1 ending\n\n" |
---|
1448 | + |
---|
1449 | +def HKDF_Bench2(): |
---|
1450 | + print "HKDF_Bench2 starting\n" |
---|
1451 | + ctxinfo = "hkdf bench test" |
---|
1452 | + hash = sha256.SHA256 |
---|
1453 | + l = 20 |
---|
1454 | + salt = "" |
---|
1455 | + start_time = time.clock() |
---|
1456 | + for times in xrange(1000): |
---|
1457 | + ikm = randstr(1000) |
---|
1458 | + hk = hkdf.new(ikm, l, salt, ctxinfo, hash) |
---|
1459 | + prk = hk.extract() |
---|
1460 | + okm = hk.expand() |
---|
1461 | + |
---|
1462 | + stop_time = time.clock() |
---|
1463 | + print "hkdf using a 1000 bytes ikm without salt, test 1000 times, Bench2: ",stop_time-start_time, "sec \n" |
---|
1464 | + print "HKDF_Bench2 ending\n\n" |
---|
1465 | + |
---|
1466 | +def HKDF_Bench3(): |
---|
1467 | + print "HKDF_Bench3 starting\n" |
---|
1468 | + ctxinfo = "hkdf bench test" |
---|
1469 | + hash = sha256.SHA256 |
---|
1470 | + l = 20 |
---|
1471 | + start_time = time.clock() |
---|
1472 | + for times in xrange(1000): |
---|
1473 | + ikm = randstr(100) |
---|
1474 | + salt = randstr(64) |
---|
1475 | + hk = hkdf.new(ikm, l, salt, ctxinfo, hash) |
---|
1476 | + prk = hk.extract() |
---|
1477 | + okm = hk.expand() |
---|
1478 | + |
---|
1479 | + stop_time = time.clock() |
---|
1480 | + print "hkdf using a 100 bytes ikm with 64 bytes salt, test 1000 times, Bench3: ", stop_time-start_time, "sec \n" |
---|
1481 | + print "HKDF_Bench3 ending\n\n" |
---|
1482 | + |
---|
1483 | +def main(): |
---|
1484 | + HKDF_Bench1() |
---|
1485 | + HKDF_Bench2() |
---|
1486 | + HKDF_Bench3() |
---|
1487 | + |
---|
1488 | +if __name__ == "__main__": |
---|
1489 | + main() |
---|
1490 | + |
---|
1491 | + |
---|
1492 | + |
---|
1493 | addfile ./pycryptopp/test/test_hkdf.py |
---|
1494 | hunk ./pycryptopp/test/test_hkdf.py 1 |
---|
1495 | +#!/usr/bin/env python |
---|
1496 | + |
---|
1497 | +import random, re |
---|
1498 | +import unittest |
---|
1499 | +import hashlib |
---|
1500 | + |
---|
1501 | +from binascii import a2b_hex, b2a_hex |
---|
1502 | +from pkg_resources import resource_string |
---|
1503 | + |
---|
1504 | +from pycryptopp.hash import hkdf, sha256 |
---|
1505 | +TEST_HKDF_RE=re.compile("\nCOUNT=([0-9]+)\nHASH=([0-9A-Z]+)\nIKM=([0-9a-f]+)\nSALT=([0-9a-z ]+)\nINFO=([0-9a-z ]+)\nL=([0-9]+)\nPRK=([0-9a-f]+)\nOKM=([0-9a-f]+)") |
---|
1506 | + |
---|
1507 | + |
---|
1508 | +class HKDFTest(unittest.TestCase): |
---|
1509 | + def test_HKDF(self): |
---|
1510 | + curfile = open('../testvectors/HKDFMsg.txt', 'r') |
---|
1511 | + s = curfile.read() |
---|
1512 | + print s, "\n" |
---|
1513 | + return self._test_HKDF(s) |
---|
1514 | + |
---|
1515 | + def _test_HKDF(self, vects_str): |
---|
1516 | + for mo in TEST_HKDF_RE.finditer(vects_str): |
---|
1517 | + count = int(mo.group(1)) |
---|
1518 | + print "test hdkf: ", count, "\n" |
---|
1519 | + hashalg =str(mo.group(2)) |
---|
1520 | + if hashalg == "SHA256": |
---|
1521 | + print "this is sha256\n" |
---|
1522 | + hash=sha256.SHA256 |
---|
1523 | + elif hashalg == "SHA1": |
---|
1524 | + print "this is sha1\n" |
---|
1525 | + hash=hashlib.sha1 |
---|
1526 | + |
---|
1527 | + ikm = a2b_hex(mo.group(3)) |
---|
1528 | + salttmp = mo.group(4) |
---|
1529 | + if salttmp == "none": |
---|
1530 | + salt = None |
---|
1531 | + elif salttmp == "zero length": |
---|
1532 | + salt = "" |
---|
1533 | + else: |
---|
1534 | + salt = a2b_hex(salttmp) |
---|
1535 | + |
---|
1536 | + infotmp = mo.group(5) |
---|
1537 | + if infotmp == "zero length": |
---|
1538 | + info = "" |
---|
1539 | + else: |
---|
1540 | + info = a2b_hex(infotmp) |
---|
1541 | + |
---|
1542 | + l = int(mo.group(6)) |
---|
1543 | + prk = a2b_hex(mo.group(7)) |
---|
1544 | + okm = a2b_hex(mo.group(8)) |
---|
1545 | + |
---|
1546 | + hk = hkdf.new(ikm, l, salt, info, hash) |
---|
1547 | + computedprk = hk.extract() |
---|
1548 | + self.failUnlessEqual(computedprk, prk, "computedprk: %s, prk: %s" % (b2a_hex(computedprk), b2a_hex(prk))) |
---|
1549 | + |
---|
1550 | + computedokm = hk.expand() |
---|
1551 | + self.failUnlessEqual(computedokm, okm, "computedokm: %s, okm: %s" % (b2a_hex(computedokm), b2a_hex(okm))) |
---|
1552 | + |
---|
1553 | + |
---|
1554 | +if __name__ == "__main__": |
---|
1555 | + unittest.main() |
---|
1556 | + |
---|
1557 | + |
---|
1558 | + |
---|
1559 | addfile ./pycryptopp/testvectors/HKDFMsg.txt |
---|
1560 | hunk ./pycryptopp/testvectors/HKDFMsg.txt 1 |
---|
1561 | + |
---|
1562 | +COUNT=1 |
---|
1563 | +HASH=SHA256 |
---|
1564 | +IKM=0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b |
---|
1565 | +SALT=000102030405060708090a0b0c |
---|
1566 | +INFO=f0f1f2f3f4f5f6f7f8f9 |
---|
1567 | +L=42 |
---|
1568 | +PRK=077709362c2e32df0ddc3f0dc47bba6390b6c73bb50f9c3122ec844ad7c2b3e5 |
---|
1569 | +OKM=3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865 |
---|
1570 | + |
---|
1571 | +COUNT=2 |
---|
1572 | +HASH=SHA256 |
---|
1573 | +IKM=000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f |
---|
1574 | +SALT=606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeaf |
---|
1575 | +INFO=b0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff |
---|
1576 | +L=82 |
---|
1577 | +PRK=06a6b88c5853361a06104c9ceb35b45cef760014904671014a193f40c15fc244 |
---|
1578 | +OKM=b11e398dc80327a1c8e7f78c596a49344f012eda2d4efad8a050cc4c19afa97c59045a99cac7827271cb41c65e590e09da3275600c2f09b8367793a9aca3db71cc30c58179ec3e87c14c01d5c1f3434f1d87 |
---|
1579 | + |
---|
1580 | +COUNT=3 |
---|
1581 | +HASH=SHA256 |
---|
1582 | +IKM=0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b |
---|
1583 | +SALT=zero length |
---|
1584 | +INFO=zero length |
---|
1585 | +L=42 |
---|
1586 | +PRK=19ef24a32c717b167f33a91d6f648bdf96596776afdb6377ac434c1c293ccb04 |
---|
1587 | +OKM=8da4e775a563c18f715f802a063c5a31b8a11f5c5ee1879ec3454e5f3c738d2d9d201395faa4b61a96c8 |
---|
1588 | + |
---|
1589 | +COUNT=4 |
---|
1590 | +HASH=SHA1 |
---|
1591 | +IKM=0b0b0b0b0b0b0b0b0b0b0b |
---|
1592 | +SALT=000102030405060708090a0b0c |
---|
1593 | +INFO=f0f1f2f3f4f5f6f7f8f9 |
---|
1594 | +L=42 |
---|
1595 | +PRK=9b6c18c432a7bf8f0e71c8eb88f4b30baa2ba243 |
---|
1596 | +OKM=085a01ea1b10f36933068b56efa5ad81a4f14b822f5b091568a9cdd4f155fda2c22e422478d305f3f896 |
---|
1597 | + |
---|
1598 | +COUNT=5 |
---|
1599 | +HASH=SHA1 |
---|
1600 | +IKM=000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f |
---|
1601 | +SALT=606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeaf |
---|
1602 | +INFO=b0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff |
---|
1603 | +L=82 |
---|
1604 | +PRK=8adae09a2a307059478d309b26c4115a224cfaf6 |
---|
1605 | +OKM=0bd770a74d1160f7c9f12cd5912a06ebff6adcae899d92191fe4305673ba2ffe8fa3f1a4e5ad79f3f334b3b202b2173c486ea37ce3d397ed034c7f9dfeb15c5e927336d0441f4c4300e2cff0d0900b52d3b4 |
---|
1606 | + |
---|
1607 | +COUNT=6 |
---|
1608 | +HASH=SHA1 |
---|
1609 | +IKM=0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b |
---|
1610 | +SALT=zero length |
---|
1611 | +INFO=zero length |
---|
1612 | +L=42 |
---|
1613 | +PRK=da8c8a73c7fa77288ec6f5e7c297786aa0d32d01 |
---|
1614 | +OKM=0ac1af7002b3d761d1e55298da9d0506b9ae52057220a306e07b6b87e8df21d0ea00033de03984d34918 |
---|
1615 | + |
---|
1616 | +COUNT=7 |
---|
1617 | +HASH=SHA1 |
---|
1618 | +IKM=0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c |
---|
1619 | +SALT=none |
---|
1620 | +INFO=zero length |
---|
1621 | +L=42 |
---|
1622 | +PRK=2adccada18779e7c2077ad2eb19d3f3e731385dd |
---|
1623 | +OKM=2c91117204d745f3500d636a62f64f0ab3bae548aa53d423b0d1f27ebba6f5e5673a081d70cce7acfc48 |
---|
1624 | + |
---|
1625 | } |
---|
1626 | |
---|
1627 | Context: |
---|
1628 | |
---|
1629 | [setup: reorganize misc/ to match Tahoe-LAFS's misc/ so that the same buildmaster config can use pycryptopp's and Tahoe-LAFS's |
---|
1630 | zooko@zooko.com**20100607062909 |
---|
1631 | Ignore-this: 500b1eab3ac1983dd72d4d120b48ac64 |
---|
1632 | ] |
---|
1633 | [TAG pycryptopp-0.5.19 |
---|
1634 | zooko@zooko.com**20100604065231 |
---|
1635 | Ignore-this: 923894ad4dca6c77ed31e80c3e4b64e7 |
---|
1636 | ] |
---|
1637 | Patch bundle hash: |
---|
1638 | 221cedd29e90d5a057c882bf0a691b51451f82e1 |
---|