aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/lib/crypto/poly1305.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-01-17 11:22:42 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2020-04-20 02:11:12 -0600
commitb27c66dcf34c5a777ef3c352935f57df15b1341f (patch)
tree035a0b2c37a9753e9200f2cf8338288670b2c139 /lib/crypto/poly1305.c
parentMerge branch 'r8169-series-with-improvements' (diff)
downloadwireguard-linux-b27c66dcf34c5a777ef3c352935f57df15b1341f.tar.xz
wireguard-linux-b27c66dcf34c5a777ef3c352935f57df15b1341f.zip
crypto: poly1305 - add library selftests
These were left out when this code was imported, but testing the library interface like this directly is useful, especially to ensure the chunking code is working correctly. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to '')
-rw-r--r--lib/crypto/poly1305.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/crypto/poly1305.c b/lib/crypto/poly1305.c
index 9d2d14df0fee..e0afa60ad8d0 100644
--- a/lib/crypto/poly1305.c
+++ b/lib/crypto/poly1305.c
@@ -3,8 +3,7 @@
* Poly1305 authenticator algorithm, RFC7539
*
* Copyright (C) 2015 Martin Willi
- *
- * Based on public domain code by Andrew Moon and Daniel J. Bernstein.
+ * Copyright (C) 2019-2020 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
*/
#include <crypto/internal/poly1305.h>
@@ -12,6 +11,8 @@
#include <linux/module.h>
#include <asm/unaligned.h>
+bool poly1305_selftest(void);
+
void poly1305_init_generic(struct poly1305_desc_ctx *desc, const u8 *key)
{
poly1305_core_setkey(&desc->core_r, key);
@@ -73,5 +74,20 @@ void poly1305_final_generic(struct poly1305_desc_ctx *desc, u8 *dst)
}
EXPORT_SYMBOL_GPL(poly1305_final_generic);
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Martin Willi <martin@strongswan.org>");
+static int __init mod_init(void)
+{
+ if (!IS_ENABLED(CONFIG_CRYPTO_MANAGER_DISABLE_TESTS) &&
+ WARN_ON(!poly1305_selftest()))
+ return -ENODEV;
+ return 0;
+}
+
+static void __exit mod_exit(void)
+{
+}
+
+module_init(mod_init);
+module_exit(mod_exit);
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("Poly1305 message authenticator");
+MODULE_AUTHOR("Jason A. Donenfeld <Jason@zx2c4.com>");