]> git.tuebingen.mpg.de Git - paraslash.git/blobdiff - crypt_common.c
com_term(): Ignore SIGTERM.
[paraslash.git] / crypt_common.c
index c1e40d920ff425ccfdcc536c5fb69cd0422472ca..d7471235682855d3f376f0d5796b39567498937b 100644 (file)
@@ -135,7 +135,7 @@ int check_private_key_file(const char *file)
        return 1;
 }
 
-void hash_to_asc(unsigned char *hash, char *asc)
+void hash_to_asc(const unsigned char *hash, char *asc)
 {
        int i;
        const char hexchar[] = "0123456789abcdef";
@@ -147,7 +147,7 @@ void hash_to_asc(unsigned char *hash, char *asc)
        asc[2 * HASH_SIZE] = '\0';
 }
 
-int hash_compare(unsigned char *h1, unsigned char *h2)
+int hash_compare(const unsigned char *h1, const unsigned char *h2)
 {
        int i;
 
@@ -160,6 +160,31 @@ int hash_compare(unsigned char *h1, unsigned char *h2)
        return 0;
 }
 
+void hash2_to_asc(const unsigned char *hash, char *asc)
+{
+       int i;
+       const char hexchar[] = "0123456789abcdef";
+
+       for (i = 0; i < HASH2_SIZE; i++) {
+               asc[2 * i] = hexchar[hash[i] >> 4];
+               asc[2 * i + 1] = hexchar[hash[i] & 0xf];
+       }
+       asc[2 * HASH2_SIZE] = '\0';
+}
+
+int hash2_compare(const unsigned char *h1, const unsigned char *h2)
+{
+       int i;
+
+       for (i = 0; i < HASH2_SIZE; i++) {
+               if (h1[i] < h2[i])
+                       return -1;
+               if (h1[i] > h2[i])
+                       return 1;
+       }
+       return 0;
+}
+
 /**
  * Check header of an openssh private key and compute bignum offset.
  *
@@ -292,7 +317,7 @@ int decode_private_key(const char *key_file, unsigned char **result,
                goto unmap;
 
        key_size = footer - begin;
-       key = para_malloc(key_size + 1);
+       key = alloc(key_size + 1);
        for (i = 0, j = 0; begin + i < footer; i++) {
                if (para_isspace(begin[i]))
                        continue;