File tree Expand file tree Collapse file tree 1 file changed +12
-12
lines changed
test/functional/test_framework Expand file tree Collapse file tree 1 file changed +12
-12
lines changed Original file line number Diff line number Diff line change 99
1010This file is copied from python-bitcoinlib.
1111"""
12- def bn2bin (v ):
13- """Convert a number to a byte array."""
14- s = bytearray ()
15- bytes_len = (v .bit_length () + 7 ) // 8
16- for i in range (bytes_len , 0 , - 1 ):
17- s .append ((v >> ((i - 1 ) * 8 )) & 0xff )
18- return s
19-
2012def bn2mpi (v ):
2113 """Convert number to MPI format, without the sign byte."""
14+ # The top bit is used to indicate the sign of the number. If there
15+ # isn't a spare bit in the bit length, add an extension byte.
2216 have_ext = False
17+ ext = bytearray ()
2318 if v .bit_length () > 0 :
2419 have_ext = (v .bit_length () & 0x07 ) == 0
20+ ext .append (0 )
2521
22+ # Is the number negative?
2623 neg = False
2724 if v < 0 :
2825 neg = True
2926 v = - v
3027
31- ext = bytearray ()
32- if have_ext :
33- ext .append (0 )
34- v_bin = bn2bin (v )
28+ # Convert the int to bytes
29+ v_bin = bytearray ()
30+ bytes_len = (v .bit_length () + 7 ) // 8
31+ for i in range (bytes_len , 0 , - 1 ):
32+ v_bin .append ((v >> ((i - 1 ) * 8 )) & 0xff )
33+
34+ # Add the sign bit if necessary
3535 if neg :
3636 if have_ext :
3737 ext [0 ] |= 0x80
You can’t perform that action at this time.
0 commit comments