Skip to content

Commit 1a759b9

Browse files
committed
remove spurious whitespace
1 parent c9fe3c2 commit 1a759b9

File tree

4 files changed

+35
-40
lines changed

4 files changed

+35
-40
lines changed

ecdsa/ecdsa.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
privkey = Private_key( pubkey, secret )
2525
2626
# Signing a hash value:
27-
27+
2828
hash = randrange( 1, n )
2929
signature = privkey.sign( hash, randrange( 1, n ) )
3030
@@ -77,7 +77,7 @@ def __init__( self, generator, point ):
7777
"""generator is the Point that generates the group,
7878
point is the Point that defines the public key.
7979
"""
80-
80+
8181
self.curve = generator.curve()
8282
self.generator = generator
8383
self.point = point
@@ -109,7 +109,7 @@ def verifies( self, hash, signature ):
109109
xy = u1 * G + u2 * self.point
110110
v = xy.x() % n
111111
return v == r
112-
112+
113113

114114

115115
class Private_key( object ):
@@ -120,7 +120,7 @@ def __init__( self, public_key, secret_multiplier ):
120120
"""public_key is of class Public_key;
121121
secret_multiplier is a large integer.
122122
"""
123-
123+
124124
self.public_key = public_key
125125
self.secret_multiplier = secret_multiplier
126126

