Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

lib/crypto: tests: Add KUnit tests for POLYVAL

Add a test suite for the POLYVAL library, including:

- All the standard tests and the benchmark from hash-test-template.h
- Comparison with a test vector from the RFC
- Test with key and message containing all one bits
- Additional tests related to the key struct

Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/r/20251109234726.638437-4-ebiggers@kernel.org
Signed-off-by: Eric Biggers <ebiggers@kernel.org>

+464 -2
+9
lib/crypto/tests/Kconfig
··· 47 47 help 48 48 KUnit tests for the Poly1305 library functions. 49 49 50 + config CRYPTO_LIB_POLYVAL_KUNIT_TEST 51 + tristate "KUnit tests for POLYVAL" if !KUNIT_ALL_TESTS 52 + depends on KUNIT 53 + default KUNIT_ALL_TESTS || CRYPTO_SELFTESTS 54 + select CRYPTO_LIB_BENCHMARK_VISIBLE 55 + select CRYPTO_LIB_POLYVAL 56 + help 57 + KUnit tests for the POLYVAL library functions. 58 + 50 59 config CRYPTO_LIB_SHA1_KUNIT_TEST 51 60 tristate "KUnit tests for SHA-1" if !KUNIT_ALL_TESTS 52 61 depends on KUNIT
+1
lib/crypto/tests/Makefile
··· 5 5 obj-$(CONFIG_CRYPTO_LIB_CURVE25519_KUNIT_TEST) += curve25519_kunit.o 6 6 obj-$(CONFIG_CRYPTO_LIB_MD5_KUNIT_TEST) += md5_kunit.o 7 7 obj-$(CONFIG_CRYPTO_LIB_POLY1305_KUNIT_TEST) += poly1305_kunit.o 8 + obj-$(CONFIG_CRYPTO_LIB_POLYVAL_KUNIT_TEST) += polyval_kunit.o 8 9 obj-$(CONFIG_CRYPTO_LIB_SHA1_KUNIT_TEST) += sha1_kunit.o 9 10 obj-$(CONFIG_CRYPTO_LIB_SHA256_KUNIT_TEST) += sha224_kunit.o sha256_kunit.o 10 11 obj-$(CONFIG_CRYPTO_LIB_SHA512_KUNIT_TEST) += sha384_kunit.o sha512_kunit.o
+186
lib/crypto/tests/polyval-testvecs.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0-or-later */ 2 + /* This file was generated by: ./scripts/crypto/gen-hash-testvecs.py polyval */ 3 + 4 + static const struct { 5 + size_t data_len; 6 + u8 digest[POLYVAL_DIGEST_SIZE]; 7 + } hash_testvecs[] = { 8 + { 9 + .data_len = 0, 10 + .digest = { 11 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 12 + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 13 + }, 14 + }, 15 + { 16 + .data_len = 1, 17 + .digest = { 18 + 0xb5, 0x51, 0x69, 0x89, 0xd4, 0x3c, 0x59, 0xca, 19 + 0x6a, 0x1c, 0x2a, 0xe9, 0xa1, 0x9c, 0x6c, 0x83, 20 + }, 21 + }, 22 + { 23 + .data_len = 2, 24 + .digest = { 25 + 0xf4, 0x50, 0xaf, 0x07, 0xda, 0x42, 0xa7, 0x41, 26 + 0x4d, 0x24, 0x88, 0x87, 0xe3, 0x40, 0x73, 0x7c, 27 + }, 28 + }, 29 + { 30 + .data_len = 3, 31 + .digest = { 32 + 0x9e, 0x88, 0x78, 0x71, 0x4c, 0x55, 0x87, 0xe8, 33 + 0xb4, 0x96, 0x3d, 0x56, 0xc8, 0xb2, 0xe1, 0x68, 34 + }, 35 + }, 36 + { 37 + .data_len = 16, 38 + .digest = { 39 + 0x9e, 0x81, 0x37, 0x8f, 0x49, 0xf7, 0xa2, 0xe4, 40 + 0x04, 0x45, 0x12, 0x78, 0x45, 0x42, 0x27, 0xad, 41 + }, 42 + }, 43 + { 44 + .data_len = 32, 45 + .digest = { 46 + 0x60, 0x19, 0xd0, 0xa4, 0xf0, 0xde, 0x9e, 0xe7, 47 + 0x6a, 0x89, 0x1a, 0xea, 0x80, 0x14, 0xa9, 0xa3, 48 + }, 49 + }, 50 + { 51 + .data_len = 48, 52 + .digest = { 53 + 0x0c, 0xa2, 0x70, 0x4d, 0x7c, 0x89, 0xac, 0x41, 54 + 0xc2, 0x9e, 0x0d, 0x07, 0x07, 0x6a, 0x7f, 0xd5, 55 + }, 56 + }, 57 + { 58 + .data_len = 49, 59 + .digest = { 60 + 0x91, 0xd3, 0xa9, 0x5c, 0x79, 0x3d, 0x6b, 0x84, 61 + 0x99, 0x54, 0xa7, 0xb4, 0x06, 0x66, 0xfd, 0x1c, 62 + }, 63 + }, 64 + { 65 + .data_len = 63, 66 + .digest = { 67 + 0x29, 0x37, 0xb8, 0xe5, 0xd8, 0x27, 0x4d, 0xfb, 68 + 0x83, 0x4f, 0x67, 0xf7, 0xf9, 0xc1, 0x0a, 0x9d, 69 + }, 70 + }, 71 + { 72 + .data_len = 64, 73 + .digest = { 74 + 0x17, 0xa9, 0x06, 0x2c, 0xf3, 0xe8, 0x2e, 0xa6, 75 + 0x6b, 0xb2, 0x1f, 0x5d, 0x94, 0x3c, 0x02, 0xa2, 76 + }, 77 + }, 78 + { 79 + .data_len = 65, 80 + .digest = { 81 + 0x7c, 0x80, 0x74, 0xd7, 0xa1, 0x37, 0x30, 0x64, 82 + 0x3b, 0xa4, 0xa3, 0x98, 0xde, 0x47, 0x10, 0x23, 83 + }, 84 + }, 85 + { 86 + .data_len = 127, 87 + .digest = { 88 + 0x27, 0x3a, 0xcf, 0xf5, 0xaf, 0x9f, 0xd8, 0xd8, 89 + 0x2d, 0x6a, 0x91, 0xfb, 0xb8, 0xfa, 0xbe, 0x0c, 90 + }, 91 + }, 92 + { 93 + .data_len = 128, 94 + .digest = { 95 + 0x97, 0x6e, 0xc4, 0xbe, 0x6b, 0x15, 0xa6, 0x7c, 96 + 0xc4, 0xa2, 0xb8, 0x0a, 0x0e, 0x9c, 0xc7, 0x3a, 97 + }, 98 + }, 99 + { 100 + .data_len = 129, 101 + .digest = { 102 + 0x2b, 0xc3, 0x98, 0xba, 0x6e, 0x42, 0xf8, 0x18, 103 + 0x85, 0x69, 0x15, 0x37, 0x10, 0x60, 0xe6, 0xac, 104 + }, 105 + }, 106 + { 107 + .data_len = 256, 108 + .digest = { 109 + 0x88, 0x21, 0x77, 0x89, 0xd7, 0x93, 0x90, 0xfc, 110 + 0xf3, 0xb0, 0xe3, 0xfb, 0x14, 0xe2, 0xcf, 0x74, 111 + }, 112 + }, 113 + { 114 + .data_len = 511, 115 + .digest = { 116 + 0x66, 0x3d, 0x3e, 0x08, 0xa0, 0x49, 0x81, 0x68, 117 + 0x3e, 0x3b, 0xc8, 0x80, 0x55, 0xd4, 0x15, 0xe9, 118 + }, 119 + }, 120 + { 121 + .data_len = 513, 122 + .digest = { 123 + 0x05, 0xf5, 0x06, 0x66, 0xe7, 0x11, 0x08, 0x84, 124 + 0xff, 0x94, 0x50, 0x85, 0x65, 0x95, 0x2a, 0x20, 125 + }, 126 + }, 127 + { 128 + .data_len = 1000, 129 + .digest = { 130 + 0xd3, 0xa0, 0x51, 0x69, 0xb5, 0x38, 0xae, 0x1b, 131 + 0xe1, 0xa2, 0x89, 0xc6, 0x8d, 0x2b, 0x62, 0x37, 132 + }, 133 + }, 134 + { 135 + .data_len = 3333, 136 + .digest = { 137 + 0x37, 0x6d, 0x6a, 0x14, 0xdc, 0xa5, 0x37, 0xfc, 138 + 0xfe, 0x67, 0x76, 0xb2, 0x64, 0x68, 0x64, 0x05, 139 + }, 140 + }, 141 + { 142 + .data_len = 4096, 143 + .digest = { 144 + 0xe3, 0x12, 0x0c, 0x58, 0x46, 0x45, 0x27, 0x7a, 145 + 0x0e, 0xa2, 0xfa, 0x2c, 0x35, 0x73, 0x6c, 0x94, 146 + }, 147 + }, 148 + { 149 + .data_len = 4128, 150 + .digest = { 151 + 0x63, 0x0d, 0xa1, 0xbc, 0x6e, 0x3e, 0xd3, 0x1d, 152 + 0x28, 0x52, 0xd2, 0xf4, 0x30, 0x2d, 0xff, 0xc4, 153 + }, 154 + }, 155 + { 156 + .data_len = 4160, 157 + .digest = { 158 + 0xb2, 0x91, 0x49, 0xe2, 0x02, 0x98, 0x00, 0x79, 159 + 0x71, 0xb9, 0xd7, 0xd4, 0xb5, 0x94, 0x6d, 0x7d, 160 + }, 161 + }, 162 + { 163 + .data_len = 4224, 164 + .digest = { 165 + 0x58, 0x96, 0x48, 0x69, 0x05, 0x17, 0xe1, 0x6d, 166 + 0xbc, 0xf2, 0x3d, 0x10, 0x96, 0x00, 0x74, 0x58, 167 + }, 168 + }, 169 + { 170 + .data_len = 16384, 171 + .digest = { 172 + 0x99, 0x3c, 0xcb, 0x4d, 0x64, 0xc9, 0xa9, 0x41, 173 + 0x52, 0x93, 0xfd, 0x65, 0xc4, 0xcc, 0xa5, 0xe5, 174 + }, 175 + }, 176 + }; 177 + 178 + static const u8 hash_testvec_consolidated[POLYVAL_DIGEST_SIZE] = { 179 + 0xdf, 0x68, 0x52, 0x99, 0x92, 0xc3, 0xe8, 0x88, 180 + 0x29, 0x13, 0xc8, 0x35, 0x67, 0xa3, 0xd3, 0xad, 181 + }; 182 + 183 + static const u8 polyval_allones_hashofhashes[POLYVAL_DIGEST_SIZE] = { 184 + 0xd5, 0xf7, 0xfd, 0xb2, 0xa6, 0xef, 0x0b, 0x85, 185 + 0x0d, 0x0a, 0x06, 0x10, 0xbc, 0x64, 0x94, 0x73, 186 + };
+223
lib/crypto/tests/polyval_kunit.c
··· 1 + // SPDX-License-Identifier: GPL-2.0-or-later 2 + /* 3 + * Copyright 2025 Google LLC 4 + */ 5 + #include <crypto/polyval.h> 6 + #include "polyval-testvecs.h" 7 + 8 + /* 9 + * A fixed key used when presenting POLYVAL as an unkeyed hash function in order 10 + * to reuse hash-test-template.h. At the beginning of the test suite, this is 11 + * initialized to a key prepared from bytes generated from a fixed seed. 12 + */ 13 + static struct polyval_key test_key; 14 + 15 + static void polyval_init_withtestkey(struct polyval_ctx *ctx) 16 + { 17 + polyval_init(ctx, &test_key); 18 + } 19 + 20 + static void polyval_withtestkey(const u8 *data, size_t len, 21 + u8 out[POLYVAL_BLOCK_SIZE]) 22 + { 23 + polyval(&test_key, data, len, out); 24 + } 25 + 26 + /* Generate the HASH_KUNIT_CASES using hash-test-template.h. */ 27 + #define HASH polyval_withtestkey 28 + #define HASH_CTX polyval_ctx 29 + #define HASH_SIZE POLYVAL_BLOCK_SIZE 30 + #define HASH_INIT polyval_init_withtestkey 31 + #define HASH_UPDATE polyval_update 32 + #define HASH_FINAL polyval_final 33 + #include "hash-test-template.h" 34 + 35 + /* 36 + * Test an example from RFC8452 ("AES-GCM-SIV: Nonce Misuse-Resistant 37 + * Authenticated Encryption") to ensure compatibility with that. 38 + */ 39 + static void test_polyval_rfc8452_testvec(struct kunit *test) 40 + { 41 + static const u8 raw_key[POLYVAL_BLOCK_SIZE] = 42 + "\x31\x07\x28\xd9\x91\x1f\x1f\x38" 43 + "\x37\xb2\x43\x16\xc3\xfa\xb9\xa0"; 44 + static const u8 data[48] = 45 + "\x65\x78\x61\x6d\x70\x6c\x65\x00" 46 + "\x00\x00\x00\x00\x00\x00\x00\x00" 47 + "\x48\x65\x6c\x6c\x6f\x20\x77\x6f" 48 + "\x72\x6c\x64\x00\x00\x00\x00\x00" 49 + "\x38\x00\x00\x00\x00\x00\x00\x00" 50 + "\x58\x00\x00\x00\x00\x00\x00\x00"; 51 + static const u8 expected_hash[POLYVAL_BLOCK_SIZE] = 52 + "\xad\x7f\xcf\x0b\x51\x69\x85\x16" 53 + "\x62\x67\x2f\x3c\x5f\x95\x13\x8f"; 54 + u8 hash[POLYVAL_BLOCK_SIZE]; 55 + struct polyval_key key; 56 + 57 + polyval_preparekey(&key, raw_key); 58 + polyval(&key, data, sizeof(data), hash); 59 + KUNIT_ASSERT_MEMEQ(test, hash, expected_hash, sizeof(hash)); 60 + } 61 + 62 + /* 63 + * Test a key and messages containing all one bits. This is useful to detect 64 + * overflow bugs in implementations that emulate carryless multiplication using 65 + * a series of standard multiplications with the bits spread out. 66 + */ 67 + static void test_polyval_allones_key_and_message(struct kunit *test) 68 + { 69 + struct polyval_key key; 70 + struct polyval_ctx hashofhashes_ctx; 71 + u8 hash[POLYVAL_BLOCK_SIZE]; 72 + 73 + static_assert(TEST_BUF_LEN >= 4096); 74 + memset(test_buf, 0xff, 4096); 75 + 76 + polyval_preparekey(&key, test_buf); 77 + polyval_init(&hashofhashes_ctx, &key); 78 + for (size_t len = 0; len <= 4096; len += 16) { 79 + polyval(&key, test_buf, len, hash); 80 + polyval_update(&hashofhashes_ctx, hash, sizeof(hash)); 81 + } 82 + polyval_final(&hashofhashes_ctx, hash); 83 + KUNIT_ASSERT_MEMEQ(test, hash, polyval_allones_hashofhashes, 84 + sizeof(hash)); 85 + } 86 + 87 + #define MAX_LEN_FOR_KEY_CHECK 1024 88 + 89 + /* 90 + * Given two prepared keys which should be identical (but may differ in 91 + * alignment and/or whether they are followed by a guard page or not), verify 92 + * that they produce consistent results on various data lengths. 93 + */ 94 + static void check_key_consistency(struct kunit *test, 95 + const struct polyval_key *key1, 96 + const struct polyval_key *key2) 97 + { 98 + u8 *data = test_buf; 99 + u8 hash1[POLYVAL_BLOCK_SIZE]; 100 + u8 hash2[POLYVAL_BLOCK_SIZE]; 101 + 102 + rand_bytes(data, MAX_LEN_FOR_KEY_CHECK); 103 + KUNIT_ASSERT_MEMEQ(test, key1, key2, sizeof(*key1)); 104 + 105 + for (int i = 0; i < 100; i++) { 106 + size_t len = rand_length(MAX_LEN_FOR_KEY_CHECK); 107 + 108 + polyval(key1, data, len, hash1); 109 + polyval(key2, data, len, hash2); 110 + KUNIT_ASSERT_MEMEQ(test, hash1, hash2, sizeof(hash1)); 111 + } 112 + } 113 + 114 + /* Test that no buffer overreads occur on either raw_key or polyval_key. */ 115 + static void test_polyval_with_guarded_key(struct kunit *test) 116 + { 117 + u8 raw_key[POLYVAL_BLOCK_SIZE]; 118 + u8 *guarded_raw_key = &test_buf[TEST_BUF_LEN - sizeof(raw_key)]; 119 + struct polyval_key key1, key2; 120 + struct polyval_key *guarded_key = 121 + (struct polyval_key *)&test_buf[TEST_BUF_LEN - sizeof(key1)]; 122 + 123 + /* Prepare with regular buffers. */ 124 + rand_bytes(raw_key, sizeof(raw_key)); 125 + polyval_preparekey(&key1, raw_key); 126 + 127 + /* Prepare with guarded raw_key, then check that it works. */ 128 + memcpy(guarded_raw_key, raw_key, sizeof(raw_key)); 129 + polyval_preparekey(&key2, guarded_raw_key); 130 + check_key_consistency(test, &key1, &key2); 131 + 132 + /* Prepare guarded polyval_key, then check that it works. */ 133 + polyval_preparekey(guarded_key, raw_key); 134 + check_key_consistency(test, &key1, guarded_key); 135 + } 136 + 137 + /* 138 + * Test that polyval_key only needs to be aligned to 139 + * __alignof__(struct polyval_key), i.e. 8 bytes. The assembly code may prefer 140 + * 16-byte or higher alignment, but it musn't require it. 141 + */ 142 + static void test_polyval_with_minimally_aligned_key(struct kunit *test) 143 + { 144 + u8 raw_key[POLYVAL_BLOCK_SIZE]; 145 + struct polyval_key key; 146 + struct polyval_key *minaligned_key = 147 + (struct polyval_key *)&test_buf[MAX_LEN_FOR_KEY_CHECK + 148 + __alignof__(struct polyval_key)]; 149 + 150 + KUNIT_ASSERT_TRUE(test, IS_ALIGNED((uintptr_t)minaligned_key, 151 + __alignof__(struct polyval_key))); 152 + KUNIT_ASSERT_TRUE(test, 153 + !IS_ALIGNED((uintptr_t)minaligned_key, 154 + 2 * __alignof__(struct polyval_key))); 155 + 156 + rand_bytes(raw_key, sizeof(raw_key)); 157 + polyval_preparekey(&key, raw_key); 158 + polyval_preparekey(minaligned_key, raw_key); 159 + check_key_consistency(test, &key, minaligned_key); 160 + } 161 + 162 + struct polyval_irq_test_state { 163 + struct polyval_key expected_key; 164 + u8 raw_key[POLYVAL_BLOCK_SIZE]; 165 + }; 166 + 167 + static bool polyval_irq_test_func(void *state_) 168 + { 169 + struct polyval_irq_test_state *state = state_; 170 + struct polyval_key key; 171 + 172 + polyval_preparekey(&key, state->raw_key); 173 + return memcmp(&key, &state->expected_key, sizeof(key)) == 0; 174 + } 175 + 176 + /* 177 + * Test that polyval_preparekey() produces the same output regardless of whether 178 + * FPU or vector registers are usable when it is called. 179 + */ 180 + static void test_polyval_preparekey_in_irqs(struct kunit *test) 181 + { 182 + struct polyval_irq_test_state state; 183 + 184 + rand_bytes(state.raw_key, sizeof(state.raw_key)); 185 + polyval_preparekey(&state.expected_key, state.raw_key); 186 + kunit_run_irq_test(test, polyval_irq_test_func, 20000, &state); 187 + } 188 + 189 + static int polyval_suite_init(struct kunit_suite *suite) 190 + { 191 + u8 raw_key[POLYVAL_BLOCK_SIZE]; 192 + 193 + rand_bytes_seeded_from_len(raw_key, sizeof(raw_key)); 194 + polyval_preparekey(&test_key, raw_key); 195 + return hash_suite_init(suite); 196 + } 197 + 198 + static void polyval_suite_exit(struct kunit_suite *suite) 199 + { 200 + hash_suite_exit(suite); 201 + } 202 + 203 + static struct kunit_case polyval_test_cases[] = { 204 + HASH_KUNIT_CASES, 205 + KUNIT_CASE(test_polyval_rfc8452_testvec), 206 + KUNIT_CASE(test_polyval_allones_key_and_message), 207 + KUNIT_CASE(test_polyval_with_guarded_key), 208 + KUNIT_CASE(test_polyval_with_minimally_aligned_key), 209 + KUNIT_CASE(test_polyval_preparekey_in_irqs), 210 + KUNIT_CASE(benchmark_hash), 211 + {}, 212 + }; 213 + 214 + static struct kunit_suite polyval_test_suite = { 215 + .name = "polyval", 216 + .test_cases = polyval_test_cases, 217 + .suite_init = polyval_suite_init, 218 + .suite_exit = polyval_suite_exit, 219 + }; 220 + kunit_test_suite(polyval_test_suite); 221 + 222 + MODULE_DESCRIPTION("KUnit tests and benchmark for POLYVAL"); 223 + MODULE_LICENSE("GPL");
+45 -2
scripts/crypto/gen-hash-testvecs.py
··· 1 1 #!/usr/bin/env python3 2 2 # SPDX-License-Identifier: GPL-2.0-or-later 3 3 # 4 - # Script that generates test vectors for the given cryptographic hash function. 4 + # Script that generates test vectors for the given hash function. 5 5 # 6 6 # Copyright 2025 Google LLC 7 7 ··· 50 50 m = (self.h + self.s) % 2**128 51 51 return m.to_bytes(16, byteorder='little') 52 52 53 + POLYVAL_POLY = sum((1 << i) for i in [128, 127, 126, 121, 0]) 54 + POLYVAL_BLOCK_SIZE = 16 55 + 56 + # A straightforward, unoptimized implementation of POLYVAL. 57 + # Reference: https://datatracker.ietf.org/doc/html/rfc8452 58 + class Polyval: 59 + def __init__(self, key): 60 + assert len(key) == 16 61 + self.h = int.from_bytes(key, byteorder='little') 62 + self.acc = 0 63 + 64 + # Note: this supports partial blocks only at the end. 65 + def update(self, data): 66 + for i in range(0, len(data), 16): 67 + # acc += block 68 + self.acc ^= int.from_bytes(data[i:i+16], byteorder='little') 69 + # acc = (acc * h * x^-128) mod POLYVAL_POLY 70 + product = 0 71 + for j in range(128): 72 + if (self.h & (1 << j)) != 0: 73 + product ^= self.acc << j 74 + if (product & (1 << j)) != 0: 75 + product ^= POLYVAL_POLY << j 76 + self.acc = product >> 128 77 + return self 78 + 79 + def digest(self): 80 + return self.acc.to_bytes(16, byteorder='little') 81 + 53 82 def hash_init(alg): 54 83 if alg == 'poly1305': 55 84 # Use a fixed random key here, to present Poly1305 as an unkeyed hash. 56 85 # This allows all the test cases for unkeyed hashes to work on Poly1305. 57 86 return Poly1305(rand_bytes(POLY1305_KEY_SIZE)) 87 + if alg == 'polyval': 88 + return Polyval(rand_bytes(POLYVAL_BLOCK_SIZE)) 58 89 return hashlib.new(alg) 59 90 60 91 def hash_update(ctx, data): ··· 196 165 'poly1305_allones_macofmacs[POLY1305_DIGEST_SIZE]', 197 166 Poly1305(key).update(data).digest()) 198 167 168 + def gen_additional_polyval_testvecs(): 169 + key = b'\xff' * POLYVAL_BLOCK_SIZE 170 + hashes = b'' 171 + for data_len in range(0, 4097, 16): 172 + hashes += Polyval(key).update(b'\xff' * data_len).digest() 173 + print_static_u8_array_definition( 174 + 'polyval_allones_hashofhashes[POLYVAL_DIGEST_SIZE]', 175 + Polyval(key).update(hashes).digest()) 176 + 199 177 if len(sys.argv) != 2: 200 178 sys.stderr.write('Usage: gen-hash-testvecs.py ALGORITHM\n') 201 - sys.stderr.write('ALGORITHM may be any supported by Python hashlib, or poly1305 or sha3.\n') 179 + sys.stderr.write('ALGORITHM may be any supported by Python hashlib; or poly1305, polyval, or sha3.\n') 202 180 sys.stderr.write('Example: gen-hash-testvecs.py sha512\n') 203 181 sys.exit(1) 204 182 ··· 220 180 elif alg == 'poly1305': 221 181 gen_unkeyed_testvecs(alg) 222 182 gen_additional_poly1305_testvecs() 183 + elif alg == 'polyval': 184 + gen_unkeyed_testvecs(alg) 185 + gen_additional_polyval_testvecs() 223 186 elif alg == 'sha3': 224 187 print() 225 188 print('/* SHA3-256 test vectors */')