Index: key2pub.py
===================================================================
--- key2pub.py (nonexistent)
+++ key2pub.py (revision 5)
@@ -0,0 +1,69 @@
+#!/usr/bin/env python
+
+import sys
+try:
+ from M2Crypto import RSA
+except ImportError, e:
+ sys.stderr.write('ERROR: Failed to import the "M2Crypto" module: %s\n' % e.message)
+ sys.stderr.write('Please install the "M2Crypto" Python module.\n')
+ sys.stderr.write('On Debian GNU/Linux the package is called "python-m2crypto".\n')
+ sys.exit(1)
+
+def print_bignum(output, name, val):
+ while val[0] == '\0':
+ val = val[1:]
+ output.write('static const uint8_t %s[%d] = {\n' % (name, len(val)))
+ idx = 0
+ for v in val:
+ if not idx:
+ output.write('\t')
+ output.write('0x%.2x, ' % ord(v))
+ idx += 1
+ if idx == 8:
+ idx = 0
+ output.write('\n')
+ if idx:
+ output.write('\n')
+ output.write('};\n\n')
+
+def print_keys(output, n):
+ output.write(r'''
+struct key_params {
+ const uint8_t *e, *n;
+ const uint32_t len_e, len_n;
+};
+
+#define KEYS(_e, _n) { \
+ .e = _e, .len_e = sizeof(_e), \
+ .n = _n, .len_n = sizeof(_n), \
+}
+
+static const struct key_params __attribute__ ((unused)) keys[] = {
+''')
+ for n in xrange(n + 1):
+ output.write(' KEYS(e_%d, n_%d),\n' % (n, n))
+ output.write('};\n')
+
+files = sys.argv[1:-1]
+outfile = sys.argv[-1]
+
+if len(files) == 0:
+ print 'Usage: %s input-file... output-file' % (sys.argv[0], )
+ sys.exit(2)
+
+output = open(outfile, 'w')
+output.write('#include <stdint.h>\n\n\n')
+
+# load key
+idx = 0
+for f in files:
+ try:
+ key = RSA.load_pub_key(f)
+ except RSA.RSAError:
+ key = RSA.load_key(f)
+
+ print_bignum(output, 'e_%d' % idx, key.e[4:])
+ print_bignum(output, 'n_%d' % idx, key.n[4:])
+ idx += 1
+
+print_keys(output, idx - 1)
Property changes on: key2pub.py
___________________________________________________________________
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Index: .
===================================================================
--- . (nonexistent)
+++ . (revision 5)
Property changes on: .
___________________________________________________________________
Added: svn:ignore
## -0,0 +1,73 ##
+
+# install dir
+dist
+
+# Target build dirs
+.a1x-newlib
+.a2x-newlib
+.at91sam7s-newlib
+
+.build-machine
+
+.a1x-glibc
+.a2x-glibc
+.h3-glibc
+.h5-glibc
+.i586-glibc
+.i686-glibc
+.imx6-glibc
+.jz47xx-glibc
+.makefile
+.am335x-glibc
+.omap543x-glibc
+.p5600-glibc
+.power8-glibc
+.power8le-glibc
+.power9-glibc
+.power9le-glibc
+.m1000-glibc
+.riscv64-glibc
+.rk328x-glibc
+.rk33xx-glibc
+.rk339x-glibc
+.s8xx-glibc
+.s9xx-glibc
+.x86_64-glibc
+
+# Hidden files (each file)
+.makefile
+.dist
+.rootfs
+
+# src & hw requires
+.src_requires
+.src_requires_depend
+.requires
+.requires_depend
+
+# Tarballs
+*.gz
+*.bz2
+*.lz
+*.xz
+*.tgz
+*.txz
+
+# Signatures
+*.asc
+*.sig
+*.sign
+*.sha1sum
+
+# Patches
+*.patch
+
+# Descriptions
+*.dsc
+*.txt
+
+# Default linux config files
+*.defconfig
+
+# backup copies
+*~