add tool to generate openssl public key bignums
authorJohannes Berg <johannes@sipsolutions.net>
Thu, 22 May 2008 17:35:24 +0000 (19:35 +0200)
committerJohannes Berg <johannes@sipsolutions.net>
Thu, 22 May 2008 17:35:24 +0000 (19:35 +0200)
daemon/dump.c
scripts/mk-openssl-bignum.sh [new file with mode: 0755]

index fec0a2a..867dd6f 100644 (file)
 #include <openssl/sha.h>
 #endif
 
-/* public key */
+/*
+ * public key
+ * generated using scripts/mk-openssl-bignum.sh
+ */
 static BN_ULONG e_1[] = { 65537, };
 
 static BN_ULONG n_1[] = {
diff --git a/scripts/mk-openssl-bignum.sh b/scripts/mk-openssl-bignum.sh
new file mode 100755 (executable)
index 0000000..6046ee1
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+openssl rsa -text -in key.priv.pem 2>/dev/null |\
+       sed 's/^Private//;T;d' |\
+       tr '\n' '\t' |\
+       sed 's/privateExponent:.*//' |\
+       sed 's/publicExponent:/\npublicExponent:/' |\
+       sed 's/\s*//g' |\
+       sed 's/publicExponent:\([^(]*\)(.*/\1/' |\
+       sed 's/^modulus://' |\
+       sed 's/://g' |\
+(
+       read modulus
+       read exponent
+       
+       echo 'static BN_ULONG e_1[] = {' $exponent', };'
+       echo ''
+       echo -n 'static BN_ULONG n_1[] = {'
+       modulus=$(echo $modulus | sed 's/^00//')
+       echo $modulus | sed 's/\(........\)/\t0x\1,\n/g' | tac
+       echo '};'
+)