shafile.c:


#include <string.h>
#include <stdio.h>

#include "environ.h"
#include "sha.h"

static sha_context acontext;
static sha_digest  adigest;

/* Digests the standard input and prints the result.
 */

main (argc, argv)
  int argc;
  char *argv[];
{
  /* Which argument are we processing? */
  int whichfile;

  FILE *file;
  int len, loop;
  BITS8 buffer[1024];

  if (argc < 2) {
     printf ("Usage:  Shffile filename\n");
     return 1;
  }

  whichfile = 1;
  while (whichfile < argc) { /* For each file that they gave us. */

    if ((file = fopen (argv[whichfile], "rb")) == NULL) {
        printf ("?? Could not open %s\n", argv[whichfile]);
        return 2;
     }
 
    shaInit   (&acontext, 1);

     while (len = fread (buffer, 1, 1024, file))
        shaUpdate (&acontext, buffer, len);
    shaFinal  (&acontext, adigest);

    fclose (file);

    for (loop=0; loop<SHF_DIGESTSIZE; loop++) printf ("%02lX", adigest[loop]);
    printf ("\n");
    whichfile ++;
 }

 return 0;
}


Go to ...


This page is http://www.cc.utah.edu/~nahaj/c/sha/shafile.c.html
© Copyright 2000 by John Halleck, All Rights Reserved.
This snapshot was last modified on August 23rd, 2000
And the underlying file was last modified on May 30th, 2000