@@ -396,31 +396,31 @@ def test_signature_validity( Msg, Qx, Qy, R, S, expected ):
396396
0x6a223d00bd22c52833409a163e057e5b5da1def2a197dd15, \
397397
0x7b482604199367f1f303f9ef627f922f97023e90eae08abf, \
398398
True )
399-
399+
400400
test_point_validity(
401401
p192, \
402402
0x6dccbde75c0948c98dab32ea0bc59fe125cf0fb1a3798eda, \
403403
0x0001171a3e0fa60cf3096f4e116b556198de430e1fbd330c8835, \
404404
False )
405-
405+
406406
test_point_validity(
407407
p192, \
408408
0xd266b39e1f491fc4acbbbc7d098430931cfa66d55015af12, \
409409
0x193782eb909e391a3148b7764e6b234aa94e48d30a16dbb2, \
410410
False )
411-
411+
412412
test_point_validity(
413413
p192, \
414414
0x9d6ddbcd439baa0c6b80a654091680e462a7d1d3f1ffeb43, \
415415
0x6ad8efc4d133ccf167c44eb4691c80abffb9f82b932b8caa, \
416416
False )
417-
417+
418418
test_point_validity(
419419
p192, \
420420
0x146479d944e6bda87e5b35818aa666a4c998a71f4e95edbc, \
421421
0xa86d6fe62bc8fbd88139693f842635f687f132255858e7f6, \
422422
False )
423-
423+
424424
test_point_validity(
425425
p192, \
426426
0xe594d4a598046f3598243f50fd2c7bd7d380edb055802253, \
@@ -550,18 +550,18 @@ def test_signature_validity( Msg, Qx, Qy, R, S, expected ):
550550
# further precautions are appropriate.)
551551

552552
randrange = random.SystemRandom().randrange
553-
553+
554554
secret = randrange( 1, n )
555555
pubkey = Public_key( g, g * secret )
556556
privkey = Private_key( pubkey, secret )
557557

558558
# Signing a hash value:
559-
559+
560560
hash = randrange( 1, n )
561561
signature = privkey.sign( hash, randrange( 1, n ) )
562562

563563
# Verifying a signature for a hash value:
564-
564+
565565
if pubkey.verifies( hash, signature ):
566566
print_("Demo verification succeeded.")
567567
else:

ecdsa/ellipticcurve.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def __init__( self, curve, x, y, order = None ):
7272
# self.curve is allowed to be None only for INFINITY:
7373
if self.__curve: assert self.__curve.contains_point( x, y )
7474
if order: assert self * order == INFINITY
75-
75+
7676
def __eq__( self, other ):
7777
"""Return True if the points are identical, False otherwise."""
7878
if self.__curve == other.__curve \
@@ -84,7 +84,7 @@ def __eq__( self, other ):
8484

8585
def __add__( self, other ):
8686
"""Add one point to another point."""
87-
87+
8888
# X9.62 B.3:
8989

9090
if other == INFINITY: return self
@@ -103,7 +103,7 @@ def __add__( self, other ):
103103

104104
x3 = ( l * l - self.__x - other.__x ) % p
105105
y3 = ( l * ( self.__x - x3 ) - self.__y ) % p
106-
106+
107107
return Point( self.__curve, x3, y3 )
108108

109109
def __mul__( self, other ):
@@ -139,7 +139,7 @@ def leftmost_bit( x ):
139139

140140
def __rmul__( self, other ):
141141
"""Multiply a point by an integer."""
142-
142+
143143
return self * other
144144

145145
def __str__( self ):
@@ -162,7 +162,7 @@ def double( self ):
162162

163163
x3 = ( l * l - 2 * self.__x ) % p
164164
y3 = ( l * ( self.__x - x3 ) - self.__y ) % p
165-
165+
166166
return Point( self.__curve, x3, y3 )
167167

168168
def x( self ):
@@ -173,13 +173,13 @@ def y( self ):
173173

174174
def curve( self ):
175175
return self.__curve
176-
176+
177177
def order( self ):
178178
return self.__order
179179

180180

181181
# This one point is the Point At Infinity for all purposes:
182-
INFINITY = Point( None, None, None )
182+
INFINITY = Point( None, None, None )
183183

184184
def __main__():
185185

ecdsa/numbertheory.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ def polynomial_multiply_mod( m1, m2, polymod, p ):
9292

9393
return polynomial_reduce_mod( prod, polymod, p )
9494

95-
9695

97-
9896
def polynomial_exp_mod( base, exponent, polymod, p ):
9997
"""Polynomial exponentiation modulo a polynomial over ints mod p.
10098
@@ -146,7 +144,6 @@ def jacobi( a, n ):
146144
if a1 == 1: return s
147145
if n%4 == 3 and a1%4 == 3: s = -s
148146
return s * jacobi( n % a1, a1 )
149-
150147

151148

152149

@@ -163,7 +160,7 @@ def square_root_mod_prime( a, p ):
163160

164161
if a == 0: return 0
165162
if p == 2: return a
166-
163+
167164
jac = jacobi( a, p )
168165
if jac == -1: raise SquareRootError( "%d has no square root modulo %d" \
169166
% ( a, p ) )
@@ -291,7 +288,7 @@ def factorization( n ):
291288
count = count + 1
292289
result.append( ( d, count ) )
293290
if n > 1: result.append( ( n, 1 ) )
294-
291+
295292
return result
296293

297294

@@ -405,12 +402,12 @@ def is_prime( n ):
405402
Miller-Rabin was (19999999 - 10000001)*(2/3)*(4/5)*(6/7)
406403
= 4.57 million.
407404
"""
408-
405+
409406
# (This is used to study the risk of false positives:)
410407
global miller_rabin_test_count
411408

412409
miller_rabin_test_count = 0
413-
410+
414411
if n <= smallprimes[-1]:
415412
if n in smallprimes: return True
416413
else: return False
@@ -496,7 +493,7 @@ def next_prime( starting_value ):
496493
miller_rabin_test_count = 0
497494

498495
def __main__():
499-
496+
500497
# Making sure locally defined exceptions work:
501498
# p = modular_exp( 2, -2, 3 )
502499
# p = square_root_mod_prime( 2, 3 )

ecdsa/rfc6979.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
'''
2-
32
RFC 6979:
43
Deterministic Usage of the Digital Signature Algorithm (DSA) and
54
Elliptic Curve Digital Signature Algorithm (ECDSA)
65
76
http://tools.ietf.org/html/rfc6979
8-
7+
98
Many thanks to Coda Hale for his implementation in Go language:
109
https://github.com/codahale/rfc6979
11-
1210
'''
1311

1412
import hmac
@@ -38,34 +36,34 @@ def bit_length(num):
3836
def bits2int(data, qlen):
3937
x = int(hexlify(data), 16)
4038
l = len(data) * 8
41-
39+
4240
if l > qlen:
4341
return x >> (l-qlen)
44-
return x
42+
return x
4543

4644
def bits2octets(data, order):
4745
z1 = bits2int(data, bit_length(order))
4846
z2 = z1 - order
49-
47+
5048
if z2 < 0:
5149
z2 = z1
52-
50+
5351
return number_to_string_crop(z2, order)
54-
52+
5553
# https://tools.ietf.org/html/rfc6979#section-3.2
5654
def generate_k(generator, secexp, hash_func, data):
5755
'''
5856
generator - ECDSA generator used in the signature
5957
secexp - secure exponent (private key) in numeric form
6058
hash_func - reference to the same hash function used for generating hash
61-
data - hash in binary form of the signing data
59+
data - hash in binary form of the signing data
6260
'''
63-
61+
6462
qlen = bit_length(generator.order())
6563
holen = hash_func().digest_size
6664
rolen = (qlen + 7) / 8
6765
bx = number_to_string(secexp, generator.order()) + bits2octets(data, generator.order())
68-
66+
6967
# Step B
7068
v = b('\x01') * holen
7169

@@ -74,11 +72,11 @@ def generate_k(generator, secexp, hash_func, data):
7472

7573
# Step D
7674

77-
k = hmac.new(k, v+b('\x00')+bx, hash_func).digest()
75+
k = hmac.new(k, v+b('\x00')+bx, hash_func).digest()
7876

7977
# Step E
8078
v = hmac.new(k, v, hash_func).digest()
81-
79+
8280
# Step F
8381
k = hmac.new(k, v+b('\x01')+bx, hash_func).digest()
8482

0 commit comments

Comments
 (0)