[PATCH 3 of 6] Make RSA Keysize definiable

Wald Commits scm-commit at wald.intevation.org
Thu Jul 10 19:17:04 CEST 2014


# HG changeset patch
# User Andre Heinecke <andre.heinecke at intevation.de>
# Date 1405012462 -7200
# Node ID 7861950f7637010c4c01a2d31d1f2c71ec3ae6ad
# Parent  44257ecdae6da866c5e508cb99385087961ca489
Make RSA Keysize definiable

diff -r 44257ecdae6d -r 7861950f7637 common/listutil.c
--- a/common/listutil.c	Thu Jul 10 19:11:09 2014 +0200
+++ b/common/listutil.c	Thu Jul 10 19:14:22 2014 +0200
@@ -98,9 +98,13 @@
     int ret = -1;
     pk_context pub_key_ctx;
     char *p;
-    /* Fixed key size of 3072 implies the sizes*/
-    const size_t sig_b64_size = 512;
-    size_t sig_size = 384;
+
+    /* Modulus / 8 are the necessary bytes. */
+#ifndef TRUSTBRIDGE_RSA_KEY_SIZE
+# error "Key size undefined"
+#endif
+    const size_t sig_b64_size = TRUSTBRIDGE_RSA_KEY_SIZE / 8 * 4 / 3;
+    size_t sig_size = TRUSTBRIDGE_RSA_KEY_SIZE / 8;
 
     char signature_b64[sig_b64_size + 1];
     unsigned char signature[sig_size];
@@ -123,7 +127,7 @@
     ret = base64_decode(signature, &sig_size,
                         (unsigned char *)signature_b64, sig_b64_size);
 
-    if (ret != 0 || sig_size != 384) {
+    if (ret != 0 || sig_size != TRUSTBRIDGE_RSA_KEY_SIZE / 8) {
 /*        printf("failed to decode signature\n"); */
         return -1;
     }
@@ -137,23 +141,6 @@
     sha256((unsigned char *)p, size - sig_b64_size - 4, hash, 0);
 
     pk_init(&pub_key_ctx);
-#if 0
-    {
-        int i;
-        FILE *foo = fopen("/tmp/testdump", "w");
-        FILE *foo2 = fopen("/tmp/rawdump", "w");
-        for (i=0; i< (int)(size - sig_b64_size - 2); i++)
-            fprintf (foo, "%c", p[i]);
-        for (i=0; i< (int)(size); i++)
-            fprintf (foo2, "%c", data[i]);
-        fclose(foo);
-        printf ("Hash: \n");
-        for (i=0; i<32; i++) {
-            printf ("%x", hash[i]);
-        }
-        printf("\n");
-    }
-#endif
 
     ret = pk_parse_public_key(&pub_key_ctx, public_key_pem,
                               public_key_pem_size);
diff -r 44257ecdae6d -r 7861950f7637 common/pubkey-release.h
--- a/common/pubkey-release.h	Thu Jul 10 19:11:09 2014 +0200
+++ b/common/pubkey-release.h	Thu Jul 10 19:14:22 2014 +0200
@@ -7,6 +7,10 @@
  */
 #ifndef PUBKEY_RELEASE_H
 #define PUBKEY_RELEASE_H
+
+/**@def The size of the RSA modulus */
+#define TRUSTBRIDGE_RSA_KEY_SIZE 3072
+
 static const unsigned char public_key_pem[] =
 "-----BEGIN PUBLIC KEY-----\n"
 "MIIDIjANBgkqhkiG9w0BAQEFAAOCAw8AMIIDCgKCAYEArUZK1sMV8cWeP48nExEh\n"
diff -r 44257ecdae6d -r 7861950f7637 common/pubkey-test.h
--- a/common/pubkey-test.h	Thu Jul 10 19:11:09 2014 +0200
+++ b/common/pubkey-test.h	Thu Jul 10 19:14:22 2014 +0200
@@ -8,6 +8,9 @@
 #ifndef PUBKEY_TEST_H
 #define PUBKEY_TEST_H
 
+/**@def The size of the RSA modulus */
+#define TRUSTBRIDGE_RSA_KEY_SIZE 3072
+
 /* PEM encoded public key */
 static const unsigned char public_key_pem[] =
 "-----BEGIN PUBLIC KEY-----\n"


More information about the Trustbridge-commits mailing list