Main Page   Compound List   File List   Compound Members   File Members  

hashsum.c File Reference

#include <stdio.h>
#include <string.h>
#include "hasher/hasher.h"

Include dependency graph for hashsum.c:

Include dependency graph

Defines

#define COMMENT
#define __USE_BSD
#define READ_SIZE
#define WRAPPER(NAME, ALGO)
#define CHECK_ALGO()

Functions

int misuse (int argL, char *arg[], const char *msg)
int hashsum_file (FILE *file, const char *path, const char *app, hasher_t *h, char **msg)
int main (int argL, char *arg[])

Variables

const char* E_no_hash = "No hash algorithm specified\n"
const char * E_no_hash_yet = "File argument found, but no hash algorithm yet specified\n"
const char * E_fopen_fail = "Could not open file %s\n"
const char * E_error_read = "%s: error reading %s\n"
const char * E_blank = ""

Define Documentation

#define CHECK_ALGO( )
 

Value:

{\
  if (!algochecked) {\
    if (algostr == NULL)\
      return misuse(argL, arg, E_no_hash_yet);\
    if (strcasecmp(algostr, "md5") == 0)\
      fprintf(stderr, "md5 is not secure.  Refer to van Oorschot's paper:\n"\
                      "  http://www.rsasecurity.com/rsalabs/faq/3-6-6.html\n");\
    algochecked = 1;\
  }\
}\

Lazy programmer. If algostr is not set, complain. If the specified algorithm was md5, complain.

#define COMMENT
 

Value:

A contribution to the open-source movement. Jean-Luc Cooke <jlcooke@certainkey.com> CertainKey Inc. Ottawa Ontario Canada

Created: July 20th, 2001

The following program code is released under the GPL license http://www.gnu.org/copyleft/gpl.html

#define READ_SIZE
 

Value:

   1024
Number of bytes read in from a file at a time

#define WRAPPER( NAME, ALGO )
 

Value:

  if (strlen(NAME) <= strlen(arg[0])) {\
    if (strcasecmp(NAME, &arg[0][strlen(arg[0])-strlen(NAME)]) == 0) {\
      algostr = ALGO;\
      if (hasher_setup(&H, algostr) != HASHER_OK)\
        return misuse(argL, arg, hasher_ret_msg(H.err));\
    }\
  }
Lazy programmer. If "/path/to/NAME" was ran, then set the algo to ALGO

#define __USE_BSD
 

Value:


Function Documentation

int hashsum_file ( FILE * file,
const char * path,
const char * app,
hasher_t * h,
char ** msg )
 

Calculate and print the digest of a given file pointer

Parameters:
file   pointer to the already opened file
path   path of the file already opened
app   the path name used to execute this application
h   hasher_t structure to calculate the hash, hasher_setup() already called
pointer   to a string to store any error messages
Returns:
1 on error, 0 on success
See also:
hasher_t , hasher_ret_msg , misuse

int main ( int argL,
char * arg[] )
 

int misuse ( int argL,
char * arg[],
const char * msg )
 

Print an error message

Parameters:
argL   number of command line arguments
arg   command line arguments
msg   pointer storing the error message to print
Returns:


Variable Documentation

const char * E_blank = ""
 

Empty error message

const char * E_error_read = "%s: error reading %s\n"
 

When opening a file fails, eg. directory

const char * E_fopen_fail = "Could not open file %s\n"
 

When opening a file fails, eg. permission denied

const char * E_no_hash = "No hash algorithm specified\n"
 

When no algorithm is specified

const char * E_no_hash_yet = "File argument found, but no hash algorithm yet specified\n"
 

When files are specified but no algorithm



Confidential