File tree Expand file tree Collapse file tree 1 file changed +6
-14
lines changed
test/functional/test_framework Expand file tree Collapse file tree 1 file changed +6
-14
lines changed Original file line number Diff line number Diff line change 9
9
10
10
This file is copied from python-bitcoinlib.
11
11
"""
12
- import struct
13
-
14
- def bn_bytes (v , have_ext = False ):
12
+ def bn_bytes (v ):
15
13
"""Return number of bytes in integer representation of v."""
16
- ext = 0
17
- if have_ext :
18
- ext = 1
19
- return (v .bit_length () + 7 ) // 8 + ext
14
+ return (v .bit_length () + 7 ) // 8
20
15
21
16
def bn2bin (v ):
22
17
"""Convert a number to a byte array."""
@@ -28,7 +23,7 @@ def bn2bin(v):
28
23
return s
29
24
30
25
def bn2mpi (v ):
31
- """Convert number to MPI format."""
26
+ """Convert number to MPI format, without the sign byte ."""
32
27
have_ext = False
33
28
if v .bit_length () > 0 :
34
29
have_ext = (v .bit_length () & 0x07 ) == 0
@@ -38,7 +33,6 @@ def bn2mpi(v):
38
33
neg = True
39
34
v = - v
40
35
41
- s = struct .pack (b">I" , bn_bytes (v , have_ext ))
42
36
ext = bytearray ()
43
37
if have_ext :
44
38
ext .append (0 )
@@ -48,13 +42,11 @@ def bn2mpi(v):
48
42
ext [0 ] |= 0x80
49
43
else :
50
44
v_bin [0 ] |= 0x80
51
- return s + ext + v_bin
45
+ return ext + v_bin
52
46
53
47
def mpi2vch (s ):
54
- """Convert MPI format to bitcoin-specific little endian format, with implicit size."""
55
- r = s [4 :] # strip size
56
- r = r [::- 1 ] # reverse string, converting BE->LE
57
- return r
48
+ """Convert MPI format to bitcoin-specific little endian format."""
49
+ return s [::- 1 ] # reverse string, converting BE->LE
58
50
59
51
def bn2vch (v ):
60
52
"""Convert number to bitcoin-specific little endian format."""
You can’t perform that action at this time.
0 commit comments