X-Git-Url: http://git.tuebingen.mpg.de/?a=blobdiff_plain;ds=sidebyside;f=crypt_common.c;h=ff24e356ab8d837f8d59d67a3c983d5264376db1;hb=refs%2Fheads%2Fnext;hp=c1e40d920ff425ccfdcc536c5fb69cd0422472ca;hpb=fb3fd5b4ddaf52e19303126ea1bacacc5954d808;p=paraslash.git diff --git a/crypt_common.c b/crypt_common.c index c1e40d92..286ebe38 100644 --- a/crypt_common.c +++ b/crypt_common.c @@ -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. * @@ -270,7 +295,7 @@ int decode_private_key(const char *key_file, unsigned char **result, key_type = PKT_PEM; begin = map + strlen(PRIVATE_PEM_KEY_HEADER); footer = strstr(map, PRIVATE_PEM_KEY_FOOTER); - PARA_INFO_LOG("detected legacy PEM key %s\n", key_file); + PARA_WARNING_LOG("detected legacy PEM key %s\n", key_file); } else if (strncmp(map, PRIVATE_OPENSSH_KEY_HEADER, strlen(PRIVATE_OPENSSH_KEY_HEADER)) == 0) { key_type = PKT_OPENSSH; @@ -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;