Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dmitry Baryshkov
nettle
Commits
9911b3a5
Commit
9911b3a5
authored
Jan 12, 2017
by
Niels Möller
Browse files
Use nettle_lookup_hash.
parent
e9f3d8a6
Changes
3
Hide whitespace changes
Inline
Side-by-side
ChangeLog
View file @
9911b3a5
2017-01-12 Niels Möller <nisse@lysator.liu.se>
* tools/nettle-hash.c (find_algorithm): Deleted function.
(main): Replaced by call to nettle_lookup_hash.
* testsuite/meta-hash-test.c (test_main): Use nettle_lookup_hash.
* nettle-meta.h (nettle_hashes): New macro, expanding to a call to
nettle_get_hashes. Direct access to the array causes the array
size to leak into the ABI, since a plain un-relocatable executable
...
...
testsuite/meta-hash-test.c
View file @
9911b3a5
...
...
@@ -21,20 +21,16 @@ const char* hashes[] = {
void
test_main
(
void
)
{
int
i
,
j
;
int
i
;
int
count
=
sizeof
(
hashes
)
/
sizeof
(
*
hashes
);
for
(
i
=
0
;
i
<
count
;
i
++
)
{
for
(
j
=
0
;
NULL
!=
nettle_hashes
[
j
];
j
++
)
{
if
(
0
==
strcmp
(
hashes
[
i
],
nettle_hashes
[
j
]
->
name
))
break
;
}
ASSERT
(
NULL
!=
nettle_hashes
[
j
]);
/* make sure we found a matching hash */
/* make sure we found a matching hash */
ASSERT
(
nettle_lookup_hash
(
hashes
[
i
])
!=
NULL
);
}
j
=
0
;
while
(
NULL
!=
nettle_hashes
[
j
])
j
++
;
ASSERT
(
j
==
count
);
/* we are not missing testing any hashes */
for
(
j
=
0
;
NULL
!=
nettle_hashes
[
j
];
j
++
)
ASSERT
(
nettle_hashes
[
j
]
->
digest_size
<=
NETTLE_MAX_HASH_DIGEST_SIZE
);
while
(
NULL
!=
nettle_hashes
[
i
])
i
++
;
ASSERT
(
i
==
count
);
/* we are not missing testing any hashes */
for
(
i
=
0
;
NULL
!=
nettle_hashes
[
i
];
i
++
)
ASSERT
(
nettle_hashes
[
i
]
->
digest_size
<=
NETTLE_MAX_HASH_DIGEST_SIZE
);
}
tools/nettle-hash.c
View file @
9911b3a5
...
...
@@ -60,19 +60,6 @@ list_algorithms (void)
alg
->
name
,
alg
->
digest_size
,
alg
->
block_size
);
};
static
const
struct
nettle_hash
*
find_algorithm
(
const
char
*
name
)
{
const
struct
nettle_hash
*
alg
;
unsigned
i
;
for
(
i
=
0
;
(
alg
=
nettle_hashes
[
i
]);
i
++
)
if
(
!
strcmp
(
name
,
alg
->
name
))
return
alg
;
return
NULL
;
}
/* Also in examples/io.c */
static
int
hash_file
(
const
struct
nettle_hash
*
hash
,
void
*
ctx
,
FILE
*
f
)
...
...
@@ -211,7 +198,7 @@ main (int argc, char **argv)
die
(
"Algorithm argument (-a option) is mandatory.
\n
"
"See nettle-hash --help for further information.
\n
"
);
alg
=
find_algorithm
(
alg_name
);
alg
=
nettle_lookup_hash
(
alg_name
);
if
(
!
alg
)
die
(
"Hash algorithm `%s' not supported or .
\n
"
"Use nettle-hash --list to list available algorithms.
\n
"
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment