asn1_integer() ensures correct DER encoding of ASN1_INTEGER (two's complement)
authorAndreas Steffen <andreas.steffen@strongswan.org>
Tue, 9 Jun 2009 11:27:59 +0000 (13:27 +0200)
committerAndreas Steffen <andreas.steffen@strongswan.org>
Tue, 9 Jun 2009 11:27:59 +0000 (13:27 +0200)
src/libstrongswan/plugins/agent/agent_private_key.c
src/libstrongswan/plugins/gcrypt/gcrypt_rsa_private_key.c
src/libstrongswan/plugins/gcrypt/gcrypt_rsa_public_key.c

index fd10c05..97ca9dc 100644 (file)
@@ -189,8 +189,8 @@ static bool matches_pubkey(chunk_t key, public_key_t *pubkey)
                return FALSE;
        }
        pubkeydata = asn1_wrap(ASN1_SEQUENCE, "mm", 
                return FALSE;
        }
        pubkeydata = asn1_wrap(ASN1_SEQUENCE, "mm", 
-                                               asn1_wrap(ASN1_INTEGER, "c", n),
-                                               asn1_wrap(ASN1_INTEGER, "c", e));
+                                               asn1_integer("c", n),
+                                               asn1_integer("c", e));
        hasher->allocate_hash(hasher, pubkeydata, &hash);
        free(pubkeydata.ptr);
        id = pubkey->get_id(pubkey, ID_PUBKEY_SHA1);
        hasher->allocate_hash(hasher, pubkeydata, &hash);
        free(pubkeydata.ptr);
        id = pubkey->get_id(pubkey, ID_PUBKEY_SHA1);
@@ -387,8 +387,8 @@ static public_key_t* get_public_key(private_agent_private_key_t *this)
        e = read_string(&key);
        n = read_string(&key);
        encoded = asn1_wrap(ASN1_SEQUENCE, "mm", 
        e = read_string(&key);
        n = read_string(&key);
        encoded = asn1_wrap(ASN1_SEQUENCE, "mm", 
-                                       asn1_wrap(ASN1_INTEGER, "c", n),
-                                       asn1_wrap(ASN1_INTEGER, "c", e));
+                                       asn1_integer("c", n),
+                                       asn1_integer("c", e));
 
        public = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_RSA, 
                                                                BUILD_BLOB_ASN1_DER, encoded, BUILD_END);
 
        public = lib->creds->create(lib->creds, CRED_PUBLIC_KEY, KEY_RSA, 
                                                                BUILD_BLOB_ASN1_DER, encoded, BUILD_END);
@@ -440,8 +440,8 @@ static bool build_ids(private_agent_private_key_t *this)
                return FALSE;
        }
        publicKey = asn1_wrap(ASN1_SEQUENCE, "mm", 
                return FALSE;
        }
        publicKey = asn1_wrap(ASN1_SEQUENCE, "mm", 
-                                       asn1_wrap(ASN1_INTEGER, "c", n),
-                                       asn1_wrap(ASN1_INTEGER, "c", e));
+                                       asn1_integer("c", n),
+                                       asn1_integer("c", e));
        hasher->allocate_hash(hasher, publicKey, &hash);
        this->keyid = identification_create_from_encoding(ID_PUBKEY_SHA1, hash);
        chunk_free(&hash);
        hasher->allocate_hash(hasher, publicKey, &hash);
        this->keyid = identification_create_from_encoding(ID_PUBKEY_SHA1, hash);
        chunk_free(&hash);
index 4bca5a5..4ee431a 100644 (file)
@@ -317,14 +317,14 @@ static chunk_t get_encoding(private_gcrypt_rsa_private_key_t *this)
        }
        
        return asn1_wrap(ASN1_SEQUENCE, "cmmmmmmmm", ASN1_INTEGER_0,
        }
        
        return asn1_wrap(ASN1_SEQUENCE, "cmmmmmmmm", ASN1_INTEGER_0,
-                       asn1_wrap(ASN1_INTEGER, "m", gcrypt_rsa_find_token(this->key, "n")),
-                       asn1_wrap(ASN1_INTEGER, "m", gcrypt_rsa_find_token(this->key, "e")),
-                       asn1_wrap(ASN1_INTEGER, "m", cd),
-                       asn1_wrap(ASN1_INTEGER, "m", cp),
-                       asn1_wrap(ASN1_INTEGER, "m", cq),
-                       asn1_wrap(ASN1_INTEGER, "m", cexp1),
-                       asn1_wrap(ASN1_INTEGER, "m", cexp2),
-                       asn1_wrap(ASN1_INTEGER, "m", gcrypt_rsa_find_token(this->key, "u")));
+                       asn1_integer("m", gcrypt_rsa_find_token(this->key, "n")),
+                       asn1_integer("m", gcrypt_rsa_find_token(this->key, "e")),
+                       asn1_integer("m", cd),
+                       asn1_integer("m", cp),
+                       asn1_integer("m", cq),
+                       asn1_integer("m", cexp1),
+                       asn1_integer("m", cexp2),
+                       asn1_integer("m", gcrypt_rsa_find_token(this->key, "u")));
 }
 
 /**
 }
 
 /**
@@ -393,8 +393,8 @@ bool gcrypt_rsa_build_keyids(gcry_sexp_t key, identification_t **keyid,
                return FALSE;
        }
        publicKey = asn1_wrap(ASN1_SEQUENCE, "mm",
                return FALSE;
        }
        publicKey = asn1_wrap(ASN1_SEQUENCE, "mm",
-                                asn1_wrap(ASN1_INTEGER, "m", gcrypt_rsa_find_token(key, "n")),
-                                asn1_wrap(ASN1_INTEGER, "m", gcrypt_rsa_find_token(key, "e")));
+                                asn1_integer("m", gcrypt_rsa_find_token(key, "n")),
+                                asn1_integer("m", gcrypt_rsa_find_token(key, "e")));
        hasher->allocate_hash(hasher, publicKey, &hash);
        *keyid = identification_create_from_encoding(ID_PUBKEY_SHA1, hash);
        chunk_free(&hash);
        hasher->allocate_hash(hasher, publicKey, &hash);
        *keyid = identification_create_from_encoding(ID_PUBKEY_SHA1, hash);
        chunk_free(&hash);
index 4c84ad6..bdb5d7f 100644 (file)
@@ -216,8 +216,8 @@ static identification_t *get_id(private_gcrypt_rsa_public_key_t *this,
 static chunk_t get_encoding(private_gcrypt_rsa_public_key_t *this)
 {
        return asn1_wrap(ASN1_SEQUENCE, "mm",
 static chunk_t get_encoding(private_gcrypt_rsa_public_key_t *this)
 {
        return asn1_wrap(ASN1_SEQUENCE, "mm",
-                       asn1_wrap(ASN1_INTEGER, "m", gcrypt_rsa_find_token(this->key, "n")),
-                       asn1_wrap(ASN1_INTEGER, "m", gcrypt_rsa_find_token(this->key, "e")));
+                       asn1_integer("m", gcrypt_rsa_find_token(this->key, "n")),
+                       asn1_integer("m", gcrypt_rsa_find_token(this->key, "e")));
 }
 
 /**
 }
 
 /**