+2025-10-16 Niels Möller <nisse@lysator.liu.se>
+
+ Delete the undocumented nettle_armor abstraction.
+ * nettle-types.h (nettle_armor_length_func)
+ (nettle_armor_init_func, nettle_armor_encode_update_func)
+ (nettle_armor_encode_final_func, nettle_armor_decode_update_func)
+ (nettle_armor_decode_final_func): Deleted typedefs.
+ * nettle-meta.h (struct nettle_armor): Deleted struct.
+ (_NETTLE_ARMOR, _NETTLE_ARMOR_0): Deleted macros.
+ (nettle_get_armors, nettle_armors, nettle_base64)
+ (nettle_base64url, nettle_base16): Deleted declarations.
+ * base16-meta.c: Deleted file.
+ * base64-meta.c: Deleted file.
+ * base64url-meta.c: Deleted file.
+ * nettle-meta-armors.c: Deleted file.
+ * Makefile.in (nettle_SOURCES): Drop deleted files.
+
+ * testsuite/base16-test.c (test_base16): New more concrete test function.
+ (test_main): Updated to use test_base16 rather than test_armor.
+ * testsuite/base64-test.c (test_base64): New more concretetest
+ function, parameterized only by init functions to use.
+ (test_main): Updated to use test_base64 rather than test_armor.
+ * testsuite/testutils.c (test_armor): Deleted function.
+ * testsuite/meta-armor-test.c: Deleted file.
+ * testsuite/Makefile.in (TS_NETTLE_SOURCES): Drop meta-armor-test.c.
+
2025-10-13 Niels Möller <nisse@lysator.liu.se>
* tools/input.h (struct sexp_input): Replace use of struct
arctwo.c arctwo-meta.c blowfish.c blowfish-bcrypt.c \
balloon.c balloon-sha1.c balloon-sha256.c \
balloon-sha384.c balloon-sha512.c \
- base16-encode.c base16-decode.c base16-meta.c \
- base64-encode.c base64-decode.c base64-meta.c \
- base64url-encode.c base64url-decode.c base64url-meta.c \
+ base16-encode.c base16-decode.c \
+ base64-encode.c base64-decode.c \
+ base64url-encode.c base64url-decode.c \
buffer.c buffer-init.c \
camellia-crypt-internal.c camellia-table.c \
camellia-absorb.c camellia-invert-key.c \
md5.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-aeads.c \
nettle-meta-ciphers.c nettle-meta-hashes.c nettle-meta-macs.c \
ocb.c ocb-aes128.c \
pbkdf2.c pbkdf2-hmac-gosthash94.c pbkdf2-hmac-sha1.c \
+++ /dev/null
-/* base16-meta.c
-
- Copyright (C) 2002 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 "nettle-meta.h"
-
-#include "base16.h"
-
-/* Same as the macros with the same name */
-static nettle_armor_length_func base16_encode_length;
-static size_t
-base16_encode_length(size_t length)
-{
- return BASE16_ENCODE_LENGTH(length);
-}
-
-static nettle_armor_length_func base16_decode_length;
-static size_t
-base16_decode_length(size_t length)
-{
- return BASE16_DECODE_LENGTH(length);
-}
-
-static nettle_armor_init_func base16_encode_init;
-static void
-base16_encode_init(void *ctx UNUSED)
-{ }
-
-static nettle_armor_encode_update_func base16_encode_update_wrapper;
-static size_t
-base16_encode_update_wrapper(void *ctx UNUSED, char *dst,
- size_t length, const uint8_t *src)
-{
- base16_encode_update(dst, length, src);
- return BASE16_ENCODE_LENGTH(length);
-}
-
-#undef base16_encode_update
-#define base16_encode_update base16_encode_update_wrapper
-
-static nettle_armor_encode_final_func base16_encode_final;
-static size_t
-base16_encode_final(void *ctx UNUSED, char *dst UNUSED)
-{
- return 0;
-}
-
-
-#define BASE16_ENCODE_FINAL_LENGTH 0
-
-const struct nettle_armor nettle_base16
-= _NETTLE_ARMOR_0(base16, BASE16);
+++ /dev/null
-/* base64-meta.c
-
- Copyright (C) 2002 Dan Egnor, 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 "nettle-meta.h"
-
-#include "base64.h"
-
-/* Same as the macros with the same name */
-static nettle_armor_length_func base64_encode_length;
-static size_t
-base64_encode_length(size_t length)
-{
- return BASE64_ENCODE_LENGTH(length);
-}
-
-static nettle_armor_length_func base64_decode_length;
-static size_t
-base64_decode_length(size_t length)
-{
- return BASE64_DECODE_LENGTH(length);
-}
-
-const struct nettle_armor nettle_base64
-= _NETTLE_ARMOR(base64, BASE64);
+++ /dev/null
-/* base64url-meta.c
-
- Copyright (C) 2015 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 "nettle-meta.h"
-
-#include "base64.h"
-
-/* Same as the macros with the same name */
-static nettle_armor_length_func base64url_encode_length;
-static size_t
-base64url_encode_length(size_t length)
-{
- return BASE64_ENCODE_LENGTH(length);
-}
-
-static nettle_armor_length_func base64url_decode_length;
-static size_t
-base64url_decode_length(size_t length)
-{
- return BASE64_DECODE_LENGTH(length);
-}
-
-#define base64url_encode_ctx base64_encode_ctx
-#define base64url_encode_update base64_encode_update
-#define base64url_encode_final base64_encode_final
-#define base64url_decode_ctx base64_decode_ctx
-#define base64url_decode_update base64_decode_update
-#define base64url_decode_final base64_decode_final
-
-const struct nettle_armor nettle_base64url
-= _NETTLE_ARMOR(base64url, BASE64);
+++ /dev/null
-/* nettle-meta-armors.c
-
- Copyright (C) 2011 Daniel Kahn Gillmor
-
- 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 "nettle-meta.h"
-
-const struct nettle_armor * const _nettle_armors[] = {
- &nettle_base64,
- &nettle_base64url,
- &nettle_base16,
- NULL
-};
-
-const struct nettle_armor * const *
-nettle_get_armors (void)
-{
- return _nettle_armors;
-}
nettle_hash_update_func *update;
nettle_crypt_func *encrypt;
nettle_crypt_func *decrypt;
- /* FIXME: Drop length argument? */
nettle_hash_digest_func *digest;
};
extern const struct nettle_aead nettle_eax_aes128;
extern const struct nettle_aead nettle_chacha_poly1305;
-struct nettle_armor
-{
- const char *name;
- unsigned encode_context_size;
- unsigned decode_context_size;
-
- unsigned encode_final_length;
-
- nettle_armor_init_func *encode_init;
- nettle_armor_length_func *encode_length;
- nettle_armor_encode_update_func *encode_update;
- nettle_armor_encode_final_func *encode_final;
-
- nettle_armor_init_func *decode_init;
- nettle_armor_length_func *decode_length;
- nettle_armor_decode_update_func *decode_update;
- nettle_armor_decode_final_func *decode_final;
-};
-
-#define _NETTLE_ARMOR(name, NAME) { \
- #name, \
- sizeof(struct name##_encode_ctx), \
- sizeof(struct name##_decode_ctx), \
- NAME##_ENCODE_FINAL_LENGTH, \
- (nettle_armor_init_func *) name##_encode_init, \
- (nettle_armor_length_func *) name##_encode_length, \
- (nettle_armor_encode_update_func *) name##_encode_update, \
- (nettle_armor_encode_final_func *) name##_encode_final, \
- (nettle_armor_init_func *) name##_decode_init, \
- (nettle_armor_length_func *) name##_decode_length, \
- (nettle_armor_decode_update_func *) name##_decode_update, \
- (nettle_armor_decode_final_func *) name##_decode_final, \
-}
-
-#define _NETTLE_ARMOR_0(name, NAME) { \
- #name, \
- 0, \
- sizeof(struct name##_decode_ctx), \
- NAME##_ENCODE_FINAL_LENGTH, \
- (nettle_armor_init_func *) name##_encode_init, \
- (nettle_armor_length_func *) name##_encode_length, \
- (nettle_armor_encode_update_func *) name##_encode_update, \
- (nettle_armor_encode_final_func *) name##_encode_final, \
- (nettle_armor_init_func *) name##_decode_init, \
- (nettle_armor_length_func *) name##_decode_length, \
- (nettle_armor_decode_update_func *) name##_decode_update, \
- (nettle_armor_decode_final_func *) name##_decode_final, \
-}
-
-/* null-terminated list of armor schemes implemented by this version of nettle */
-const struct nettle_armor * const * _NETTLE_ATTRIBUTE_PURE
-nettle_get_armors (void);
-
-#define nettle_armors (nettle_get_armors())
-
-extern const struct nettle_armor nettle_base64;
-extern const struct nettle_armor nettle_base64url;
-extern const struct nettle_armor nettle_base16;
-
#define _NETTLE_HMAC(name, HASH) { \
#name, \
sizeof(struct name##_ctx), \
const uint8_t *src);
typedef void nettle_hash_digest_func(void *ctx, uint8_t *dst);
-/* ASCII armor codecs. NOTE: Experimental and subject to change. */
-
-typedef size_t nettle_armor_length_func(size_t length);
-typedef void nettle_armor_init_func(void *ctx);
-
-typedef size_t nettle_armor_encode_update_func(void *ctx,
- char *dst,
- size_t src_length,
- const uint8_t *src);
-
-typedef size_t nettle_armor_encode_final_func(void *ctx, char *dst);
-
-typedef int nettle_armor_decode_update_func(void *ctx,
- size_t *dst_length,
- uint8_t *dst,
- size_t src_length,
- const char *src);
-
-typedef int nettle_armor_decode_final_func(void *ctx);
-
#ifdef __cplusplus
}
#endif
poly1305-test.c chacha-poly1305-test.c \
hmac-test.c umac-test.c \
meta-hash-test.c meta-cipher-test.c\
- meta-aead-test.c meta-armor-test.c meta-mac-test.c \
+ meta-aead-test.c meta-mac-test.c \
buffer-test.c yarrow-test.c xts-test.c pbkdf2-test.c \
x86-ibt-test.c drbg-ctr-aes256-test.c \
slh-dsa-test.c
#include "testutils.h"
#include "base16.h"
+static void
+test_base16 (size_t data_length, const uint8_t *data,
+ const char *ascii)
+{
+ size_t ascii_length = strlen(ascii);
+ char *buffer = xalloc(1 + ascii_length);
+ uint8_t *check = xalloc(1 + BASE16_DECODE_LENGTH (ascii_length));
+ struct base16_decode_ctx decode;
+ size_t done;
+
+ ASSERT(ascii_length <= BASE16_ENCODE_LENGTH (data_length));
+ ASSERT(data_length <= BASE16_DECODE_LENGTH (ascii_length));
+
+ memset(buffer, 0x33, 1 + ascii_length);
+ memset(check, 0x55, 1 + data_length);
+
+ base16_encode_update (buffer, data_length, data);
+
+ ASSERT (MEMEQ(ascii_length, buffer, ascii));
+ ASSERT (0x33 == buffer[ascii_length]);
+
+ base16_decode_init (&decode);
+ done = BASE16_DECODE_LENGTH (ascii_length);
+
+ ASSERT (base16_decode_update(&decode, &done, check, ascii_length, buffer));
+ ASSERT (done == data_length);
+ ASSERT (base16_decode_final (&decode));
+
+ ASSERT (MEMEQ(data_length, check, data));
+ ASSERT (0x55 == check[data_length]);
+
+ free(buffer);
+ free(check);
+}
+
void
test_main(void)
{
ASSERT(BASE16_DECODE_LENGTH(2) == 1);
ASSERT(BASE16_DECODE_LENGTH(3) == 2);
ASSERT(BASE16_DECODE_LENGTH(4) == 2);
-
- test_armor(&nettle_base16, LDATA(""), "");
- test_armor(&nettle_base16, LDATA("H"), "48");
- test_armor(&nettle_base16, LDATA("He"), "4865");
- test_armor(&nettle_base16, LDATA("Hel"), "48656c");
- test_armor(&nettle_base16, LDATA("Hell"), "48656c6c");
- test_armor(&nettle_base16, LDATA("Hello"), "48656c6c6f");
- test_armor(&nettle_base16, LDATA("Hello\0"), "48656c6c6f00");
+
+ test_base16 (LDATA(""), "");
+ test_base16 (LDATA("H"), "48");
+ test_base16 (LDATA("He"), "4865");
+ test_base16 (LDATA("Hel"), "48656c");
+ test_base16 (LDATA("Hell"), "48656c6c");
+ test_base16 (LDATA("Hello"), "48656c6c6f");
+ test_base16 (LDATA("Hello\0"), "48656c6c6f00");
}
-
#include "base64.h"
#include "knuth-lfib.h"
+struct base64_variant
+{
+ void (*encode_init)(struct base64_encode_ctx *ctx);
+ void (*decode_init)(struct base64_decode_ctx *ctx);
+};
+
+static const struct base64_variant base64std = {
+ base64_encode_init, base64_decode_init,
+};
+static const struct base64_variant base64url = {
+ base64url_encode_init, base64url_decode_init,
+};
+
+static void
+test_base64 (const struct base64_variant *variant,
+ size_t data_length,
+ const uint8_t *data,
+ const char *ascii)
+{
+ size_t ascii_length = strlen (ascii);
+ char *buffer = xalloc (1 + ascii_length);
+ uint8_t *check = xalloc (1 + BASE64_DECODE_LENGTH (ascii_length));
+ struct base64_encode_ctx encode;
+ struct base64_decode_ctx decode;
+ size_t done;
+
+ ASSERT (ascii_length
+ <= (BASE64_ENCODE_LENGTH (data_length) + BASE64_ENCODE_FINAL_LENGTH));
+ ASSERT (data_length <= BASE64_DECODE_LENGTH (ascii_length));
+
+ memset(buffer, 0x33, 1 + ascii_length);
+ memset(check, 0x55, 1 + data_length);
+
+ variant->encode_init(&encode);
+
+ done = base64_encode_update (&encode, buffer, data_length, data);
+ done += base64_encode_final (&encode, buffer + done);
+ ASSERT (done == ascii_length);
+
+ ASSERT (MEMEQ(ascii_length, buffer, ascii));
+ ASSERT (0x33 == buffer[ascii_length]);
+
+ variant->decode_init (&decode);
+ done = BASE64_DECODE_LENGTH (ascii_length);
+
+ ASSERT (base64_decode_update(&decode, &done, check, ascii_length, buffer));
+ ASSERT (done == data_length);
+ ASSERT (base64_decode_final(&decode));
+
+ ASSERT (MEMEQ(data_length, check, data));
+ ASSERT (0x55 == check[data_length]);
+
+ free(buffer);
+ free(check);
+}
+
static void
test_fuzz_once(struct base64_encode_ctx *encode,
struct base64_decode_ctx *decode,
ASSERT(BASE64_DECODE_LENGTH(3) == 3); /* At most 24 bits */
ASSERT(BASE64_DECODE_LENGTH(4) == 3); /* At most 30 bits */
- test_armor(&nettle_base64, LDATA(""), "");
- test_armor(&nettle_base64, LDATA("H"), "SA==");
- test_armor(&nettle_base64, LDATA("He"), "SGU=");
- test_armor(&nettle_base64, LDATA("Hel"), "SGVs");
- test_armor(&nettle_base64, LDATA("Hell"), "SGVsbA==");
- test_armor(&nettle_base64, LDATA("Hello"), "SGVsbG8=");
- test_armor(&nettle_base64, LDATA("Hello\0"), "SGVsbG8A");
- test_armor(&nettle_base64, LDATA("Hello?>>>"), "SGVsbG8/Pj4+");
- test_armor(&nettle_base64, LDATA("\xff\xff\xff\xff"), "/////w==");
-
- test_armor(&nettle_base64url, LDATA(""), "");
- test_armor(&nettle_base64url, LDATA("H"), "SA==");
- test_armor(&nettle_base64url, LDATA("He"), "SGU=");
- test_armor(&nettle_base64url, LDATA("Hel"), "SGVs");
- test_armor(&nettle_base64url, LDATA("Hell"), "SGVsbA==");
- test_armor(&nettle_base64url, LDATA("Hello"), "SGVsbG8=");
- test_armor(&nettle_base64url, LDATA("Hello\0"), "SGVsbG8A");
- test_armor(&nettle_base64url, LDATA("Hello?>>>"), "SGVsbG8_Pj4-");
- test_armor(&nettle_base64url, LDATA("\xff\xff\xff\xff"), "_____w==");
+ test_base64(&base64std, LDATA(""), "");
+ test_base64(&base64std, LDATA("H"), "SA==");
+ test_base64(&base64std, LDATA("He"), "SGU=");
+ test_base64(&base64std, LDATA("Hel"), "SGVs");
+ test_base64(&base64std, LDATA("Hell"), "SGVsbA==");
+ test_base64(&base64std, LDATA("Hello"), "SGVsbG8=");
+ test_base64(&base64std, LDATA("Hello\0"), "SGVsbG8A");
+ test_base64(&base64std, LDATA("Hello?>>>"), "SGVsbG8/Pj4+");
+ test_base64(&base64std, LDATA("\xff\xff\xff\xff"), "/////w==");
+
+ test_base64(&base64url, LDATA(""), "");
+ test_base64(&base64url, LDATA("H"), "SA==");
+ test_base64(&base64url, LDATA("He"), "SGU=");
+ test_base64(&base64url, LDATA("Hel"), "SGVs");
+ test_base64(&base64url, LDATA("Hell"), "SGVsbA==");
+ test_base64(&base64url, LDATA("Hello"), "SGVsbG8=");
+ test_base64(&base64url, LDATA("Hello\0"), "SGVsbG8A");
+ test_base64(&base64url, LDATA("Hello?>>>"), "SGVsbG8_Pj4-");
+ test_base64(&base64url, LDATA("\xff\xff\xff\xff"), "_____w==");
{
/* Test overlapping areas */
+++ /dev/null
-#include "testutils.h"
-#include "nettle-meta.h"
-
-const char* armors[] = {
- "base16",
- "base64",
- "base64url",
-};
-
-void
-test_main(void)
-{
- int i,j;
- int count = sizeof(armors)/sizeof(*armors);
- for (i = 0; i < count; i++) {
- for (j = 0; NULL != nettle_armors[j]; j++) {
- if (0 == strcmp(armors[i], nettle_armors[j]->name))
- break;
- }
- ASSERT(NULL != nettle_armors[j]); /* make sure we found a matching armor */
- }
- j = 0;
- while (NULL != nettle_armors[j])
- j++;
- ASSERT(j == count); /* we are not missing testing any armors */
-}
-
free (hash);
}
-void
-test_armor(const struct nettle_armor *armor,
- size_t data_length,
- const uint8_t *data,
- const char *ascii)
-{
- size_t ascii_length = strlen(ascii);
- char *buffer = xalloc(1 + ascii_length);
- uint8_t *check = xalloc(1 + armor->decode_length(ascii_length));
- void *encode = xalloc(armor->encode_context_size);
- void *decode = xalloc(armor->decode_context_size);
- size_t done;
-
- ASSERT(ascii_length
- <= (armor->encode_length(data_length) + armor->encode_final_length));
- ASSERT(data_length <= armor->decode_length(ascii_length));
-
- memset(buffer, 0x33, 1 + ascii_length);
- memset(check, 0x55, 1 + data_length);
-
- armor->encode_init(encode);
-
- done = armor->encode_update(encode, buffer, data_length, data);
- done += armor->encode_final(encode, buffer + done);
- ASSERT(done == ascii_length);
-
- ASSERT (MEMEQ(ascii_length, buffer, ascii));
- ASSERT (0x33 == buffer[strlen(ascii)]);
-
- armor->decode_init(decode);
- done = armor->decode_length(ascii_length);
-
- ASSERT(armor->decode_update(decode, &done, check, ascii_length, buffer));
- ASSERT(done == data_length);
- ASSERT(armor->decode_final(decode));
-
- ASSERT (MEMEQ(data_length, check, data));
- ASSERT (0x55 == check[data_length]);
-
- free(buffer);
- free(check);
- free(encode);
- free(decode);
-}
-
#if WITH_HOGWEED
void
const struct tstring *msg,
const struct tstring *digest);
-void
-test_armor(const struct nettle_armor *armor,
- size_t data_length,
- const uint8_t *data,
- const char *ascii);
-
#if WITH_HOGWEED
#if NETTLE_USE_MINI_GMP