Commit e9f3d8a6 authored by Niels Möller's avatar Niels Möller

New functions nettle_get_hashes and nettle_lookup_hash.

parent f8ad54fa
2017-01-12 Niels Möller <nisse@lysator.liu.se>
* 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
linking with libnettle.so gets copy relocations for any referenced
data items in the shared library.
* nettle-meta-hashes.c (_nettle_hashes): Renamed array, from...
(nettle_hashes): ... old name.
(nettle_get_hashes): New function.
2016-10-10 Niels Möller <nisse@lysator.liu.se>
* write-be32.c (_nettle_write_be32): Use const for source argument.
......
......@@ -110,6 +110,7 @@ nettle_SOURCES = aes-decrypt-internal.c aes-decrypt.c \
md2.c md2-meta.c md4.c md4-meta.c \
md5.c md5-compress.c md5-compat.c md5-meta.c \
memeql-sec.c memxor.c memxor3.c \
nettle-lookup-hash.c \
nettle-meta-aeads.c nettle-meta-armors.c \
nettle-meta-ciphers.c nettle-meta-hashes.c \
pbkdf2.c pbkdf2-hmac-sha1.c pbkdf2-hmac-sha256.c \
......
/* nettle-lookup-hash.c
Copyright (C) 2016 Niels Möller.
This file is part of GNU Nettle.
GNU Nettle is free software: you can redistribute it and/or
modify it under the terms of either:
* the GNU Lesser General Public License as published by the Free
Software Foundation; either version 3 of the License, or (at your
option) any later version.
or
* the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your
option) any later version.
or both in parallel, as here.
GNU Nettle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received copies of the GNU General Public License and
the GNU Lesser General Public License along with this program. If
not, see http://www.gnu.org/licenses/.
*/
#if HAVE_CONFIG_H
# include "config.h"
#endif
#include <stddef.h>
#include <string.h>
#include "nettle-meta.h"
/* Direct access to the array. */
#undef nettle_hashes
#define nettle_hashes _nettle_hashes
const struct nettle_hash *
nettle_lookup_hash (const char *name)
{
unsigned i;
for (i = 0; nettle_hashes[i]; i++)
if (!strcmp (name, nettle_hashes[i]->name))
return nettle_hashes[i];
return NULL;
}
......@@ -34,9 +34,10 @@
#endif
#include <stddef.h>
#include "nettle-meta.h"
const struct nettle_hash * const nettle_hashes[] = {
const struct nettle_hash * const _nettle_hashes[] = {
&nettle_md2,
&nettle_md4,
&nettle_md5,
......@@ -52,3 +53,9 @@ const struct nettle_hash * const nettle_hashes[] = {
&nettle_sha3_512,
NULL
};
const struct nettle_hash * const *
nettle_get_hashes (void)
{
return _nettle_hashes;
}
......@@ -115,7 +115,18 @@ struct nettle_hash
}
/* null-terminated list of digests implemented by this version of nettle */
extern const struct nettle_hash * const nettle_hashes[];
extern const struct nettle_hash * const _nettle_hashes[];
const struct nettle_hash * const *
#ifdef __GNUC__
__attribute__((pure))
#endif
nettle_get_hashes (void);
#define nettle_hashes (nettle_get_hashes())
const struct nettle_hash *
nettle_lookup_hash (const char *name);
extern const struct nettle_hash nettle_md2;
extern const struct nettle_hash nettle_md4;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment