]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
Extract function to convert ASN.1 INTEGER object to u_int64_t
authorTobias Brunner <tobias@strongswan.org>
Mon, 8 Apr 2013 16:31:34 +0000 (18:31 +0200)
committerTobias Brunner <tobias@strongswan.org>
Wed, 8 May 2013 12:53:08 +0000 (14:53 +0200)
src/libstrongswan/asn1/asn1.c
src/libstrongswan/asn1/asn1.h
src/libstrongswan/crypto/pkcs5.c

index f438cb20e1b5b4edfbc2eb844693e92df9ff6a35..68f37f47116e832824cfea2c717632c44237de91 100644 (file)
@@ -549,6 +549,22 @@ bool asn1_parse_simple_object(chunk_t *object, asn1_t type, u_int level, const c
        return TRUE;
 }
 
+/*
+ * Described in header
+ */
+u_int64_t asn1_parse_integer_uint64(chunk_t blob)
+{
+       u_int64_t val = 0;
+       int i;
+
+       for (i = 0; i < blob.len; i++)
+       {       /* if it is longer than 8 bytes, we just use the 8 LSBs */
+               val <<= 8;
+               val |= (u_int64_t)blob.ptr[i];
+       }
+       return val;
+}
+
 /**
  * ASN.1 definition of an algorithmIdentifier
  */
index 15ffff62e33661805eac715e074da2ff5f596fac..a1d62538035edd311ab682d8488c9c368e241ae5 100644 (file)
@@ -170,6 +170,15 @@ int asn1_parse_algorithmIdentifier(chunk_t blob, int level0, chunk_t *params);
 bool asn1_parse_simple_object(chunk_t *object, asn1_t type, u_int level0,
                                                          const char* name);
 
+/**
+ * Converts an ASN.1 INTEGER object to an u_int64_t. If the INTEGER is longer
+ * than 8 bytes only the 8 LSBs are returned.
+ *
+ * @param blob         body of an ASN.1 coded integer object
+ * @return                     converted integer
+ */
+u_int64_t asn1_parse_integer_uint64(chunk_t blob);
+
 /**
  * Print the value of an ASN.1 simple object
  *
index 76a67fc4a2cab05b0fd234aedfda003e763575e7..5c5d78c282a2217e63a3f9fb1de57e9450cb1508 100644 (file)
@@ -346,26 +346,6 @@ METHOD(pkcs5_t, decrypt, bool,
                                                   keymat, key, iv);
 }
 
-/**
- * Converts an ASN.1 INTEGER object to an u_int64_t. If the INTEGER is longer
- * than 8 bytes only the 8 LSBs are returned.
- *
- * @param blob         body of an ASN.1 coded integer object
- * @return                     converted integer
- */
-static u_int64_t parse_asn1_integer_uint64(chunk_t blob)
-{
-       u_int64_t val = 0;
-       int i;
-
-       for (i = 0; i < blob.len; i++)
-       {       /* if it is longer than 8 bytes, we just use the 8 LSBs */
-               val <<= 8;
-               val |= (u_int64_t)blob.ptr[i];
-       }
-       return val;
-}
-
 /**
  * ASN.1 definition of a PBEParameter structure
  */
@@ -402,7 +382,7 @@ static bool parse_pbes1_params(private_pkcs5_t *this, chunk_t blob, int level0)
                        }
                        case PBEPARAM_ITERATION_COUNT:
                        {
-                               this->iterations = parse_asn1_integer_uint64(object);
+                               this->iterations = asn1_parse_integer_uint64(object);
                                break;
                        }
                }
@@ -458,12 +438,12 @@ static bool parse_pbkdf2_params(private_pkcs5_t *this, chunk_t blob, int level0)
                        }
                        case PBKDF2_ITERATION_COUNT:
                        {
-                               this->iterations = parse_asn1_integer_uint64(object);
+                               this->iterations = asn1_parse_integer_uint64(object);
                                break;
                        }
                        case PBKDF2_KEYLENGTH:
                        {
-                               this->keylen = (size_t)parse_asn1_integer_uint64(object);
+                               this->keylen = (size_t)asn1_parse_integer_uint64(object);
                                break;
                        }
                        case PBKDF2_PRF: