1 | Thu Aug 27 07:45:41 PDT 2009 nejucomo@gmail.com |
---|
2 | * Attempted minimal patch to re-enable ECDSA wrapper. |
---|
3 | |
---|
4 | Tue Sep 1 08:36:34 PDT 2009 nejucomo@gmail.com |
---|
5 | * Replace serialization length magic number with named constant. |
---|
6 | |
---|
7 | Tue Sep 1 08:37:39 PDT 2009 nejucomo@gmail.com |
---|
8 | * Add a unit test that serialized format is not too long. |
---|
9 | |
---|
10 | New patches: |
---|
11 | |
---|
12 | [Attempted minimal patch to re-enable ECDSA wrapper. |
---|
13 | nejucomo@gmail.com**20090827144541 |
---|
14 | Ignore-this: e0ef1c7008cbf38134c32365f1340d3d |
---|
15 | ] { |
---|
16 | hunk ./pycryptopp/_pycryptoppmodule.cpp 4 |
---|
17 | |
---|
18 | #include <Python.h> |
---|
19 | |
---|
20 | -//#include "publickey/ecdsamodule.hpp" |
---|
21 | +#include "publickey/ecdsamodule.hpp" |
---|
22 | #include "publickey/rsamodule.hpp" |
---|
23 | #include "hash/sha256module.hpp" |
---|
24 | #include "cipher/aesmodule.hpp" |
---|
25 | hunk ./pycryptopp/_pycryptoppmodule.cpp 38 |
---|
26 | if (!module) |
---|
27 | return; |
---|
28 | |
---|
29 | - //init_ecdsa(module); |
---|
30 | + init_ecdsa(module); |
---|
31 | init_rsa(module); |
---|
32 | init_sha256(module); |
---|
33 | init_aes(module); |
---|
34 | hunk ./pycryptopp/test/test_ecdsa.py 34 |
---|
35 | |
---|
36 | import unittest |
---|
37 | |
---|
38 | -#from pycryptopp.publickey import ecdsa |
---|
39 | -ecdsa = None # silence pyflakes |
---|
40 | +from pycryptopp.publickey import ecdsa |
---|
41 | +#ecdsa = None # silence pyflakes |
---|
42 | |
---|
43 | def randstr(n, rr=randrange): |
---|
44 | return ''.join([chr(rr(0, 256)) for x in xrange(n)]) |
---|
45 | hunk ./pycryptopp/test/test_ecdsa.py 72 |
---|
46 | SIGBYTES=div_ceil(SIGBITS, 8) |
---|
47 | |
---|
48 | class Signer(unittest.TestCase): |
---|
49 | - def disabletest_construct(self): |
---|
50 | + def test_construct(self): |
---|
51 | seed = randstr(SEEDBYTES) |
---|
52 | signer = ecdsa.SigningKey(seed) |
---|
53 | |
---|
54 | hunk ./pycryptopp/test/test_ecdsa.py 76 |
---|
55 | - def disabletest_sign(self): |
---|
56 | + def test_sign(self): |
---|
57 | seed = randstr(SEEDBYTES) |
---|
58 | signer = ecdsa.SigningKey(seed) |
---|
59 | sig = signer.sign("message") |
---|
60 | hunk ./pycryptopp/test/test_ecdsa.py 82 |
---|
61 | self.failUnlessEqual(len(sig), SIGBYTES) |
---|
62 | |
---|
63 | - def disabletest_sign_and_verify(self): |
---|
64 | + def test_sign_and_verify(self): |
---|
65 | seed = randstr(SEEDBYTES) |
---|
66 | signer = ecdsa.SigningKey(seed) |
---|
67 | sig = signer.sign("message") |
---|
68 | hunk ./pycryptopp/test/test_ecdsa.py 89 |
---|
69 | v = signer.get_verifying_key() |
---|
70 | self.failUnless(v.verify("message", sig)) |
---|
71 | |
---|
72 | - def disabletest_sign_and_verify_emptymsg(self): |
---|
73 | + def test_sign_and_verify_emptymsg(self): |
---|
74 | seed = randstr(SEEDBYTES) |
---|
75 | signer = ecdsa.SigningKey(seed) |
---|
76 | sig = signer.sign("") |
---|
77 | hunk ./pycryptopp/test/test_ecdsa.py 96 |
---|
78 | v = signer.get_verifying_key() |
---|
79 | self.failUnless(v.verify("", sig)) |
---|
80 | |
---|
81 | - def disabletest_construct_from_same_seed_is_reproducible(self): |
---|
82 | + def test_construct_from_same_seed_is_reproducible(self): |
---|
83 | seed = randstr(SEEDBYTES) |
---|
84 | signer1 = ecdsa.SigningKey(seed) |
---|
85 | signer2 = ecdsa.SigningKey(seed) |
---|
86 | hunk ./pycryptopp/test/test_ecdsa.py 118 |
---|
87 | signer5 = ecdsa.SigningKey(seed4) |
---|
88 | self.failUnlessEqual(signer5.get_verifying_key().serialize(), signer4.get_verifying_key().serialize()) |
---|
89 | |
---|
90 | - def disabletest_construct_short_seed(self): |
---|
91 | + def test_construct_short_seed(self): |
---|
92 | try: |
---|
93 | signer = ecdsa.SigningKey("\x00\x00\x00") |
---|
94 | except ecdsa.Error, le: |
---|
95 | hunk ./pycryptopp/test/test_ecdsa.py 126 |
---|
96 | else: |
---|
97 | self.fail("Should have raised error from seed being too short.") |
---|
98 | |
---|
99 | - def disabletest_construct_bad_arg_type(self): |
---|
100 | + def test_construct_bad_arg_type(self): |
---|
101 | try: |
---|
102 | signer = ecdsa.SigningKey(1) |
---|
103 | except TypeError, le: |
---|
104 | hunk ./pycryptopp/test/test_ecdsa.py 135 |
---|
105 | self.fail("Should have raised error from seed being of the wrong type.") |
---|
106 | |
---|
107 | class Verifier(unittest.TestCase): |
---|
108 | - def disabletest_from_signer_and_serialize_and_deserialize(self): |
---|
109 | + def test_from_signer_and_serialize_and_deserialize(self): |
---|
110 | seed = randstr(SEEDBYTES) |
---|
111 | signer = ecdsa.SigningKey(seed) |
---|
112 | |
---|
113 | hunk ./pycryptopp/test/test_ecdsa.py 195 |
---|
114 | self.failUnlessEqual(len(sig), SIGBYTES) |
---|
115 | self.failIf(verifier.verify(msg, sig)) |
---|
116 | |
---|
117 | - def disabletest(self): |
---|
118 | + def test(self): |
---|
119 | seed = randstr(SEEDBYTES) |
---|
120 | signer = ecdsa.SigningKey(seed) |
---|
121 | verifier = signer.get_verifying_key() |
---|
122 | hunk ./pycryptopp/test/test_ecdsa.py 247 |
---|
123 | self._help_test_sign_and_check_bad_keys(badsigner, verifier) |
---|
124 | |
---|
125 | class Compatibility(unittest.TestCase): |
---|
126 | - def disabletest_compatibility(self): |
---|
127 | + def test_compatibility(self): |
---|
128 | # Confirm that the KDF used by the SigningKey constructor doesn't |
---|
129 | # change without suitable backwards-compability |
---|
130 | seed = base64.b32decode('XS27TJRP3JBZKDEFBDKQ====') |
---|
131 | hunk ./setup.py 27 |
---|
132 | # ECDSA isn't yet supported, but it can be turned on by testing purposes. But |
---|
133 | # you'll have to comment-in some lines in the C++ code to make it work. Also |
---|
134 | # comment-in the unit tests. |
---|
135 | -ECDSA=False |
---|
136 | -# ECDSA=True |
---|
137 | +#ECDSA=False |
---|
138 | +ECDSA=True |
---|
139 | |
---|
140 | DEBUG=False |
---|
141 | if "--debug" in sys.argv: |
---|
142 | } |
---|
143 | [Replace serialization length magic number with named constant. |
---|
144 | nejucomo@gmail.com**20090901153634 |
---|
145 | Ignore-this: 9e23ba14798d4c6763ee3592aa1eed4 |
---|
146 | ] { |
---|
147 | hunk ./pycryptopp/publickey/ecdsamodule.cpp 66 |
---|
148 | #endif |
---|
149 | |
---|
150 | static const int KEY_SIZE_BITS=192; |
---|
151 | +// Serialization size adds one byte of overhead: |
---|
152 | +static const int KEY_SERIALIZATION_SIZE_BYTES = (KEY_SIZE_BITS / 8) + 1 |
---|
153 | |
---|
154 | USING_NAMESPACE(CryptoPP) |
---|
155 | |
---|
156 | hunk ./pycryptopp/publickey/ecdsamodule.cpp 101 |
---|
157 | return NULL; |
---|
158 | assert (serializedverifyingkeysize >= 0); |
---|
159 | |
---|
160 | - if (serializedverifyingkeysize != 25) { |
---|
161 | - PyErr_Format(ecdsa_error, "Precondition violation: size in bits is required to be %d (for %d-bit key), but it was %Zd", 25, KEY_SIZE_BITS, serializedverifyingkeysize); |
---|
162 | + if (serializedverifyingkeysize != KEY_SERIALIZATION_SIZE_BYTES) { |
---|
163 | + PyErr_Format(ecdsa_error, |
---|
164 | + "Precondition violation: size in bits is required to be %d (for %d-bit key), but it was %Zd", |
---|
165 | + KEY_SERIALIZATION_SIZE_BYTES, |
---|
166 | + KEY_SIZE_BITS, |
---|
167 | + serializedverifyingkeysize); |
---|
168 | return -1; |
---|
169 | } |
---|
170 | |
---|
171 | } |
---|
172 | [Add a unit test that serialized format is not too long. |
---|
173 | nejucomo@gmail.com**20090901153739 |
---|
174 | Ignore-this: 2e26c11aa3bd24999840387463726c76 |
---|
175 | ] hunk ./pycryptopp/test/test_ecdsa.py 146 |
---|
176 | s2 = verifier.serialize() |
---|
177 | self.failUnlessEqual(s1, s2) |
---|
178 | |
---|
179 | + def test_verifier_serialization_lacks_fluff(self): |
---|
180 | + KeySizeBits = 192 |
---|
181 | + KeySerializationSizeBytes = (KeySizeBits / 8) + 1 |
---|
182 | + |
---|
183 | + seed = randstr(SEEDBYTES) |
---|
184 | + signer = ecdsa.SigningKey(seed) |
---|
185 | + |
---|
186 | + verifier = signer.get_verifying_key() |
---|
187 | + serialized = verifier.serialize() |
---|
188 | + self.failUnlessEqual(len(serialized), |
---|
189 | + KeySerializationSizeBytes) |
---|
190 | + |
---|
191 | + |
---|
192 | def flip_one_bit(s): |
---|
193 | assert s |
---|
194 | i = randrange(0, len(s)) |
---|
195 | |
---|
196 | Context: |
---|
197 | |
---|
198 | [docs: small edit to README.txt |
---|
199 | zooko@zooko.com**20090729132324 |
---|
200 | Ignore-this: f1d6a6b81405705515c9d26b36400988 |
---|
201 | ] |
---|
202 | [TAG pycryptopp-0.5.16 |
---|
203 | zooko@zooko.com**20090727125049 |
---|
204 | Ignore-this: be0408712088064c264fe4c8324e8809 |
---|
205 | ] |
---|
206 | Patch bundle hash: |
---|
207 | 06e4357ddf24a13d092c087556034c1de2a70cac |
---|