digest_cmd.c File Reference

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <gpxe/command.h>
#include <gpxe/image.h>
#include <gpxe/crypto.h>
#include <gpxe/md5.h>
#include <gpxe/sha1.h>

Go to the source code of this file.

Functions

static void digest_syntax (char **argv)
 "digest" command syntax message
static int digest_exec (int argc, char **argv, struct digest_algorithm *digest)
 The "digest" command.
static int md5sum_exec (int argc, char **argv)
static int sha1sum_exec (int argc, char **argv)

Variables

struct command md5sum_command __command


Function Documentation

static void digest_syntax ( char **  argv  )  [static]

"digest" command syntax message

Parameters:
argv Argument list

Definition at line 34 of file digest_cmd.c.

References printf().

Referenced by digest_exec().

00034                                           {
00035         printf ( "Usage:\n"
00036                  "  %s <image name>\n"
00037                  "\n"
00038                  "Calculate the %s of an image\n",
00039                  argv[0], argv[0] );
00040 }

static int digest_exec ( int  argc,
char **  argv,
struct digest_algorithm digest 
) [static]

The "digest" command.

Parameters:
argc Argument count
argv Argument list
digest Digest algorithm
Return values:
rc Exit code

Definition at line 50 of file digest_cmd.c.

References copy_from_user(), digest_algorithm::ctxsize, image::data, digest_final(), digest_init(), digest_syntax(), digest_update(), digest_algorithm::digestsize, find_image(), image::len, image::name, offset, printf(), and strcmp().

Referenced by md5sum_exec(), and sha1sum_exec().

00051                                                            {
00052         const char *image_name;
00053         struct image *image;
00054         uint8_t digest_ctx[digest->ctxsize];
00055         uint8_t digest_out[digest->digestsize];
00056         uint8_t buf[128];
00057         size_t offset;
00058         size_t len;
00059         size_t frag_len;
00060         int i;
00061         unsigned j;
00062 
00063         if ( argc < 2 ||
00064              !strcmp ( argv[1], "--help" ) ||
00065              !strcmp ( argv[1], "-h" ) ) {
00066                 digest_syntax ( argv );
00067                 return 1;
00068         }
00069 
00070         for ( i = 1 ; i < argc ; i++ ) {
00071                 image_name = argv[i];
00072 
00073                 /* find image */
00074                 image = find_image ( image_name );
00075                 if ( ! image ) {
00076                         printf ( "No such image: %s\n", image_name );
00077                         continue;
00078                 }
00079                 offset = 0;
00080                 len = image->len;
00081 
00082                 /* calculate digest */
00083                 digest_init ( digest, digest_ctx );
00084                 while ( len ) {
00085                         frag_len = len;
00086                         if ( frag_len > sizeof ( buf ) )
00087                                 frag_len = sizeof ( buf );
00088                         copy_from_user ( buf, image->data, offset, frag_len );
00089                         digest_update ( digest, digest_ctx, buf, frag_len );
00090                         len -= frag_len;
00091                         offset += frag_len;
00092                 }
00093                 digest_final ( digest, digest_ctx, digest_out );
00094 
00095                 for ( j = 0 ; j < sizeof ( digest_out ) ; j++ )
00096                         printf ( "%02x", digest_out[j] );
00097 
00098                 printf ( "  %s\n", image->name );
00099         }
00100 
00101         return 0;
00102 }

static int md5sum_exec ( int  argc,
char **  argv 
) [static]

Definition at line 104 of file digest_cmd.c.

References digest_exec(), and md5_algorithm.

00104                                                  {
00105         return digest_exec ( argc, argv, &md5_algorithm );
00106 }

static int sha1sum_exec ( int  argc,
char **  argv 
) [static]

Definition at line 108 of file digest_cmd.c.

References digest_exec(), and sha1_algorithm.

00108                                                   {
00109         return digest_exec ( argc, argv, &sha1_algorithm );
00110 }


Variable Documentation

struct command sha1sum_command __command [read]

Initial value:

 {
        .name = "md5sum",
        .exec = md5sum_exec,
}

Definition at line 112 of file digest_cmd.c.


Generated on Tue Apr 6 20:01:46 2010 for gPXE by  doxygen 1.5.7.1