1 diff --git a/utils/key2pub.py b/utils/key2pub.py
2 index 9bb04cd..632e6a6 100755
8 from M2Crypto import RSA
9 -except ImportError, e:
10 +except ImportError as e:
11 sys.stderr.write('ERROR: Failed to import the "M2Crypto" module: %s\n' % e.message)
12 sys.stderr.write('Please install the "M2Crypto" Python module.\n')
13 sys.stderr.write('On Debian GNU/Linux the package is called "python-m2crypto".\n')
16 def print_ssl_64(output, name, val):
17 - while val[0] == '\0':
18 + while val[0:1] == b'\0':
25 - vnew.append((val[0], val[1], val[2], val[3], val[4], val[5], val[6], val[7]))
26 + vnew.append((val[0:1], val[1:2], val[2:3], val[3:4], val[4:5], val[5:6], val[6:7], val[7:8]))
29 output.write('static BN_ULONG %s[%d] = {\n' % (name, len(vnew)))
30 @@ -34,13 +34,13 @@ def print_ssl_64(output, name, val):
31 output.write('};\n\n')
33 def print_ssl_32(output, name, val):
34 - while val[0] == '\0':
35 + while val[0:1] == b'\0':
42 - vnew.append((val[0], val[1], val[2], val[3], ))
43 + vnew.append((val[0:1], val[1:2], val[2:3], val[3:4]))
46 output.write('static BN_ULONG %s[%d] = {\n' % (name, len(vnew)))
47 @@ -80,21 +80,21 @@ struct pubkey {
49 static struct pubkey keys[] = {
51 - for n in xrange(n + 1):
52 + for n in range(n + 1):
53 output.write(' KEYS(e_%d, n_%d),\n' % (n, n))
57 def print_gcrypt(output, name, val):
58 output.write('#include <stdint.h>\n')
59 - while val[0] == '\0':
60 + while val[0:1] == b'\0':
62 output.write('static const uint8_t %s[%d] = {\n' % (name, len(val)))
67 - output.write('0x%.2x, ' % ord(v))
68 + output.write('0x%.2x, ' % (v if sys.version_info[0] >=3 else ord(v)))
72 @@ -117,7 +117,7 @@ struct key_params {
74 static const struct key_params __attribute__ ((unused)) keys[] = {
76 - for n in xrange(n + 1):
77 + for n in range(n + 1):
78 output.write(' KEYS(e_%d, n_%d),\n' % (n, n))
81 @@ -135,7 +135,7 @@ except IndexError:
85 - print 'Usage: %s [%s] input-file... output-file' % (sys.argv[0], '|'.join(modes.keys()))
86 + print('Usage: %s [%s] input-file... output-file' % (sys.argv[0], '|'.join(modes.keys())))
89 output = open(outfile, 'w')
90 @@ -153,3 +153,5 @@ for f in files:
93 modes[mode][1](output, idx - 1)