Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
- Copyright (C) 1997 - 2000 Pekka Riikonen
+ Copyright (C) 1997 - 2001 Pekka Riikonen
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
GNU General Public License for more details.
*/
-/*
- * $Id$
- * $Log$
- * Revision 1.2 2000/07/05 06:08:43 priikone
- * Global cosmetic change.
- *
- * Revision 1.1.1.1 2000/06/27 11:36:55 priikone
- * Imported from internal CVS/Added Log headers.
- *
- *
- */
+/* $Id$ */
#include "silcincludes.h"
hash->hash->update(hash->context, (unsigned char *)data, len);
hash->hash->final(hash->context, return_hash);
}
+
+/* Creates fingerprint of the data. If `hash' is NULL SHA1 is used as
+ default hash function. The returned fingerprint must be free's by the
+ caller. */
+
+char *silc_hash_fingerprint(SilcHash hash, const unsigned char *data,
+ unsigned int data_len)
+{
+ char fingerprint[64], *cp;
+ unsigned char h[32];
+ int i;
+
+ if (!hash)
+ silc_hash_alloc("sha1", &hash);
+
+ silc_hash_make(hash, data, data_len, h);
+
+ memset(fingerprint, 0, sizeof(fingerprint));
+ cp = fingerprint;
+ for (i = 0; i < hash->hash->hash_len; i++) {
+ snprintf(cp, sizeof(fingerprint), "%02X", h[i]);
+ cp += 2;
+
+ if ((i + 1) % 2 == 0)
+ snprintf(cp++, sizeof(fingerprint), " ");
+
+ if ((i + 1) % 10 == 0)
+ snprintf(cp++, sizeof(fingerprint), " ");
+ }
+
+ return strdup(fingerprint);
+}