iPXE
Data Structures | Functions | Variables
digest_cmd.c File Reference

Digest commands. More...

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include <ipxe/command.h>
#include <ipxe/parseopt.h>
#include <ipxe/image.h>
#include <ipxe/crypto.h>
#include <ipxe/md5.h>
#include <ipxe/sha1.h>
#include <usr/imgmgmt.h>

Go to the source code of this file.

Data Structures

struct  digest_options
 "digest" options More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 
static int digest_exec (int argc, char **argv, struct digest_algorithm *digest)
 The "digest" command. More...
 
static int md5sum_exec (int argc, char **argv)
 
static int sha1sum_exec (int argc, char **argv)
 

Variables

static struct option_descriptor digest_opts [] = {}
 "digest" option list More...
 
static struct command_descriptor digest_cmd
 "digest" command descriptor More...
 
struct command md5sum_command __command
 

Detailed Description

Digest commands.

Definition in file digest_cmd.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER  )

◆ digest_exec()

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

The "digest" command.

Parameters
argcArgument count
argvArgument list
digestDigest algorithm
Return values
rcReturn status code

Definition at line 59 of file digest_cmd.c.

60  {
61  struct digest_options opts;
62  struct image *image;
63  uint8_t digest_ctx[digest->ctxsize];
64  uint8_t digest_out[digest->digestsize];
65  uint8_t buf[128];
66  size_t offset;
67  size_t len;
68  size_t frag_len;
69  int i;
70  unsigned j;
71  int rc;
72 
73  /* Parse options */
74  if ( ( rc = parse_options ( argc, argv, &digest_cmd, &opts ) ) != 0 )
75  return rc;
76 
77  for ( i = optind ; i < argc ; i++ ) {
78 
79  /* Acquire image */
80  if ( ( rc = imgacquire ( argv[i], 0, &image ) ) != 0 )
81  continue;
82  offset = 0;
83  len = image->len;
84 
85  /* calculate digest */
86  digest_init ( digest, digest_ctx );
87  while ( len ) {
88  frag_len = len;
89  if ( frag_len > sizeof ( buf ) )
90  frag_len = sizeof ( buf );
91  copy_from_user ( buf, image->data, offset, frag_len );
92  digest_update ( digest, digest_ctx, buf, frag_len );
93  len -= frag_len;
94  offset += frag_len;
95  }
96  digest_final ( digest, digest_ctx, digest_out );
97 
98  for ( j = 0 ; j < sizeof ( digest_out ) ; j++ )
99  printf ( "%02x", digest_out[j] );
100 
101  printf ( " %s\n", image->name );
102  }
103 
104  return 0;
105 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
static void digest_update(struct digest_algorithm *digest, void *ctx, const void *data, size_t len)
Definition: crypto.h:177
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
userptr_t data
Raw file image.
Definition: image.h:41
int optind
Current option index.
Definition: getopt.c:51
static union @424 opts
"cert<xxx>" option list
static void digest_final(struct digest_algorithm *digest, void *ctx, void *out)
Definition: crypto.h:182
static __always_inline void copy_from_user(void *dest, userptr_t src, off_t src_off, size_t len)
Copy data from user buffer.
Definition: uaccess.h:337
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:447
An executable image.
Definition: image.h:24
static struct command_descriptor digest_cmd
"digest" command descriptor
Definition: digest_cmd.c:47
struct md4_digest digest
Digest of data already processed.
Definition: md4.h:12
"digest" options
Definition: digest_cmd.c:41
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
static void digest_init(struct digest_algorithm *digest, void *ctx)
Definition: crypto.h:172
size_t len
Length of raw file image.
Definition: image.h:43
unsigned char uint8_t
Definition: stdint.h:10
uint32_t len
Length.
Definition: ena.h:14
char * name
Name.
Definition: image.h:34
int imgacquire(const char *name_uri, unsigned long timeout, struct image **image)
Acquire an image.
Definition: imgmgmt.c:141

References copy_from_user(), image::data, digest, digest_cmd, digest_final(), digest_init(), digest_update(), imgacquire(), len, image::len, image::name, offset, optind, opts, parse_options(), printf(), and rc.

Referenced by md5sum_exec(), and sha1sum_exec().

◆ md5sum_exec()

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

Definition at line 107 of file digest_cmd.c.

107  {
108  return digest_exec ( argc, argv, &md5_algorithm );
109 }
static int digest_exec(int argc, char **argv, struct digest_algorithm *digest)
The "digest" command.
Definition: digest_cmd.c:59
struct digest_algorithm md5_algorithm
MD5 algorithm.
Definition: md5.c:286

References digest_exec(), and md5_algorithm.

◆ sha1sum_exec()

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

Definition at line 111 of file digest_cmd.c.

111  {
112  return digest_exec ( argc, argv, &sha1_algorithm );
113 }
static int digest_exec(int argc, char **argv, struct digest_algorithm *digest)
The "digest" command.
Definition: digest_cmd.c:59
struct digest_algorithm sha1_algorithm
SHA-1 algorithm.
Definition: sha1.c:257

References digest_exec(), and sha1_algorithm.

Variable Documentation

◆ digest_opts

struct option_descriptor digest_opts[] = {}
static

"digest" option list

Definition at line 44 of file digest_cmd.c.

◆ digest_cmd

struct command_descriptor digest_cmd
static
Initial value:
=
"<image> [<image>...]" )
static struct option_descriptor digest_opts[]
"digest" option list
Definition: digest_cmd.c:44
"digest" options
Definition: digest_cmd.c:41
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition: parseopt.h:96
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:107

"digest" command descriptor

Definition at line 47 of file digest_cmd.c.

Referenced by digest_exec().

◆ __command

struct command sha1sum_command __command
Initial value:
= {
.name = "md5sum",
.exec = md5sum_exec,
}
static int md5sum_exec(int argc, char **argv)
Definition: digest_cmd.c:107

Definition at line 115 of file digest_cmd.c.