summaryrefslogtreecommitdiffhomepage
path: root/libtomcrypt/demos/hashsum.c
diff options
context:
space:
mode:
authorMatt Johnston <matt@ucc.asn.au>2006-03-08 13:23:58 +0000
committerMatt Johnston <matt@ucc.asn.au>2006-03-08 13:23:58 +0000
commit6ae3a09ef33b62811a7f60a1f97dcb89907c1ac1 (patch)
tree37e84722c5b30bbfc86947bee260473d4604b616 /libtomcrypt/demos/hashsum.c
parent33defd1f9b6c4889fe5b075e6abb0b24c00f3a59 (diff)
parent8608a8e64c1aeda096867f43f89e29e1aee207ae (diff)
propagate from branch 'au.asn.ucc.matt.ltc.dropbear' (head 20dccfc09627970a312d77fb41dc2970b62689c3)
to branch 'au.asn.ucc.matt.dropbear' (head fdf4a7a3b97ae5046139915de7e40399cceb2c01) --HG-- extra : convert_revision : dc4809882e1b9f2dcd3f8bbe38c74a0a52c39ce4
Diffstat (limited to 'libtomcrypt/demos/hashsum.c')
-rw-r--r--libtomcrypt/demos/hashsum.c119
1 files changed, 119 insertions, 0 deletions
diff --git a/libtomcrypt/demos/hashsum.c b/libtomcrypt/demos/hashsum.c
new file mode 100644
index 0000000..653b6ef
--- /dev/null
+++ b/libtomcrypt/demos/hashsum.c
@@ -0,0 +1,119 @@
+/*
+ * Written by Daniel Richards <kyhwana@world-net.co.nz> 6/7/2002
+ * hash.c: This app uses libtomcrypt to hash either stdin or a file
+ * This file is Public Domain. No rights are reserved.
+ * Compile with 'gcc hashsum.c -o hashsum -ltomcrypt'
+ * This example isn't really big enough to warrent splitting into
+ * more functions ;)
+*/
+
+#include <tomcrypt.h>
+
+int errno;
+
+void register_algs();
+
+int main(int argc, char **argv)
+{
+ int idx, x, z;
+ unsigned long w;
+ unsigned char hash_buffer[MAXBLOCKSIZE];
+ hash_state md;
+
+ /* You need to register algorithms before using them */
+ register_algs();
+ if (argc < 2) {
+ printf("usage: ./hash algorithm file [file ...]\n");
+ printf("Algorithms:\n");
+ for (x = 0; hash_descriptor[x].name != NULL; x++) {
+ printf(" %s (%d)\n", hash_descriptor[x].name, hash_descriptor[x].ID);
+ }
+ exit(EXIT_SUCCESS);
+ }
+
+ idx = find_hash(argv[1]);
+ if (idx == -1) {
+ fprintf(stderr, "\nInvalid hash specified on command line.\n");
+ return -1;
+ }
+
+ if (argc == 2) {
+ hash_descriptor[idx].init(&md);
+ do {
+ x = fread(hash_buffer, 1, sizeof(hash_buffer), stdin);
+ hash_descriptor[idx].process(&md, hash_buffer, x);
+ } while (x == sizeof(hash_buffer));
+ hash_descriptor[idx].done(&md, hash_buffer);
+ for (x = 0; x < (int)hash_descriptor[idx].hashsize; x++) {
+ printf("%02x",hash_buffer[x]);
+ }
+ printf(" (stdin)\n");
+ } else {
+ for (z = 2; z < argc; z++) {
+ w = sizeof(hash_buffer);
+ if ((errno = hash_file(idx,argv[z],hash_buffer,&w)) != CRYPT_OK) {
+ printf("File hash error: %s\n", error_to_string(errno));
+ } else {
+ for (x = 0; x < (int)hash_descriptor[idx].hashsize; x++) {
+ printf("%02x",hash_buffer[x]);
+ }
+ printf(" %s\n", argv[z]);
+ }
+ }
+ }
+ return EXIT_SUCCESS;
+}
+
+void register_algs(void)
+{
+ int err;
+
+#ifdef TIGER
+ register_hash (&tiger_desc);
+#endif
+#ifdef MD2
+ register_hash (&md2_desc);
+#endif
+#ifdef MD4
+ register_hash (&md4_desc);
+#endif
+#ifdef MD5
+ register_hash (&md5_desc);
+#endif
+#ifdef SHA1
+ register_hash (&sha1_desc);
+#endif
+#ifdef SHA224
+ register_hash (&sha224_desc);
+#endif
+#ifdef SHA256
+ register_hash (&sha256_desc);
+#endif
+#ifdef SHA384
+ register_hash (&sha384_desc);
+#endif
+#ifdef SHA512
+ register_hash (&sha512_desc);
+#endif
+#ifdef RIPEMD128
+ register_hash (&rmd128_desc);
+#endif
+#ifdef RIPEMD160
+ register_hash (&rmd160_desc);
+#endif
+#ifdef WHIRLPOOL
+ register_hash (&whirlpool_desc);
+#endif
+#ifdef CHC_HASH
+ register_hash(&chc_desc);
+ if ((err = chc_register(register_cipher(&aes_enc_desc))) != CRYPT_OK) {
+ printf("chc_register error: %s\n", error_to_string(err));
+ exit(EXIT_FAILURE);
+ }
+#endif
+
+}
+
+/* $Source: /cvs/libtom/libtomcrypt/demos/hashsum.c,v $ */
+/* $Revision: 1.2 $ */
+/* $Date: 2005/05/05 14:35:56 $ */