Nikos Mavrogiannopoulos n.mavrogiannopoulos@gmail.com writes:
The more long term question, is should nettle be striving to provide an ABI? If not, it could transform to low-level library gnulib or ccan are (i.e. like a copy-lib)... or alternatively, if yes, provide a high level stable API which hides details and the ABI is easier to provide.
I'm experimenting with this... Starting with hashes which are the simplest primitive. Header file changes below. Comments appreciated, including naming suggestions.
Regards, /Niels
--- a/nettle-hash.h +++ b/nettle-hash.h @@ -0,0 +1,66 @@ +/* nettle-hash.h + + This file defines an opaque API for Nettle hash functions. + + 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/. +*/ + +#ifndef NETTLE_HASH_H_INCLUDED +#define NETTLE_HASH_H_INCLUDED + +#include "nettle-types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +struct nettle_hash; + +size_t +nettle_hash_get_context_size(const struct nettle_hash *hash); + +size_t +nettle_hash_get_digest_size(const struct nettle_hash *hash); + +void +nettle_hash_init(const struct nettle_hash *hash, void *ctx); + +void +nettle_hash_update(const struct nettle_hash *hash, + void *ctx, size_t length, const uint8_t *src); + +void +nettle_hash_digest(const struct nettle_hash *hash, + void *ctx, size_t length, uint8_t *dst); + +#ifdef __cplusplus +} +#endif + +#endif /* NETTLE_HASH_H_INCLUDED */ --- a/nettle-meta.h +++ b/nettle-meta.h @@ -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;