mirror of
https://github.com/brain-hackers/u-boot-brain
synced 2024-09-30 00:20:44 +09:00
hash: Use lower case for hash algorithm names
Rather than use strcasecmp() in the hash algorithm search, require the caller to do this first. Most of U-Boot can use lower case anyway, and the hash command can convert to lower case before calling hash_command(). This saves needing strcasecmp() for boards that use hashing but not the hash command. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
bd091b67d0
commit
218da0f35f
@ -26,9 +26,11 @@
|
|||||||
#include <common.h>
|
#include <common.h>
|
||||||
#include <command.h>
|
#include <command.h>
|
||||||
#include <hash.h>
|
#include <hash.h>
|
||||||
|
#include <linux/ctype.h>
|
||||||
|
|
||||||
static int do_hash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
static int do_hash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
||||||
{
|
{
|
||||||
|
char *s;
|
||||||
#ifdef CONFIG_HASH_VERIFY
|
#ifdef CONFIG_HASH_VERIFY
|
||||||
int flags = HASH_FLAG_ENV;
|
int flags = HASH_FLAG_ENV;
|
||||||
|
|
||||||
@ -45,6 +47,8 @@ static int do_hash(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
|||||||
/* Move forward to 'algorithm' parameter */
|
/* Move forward to 'algorithm' parameter */
|
||||||
argc--;
|
argc--;
|
||||||
argv++;
|
argv++;
|
||||||
|
for (s = *argv; *s; s++)
|
||||||
|
*s = tolower(*s);
|
||||||
return hash_command(*argv, flags, cmdtp, flag, argc - 1, argv + 1);
|
return hash_command(*argv, flags, cmdtp, flag, argc - 1, argv + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,7 +32,8 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* These are the hash algorithms we support. Chips which support accelerated
|
* These are the hash algorithms we support. Chips which support accelerated
|
||||||
* crypto could perhaps add named version of these algorithms here.
|
* crypto could perhaps add named version of these algorithms here. Note that
|
||||||
|
* algorithm names must be in lower case.
|
||||||
*/
|
*/
|
||||||
static struct hash_algo hash_algo[] = {
|
static struct hash_algo hash_algo[] = {
|
||||||
/*
|
/*
|
||||||
@ -42,7 +43,7 @@ static struct hash_algo hash_algo[] = {
|
|||||||
*/
|
*/
|
||||||
#ifdef CONFIG_CMD_SHA1SUM
|
#ifdef CONFIG_CMD_SHA1SUM
|
||||||
{
|
{
|
||||||
"SHA1",
|
"sha1",
|
||||||
SHA1_SUM_LEN,
|
SHA1_SUM_LEN,
|
||||||
sha1_csum_wd,
|
sha1_csum_wd,
|
||||||
CHUNKSZ_SHA1,
|
CHUNKSZ_SHA1,
|
||||||
@ -51,7 +52,7 @@ static struct hash_algo hash_algo[] = {
|
|||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_SHA256
|
#ifdef CONFIG_SHA256
|
||||||
{
|
{
|
||||||
"SHA256",
|
"sha256",
|
||||||
SHA256_SUM_LEN,
|
SHA256_SUM_LEN,
|
||||||
sha256_csum_wd,
|
sha256_csum_wd,
|
||||||
CHUNKSZ_SHA256,
|
CHUNKSZ_SHA256,
|
||||||
@ -59,7 +60,7 @@ static struct hash_algo hash_algo[] = {
|
|||||||
#define MULTI_HASH
|
#define MULTI_HASH
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
"CRC32",
|
"crc32",
|
||||||
4,
|
4,
|
||||||
crc32_wd_buf,
|
crc32_wd_buf,
|
||||||
CHUNKSZ_CRC32,
|
CHUNKSZ_CRC32,
|
||||||
@ -202,7 +203,7 @@ static struct hash_algo *find_hash_algo(const char *name)
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < ARRAY_SIZE(hash_algo); i++) {
|
for (i = 0; i < ARRAY_SIZE(hash_algo); i++) {
|
||||||
if (!strcasecmp(name, hash_algo[i].name))
|
if (!strcmp(name, hash_algo[i].name))
|
||||||
return &hash_algo[i];
|
return &hash_algo[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ enum {
|
|||||||
*
|
*
|
||||||
* This common function is used to implement specific hash commands.
|
* This common function is used to implement specific hash commands.
|
||||||
*
|
*
|
||||||
* @algo_name: Hash algorithm being used
|
* @algo_name: Hash algorithm being used (lower case!)
|
||||||
* @flags: Flags value (HASH_FLAG_...)
|
* @flags: Flags value (HASH_FLAG_...)
|
||||||
* @cmdtp: Pointer to command table entry
|
* @cmdtp: Pointer to command table entry
|
||||||
* @flag: Some flags normally 0 (see CMD_FLAG_.. above)
|
* @flag: Some flags normally 0 (see CMD_FLAG_.. above)
|
||||||
|
Loading…
Reference in New Issue
Block a user