iPXE
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/settings.h>
#include <ipxe/crypto.h>
#include <ipxe/md5.h>
#include <ipxe/sha1.h>
#include <usr/imgmgmt.h>
#include <hci/digest_cmd.h>

Go to the source code of this file.

Data Structures

struct  digest_options
 "digest" options More...

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 FILE_SECBOOT (PERMITTED)
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)
 COMMAND (md5sum, md5sum_exec)
 COMMAND (sha1sum, sha1sum_exec)
 REQUIRING_SYMBOL (digest_exec)
 REQUIRE_OBJECT (config_digest_cmd)

Variables

static struct option_descriptor digest_opts []
 "digest" option list
static struct command_descriptor digest_cmd
 "digest" command descriptor

Detailed Description

Digest commands.

Definition in file digest_cmd.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ digest_exec()

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

The "digest" command.

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

Definition at line 68 of file digest_cmd.c.

68 {
69 struct digest_options opts;
70 struct image *image;
71 uint8_t ctx[digest->ctxsize];
72 uint8_t out[digest->digestsize];
73 unsigned int j;
74 int i;
75 int rc;
76
77 /* Parse options */
78 if ( ( rc = parse_options ( argc, argv, &digest_cmd, &opts ) ) != 0 )
79 return rc;
80
81 /* Use default setting type, if not specified */
82 if ( ! opts.setting.setting.type )
83 opts.setting.setting.type = &setting_type_hexraw;
84
85 /* Calculate digests for each image */
86 for ( i = optind ; i < argc ; i++ ) {
87
88 /* Acquire image */
89 if ( ( rc = imgacquire ( argv[i], 0, &image ) ) != 0 )
90 return rc;
91
92 /* Calculate digest */
93 digest_init ( digest, ctx );
94 digest_update ( digest, ctx, image->data, image->len );
95 digest_final ( digest, ctx, out );
96
97 /* Display or store digest as directed */
98 if ( opts.setting.settings ) {
99
100 /* Store digest */
101 if ( ( rc = store_setting ( opts.setting.settings,
102 &opts.setting.setting, out,
103 sizeof ( out ) ) ) != 0 ) {
104 printf ( "Could not store \"%s\": %s\n",
105 opts.setting.setting.name,
106 strerror ( rc ) );
107 return rc;
108 }
109
110 } else {
111
112 /* Print digest */
113 for ( j = 0 ; j < sizeof ( out ) ; j++ )
114 printf ( "%02x", out[j] );
115 printf ( " %s\n", image->name );
116 }
117 }
118
119 return 0;
120}
struct golan_eq_context ctx
Definition CIB_PRM.h:0
__be32 out[4]
Definition CIB_PRM.h:8
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
unsigned char uint8_t
Definition stdint.h:10
static union @024010030001061367220137227263210031030210157031 opts
"cert<xxx>" option list
static struct command_descriptor digest_cmd
"digest" command descriptor
Definition digest_cmd.c:56
int optind
Current option index.
Definition getopt.c:52
int imgacquire(const char *name_uri, unsigned long timeout, struct image **image)
Acquire an image.
Definition imgmgmt.c:143
static void digest_init(struct digest_algorithm *digest, void *ctx)
Definition crypto.h:219
static void digest_final(struct digest_algorithm *digest, void *ctx, void *out)
Definition crypto.h:230
static void digest_update(struct digest_algorithm *digest, void *ctx, const void *data, size_t len)
Definition crypto.h:224
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition parseopt.c:485
int store_setting(struct settings *settings, const struct setting *setting, const void *data, size_t len)
Store value of setting.
Definition settings.c:616
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
size_t digestsize
Digest size.
Definition crypto.h:27
size_t ctxsize
Context size.
Definition crypto.h:23
"digest" options
Definition digest_cmd.c:44
An executable image.
Definition image.h:24
const void * data
Read-only data.
Definition image.h:51
char * name
Name.
Definition image.h:38
size_t len
Length of raw file image.
Definition image.h:56
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition vsprintf.c:465

References ctx, digest_algorithm::ctxsize, image::data, digest_cmd, digest_final(), digest_init(), digest_update(), digest_algorithm::digestsize, imgacquire(), image::len, image::name, optind, opts, out, parse_options(), printf(), rc, store_setting(), and strerror().

Referenced by md4sum_exec(), md5sum_exec(), REQUIRING_SYMBOL(), sha1sum_exec(), sha224sum_exec(), sha256sum_exec(), sha384sum_exec(), and sha512sum_exec().

◆ md5sum_exec()

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

Definition at line 124 of file digest_cmd.c.

124 {
125 return digest_exec ( argc, argv, &md5_algorithm );
126}
int digest_exec(int argc, char **argv, struct digest_algorithm *digest)
The "digest" command.
Definition digest_cmd.c:68
struct digest_algorithm md5_algorithm
MD5 algorithm.
Definition md5.c:287

References digest_exec(), and md5_algorithm.

Referenced by COMMAND().

◆ sha1sum_exec()

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

Definition at line 128 of file digest_cmd.c.

128 {
129 return digest_exec ( argc, argv, &sha1_algorithm );
130}
struct digest_algorithm sha1_algorithm
SHA-1 algorithm.
Definition sha1.c:258

References digest_exec(), and sha1_algorithm.

Referenced by COMMAND().

◆ COMMAND() [1/2]

COMMAND ( md5sum ,
md5sum_exec  )

References md5sum_exec().

◆ COMMAND() [2/2]

COMMAND ( sha1sum ,
sha1sum_exec  )

References sha1sum_exec().

◆ REQUIRING_SYMBOL()

REQUIRING_SYMBOL ( digest_exec )

References digest_exec().

◆ REQUIRE_OBJECT()

REQUIRE_OBJECT ( config_digest_cmd )

Variable Documentation

◆ digest_opts

struct option_descriptor digest_opts[]
static
Initial value:
= {
}
@ required_argument
Option requires an argument.
Definition getopt.h:19
int parse_autovivified_setting(char *text, struct named_setting *setting)
Parse and autovivify setting name.
Definition parseopt.c:337
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition parseopt.h:68
A setting.
Definition settings.h:24

"digest" option list

Definition at line 50 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:50
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition parseopt.h:98
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition parseopt.h:109

"digest" command descriptor

Definition at line 56 of file digest_cmd.c.

Referenced by digest_exec(), and PROVIDE_REQUIRING_SYMBOL().