summaryrefslogtreecommitdiffstats
path: root/qemu/roms/ipxe/src/tests
diff options
context:
space:
mode:
Diffstat (limited to 'qemu/roms/ipxe/src/tests')
-rw-r--r--qemu/roms/ipxe/src/tests/aes_cbc_test.c193
-rw-r--r--qemu/roms/ipxe/src/tests/aes_test.c193
-rw-r--r--qemu/roms/ipxe/src/tests/base16_test.c52
-rw-r--r--qemu/roms/ipxe/src/tests/base64_test.c52
-rw-r--r--qemu/roms/ipxe/src/tests/bigint_test.c6
-rw-r--r--qemu/roms/ipxe/src/tests/bofm_test.c6
-rw-r--r--qemu/roms/ipxe/src/tests/byteswap_test.c6
-rw-r--r--qemu/roms/ipxe/src/tests/cbc_test.h57
-rw-r--r--qemu/roms/ipxe/src/tests/cipher_test.c (renamed from qemu/roms/ipxe/src/tests/cbc_test.c)118
-rw-r--r--qemu/roms/ipxe/src/tests/cipher_test.h111
-rw-r--r--qemu/roms/ipxe/src/tests/cms_test.c7
-rw-r--r--qemu/roms/ipxe/src/tests/crc32_test.c6
-rw-r--r--qemu/roms/ipxe/src/tests/deflate_test.c6
-rw-r--r--qemu/roms/ipxe/src/tests/digest_test.c69
-rw-r--r--qemu/roms/ipxe/src/tests/digest_test.h120
-rw-r--r--qemu/roms/ipxe/src/tests/dns_test.c6
-rw-r--r--qemu/roms/ipxe/src/tests/entropy_sample.c6
-rw-r--r--qemu/roms/ipxe/src/tests/hash_df_test.c6
-rw-r--r--qemu/roms/ipxe/src/tests/hmac_drbg_test.c6
-rw-r--r--qemu/roms/ipxe/src/tests/ipv4_test.c154
-rw-r--r--qemu/roms/ipxe/src/tests/ipv6_test.c6
-rw-r--r--qemu/roms/ipxe/src/tests/linebuf_test.c337
-rw-r--r--qemu/roms/ipxe/src/tests/list_test.c6
-rw-r--r--qemu/roms/ipxe/src/tests/math_test.c80
-rw-r--r--qemu/roms/ipxe/src/tests/md5_test.c82
-rw-r--r--qemu/roms/ipxe/src/tests/memcpy_test.c6
-rw-r--r--qemu/roms/ipxe/src/tests/memset_test.c157
-rw-r--r--qemu/roms/ipxe/src/tests/ocsp_test.c7
-rw-r--r--qemu/roms/ipxe/src/tests/pccrc_test.c529
-rw-r--r--qemu/roms/ipxe/src/tests/pixbuf_test.c13
-rw-r--r--qemu/roms/ipxe/src/tests/pixbuf_test.h2
-rw-r--r--qemu/roms/ipxe/src/tests/png_test.c6
-rw-r--r--qemu/roms/ipxe/src/tests/pnm_test.c6
-rw-r--r--qemu/roms/ipxe/src/tests/profile_test.c6
-rw-r--r--qemu/roms/ipxe/src/tests/pubkey_test.h2
-rw-r--r--qemu/roms/ipxe/src/tests/rsa_test.c6
-rw-r--r--qemu/roms/ipxe/src/tests/setjmp_test.c171
-rw-r--r--qemu/roms/ipxe/src/tests/settings_test.c25
-rw-r--r--qemu/roms/ipxe/src/tests/sha1_test.c92
-rw-r--r--qemu/roms/ipxe/src/tests/sha256_test.c131
-rw-r--r--qemu/roms/ipxe/src/tests/sha512_test.c185
-rw-r--r--qemu/roms/ipxe/src/tests/string_test.c142
-rw-r--r--qemu/roms/ipxe/src/tests/tcpip_test.c6
-rw-r--r--qemu/roms/ipxe/src/tests/test.c6
-rw-r--r--qemu/roms/ipxe/src/tests/tests.c15
-rw-r--r--qemu/roms/ipxe/src/tests/time_test.c6
-rw-r--r--qemu/roms/ipxe/src/tests/uri_test.c30
-rw-r--r--qemu/roms/ipxe/src/tests/vsprintf_test.c6
-rw-r--r--qemu/roms/ipxe/src/tests/x509_test.c7
49 files changed, 2640 insertions, 613 deletions
diff --git a/qemu/roms/ipxe/src/tests/aes_cbc_test.c b/qemu/roms/ipxe/src/tests/aes_cbc_test.c
deleted file mode 100644
index 4ae3a92e5..000000000
--- a/qemu/roms/ipxe/src/tests/aes_cbc_test.c
+++ /dev/null
@@ -1,193 +0,0 @@
-/*
- * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of the
- * License, or any later version.
- *
- * This program 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 a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
- */
-
-FILE_LICENCE ( GPL2_OR_LATER );
-
-/** @file
- *
- * AES-in-CBC-mode tests
- *
- * These test vectors are provided by NIST as part of the
- * Cryptographic Toolkit Examples, downloadable from:
- *
- * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/AES_CBC.pdf
- *
- */
-
-/* Forcibly enable assertions */
-#undef NDEBUG
-
-#include <assert.h>
-#include <string.h>
-#include <ipxe/aes.h>
-#include <ipxe/test.h>
-#include "cbc_test.h"
-
-/** Define inline key */
-#define KEY(...) { __VA_ARGS__ }
-
-/** Define inline initialisation vector */
-#define IV(...) { __VA_ARGS__ }
-
-/** Define inline plaintext data */
-#define PLAINTEXT(...) { __VA_ARGS__ }
-
-/** Define inline ciphertext data */
-#define CIPHERTEXT(...) { __VA_ARGS__ }
-
-/** An AES-in-CBC-mode test */
-struct aes_cbc_test {
- /** Key */
- const void *key;
- /** Length of key */
- size_t key_len;
- /** Initialisation vector */
- const void *iv;
- /** Length of initialisation vector */
- size_t iv_len;
- /** Plaintext */
- const void *plaintext;
- /** Length of plaintext */
- size_t plaintext_len;
- /** Ciphertext */
- const void *ciphertext;
- /** Length of ciphertext */
- size_t ciphertext_len;
-};
-
-/**
- * Define an AES-in-CBC-mode test
- *
- * @v name Test name
- * @v key_array Key
- * @v iv_array Initialisation vector
- * @v plaintext_array Plaintext
- * @v ciphertext_array Ciphertext
- * @ret test AES-in-CBC-mode test
- */
-#define AES_CBC_TEST( name, key_array, iv_array, plaintext_array, \
- ciphertext_array ) \
- static const uint8_t name ## _key [] = key_array; \
- static const uint8_t name ## _iv [] = iv_array; \
- static const uint8_t name ## _plaintext [] = plaintext_array; \
- static const uint8_t name ## _ciphertext [] = ciphertext_array; \
- static struct aes_cbc_test name = { \
- .key = name ## _key, \
- .key_len = sizeof ( name ## _key ), \
- .iv = name ## _iv, \
- .iv_len = sizeof ( name ## _iv ), \
- .plaintext = name ## _plaintext, \
- .plaintext_len = sizeof ( name ## _plaintext ), \
- .ciphertext = name ## _ciphertext, \
- .ciphertext_len = sizeof ( name ## _ciphertext ), \
- }
-
-/**
- * Report AES-in-CBC-mode
- *
- * @v state HMAC_DRBG internal state
- * @v test Instantiation test
- */
-#define aes_cbc_ok( test ) do { \
- struct cipher_algorithm *cipher = &aes_cbc_algorithm; \
- \
- assert ( (test)->iv_len == cipher->blocksize ); \
- assert ( (test)->plaintext_len == (test)->ciphertext_len ); \
- cbc_encrypt_ok ( cipher, (test)->key, (test)->key_len, \
- (test)->iv, (test)->plaintext, \
- (test)->ciphertext, (test)->plaintext_len ); \
- cbc_decrypt_ok ( cipher, (test)->key, (test)->key_len, \
- (test)->iv, (test)->ciphertext, \
- (test)->plaintext, (test)->ciphertext_len ); \
- } while ( 0 )
-
-/** CBC_AES128 */
-AES_CBC_TEST ( test_128,
- KEY ( 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15,
- 0x88, 0x09, 0xcf, 0x4f, 0x3c ),
- IV ( 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
- 0x0b, 0x0c, 0x0d, 0x0e, 0x0f ),
- PLAINTEXT ( 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
- 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
- 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
- 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
- 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
- 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
- 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
- 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 ),
- CIPHERTEXT ( 0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46,
- 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d,
- 0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee,
- 0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2,
- 0x73, 0xbe, 0xd6, 0xb8, 0xe3, 0xc1, 0x74, 0x3b,
- 0x71, 0x16, 0xe6, 0x9e, 0x22, 0x22, 0x95, 0x16,
- 0x3f, 0xf1, 0xca, 0xa1, 0x68, 0x1f, 0xac, 0x09,
- 0x12, 0x0e, 0xca, 0x30, 0x75, 0x86, 0xe1, 0xa7 ) );
-
-/** CBC_AES256 */
-AES_CBC_TEST ( test_256,
- KEY ( 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, 0x73, 0xae,
- 0xf0, 0x85, 0x7d, 0x77, 0x81, 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61,
- 0x08, 0xd7, 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4 ),
- IV ( 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
- 0x0b, 0x0c, 0x0d, 0x0e, 0x0f ),
- PLAINTEXT ( 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
- 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
- 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
- 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
- 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
- 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
- 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
- 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 ),
- CIPHERTEXT ( 0xf5, 0x8c, 0x4c, 0x04, 0xd6, 0xe5, 0xf1, 0xba,
- 0x77, 0x9e, 0xab, 0xfb, 0x5f, 0x7b, 0xfb, 0xd6,
- 0x9c, 0xfc, 0x4e, 0x96, 0x7e, 0xdb, 0x80, 0x8d,
- 0x67, 0x9f, 0x77, 0x7b, 0xc6, 0x70, 0x2c, 0x7d,
- 0x39, 0xf2, 0x33, 0x69, 0xa9, 0xd9, 0xba, 0xcf,
- 0xa5, 0x30, 0xe2, 0x63, 0x04, 0x23, 0x14, 0x61,
- 0xb2, 0xeb, 0x05, 0xe2, 0xc3, 0x9b, 0xe9, 0xfc,
- 0xda, 0x6c, 0x19, 0x07, 0x8c, 0x6a, 0x9d, 0x1b ) );
-
-/**
- * Perform AES-in-CBC-mode self-test
- *
- */
-static void aes_cbc_test_exec ( void ) {
- struct cipher_algorithm *cipher = &aes_cbc_algorithm;
-
- /* Correctness tests */
- aes_cbc_ok ( &test_128 );
- aes_cbc_ok ( &test_256 );
-
- /* Speed tests */
- DBG ( "AES128 encryption required %ld cycles per byte\n",
- cbc_cost_encrypt ( cipher, test_128.key_len ) );
- DBG ( "AES128 decryption required %ld cycles per byte\n",
- cbc_cost_decrypt ( cipher, test_128.key_len ) );
- DBG ( "AES256 encryption required %ld cycles per byte\n",
- cbc_cost_encrypt ( cipher, test_256.key_len ) );
- DBG ( "AES256 decryption required %ld cycles per byte\n",
- cbc_cost_decrypt ( cipher, test_256.key_len ) );
-}
-
-/** AES-in-CBC-mode self-test */
-struct self_test aes_cbc_test __self_test = {
- .name = "aes_cbc",
- .exec = aes_cbc_test_exec,
-};
diff --git a/qemu/roms/ipxe/src/tests/aes_test.c b/qemu/roms/ipxe/src/tests/aes_test.c
new file mode 100644
index 000000000..ad66c734c
--- /dev/null
+++ b/qemu/roms/ipxe/src/tests/aes_test.c
@@ -0,0 +1,193 @@
+/*
+ * Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or any later version.
+ *
+ * This program 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 a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+/** @file
+ *
+ * AES tests
+ *
+ * These test vectors are provided by NIST as part of the
+ * Cryptographic Toolkit Examples, downloadable from:
+ *
+ * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/AES_Core_All.pdf
+ * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/AES_ECB.pdf
+ * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/AES_CBC.pdf
+ *
+ */
+
+/* Forcibly enable assertions */
+#undef NDEBUG
+
+#include <assert.h>
+#include <string.h>
+#include <ipxe/aes.h>
+#include <ipxe/test.h>
+#include "cipher_test.h"
+
+/** Key used for NIST 128-bit test vectors */
+#define AES_KEY_NIST_128 \
+ KEY ( 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, \
+ 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c )
+
+/** Key used for NIST 192-bit test vectors */
+#define AES_KEY_NIST_192 \
+ KEY ( 0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52, 0xc8, \
+ 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5, 0x62, 0xf8, \
+ 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b )
+
+/** Key used for NIST 256-bit test vectors */
+#define AES_KEY_NIST_256 \
+ KEY ( 0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe, 0x2b, \
+ 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81, 0x1f, 0x35, \
+ 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7, 0x2d, 0x98, 0x10, \
+ 0xa3, 0x09, 0x14, 0xdf, 0xf4 )
+
+/** Dummy initialisation vector used for NIST ECB-mode test vectors */
+#define AES_IV_NIST_DUMMY \
+ IV ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 )
+
+/** Initialisation vector used for NIST CBC-mode test vectors */
+#define AES_IV_NIST_CBC \
+ IV ( 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, \
+ 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f )
+
+/** Plaintext used for NIST test vectors */
+#define AES_PLAINTEXT_NIST \
+ PLAINTEXT ( 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, \
+ 0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, \
+ 0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c, \
+ 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51, \
+ 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11, \
+ 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, \
+ 0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, \
+ 0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 )
+
+/** AES-128-ECB (same test as AES-128-Core) */
+CIPHER_TEST ( aes_128_ecb, &aes_ecb_algorithm,
+ AES_KEY_NIST_128, AES_IV_NIST_DUMMY, AES_PLAINTEXT_NIST,
+ CIPHERTEXT ( 0x3a, 0xd7, 0x7b, 0xb4, 0x0d, 0x7a, 0x36, 0x60,
+ 0xa8, 0x9e, 0xca, 0xf3, 0x24, 0x66, 0xef, 0x97,
+ 0xf5, 0xd3, 0xd5, 0x85, 0x03, 0xb9, 0x69, 0x9d,
+ 0xe7, 0x85, 0x89, 0x5a, 0x96, 0xfd, 0xba, 0xaf,
+ 0x43, 0xb1, 0xcd, 0x7f, 0x59, 0x8e, 0xce, 0x23,
+ 0x88, 0x1b, 0x00, 0xe3, 0xed, 0x03, 0x06, 0x88,
+ 0x7b, 0x0c, 0x78, 0x5e, 0x27, 0xe8, 0xad, 0x3f,
+ 0x82, 0x23, 0x20, 0x71, 0x04, 0x72, 0x5d, 0xd4 ) );
+
+/** AES-128-CBC */
+CIPHER_TEST ( aes_128_cbc, &aes_cbc_algorithm,
+ AES_KEY_NIST_128, AES_IV_NIST_CBC, AES_PLAINTEXT_NIST,
+ CIPHERTEXT ( 0x76, 0x49, 0xab, 0xac, 0x81, 0x19, 0xb2, 0x46,
+ 0xce, 0xe9, 0x8e, 0x9b, 0x12, 0xe9, 0x19, 0x7d,
+ 0x50, 0x86, 0xcb, 0x9b, 0x50, 0x72, 0x19, 0xee,
+ 0x95, 0xdb, 0x11, 0x3a, 0x91, 0x76, 0x78, 0xb2,
+ 0x73, 0xbe, 0xd6, 0xb8, 0xe3, 0xc1, 0x74, 0x3b,
+ 0x71, 0x16, 0xe6, 0x9e, 0x22, 0x22, 0x95, 0x16,
+ 0x3f, 0xf1, 0xca, 0xa1, 0x68, 0x1f, 0xac, 0x09,
+ 0x12, 0x0e, 0xca, 0x30, 0x75, 0x86, 0xe1, 0xa7 ) );
+
+/** AES-192-ECB (same test as AES-192-Core) */
+CIPHER_TEST ( aes_192_ecb, &aes_ecb_algorithm,
+ AES_KEY_NIST_192, AES_IV_NIST_DUMMY, AES_PLAINTEXT_NIST,
+ CIPHERTEXT ( 0xbd, 0x33, 0x4f, 0x1d, 0x6e, 0x45, 0xf2, 0x5f,
+ 0xf7, 0x12, 0xa2, 0x14, 0x57, 0x1f, 0xa5, 0xcc,
+ 0x97, 0x41, 0x04, 0x84, 0x6d, 0x0a, 0xd3, 0xad,
+ 0x77, 0x34, 0xec, 0xb3, 0xec, 0xee, 0x4e, 0xef,
+ 0xef, 0x7a, 0xfd, 0x22, 0x70, 0xe2, 0xe6, 0x0a,
+ 0xdc, 0xe0, 0xba, 0x2f, 0xac, 0xe6, 0x44, 0x4e,
+ 0x9a, 0x4b, 0x41, 0xba, 0x73, 0x8d, 0x6c, 0x72,
+ 0xfb, 0x16, 0x69, 0x16, 0x03, 0xc1, 0x8e, 0x0e ) );
+
+/** AES-192-CBC */
+CIPHER_TEST ( aes_192_cbc, &aes_cbc_algorithm,
+ AES_KEY_NIST_192, AES_IV_NIST_CBC, AES_PLAINTEXT_NIST,
+ CIPHERTEXT ( 0x4f, 0x02, 0x1d, 0xb2, 0x43, 0xbc, 0x63, 0x3d,
+ 0x71, 0x78, 0x18, 0x3a, 0x9f, 0xa0, 0x71, 0xe8,
+ 0xb4, 0xd9, 0xad, 0xa9, 0xad, 0x7d, 0xed, 0xf4,
+ 0xe5, 0xe7, 0x38, 0x76, 0x3f, 0x69, 0x14, 0x5a,
+ 0x57, 0x1b, 0x24, 0x20, 0x12, 0xfb, 0x7a, 0xe0,
+ 0x7f, 0xa9, 0xba, 0xac, 0x3d, 0xf1, 0x02, 0xe0,
+ 0x08, 0xb0, 0xe2, 0x79, 0x88, 0x59, 0x88, 0x81,
+ 0xd9, 0x20, 0xa9, 0xe6, 0x4f, 0x56, 0x15, 0xcd ) );
+
+/** AES-256-ECB (same test as AES-256-Core) */
+CIPHER_TEST ( aes_256_ecb, &aes_ecb_algorithm,
+ AES_KEY_NIST_256, AES_IV_NIST_DUMMY, AES_PLAINTEXT_NIST,
+ CIPHERTEXT ( 0xf3, 0xee, 0xd1, 0xbd, 0xb5, 0xd2, 0xa0, 0x3c,
+ 0x06, 0x4b, 0x5a, 0x7e, 0x3d, 0xb1, 0x81, 0xf8,
+ 0x59, 0x1c, 0xcb, 0x10, 0xd4, 0x10, 0xed, 0x26,
+ 0xdc, 0x5b, 0xa7, 0x4a, 0x31, 0x36, 0x28, 0x70,
+ 0xb6, 0xed, 0x21, 0xb9, 0x9c, 0xa6, 0xf4, 0xf9,
+ 0xf1, 0x53, 0xe7, 0xb1, 0xbe, 0xaf, 0xed, 0x1d,
+ 0x23, 0x30, 0x4b, 0x7a, 0x39, 0xf9, 0xf3, 0xff,
+ 0x06, 0x7d, 0x8d, 0x8f, 0x9e, 0x24, 0xec, 0xc7 ) );
+
+/** AES-256-CBC */
+CIPHER_TEST ( aes_256_cbc, &aes_cbc_algorithm,
+ AES_KEY_NIST_256, AES_IV_NIST_CBC, AES_PLAINTEXT_NIST,
+ CIPHERTEXT ( 0xf5, 0x8c, 0x4c, 0x04, 0xd6, 0xe5, 0xf1, 0xba,
+ 0x77, 0x9e, 0xab, 0xfb, 0x5f, 0x7b, 0xfb, 0xd6,
+ 0x9c, 0xfc, 0x4e, 0x96, 0x7e, 0xdb, 0x80, 0x8d,
+ 0x67, 0x9f, 0x77, 0x7b, 0xc6, 0x70, 0x2c, 0x7d,
+ 0x39, 0xf2, 0x33, 0x69, 0xa9, 0xd9, 0xba, 0xcf,
+ 0xa5, 0x30, 0xe2, 0x63, 0x04, 0x23, 0x14, 0x61,
+ 0xb2, 0xeb, 0x05, 0xe2, 0xc3, 0x9b, 0xe9, 0xfc,
+ 0xda, 0x6c, 0x19, 0x07, 0x8c, 0x6a, 0x9d, 0x1b ) );
+
+/**
+ * Perform AES self-test
+ *
+ */
+static void aes_test_exec ( void ) {
+ struct cipher_algorithm *ecb = &aes_ecb_algorithm;
+ struct cipher_algorithm *cbc = &aes_cbc_algorithm;
+ unsigned int keylen;
+
+ /* Correctness tests */
+ cipher_ok ( &aes_128_ecb );
+ cipher_ok ( &aes_128_cbc );
+ cipher_ok ( &aes_192_ecb );
+ cipher_ok ( &aes_192_cbc );
+ cipher_ok ( &aes_256_ecb );
+ cipher_ok ( &aes_256_cbc );
+
+ /* Speed tests */
+ for ( keylen = 128 ; keylen <= 256 ; keylen += 64 ) {
+ DBG ( "AES-%d-ECB encryption required %ld cycles per byte\n",
+ keylen, cipher_cost_encrypt ( ecb, ( keylen / 8 ) ) );
+ DBG ( "AES-%d-ECB decryption required %ld cycles per byte\n",
+ keylen, cipher_cost_decrypt ( ecb, ( keylen / 8 ) ) );
+ DBG ( "AES-%d-CBC encryption required %ld cycles per byte\n",
+ keylen, cipher_cost_encrypt ( cbc, ( keylen / 8 ) ) );
+ DBG ( "AES-%d-CBC decryption required %ld cycles per byte\n",
+ keylen, cipher_cost_decrypt ( cbc, ( keylen / 8 ) ) );
+ }
+}
+
+/** AES self-test */
+struct self_test aes_test __self_test = {
+ .name = "aes",
+ .exec = aes_test_exec,
+};
diff --git a/qemu/roms/ipxe/src/tests/base16_test.c b/qemu/roms/ipxe/src/tests/base16_test.c
index 9b047b74c..46884aef7 100644
--- a/qemu/roms/ipxe/src/tests/base16_test.c
+++ b/qemu/roms/ipxe/src/tests/base16_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
@@ -73,30 +77,42 @@ BASE16 ( random_test,
* Report a base16 encoding test result
*
* @v test Base16 test
+ * @v file Test code file
+ * @v line Test code line
*/
-#define base16_encode_ok( test ) do { \
- size_t len = base16_encoded_len ( (test)->len ); \
- char buf[ len + 1 /* NUL */ ]; \
- ok ( len == strlen ( (test)->encoded ) ); \
- base16_encode ( (test)->data, (test)->len, buf ); \
- ok ( strcmp ( (test)->encoded, buf ) == 0 ); \
- } while ( 0 )
+static void base16_encode_okx ( struct base16_test *test, const char *file,
+ unsigned int line ) {
+ size_t len = base16_encoded_len ( test->len );
+ char buf[ len + 1 /* NUL */ ];
+ size_t check_len;
+
+ okx ( len == strlen ( test->encoded ), file, line );
+ check_len = base16_encode ( test->data, test->len, buf, sizeof ( buf ));
+ okx ( check_len == len, file, line );
+ okx ( strcmp ( test->encoded, buf ) == 0, file, line );
+}
+#define base16_encode_ok( test ) base16_encode_okx ( test, __FILE__, __LINE__ )
/**
* Report a base16 decoding test result
*
* @v test Base16 test
+ * @v file Test code file
+ * @v line Test code line
*/
-#define base16_decode_ok( test ) do { \
- size_t max_len = base16_decoded_max_len ( (test)->encoded ); \
- uint8_t buf[max_len]; \
- int len; \
- len = base16_decode ( (test)->encoded, buf ); \
- ok ( len >= 0 ); \
- ok ( ( size_t ) len <= max_len ); \
- ok ( ( size_t ) len == (test)->len ); \
- ok ( memcmp ( (test)->data, buf, len ) == 0 ); \
- } while ( 0 )
+static void base16_decode_okx ( struct base16_test *test, const char *file,
+ unsigned int line ) {
+ size_t max_len = base16_decoded_max_len ( test->encoded );
+ uint8_t buf[max_len];
+ int len;
+
+ len = base16_decode ( test->encoded, buf, sizeof ( buf ) );
+ okx ( len >= 0, file, line );
+ okx ( ( size_t ) len <= max_len, file, line );
+ okx ( ( size_t ) len == test->len, file, line );
+ okx ( memcmp ( test->data, buf, len ) == 0, file, line );
+}
+#define base16_decode_ok( test ) base16_decode_okx ( test, __FILE__, __LINE__ )
/**
* Perform Base16 self-tests
diff --git a/qemu/roms/ipxe/src/tests/base64_test.c b/qemu/roms/ipxe/src/tests/base64_test.c
index c088298ca..0fc595d90 100644
--- a/qemu/roms/ipxe/src/tests/base64_test.c
+++ b/qemu/roms/ipxe/src/tests/base64_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
@@ -76,30 +80,42 @@ BASE64 ( random_test,
* Report a base64 encoding test result
*
* @v test Base64 test
+ * @v file Test code file
+ * @v line Test code line
*/
-#define base64_encode_ok( test ) do { \
- size_t len = base64_encoded_len ( (test)->len ); \
- char buf[ len + 1 /* NUL */ ]; \
- ok ( len == strlen ( (test)->encoded ) ); \
- base64_encode ( (test)->data, (test)->len, buf ); \
- ok ( strcmp ( (test)->encoded, buf ) == 0 ); \
- } while ( 0 )
+static void base64_encode_okx ( struct base64_test *test, const char *file,
+ unsigned int line ) {
+ size_t len = base64_encoded_len ( test->len );
+ char buf[ len + 1 /* NUL */ ];
+ size_t check_len;
+
+ okx ( len == strlen ( test->encoded ), file, line );
+ check_len = base64_encode ( test->data, test->len, buf, sizeof ( buf ));
+ okx ( check_len == len, file, line );
+ okx ( strcmp ( test->encoded, buf ) == 0, file, line );
+}
+#define base64_encode_ok( test ) base64_encode_okx ( test, __FILE__, __LINE__ )
/**
* Report a base64 decoding test result
*
* @v test Base64 test
+ * @v file Test code file
+ * @v line Test code line
*/
-#define base64_decode_ok( test ) do { \
- size_t max_len = base64_decoded_max_len ( (test)->encoded ); \
- uint8_t buf[max_len]; \
- int len; \
- len = base64_decode ( (test)->encoded, buf ); \
- ok ( len >= 0 ); \
- ok ( ( size_t ) len <= max_len ); \
- ok ( ( size_t ) len == (test)->len ); \
- ok ( memcmp ( (test)->data, buf, len ) == 0 ); \
- } while ( 0 )
+static void base64_decode_okx ( struct base64_test *test, const char *file,
+ unsigned int line ) {
+ size_t max_len = base64_decoded_max_len ( test->encoded );
+ uint8_t buf[max_len];
+ int len;
+
+ len = base64_decode ( test->encoded, buf, sizeof ( buf ) );
+ okx ( len >= 0, file, line );
+ okx ( ( size_t ) len <= max_len, file, line );
+ okx ( ( size_t ) len == test->len, file, line );
+ okx ( memcmp ( test->data, buf, len ) == 0, file, line );
+}
+#define base64_decode_ok( test ) base64_decode_okx ( test, __FILE__, __LINE__ )
/**
* Perform Base64 self-tests
diff --git a/qemu/roms/ipxe/src/tests/bigint_test.c b/qemu/roms/ipxe/src/tests/bigint_test.c
index 75a80622f..8d40c3188 100644
--- a/qemu/roms/ipxe/src/tests/bigint_test.c
+++ b/qemu/roms/ipxe/src/tests/bigint_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
diff --git a/qemu/roms/ipxe/src/tests/bofm_test.c b/qemu/roms/ipxe/src/tests/bofm_test.c
index e430d12d4..829924887 100644
--- a/qemu/roms/ipxe/src/tests/bofm_test.c
+++ b/qemu/roms/ipxe/src/tests/bofm_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdint.h>
#include <stdio.h>
diff --git a/qemu/roms/ipxe/src/tests/byteswap_test.c b/qemu/roms/ipxe/src/tests/byteswap_test.c
index a500218be..92bdb1d59 100644
--- a/qemu/roms/ipxe/src/tests/byteswap_test.c
+++ b/qemu/roms/ipxe/src/tests/byteswap_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
diff --git a/qemu/roms/ipxe/src/tests/cbc_test.h b/qemu/roms/ipxe/src/tests/cbc_test.h
deleted file mode 100644
index ad9e6f341..000000000
--- a/qemu/roms/ipxe/src/tests/cbc_test.h
+++ /dev/null
@@ -1,57 +0,0 @@
-#ifndef _CBC_TEST_H
-#define _CBC_TEST_H
-
-FILE_LICENCE ( GPL2_OR_LATER );
-
-#include <stdint.h>
-#include <ipxe/crypto.h>
-#include <ipxe/test.h>
-
-extern int cbc_test_encrypt ( struct cipher_algorithm *cipher, const void *key,
- size_t key_len, const void *iv,
- const void *plaintext,
- const void *expected_ciphertext, size_t len );
-extern int cbc_test_decrypt ( struct cipher_algorithm *cipher, const void *key,
- size_t key_len, const void *iv,
- const void *ciphertext,
- const void *expected_plaintext, size_t len );
-extern unsigned long cbc_cost_encrypt ( struct cipher_algorithm *cipher,
- size_t key_len );
-extern unsigned long cbc_cost_decrypt ( struct cipher_algorithm *cipher,
- size_t key_len );
-
-/**
- * Report CBC encryption test result
- *
- * @v cipher Cipher algorithm
- * @v key Key
- * @v key_len Length of key
- * @v iv Initialisation vector
- * @v plaintext Plaintext data
- * @v expected_ciphertext Expected ciphertext data
- * @v len Length of data
- */
-#define cbc_encrypt_ok( cipher, key, key_len, iv, plaintext, \
- expected_ciphertext, len ) do { \
- ok ( cbc_test_encrypt ( cipher, key, key_len, iv, plaintext, \
- expected_ciphertext, len ) ); \
- } while ( 0 )
-
-/**
- * Report CBC decryption test result
- *
- * @v cipher Cipher algorithm
- * @v key Key
- * @v key_len Length of key
- * @v iv Initialisation vector
- * @v ciphertext Ciphertext data
- * @v expected_plaintext Expected plaintext data
- * @v len Length of data
- */
-#define cbc_decrypt_ok( cipher, key, key_len, iv, ciphertext, \
- expected_plaintext, len ) do { \
- ok ( cbc_test_decrypt ( cipher, key, key_len, iv, ciphertext, \
- expected_plaintext, len ) ); \
- } while ( 0 )
-
-#endif /* _CBC_TEST_H */
diff --git a/qemu/roms/ipxe/src/tests/cbc_test.c b/qemu/roms/ipxe/src/tests/cipher_test.c
index cb0f7bdea..800d6c138 100644
--- a/qemu/roms/ipxe/src/tests/cbc_test.c
+++ b/qemu/roms/ipxe/src/tests/cipher_test.c
@@ -15,13 +15,17 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
- * CBC self-tests
+ * Cipher self-tests
*
*/
@@ -34,86 +38,90 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <assert.h>
#include <ipxe/crypto.h>
#include <ipxe/profile.h>
-#include "cbc_test.h"
+#include <ipxe/test.h>
+#include "cipher_test.h"
/** Number of sample iterations for profiling */
#define PROFILE_COUNT 16
/**
- * Test CBC encryption
+ * Report a cipher encryption test result
*
- * @v cipher Cipher algorithm
- * @v key Key
- * @v key_len Length of key
- * @v iv Initialisation vector
- * @v plaintext Plaintext data
- * @v expected_ciphertext Expected ciphertext data
- * @v len Length of data
- * @ret ok Ciphertext is as expected
+ * @v test Cipher test
+ * @v file Test code file
+ * @v line Test code line
*/
-int cbc_test_encrypt ( struct cipher_algorithm *cipher, const void *key,
- size_t key_len, const void *iv, const void *plaintext,
- const void *expected_ciphertext, size_t len ) {
+void cipher_encrypt_okx ( struct cipher_test *test, const char *file,
+ unsigned int line ) {
+ struct cipher_algorithm *cipher = test->cipher;
+ size_t len = test->len;
uint8_t ctx[cipher->ctxsize];
uint8_t ciphertext[len];
- int rc;
/* Initialise cipher */
- rc = cipher_setkey ( cipher, ctx, key, key_len );
- assert ( rc == 0 );
- cipher_setiv ( cipher, ctx, iv );
+ okx ( cipher_setkey ( cipher, ctx, test->key, test->key_len ) == 0,
+ file, line );
+ cipher_setiv ( cipher, ctx, test->iv );
/* Perform encryption */
- cipher_encrypt ( cipher, ctx, plaintext, ciphertext, len );
+ cipher_encrypt ( cipher, ctx, test->plaintext, ciphertext, len );
- /* Verify result */
- return ( memcmp ( ciphertext, expected_ciphertext, len ) == 0 );
+ /* Compare against expected ciphertext */
+ okx ( memcmp ( ciphertext, test->ciphertext, len ) == 0, file, line );
}
/**
- * Test CBC decryption
+ * Report a cipher decryption test result
*
- * @v cipher Cipher algorithm
- * @v key Key
- * @v key_len Length of key
- * @v iv Initialisation vector
- * @v ciphertext Ciphertext data
- * @v expected_plaintext Expected plaintext data
- * @v len Length of data
- * @ret ok Plaintext is as expected
+ * @v test Cipher test
+ * @v file Test code file
+ * @v line Test code line
*/
-int cbc_test_decrypt ( struct cipher_algorithm *cipher, const void *key,
- size_t key_len, const void *iv, const void *ciphertext,
- const void *expected_plaintext, size_t len ) {
+void cipher_decrypt_okx ( struct cipher_test *test, const char *file,
+ unsigned int line ) {
+ struct cipher_algorithm *cipher = test->cipher;
+ size_t len = test->len;
uint8_t ctx[cipher->ctxsize];
uint8_t plaintext[len];
- int rc;
/* Initialise cipher */
- rc = cipher_setkey ( cipher, ctx, key, key_len );
- assert ( rc == 0 );
- cipher_setiv ( cipher, ctx, iv );
+ okx ( cipher_setkey ( cipher, ctx, test->key, test->key_len ) == 0,
+ file, line );
+ cipher_setiv ( cipher, ctx, test->iv );
/* Perform encryption */
- cipher_decrypt ( cipher, ctx, ciphertext, plaintext, len );
+ cipher_decrypt ( cipher, ctx, test->ciphertext, plaintext, len );
+
+ /* Compare against expected plaintext */
+ okx ( memcmp ( plaintext, test->plaintext, len ) == 0, file, line );
+}
+
+/**
+ * Report a cipher encryption and decryption test result
+ *
+ * @v test Cipher test
+ * @v file Test code file
+ * @v line Test code line
+ */
+void cipher_okx ( struct cipher_test *test, const char *file,
+ unsigned int line ) {
- /* Verify result */
- return ( memcmp ( plaintext, expected_plaintext, len ) == 0 );
+ cipher_encrypt_okx ( test, file, line );
+ cipher_decrypt_okx ( test, file, line );
}
/**
- * Calculate CBC encryption or decryption cost
+ * Calculate cipher encryption or decryption cost
*
* @v cipher Cipher algorithm
* @v key_len Length of key
* @v op Encryption or decryption operation
* @ret cost Cost (in cycles per byte)
*/
-static unsigned long cbc_cost ( struct cipher_algorithm *cipher,
- size_t key_len,
- void ( * op ) ( struct cipher_algorithm *cipher,
- void *ctx, const void *src,
- void *dst, size_t len ) ) {
+static unsigned long
+cipher_cost ( struct cipher_algorithm *cipher, size_t key_len,
+ void ( * op ) ( struct cipher_algorithm *cipher, void *ctx,
+ const void *src, void *dst, size_t len ) ) {
static uint8_t random[8192]; /* Too large for stack */
uint8_t key[key_len];
uint8_t iv[cipher->blocksize];
@@ -153,25 +161,25 @@ static unsigned long cbc_cost ( struct cipher_algorithm *cipher,
}
/**
- * Calculate CBC encryption cost
+ * Calculate cipher encryption cost
*
* @v cipher Cipher algorithm
* @v key_len Length of key
* @ret cost Cost (in cycles per byte)
*/
-unsigned long cbc_cost_encrypt ( struct cipher_algorithm *cipher,
- size_t key_len ) {
- return cbc_cost ( cipher, key_len, cipher_encrypt );
+unsigned long cipher_cost_encrypt ( struct cipher_algorithm *cipher,
+ size_t key_len ) {
+ return cipher_cost ( cipher, key_len, cipher_encrypt );
}
/**
- * Calculate CBC decryption cost
+ * Calculate cipher decryption cost
*
* @v cipher Cipher algorithm
* @v key_len Length of key
* @ret cost Cost (in cycles per byte)
*/
-unsigned long cbc_cost_decrypt ( struct cipher_algorithm *cipher,
- size_t key_len ) {
- return cbc_cost ( cipher, key_len, cipher_decrypt );
+unsigned long cipher_cost_decrypt ( struct cipher_algorithm *cipher,
+ size_t key_len ) {
+ return cipher_cost ( cipher, key_len, cipher_decrypt );
}
diff --git a/qemu/roms/ipxe/src/tests/cipher_test.h b/qemu/roms/ipxe/src/tests/cipher_test.h
new file mode 100644
index 000000000..d7c5aef8f
--- /dev/null
+++ b/qemu/roms/ipxe/src/tests/cipher_test.h
@@ -0,0 +1,111 @@
+#ifndef _CIPHER_TEST_H
+#define _CIPHER_TEST_H
+
+/** @file
+ *
+ * Cipher self-tests
+ *
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+#include <stdint.h>
+#include <ipxe/crypto.h>
+#include <ipxe/test.h>
+
+/** A cipher test */
+struct cipher_test {
+ /** Cipher algorithm */
+ struct cipher_algorithm *cipher;
+ /** Key */
+ const void *key;
+ /** Length of key */
+ size_t key_len;
+ /** Initialisation vector */
+ const void *iv;
+ /** Length of initialisation vector */
+ size_t iv_len;
+ /** Plaintext */
+ const void *plaintext;
+ /** Ciphertext */
+ const void *ciphertext;
+ /** Length of text */
+ size_t len;
+};
+
+/** Define inline key */
+#define KEY(...) { __VA_ARGS__ }
+
+/** Define inline initialisation vector */
+#define IV(...) { __VA_ARGS__ }
+
+/** Define inline plaintext data */
+#define PLAINTEXT(...) { __VA_ARGS__ }
+
+/** Define inline ciphertext data */
+#define CIPHERTEXT(...) { __VA_ARGS__ }
+
+/**
+ * Define a cipher test
+ *
+ * @v name Test name
+ * @v CIPHER Cipher algorithm
+ * @v KEY Key
+ * @v IV Initialisation vector
+ * @v PLAINTEXT Plaintext
+ * @v CIPHERTEXT Ciphertext
+ * @ret test Cipher test
+ */
+#define CIPHER_TEST( name, CIPHER, KEY, IV, PLAINTEXT, CIPHERTEXT ) \
+ static const uint8_t name ## _key [] = KEY; \
+ static const uint8_t name ## _iv [] = IV; \
+ static const uint8_t name ## _plaintext [] = PLAINTEXT; \
+ static const uint8_t name ## _ciphertext \
+ [ sizeof ( name ## _plaintext ) ] = CIPHERTEXT; \
+ static struct cipher_test name = { \
+ .cipher = CIPHER, \
+ .key = name ## _key, \
+ .key_len = sizeof ( name ## _key ), \
+ .iv = name ## _iv, \
+ .iv_len = sizeof ( name ## _iv ), \
+ .plaintext = name ## _plaintext, \
+ .ciphertext = name ## _ciphertext, \
+ .len = sizeof ( name ## _plaintext ), \
+ }
+
+extern void cipher_encrypt_okx ( struct cipher_test *test, const char *file,
+ unsigned int line );
+extern void cipher_decrypt_okx ( struct cipher_test *test, const char *file,
+ unsigned int line );
+extern void cipher_okx ( struct cipher_test *test, const char *file,
+ unsigned int line );
+extern unsigned long cipher_cost_encrypt ( struct cipher_algorithm *cipher,
+ size_t key_len );
+extern unsigned long cipher_cost_decrypt ( struct cipher_algorithm *cipher,
+ size_t key_len );
+
+/**
+ * Report a cipher encryption test result
+ *
+ * @v test Cipher test
+ */
+#define cipher_encrypt_ok( test ) \
+ cipher_encrypt_okx ( test, __FILE__, __LINE__ )
+
+/**
+ * Report a cipher decryption test result
+ *
+ * @v test Cipher test
+ */
+#define cipher_decrypt_ok( test ) \
+ cipher_decrypt_okx ( test, __FILE__, __LINE__ )
+
+/**
+ * Report a cipher encryption and decryption test result
+ *
+ * @v test Cipher test
+ */
+#define cipher_ok( test ) \
+ cipher_okx ( test, __FILE__, __LINE__ )
+
+#endif /* _CIPHER_TEST_H */
diff --git a/qemu/roms/ipxe/src/tests/cms_test.c b/qemu/roms/ipxe/src/tests/cms_test.c
index 8767504c0..b805a9974 100644
--- a/qemu/roms/ipxe/src/tests/cms_test.c
+++ b/qemu/roms/ipxe/src/tests/cms_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
@@ -1470,6 +1474,7 @@ struct self_test cms_test __self_test = {
};
/* Drag in algorithms required for tests */
+REQUIRING_SYMBOL ( cms_test );
REQUIRE_OBJECT ( rsa );
REQUIRE_OBJECT ( md5 );
REQUIRE_OBJECT ( sha1 );
diff --git a/qemu/roms/ipxe/src/tests/crc32_test.c b/qemu/roms/ipxe/src/tests/crc32_test.c
index 873f633a5..46cde0f7b 100644
--- a/qemu/roms/ipxe/src/tests/crc32_test.c
+++ b/qemu/roms/ipxe/src/tests/crc32_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
diff --git a/qemu/roms/ipxe/src/tests/deflate_test.c b/qemu/roms/ipxe/src/tests/deflate_test.c
index 68c1aad96..20ff5b9a2 100644
--- a/qemu/roms/ipxe/src/tests/deflate_test.c
+++ b/qemu/roms/ipxe/src/tests/deflate_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
diff --git a/qemu/roms/ipxe/src/tests/digest_test.c b/qemu/roms/ipxe/src/tests/digest_test.c
index 4df26c099..c3a128853 100644
--- a/qemu/roms/ipxe/src/tests/digest_test.c
+++ b/qemu/roms/ipxe/src/tests/digest_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
@@ -34,27 +38,47 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/profile.h>
#include "digest_test.h"
+/** Maximum number of digest test fragments */
+#define NUM_DIGEST_TEST_FRAG 8
+
+/** A digest test fragment list */
+struct digest_test_fragments {
+ /** Fragment lengths */
+ size_t len[NUM_DIGEST_TEST_FRAG];
+};
+
+/** Digest test fragment lists */
+static struct digest_test_fragments digest_test_fragments[] = {
+ { { 0, -1UL, } },
+ { { 1, 1, 1, 1, 1, 1, 1, 1 } },
+ { { 2, 0, 23, 4, 6, 1, 0 } },
+};
+
/** Number of sample iterations for profiling */
#define PROFILE_COUNT 16
/**
- * Test digest algorithm
+ * Report a digest fragmented test result
*
- * @v digest Digest algorithm
- * @v fragments Digest test fragment list, or NULL
- * @v data Test data
- * @v len Length of test data
- * @v expected Expected digest value
- * @ret ok Digest value is as expected
+ * @v test Digest test
+ * @v fragments Fragment list
+ * @v file Test code file
+ * @v line Test code line
*/
-int digest_test ( struct digest_algorithm *digest,
- struct digest_test_fragments *fragments,
- void *data, size_t len, void *expected ) {
+void digest_frag_okx ( struct digest_test *test,
+ struct digest_test_fragments *fragments,
+ const char *file, unsigned int line ) {
+ struct digest_algorithm *digest = test->digest;
uint8_t ctx[digest->ctxsize];
uint8_t out[digest->digestsize];
+ const void *data = test->data;
+ size_t len = test->len;
size_t frag_len = 0;
unsigned int i;
+ /* Sanity check */
+ okx ( test->expected_len == sizeof ( out ), file, line );
+
/* Initialise digest */
digest_init ( digest, ctx );
@@ -74,7 +98,28 @@ int digest_test ( struct digest_algorithm *digest,
digest_final ( digest, ctx, out );
/* Compare against expected output */
- return ( memcmp ( expected, out, sizeof ( out ) ) == 0 );
+ okx ( memcmp ( test->expected, out, sizeof ( out ) ) == 0, file, line );
+}
+
+/**
+ * Report a digest test result
+ *
+ * @v test Digest test
+ * @v file Test code file
+ * @v line Test code line
+ */
+void digest_okx ( struct digest_test *test, const char *file,
+ unsigned int line ) {
+ unsigned int i;
+
+ /* Test with a single pass */
+ digest_frag_okx ( test, NULL, file, line );
+
+ /* Test with fragment lists */
+ for ( i = 0 ; i < ( sizeof ( digest_test_fragments ) /
+ sizeof ( digest_test_fragments[0] ) ) ; i++ ) {
+ digest_frag_okx ( test, &digest_test_fragments[i], file, line );
+ }
}
/**
diff --git a/qemu/roms/ipxe/src/tests/digest_test.h b/qemu/roms/ipxe/src/tests/digest_test.h
index 49e06d1cb..abf1b834f 100644
--- a/qemu/roms/ipxe/src/tests/digest_test.h
+++ b/qemu/roms/ipxe/src/tests/digest_test.h
@@ -1,37 +1,115 @@
#ifndef _DIGEST_TEST_H
#define _DIGEST_TEST_H
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdint.h>
#include <ipxe/crypto.h>
#include <ipxe/test.h>
-/** Maximum number of digest test fragments */
-#define NUM_DIGEST_TEST_FRAG 8
-
-/** A digest test fragment list */
-struct digest_test_fragments {
- /** Fragment lengths */
- size_t len[NUM_DIGEST_TEST_FRAG];
+/** A digest test */
+struct digest_test {
+ /** Digest algorithm */
+ struct digest_algorithm *digest;
+ /** Test data */
+ const void *data;
+ /** Length of test data */
+ size_t len;
+ /** Expected digest value */
+ const void *expected;
+ /** Expected digest length */
+ size_t expected_len;
};
-extern int digest_test ( struct digest_algorithm *digest,
- struct digest_test_fragments *fragments,
- void *data, size_t len, void *expected );
-extern unsigned long digest_cost ( struct digest_algorithm *digest );
+/** Define inline test data */
+#define DATA(...) { __VA_ARGS__ }
+
+/** Define inline expected digest value */
+#define DIGEST(...) { __VA_ARGS__ }
+
+/**
+ * Define a digest test
+ *
+ * @v name Test name
+ * @v DIGEST Digest algorithm
+ * @v DATA Test data
+ * @v EXPECTED Expected digest value
+ * @ret test Digest test
+ */
+#define DIGEST_TEST( name, DIGEST, DATA, EXPECTED ) \
+ static const uint8_t name ## _data[] = DATA; \
+ static const uint8_t name ## _expected[] = EXPECTED; \
+ static struct digest_test name = { \
+ .digest = DIGEST, \
+ .data = name ## _data, \
+ .len = sizeof ( name ## _data ), \
+ .expected = name ## _expected, \
+ .expected_len = sizeof ( name ## _expected ), \
+ };
+
+/** Standard test vector: empty data */
+#define DIGEST_EMPTY DATA()
+
+/** Standard test vector: NIST string "abc"
+ *
+ * The NIST Cryptographic Toolkit examples for all digest algorithms
+ * include a test vector which is the unterminated string
+ *
+ * "abc"
+ */
+#define DIGEST_NIST_ABC \
+ DATA ( 0x61, 0x62, 0x63 )
+
+/** Standard test vector: NIST string "abc...opq"
+ *
+ * The NIST Cryptographic Toolkit examples for all 32-bit digest
+ * algorithms (SHA-1 and the SHA-256 family) include a test vector
+ * which is the unterminated string
+ *
+ * "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
+ */
+#define DIGEST_NIST_ABC_OPQ \
+ DATA ( 0x61, 0x62, 0x63, 0x64, 0x62, 0x63, 0x64, 0x65, 0x63, \
+ 0x64, 0x65, 0x66, 0x64, 0x65, 0x66, 0x67, 0x65, 0x66, \
+ 0x67, 0x68, 0x66, 0x67, 0x68, 0x69, 0x67, 0x68, 0x69, \
+ 0x6a, 0x68, 0x69, 0x6a, 0x6b, 0x69, 0x6a, 0x6b, 0x6c, \
+ 0x6a, 0x6b, 0x6c, 0x6d, 0x6b, 0x6c, 0x6d, 0x6e, 0x6c, \
+ 0x6d, 0x6e, 0x6f, 0x6d, 0x6e, 0x6f, 0x70, 0x6e, 0x6f, \
+ 0x70, 0x71 )
+
+/** Standard test vector: NIST string "abc...stu"
+ *
+ * The NIST Cryptographic Toolkit examples for all 64-bit digest
+ * algorithms (SHA-512 family) include a test vector which is the
+ * unterminated string
+ *
+ * "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
+ * "hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
+ */
+#define DIGEST_NIST_ABC_STU \
+ DATA ( 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x62, \
+ 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x63, 0x64, \
+ 0x65, 0x66, 0x67, 0x68, 0x69, 0x6a, 0x64, 0x65, 0x66, \
+ 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x65, 0x66, 0x67, 0x68, \
+ 0x69, 0x6a, 0x6b, 0x6c, 0x66, 0x67, 0x68, 0x69, 0x6a, \
+ 0x6b, 0x6c, 0x6d, 0x67, 0x68, 0x69, 0x6a, 0x6b, 0x6c, \
+ 0x6d, 0x6e, 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, \
+ 0x6f, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, \
+ 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x6b, \
+ 0x6c, 0x6d, 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x6c, 0x6d, \
+ 0x6e, 0x6f, 0x70, 0x71, 0x72, 0x73, 0x6d, 0x6e, 0x6f, \
+ 0x70, 0x71, 0x72, 0x73, 0x74, 0x6e, 0x6f, 0x70, 0x71, \
+ 0x72, 0x73, 0x74, 0x75 )
/**
- * Report digest test result
+ * Report a digest test result
*
- * @v digest Digest algorithm
- * @v fragments Digest test fragment list, or NULL
- * @v data Test data
- * @v len Length of test data
- * @v expected Expected digest value
+ * @v test Digest test
*/
-#define digest_ok( digest, fragments, data, len, expected ) do { \
- ok ( digest_test ( digest, fragments, data, len, expected ) ); \
- } while ( 0 )
+#define digest_ok(test) digest_okx ( test, __FILE__, __LINE__ )
+
+extern void digest_okx ( struct digest_test *test, const char *file,
+ unsigned int line );
+extern unsigned long digest_cost ( struct digest_algorithm *digest );
#endif /* _DIGEST_TEST_H */
diff --git a/qemu/roms/ipxe/src/tests/dns_test.c b/qemu/roms/ipxe/src/tests/dns_test.c
index 52f5f19f2..f08e7810f 100644
--- a/qemu/roms/ipxe/src/tests/dns_test.c
+++ b/qemu/roms/ipxe/src/tests/dns_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
diff --git a/qemu/roms/ipxe/src/tests/entropy_sample.c b/qemu/roms/ipxe/src/tests/entropy_sample.c
index 95a662e3e..b45648c11 100644
--- a/qemu/roms/ipxe/src/tests/entropy_sample.c
+++ b/qemu/roms/ipxe/src/tests/entropy_sample.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
diff --git a/qemu/roms/ipxe/src/tests/hash_df_test.c b/qemu/roms/ipxe/src/tests/hash_df_test.c
index 74c8d0f4d..0b7d56ad7 100644
--- a/qemu/roms/ipxe/src/tests/hash_df_test.c
+++ b/qemu/roms/ipxe/src/tests/hash_df_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
diff --git a/qemu/roms/ipxe/src/tests/hmac_drbg_test.c b/qemu/roms/ipxe/src/tests/hmac_drbg_test.c
index 8cbf1cc8b..ddf9db2c5 100644
--- a/qemu/roms/ipxe/src/tests/hmac_drbg_test.c
+++ b/qemu/roms/ipxe/src/tests/hmac_drbg_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
diff --git a/qemu/roms/ipxe/src/tests/ipv4_test.c b/qemu/roms/ipxe/src/tests/ipv4_test.c
new file mode 100644
index 000000000..f84a8b81f
--- /dev/null
+++ b/qemu/roms/ipxe/src/tests/ipv4_test.c
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of 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.
+ *
+ * This program 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 a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+/** @file
+ *
+ * IPv4 tests
+ *
+ */
+
+/* Forcibly enable assertions */
+#undef NDEBUG
+
+#include <stdint.h>
+#include <string.h>
+#include <byteswap.h>
+#include <ipxe/in.h>
+#include <ipxe/test.h>
+
+/** Define inline IPv4 address */
+#define IPV4(a,b,c,d) \
+ htonl ( ( (a) << 24 ) | ( (b) << 16 ) | ( (c) << 8 ) | (d) )
+
+/**
+ * Report an inet_ntoa() test result
+ *
+ * @v addr IPv4 address
+ * @v text Expected textual representation
+ * @v file Test code file
+ * @v line Test code line
+ */
+static void inet_ntoa_okx ( uint32_t addr, const char *text, const char *file,
+ unsigned int line ) {
+ struct in_addr in = { .s_addr = addr };
+ char *actual;
+
+ /* Format address */
+ actual = inet_ntoa ( in );
+ DBG ( "inet_ntoa ( %d.%d.%d.%d ) = %s\n",
+ ( ( ntohl ( addr ) >> 24 ) & 0xff ),
+ ( ( ntohl ( addr ) >> 16 ) & 0xff ),
+ ( ( ntohl ( addr ) >> 8 ) & 0xff ),
+ ( ( ntohl ( addr ) >> 0 ) & 0xff ), actual );
+ okx ( strcmp ( actual, text ) == 0, file, line );
+}
+#define inet_ntoa_ok( addr, text ) \
+ inet_ntoa_okx ( addr, text, __FILE__, __LINE__ )
+
+/**
+ * Report an inet_aton() test result
+ *
+ * @v text Textual representation
+ * @v addr Expected IPv4 address
+ * @v file Test code file
+ * @v line Test code line
+ */
+static void inet_aton_okx ( const char *text, uint32_t addr, const char *file,
+ unsigned int line ) {
+ struct in_addr actual;
+
+ /* Parse address */
+ okx ( inet_aton ( text, &actual ) != 0, file, line );
+ DBG ( "inet_aton ( \"%s\" ) = %s\n", text, inet_ntoa ( actual ) );
+ okx ( actual.s_addr == addr, file, line );
+};
+#define inet_aton_ok( text, addr ) \
+ inet_aton_okx ( text, addr, __FILE__, __LINE__ )
+
+/**
+ * Report an inet_aton() failure test result
+ *
+ * @v text Textual representation
+ * @v file Test code file
+ * @v line Test code line
+ */
+static void inet_aton_fail_okx ( const char *text, const char *file,
+ unsigned int line ) {
+ struct in_addr actual;
+
+ /* Attempt to parse address */
+ okx ( inet_aton ( text, &actual ) == 0, file, line );
+}
+#define inet_aton_fail_ok( text ) \
+ inet_aton_fail_okx ( text, __FILE__, __LINE__ )
+
+/**
+ * Perform IPv4 self-tests
+ *
+ */
+static void ipv4_test_exec ( void ) {
+
+ /* Address testing macros */
+ ok ( IN_IS_CLASSA ( IPV4 ( 10, 0, 0, 1 ) ) );
+ ok ( ! IN_IS_CLASSB ( IPV4 ( 10, 0, 0, 1 ) ) );
+ ok ( ! IN_IS_CLASSC ( IPV4 ( 10, 0, 0, 1 ) ) );
+ ok ( ! IN_IS_CLASSA ( IPV4 ( 172, 16, 0, 1 ) ) );
+ ok ( IN_IS_CLASSB ( IPV4 ( 172, 16, 0, 1 ) ) );
+ ok ( ! IN_IS_CLASSC ( IPV4 ( 172, 16, 0, 1 ) ) );
+ ok ( ! IN_IS_CLASSA ( IPV4 ( 192, 168, 0, 1 ) ) );
+ ok ( ! IN_IS_CLASSB ( IPV4 ( 192, 168, 0, 1 ) ) );
+ ok ( IN_IS_CLASSC ( IPV4 ( 192, 168, 0, 1 ) ) );
+ ok ( ! IN_IS_MULTICAST ( IPV4 ( 127, 0, 0, 1 ) ) );
+ ok ( ! IN_IS_MULTICAST ( IPV4 ( 8, 8, 8, 8 ) ) );
+ ok ( ! IN_IS_MULTICAST ( IPV4 ( 0, 0, 0, 0 ) ) );
+ ok ( ! IN_IS_MULTICAST ( IPV4 ( 223, 0, 0, 1 ) ) );
+ ok ( ! IN_IS_MULTICAST ( IPV4 ( 240, 0, 0, 1 ) ) );
+ ok ( IN_IS_MULTICAST ( IPV4 ( 224, 0, 0, 1 ) ) );
+ ok ( IN_IS_MULTICAST ( IPV4 ( 231, 89, 0, 2 ) ) );
+ ok ( IN_IS_MULTICAST ( IPV4 ( 239, 6, 1, 17 ) ) );
+
+ /* inet_ntoa() tests */
+ inet_ntoa_ok ( IPV4 ( 127, 0, 0, 1 ), "127.0.0.1" );
+ inet_ntoa_ok ( IPV4 ( 0, 0, 0, 0 ), "0.0.0.0" );
+ inet_ntoa_ok ( IPV4 ( 255, 255, 255, 255 ), "255.255.255.255" );
+ inet_ntoa_ok ( IPV4 ( 212, 13, 204, 60 ), "212.13.204.60" );
+
+ /* inet_aton() tests */
+ inet_aton_ok ( "212.13.204.60", IPV4 ( 212, 13, 204, 60 ) );
+ inet_aton_ok ( "127.0.0.1", IPV4 ( 127, 0, 0, 1 ) );
+
+ /* inet_aton() failure tests */
+ inet_aton_fail_ok ( "256.0.0.1" ); /* Byte out of range */
+ inet_aton_fail_ok ( "212.13.204.60.1" ); /* Too long */
+ inet_aton_fail_ok ( "127.0.0" ); /* Too short */
+ inet_aton_fail_ok ( "1.2.3.a" ); /* Invalid characters */
+ inet_aton_fail_ok ( "127.0..1" ); /* Missing bytes */
+}
+
+/** IPv4 self-test */
+struct self_test ipv4_test __self_test = {
+ .name = "ipv4",
+ .exec = ipv4_test_exec,
+};
diff --git a/qemu/roms/ipxe/src/tests/ipv6_test.c b/qemu/roms/ipxe/src/tests/ipv6_test.c
index e16fc7c3d..772eb1b82 100644
--- a/qemu/roms/ipxe/src/tests/ipv6_test.c
+++ b/qemu/roms/ipxe/src/tests/ipv6_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
diff --git a/qemu/roms/ipxe/src/tests/linebuf_test.c b/qemu/roms/ipxe/src/tests/linebuf_test.c
index e06ac7d86..0dd486e9d 100644
--- a/qemu/roms/ipxe/src/tests/linebuf_test.c
+++ b/qemu/roms/ipxe/src/tests/linebuf_test.c
@@ -1,35 +1,320 @@
-#include <stdint.h>
+/*
+ * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of 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.
+ *
+ * This program 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 a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+/** @file
+ *
+ * Line buffer self-tests
+ *
+ */
+
+/* Forcibly enable assertions */
+#undef NDEBUG
+
#include <string.h>
-#include <stdio.h>
+#include <assert.h>
#include <ipxe/linebuf.h>
+#include <ipxe/test.h>
-static const char data1[] =
-"Hello world\r\n"
-"This is a reasonably nice set of lines\n"
-"with not many different terminators\r\n\r\n"
-"There should be exactly one blank line above\n"
-"and this line should never appear at all since it has no terminator";
+/** Define inline raw data */
+#define DATA(...) { __VA_ARGS__ }
-void linebuf_test ( void ) {
- struct line_buffer linebuf;
- const char *data = data1;
- size_t len = ( sizeof ( data1 ) - 1 /* be mean; strip the NUL */ );
- ssize_t frag_len;
- char *line;
-
- memset ( &linebuf, 0, sizeof ( linebuf ) );
- while ( len ) {
- frag_len = line_buffer ( &linebuf, data, len );
- if ( frag_len < 0 ) {
- printf ( "line_buffer() failed: %s\n",
- strerror ( frag_len ) );
+/** Define inline lines */
+#define LINES(...) { __VA_ARGS__ }
+
+/** A line buffer test */
+struct linebuf_test {
+ /** Raw data */
+ const void *data;
+ /** Length of raw data */
+ size_t len;
+ /** Expected sequence of lines */
+ const char **lines;
+ /** Number of expected lines */
+ unsigned int count;
+};
+
+/** Line buffer test expected failure indicator */
+static const char linebuf_failure[1];
+
+/**
+ * Define a line buffer test
+ *
+ * @v name Test name
+ * @v DATA Raw data
+ * @v LINES Expected sequence of lines
+ * @ret test Line buffer test
+ */
+#define LINEBUF_TEST( name, DATA, LINES ) \
+ static const char name ## _data[] = DATA; \
+ static const char * name ## _lines[] = LINES; \
+ static struct linebuf_test name = { \
+ .data = name ## _data, \
+ .len = ( sizeof ( name ## _data ) - 1 /* NUL */ ), \
+ .lines = name ## _lines, \
+ .count = ( sizeof ( name ## _lines ) / \
+ sizeof ( name ## _lines[0] ) ), \
+ }
+
+/** Simple line buffer test */
+LINEBUF_TEST ( simple,
+ ( "HTTP/1.1 200 OK\r\n"
+ "Content-Length: 123\r\n"
+ "Content-Type: text/plain\r\n"
+ "\r\n" ),
+ LINES ( "HTTP/1.1 200 OK",
+ "Content-Length: 123",
+ "Content-Type: text/plain",
+ "" ) );
+
+/** Mixed line terminators */
+LINEBUF_TEST ( mixed,
+ ( "LF only\n" "CRLF\r\n" "\n" "\n" "\r\n" "\r\n" "CR only\r" ),
+ LINES ( "LF only", "CRLF", "", "", "", "",
+ NULL /* \r should not be treated as a terminator */ ) );
+
+/** Split consumption: part 1 */
+LINEBUF_TEST ( split_1,
+ ( "This line was" ),
+ LINES ( NULL ) );
+
+/** Split consumption: part 2 */
+LINEBUF_TEST ( split_2,
+ ( " split across" ),
+ LINES ( NULL ) );
+
+/** Split consumption: part 3 */
+LINEBUF_TEST ( split_3,
+ ( " multiple calls\r\nand so was this one\r" ),
+ LINES ( "This line was split across multiple calls", NULL ) );
+
+/** Split consumption: part 4 */
+LINEBUF_TEST ( split_4,
+ ( "\nbut not this one\r\n" ),
+ LINES ( "and so was this one", "but not this one" ) );
+
+/** Split consumption: part 5 */
+LINEBUF_TEST ( split_5,
+ ( "" ),
+ LINES ( NULL ) );
+
+/** Split consumption: part 6 */
+LINEBUF_TEST ( split_6,
+ ( "This line came after a zero-length call\r\n" ),
+ LINES ( "This line came after a zero-length call" ) );
+
+/** Embedded NULs */
+LINEBUF_TEST ( embedded_nuls,
+ ( "This\r\ntest\r\nincludes\r\n\r\nsome\0binary\0data\r\n" ),
+ LINES ( "This", "test", "includes", "", linebuf_failure ) );
+
+/**
+ * Report line buffer initialisation test result
+ *
+ * @v linebuf Line buffer
+ * @v file Test code file
+ * @v line Test code line
+ */
+static void linebuf_init_okx ( struct line_buffer *linebuf,
+ const char *file, unsigned int line ) {
+
+ /* Initialise line buffer */
+ memset ( linebuf, 0, sizeof ( *linebuf ) );
+ okx ( buffered_line ( linebuf ) == NULL, file, line );
+}
+#define linebuf_init_ok( linebuf ) \
+ linebuf_init_okx ( linebuf, __FILE__, __LINE__ )
+
+/**
+ * Report line buffer consumption test result
+ *
+ * @v test Line buffer test
+ * @v linebuf Line buffer
+ * @v file Test code file
+ * @v line Test code line
+ */
+static void linebuf_consume_okx ( struct linebuf_test *test,
+ struct line_buffer *linebuf,
+ const char *file, unsigned int line ) {
+ const char *data = test->data;
+ size_t remaining = test->len;
+ int len;
+ unsigned int i;
+ const char *expected;
+ char *actual;
+ int rc;
+
+ DBGC ( test, "LINEBUF %p:\n", test );
+ DBGC_HDA ( test, 0, data, remaining );
+
+ /* Consume data one line at a time */
+ for ( i = 0 ; i < test->count ; i++ ) {
+
+ /* Add data to line buffer */
+ len = line_buffer ( linebuf, data, remaining );
+
+ /* Get buffered line, if any */
+ actual = buffered_line ( linebuf );
+ if ( len < 0 ) {
+ rc = len;
+ DBGC ( test, "LINEBUF %p %s\n", test, strerror ( rc ) );
+ } else if ( actual != NULL ) {
+ DBGC ( test, "LINEBUF %p \"%s\" (consumed %d)\n",
+ test, actual, len );
+ } else {
+ DBGC ( test, "LINEBUF %p unterminated (consumed %d)\n",
+ test, len );
+ }
+
+ /* Check for success/failure */
+ expected = test->lines[i];
+ if ( expected == linebuf_failure ) {
+ rc = len;
+ okx ( rc < 0, file, line );
+ okx ( remaining > 0, file, line );
return;
}
- data += frag_len;
- len -= frag_len;
- if ( ( line = buffered_line ( &linebuf ) ) )
- printf ( "\"%s\"\n", line );
+ okx ( len >= 0, file, line );
+ okx ( ( ( size_t ) len ) <= remaining, file, line );
+
+ /* Check expected result */
+ if ( expected == NULL ) {
+ okx ( actual == NULL, file, line );
+ } else {
+ okx ( actual != NULL, file, line );
+ okx ( strcmp ( actual, expected ) == 0, file, line );
+ }
+
+ /* Consume data */
+ data += len;
+ remaining -= len;
+ }
+
+ /* Check that all data was consumed */
+ okx ( remaining == 0, file, line );
+}
+#define linebuf_consume_ok( test, linebuf ) \
+ linebuf_consume_okx ( test, linebuf, __FILE__, __LINE__ )
+
+/**
+ * Report line buffer accumulation test result
+ *
+ * @v test Line buffer test
+ * @v linebuf Line buffer
+ * @v file Test code file
+ * @v line Test code line
+ */
+static void linebuf_accumulated_okx ( struct linebuf_test *test,
+ struct line_buffer *linebuf,
+ const char *file, unsigned int line ) {
+ const char *actual;
+ const char *expected;
+ unsigned int i;
+
+ /* Check each accumulated line */
+ actual = linebuf->data;
+ for ( i = 0 ; i < test->count ; i++ ) {
+
+ /* Check accumulated line */
+ okx ( actual != NULL, file, line );
+ okx ( actual >= linebuf->data, file, line );
+ expected = test->lines[i];
+ if ( ( expected == NULL ) || ( expected == linebuf_failure ) )
+ return;
+ okx ( strcmp ( actual, expected ) == 0, file, line );
+
+ /* Move to next line */
+ actual += ( strlen ( actual ) + 1 /* NUL */ );
+ okx ( actual <= ( linebuf->data + linebuf->len ), file, line );
}
+}
+#define linebuf_accumulated_ok( test, linebuf ) \
+ linebuf_accumulated_okx ( test, linebuf, __FILE__, __LINE__ )
+
+/**
+ * Report line buffer emptying test result
+ *
+ * @v linebuf Line buffer
+ * @v file Test code file
+ * @v line Test code line
+ */
+static void linebuf_empty_okx ( struct line_buffer *linebuf,
+ const char *file, unsigned int line ) {
- empty_line_buffer ( &linebuf );
+ /* Empty line buffer */
+ empty_line_buffer ( linebuf );
+ okx ( buffered_line ( linebuf ) == NULL, file, line );
}
+#define linebuf_empty_ok( linebuf ) \
+ linebuf_empty_okx ( linebuf, __FILE__, __LINE__ )
+
+/**
+ * Report line buffer combined test result
+ *
+ * @v test Line buffer test
+ * @v file Test code file
+ * @v line Test code line
+ */
+static void linebuf_okx ( struct linebuf_test *test, const char *file,
+ unsigned int line ) {
+ struct line_buffer linebuf;
+
+ linebuf_init_okx ( &linebuf, file, line );
+ linebuf_consume_okx ( test, &linebuf, file, line );
+ linebuf_accumulated_okx ( test, &linebuf, file, line );
+ linebuf_empty_okx ( &linebuf, file, line );
+}
+#define linebuf_ok( test ) \
+ linebuf_okx ( test, __FILE__, __LINE__ )
+
+/**
+ * Perform line buffer self-tests
+ *
+ */
+static void linebuf_test_exec ( void ) {
+ struct line_buffer linebuf;
+
+ /* Basic tests */
+ linebuf_ok ( &simple );
+ linebuf_ok ( &mixed );
+
+ /* Split consumption test */
+ linebuf_init_ok ( &linebuf );
+ linebuf_consume_ok ( &split_1, &linebuf );
+ linebuf_consume_ok ( &split_2, &linebuf );
+ linebuf_consume_ok ( &split_3, &linebuf );
+ linebuf_consume_ok ( &split_4, &linebuf );
+ linebuf_consume_ok ( &split_5, &linebuf );
+ linebuf_consume_ok ( &split_6, &linebuf );
+ linebuf_empty_ok ( &linebuf );
+
+ /* Embedded NULs */
+ linebuf_ok ( &embedded_nuls );
+}
+
+/** Line buffer self-test */
+struct self_test linebuf_test __self_test = {
+ .name = "linebuf",
+ .exec = linebuf_test_exec,
+};
diff --git a/qemu/roms/ipxe/src/tests/list_test.c b/qemu/roms/ipxe/src/tests/list_test.c
index 35cbd5e5f..352c87da0 100644
--- a/qemu/roms/ipxe/src/tests/list_test.c
+++ b/qemu/roms/ipxe/src/tests/list_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
diff --git a/qemu/roms/ipxe/src/tests/math_test.c b/qemu/roms/ipxe/src/tests/math_test.c
index e12b7939d..1a244f1eb 100644
--- a/qemu/roms/ipxe/src/tests/math_test.c
+++ b/qemu/roms/ipxe/src/tests/math_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
@@ -35,6 +39,26 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <ipxe/isqrt.h>
/**
+ * Force a call to the non-constant implementation of ffsl()
+ *
+ * @v value Value
+ * @ret lsb Least significant bit set in value (LSB=1), or zero
+ */
+__attribute__ (( noinline )) int ffsl_var ( long value ) {
+ return ffsl ( value );
+}
+
+/**
+ * Force a call to the non-constant implementation of ffsll()
+ *
+ * @v value Value
+ * @ret lsb Least significant bit set in value (LSB=1), or zero
+ */
+__attribute__ (( noinline )) int ffsll_var ( long long value ) {
+ return ffsll ( value );
+}
+
+/**
* Force a call to the non-constant implementation of flsl()
*
* @v value Value
@@ -173,6 +197,44 @@ __attribute__ (( noinline )) int64_t s64mod_var ( int64_t dividend,
}
/**
+ * Report a ffsl() test result
+ *
+ * @v value Value
+ * @v lsb Expected LSB
+ * @v file Test code file
+ * @v line Test code line
+ */
+static inline __attribute__ (( always_inline )) void
+ffsl_okx ( long value, int lsb, const char *file, unsigned int line ) {
+
+ /* Verify as a constant (requires to be inlined) */
+ okx ( ffsl ( value ) == lsb, file, line );
+
+ /* Verify as a non-constant */
+ okx ( ffsl_var ( value ) == lsb, file, line );
+}
+#define ffsl_ok( value, lsb ) ffsl_okx ( value, lsb, __FILE__, __LINE__ )
+
+/**
+ * Report a ffsll() test result
+ *
+ * @v value Value
+ * @v lsb Expected LSB
+ * @v file Test code file
+ * @v line Test code line
+ */
+static inline __attribute__ (( always_inline )) void
+ffsll_okx ( long long value, int lsb, const char *file, unsigned int line ) {
+
+ /* Verify as a constant (requires to be inlined) */
+ okx ( ffsll ( value ) == lsb, file, line );
+
+ /* Verify as a non-constant */
+ okx ( ffsll_var ( value ) == lsb, file, line );
+}
+#define ffsll_ok( value, lsb ) ffsll_okx ( value, lsb, __FILE__, __LINE__ )
+
+/**
* Report a flsl() test result
*
* @v value Value
@@ -270,6 +332,22 @@ static void s64divmod_okx ( int64_t dividend, int64_t divisor,
*/
static void math_test_exec ( void ) {
+ /* Test ffsl() */
+ ffsl_ok ( 0, 0 );
+ ffsl_ok ( 1, 1 );
+ ffsl_ok ( 255, 1 );
+ ffsl_ok ( 256, 9 );
+ ffsl_ok ( 257, 1 );
+ ffsl_ok ( 0x54850596, 2 );
+ ffsl_ok ( 0x80000000, 32 );
+
+ /* Test ffsll() */
+ ffsll_ok ( 0, 0 );
+ ffsll_ok ( 1, 1 );
+ ffsll_ok ( 0x6d63623330ULL, 5 );
+ ffsll_ok ( 0x80000000UL, 32 );
+ ffsll_ok ( 0x8000000000000000ULL, 64 );
+
/* Test flsl() */
flsl_ok ( 0, 0 );
flsl_ok ( 1, 1 );
diff --git a/qemu/roms/ipxe/src/tests/md5_test.c b/qemu/roms/ipxe/src/tests/md5_test.c
index ba5f24c3e..e9ed2716a 100644
--- a/qemu/roms/ipxe/src/tests/md5_test.c
+++ b/qemu/roms/ipxe/src/tests/md5_test.c
@@ -15,82 +15,58 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
* MD5 tests
*
+ * Test inputs borrowed from NIST SHA-1 tests, with results calculated
+ * using md5sum.
*/
-#include <stdint.h>
+/* Forcibly enable assertions */
+#undef NDEBUG
+
#include <ipxe/md5.h>
#include <ipxe/test.h>
#include "digest_test.h"
-/** An MD5 test vector */
-struct md5_test_vector {
- /** Test data */
- void *data;
- /** Test data length */
- size_t len;
- /** Expected digest */
- uint8_t digest[MD5_DIGEST_SIZE];
-};
+/* Empty test vector (digest obtained from "md5sum /dev/null") */
+DIGEST_TEST ( md5_empty, &md5_algorithm, DIGEST_EMPTY,
+ DIGEST ( 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04, 0xe9,
+ 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e ) );
-/** MD5 test vectors */
-static struct md5_test_vector md5_test_vectors[] = {
- /* Test inputs borrowed from SHA-1 tests, with results
- * calculated using md5sum.
- */
- { NULL, 0,
- { 0xd4, 0x1d, 0x8c, 0xd9, 0x8f, 0x00, 0xb2, 0x04,
- 0xe9, 0x80, 0x09, 0x98, 0xec, 0xf8, 0x42, 0x7e } },
- { "abc", 3,
- { 0x90, 0x01, 0x50, 0x98, 0x3c, 0xd2, 0x4f, 0xb0,
- 0xd6, 0x96, 0x3f, 0x7d, 0x28, 0xe1, 0x7f, 0x72 } },
- { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56,
- { 0x82, 0x15, 0xef, 0x07, 0x96, 0xa2, 0x0b, 0xca,
- 0xaa, 0xe1, 0x16, 0xd3, 0x87, 0x6c, 0x66, 0x4a } },
-};
+/* NIST test vector "abc" (digest obtained from "md5sum <data>") */
+DIGEST_TEST ( md5_nist_abc, &md5_algorithm, DIGEST_NIST_ABC,
+ DIGEST ( 0x90, 0x01, 0x50, 0x98, 0x3c, 0xd2, 0x4f, 0xb0, 0xd6,
+ 0x96, 0x3f, 0x7d, 0x28, 0xe1, 0x7f, 0x72 ) );
-/** MD5 test fragment lists */
-static struct digest_test_fragments md5_test_fragments[] = {
- { { 0, -1UL, } },
- { { 1, 1, 1, 1, 1, 1, 1, 1 } },
- { { 2, 0, 23, 4, 6, 1, 0 } },
-};
+/* NIST test vector "abc...opq" (digest obtained from "md5sum <data>") */
+DIGEST_TEST ( md5_nist_abc_opq, &md5_algorithm, DIGEST_NIST_ABC_OPQ,
+ DIGEST ( 0x82, 0x15, 0xef, 0x07, 0x96, 0xa2, 0x0b, 0xca, 0xaa,
+ 0xe1, 0x16, 0xd3, 0x87, 0x6c, 0x66, 0x4a ) );
/**
* Perform MD5 self-test
*
*/
static void md5_test_exec ( void ) {
- struct digest_algorithm *digest = &md5_algorithm;
- struct md5_test_vector *test;
- unsigned long cost;
- unsigned int i;
- unsigned int j;
- /* Correctness test */
- for ( i = 0 ; i < ( sizeof ( md5_test_vectors ) /
- sizeof ( md5_test_vectors[0] ) ) ; i++ ) {
- test = &md5_test_vectors[i];
- /* Test with a single pass */
- digest_ok ( digest, NULL, test->data, test->len, test->digest );
- /* Test with fragment lists */
- for ( j = 0 ; j < ( sizeof ( md5_test_fragments ) /
- sizeof ( md5_test_fragments[0] ) ) ; j++ ){
- digest_ok ( digest, &md5_test_fragments[j],
- test->data, test->len, test->digest );
- }
- }
+ /* Correctness tests */
+ digest_ok ( &md5_empty );
+ digest_ok ( &md5_nist_abc );
+ digest_ok ( &md5_nist_abc_opq );
- /* Speed test */
- cost = digest_cost ( digest );
- DBG ( "MD5 required %ld cycles per byte\n", cost );
+ /* Speed tests */
+ DBG ( "MD5 required %ld cycles per byte\n",
+ digest_cost ( &md5_algorithm ) );
}
/** MD5 self-test */
diff --git a/qemu/roms/ipxe/src/tests/memcpy_test.c b/qemu/roms/ipxe/src/tests/memcpy_test.c
index f1e5503a6..0247c71d4 100644
--- a/qemu/roms/ipxe/src/tests/memcpy_test.c
+++ b/qemu/roms/ipxe/src/tests/memcpy_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
diff --git a/qemu/roms/ipxe/src/tests/memset_test.c b/qemu/roms/ipxe/src/tests/memset_test.c
new file mode 100644
index 000000000..d96f83fa6
--- /dev/null
+++ b/qemu/roms/ipxe/src/tests/memset_test.c
@@ -0,0 +1,157 @@
+/*
+ * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of 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.
+ *
+ * This program 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 a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+/** @file
+ *
+ * memset() self-tests
+ *
+ */
+
+/* Forcibly enable assertions */
+#undef NDEBUG
+
+#include <string.h>
+#include <ipxe/test.h>
+
+/* Provide global functions to allow inspection of generated code */
+
+void memset_zero_0 ( void *dest ) { memset ( dest, 0, 0 ); }
+void memset_zero_1 ( void *dest ) { memset ( dest, 0, 1 ); }
+void memset_zero_2 ( void *dest ) { memset ( dest, 0, 2 ); }
+void memset_zero_3 ( void *dest ) { memset ( dest, 0, 3 ); }
+void memset_zero_4 ( void *dest ) { memset ( dest, 0, 4 ); }
+void memset_zero_5 ( void *dest ) { memset ( dest, 0, 5 ); }
+void memset_zero_6 ( void *dest ) { memset ( dest, 0, 6 ); }
+void memset_zero_7 ( void *dest ) { memset ( dest, 0, 7 ); }
+void memset_zero_8 ( void *dest ) { memset ( dest, 0, 8 ); }
+void memset_zero_9 ( void *dest ) { memset ( dest, 0, 9 ); }
+void memset_zero_10 ( void *dest ) { memset ( dest, 0, 10 ); }
+void memset_zero_11 ( void *dest ) { memset ( dest, 0, 11 ); }
+void memset_zero_12 ( void *dest ) { memset ( dest, 0, 12 ); }
+void memset_zero_13 ( void *dest ) { memset ( dest, 0, 13 ); }
+void memset_zero_14 ( void *dest ) { memset ( dest, 0, 14 ); }
+void memset_zero_15 ( void *dest ) { memset ( dest, 0, 15 ); }
+void memset_zero_16 ( void *dest ) { memset ( dest, 0, 16 ); }
+void memset_zero_17 ( void *dest ) { memset ( dest, 0, 17 ); }
+void memset_zero_18 ( void *dest ) { memset ( dest, 0, 18 ); }
+void memset_zero_19 ( void *dest ) { memset ( dest, 0, 19 ); }
+void memset_zero_20 ( void *dest ) { memset ( dest, 0, 20 ); }
+void memset_zero_21 ( void *dest ) { memset ( dest, 0, 21 ); }
+void memset_zero_22 ( void *dest ) { memset ( dest, 0, 22 ); }
+void memset_zero_23 ( void *dest ) { memset ( dest, 0, 23 ); }
+void memset_zero_24 ( void *dest ) { memset ( dest, 0, 24 ); }
+void memset_zero_25 ( void *dest ) { memset ( dest, 0, 25 ); }
+void memset_zero_26 ( void *dest ) { memset ( dest, 0, 26 ); }
+void memset_zero_27 ( void *dest ) { memset ( dest, 0, 27 ); }
+void memset_zero_28 ( void *dest ) { memset ( dest, 0, 28 ); }
+void memset_zero_29 ( void *dest ) { memset ( dest, 0, 29 ); }
+void memset_zero_30 ( void *dest ) { memset ( dest, 0, 30 ); }
+void memset_zero_31 ( void *dest ) { memset ( dest, 0, 31 ); }
+
+/**
+ * Force a call to the variable-length implementation of memset()
+ *
+ * @v dest Destination address
+ * @v fill Fill pattern
+ * @v len Length of data
+ * @ret dest Destination address
+ */
+__attribute__ (( noinline )) void * memset_var ( void *dest, unsigned int fill,
+ size_t len ) {
+ return memset ( dest, fill, len );
+}
+
+/**
+ * Perform a constant-length memset() test
+ *
+ * @v len Length of data
+ */
+#define MEMSET_TEST_CONSTANT( len ) do { \
+ uint8_t dest_const[ 1 + len + 1 ]; \
+ uint8_t dest_var[ 1 + len + 1 ]; \
+ static uint8_t zero[len]; \
+ unsigned int i; \
+ \
+ for ( i = 0 ; i < sizeof ( dest_const ) ; i++ ) \
+ dest_const[i] = 0xaa; \
+ memset ( ( dest_const + 1 ), 0, len ); \
+ ok ( dest_const[0] == 0xaa ); \
+ ok ( dest_const[ sizeof ( dest_const ) - 1 ] == 0xaa ); \
+ ok ( memcmp ( ( dest_const + 1 ), zero, len ) == 0 ); \
+ \
+ for ( i = 0 ; i < sizeof ( dest_var ) ; i++ ) \
+ dest_var[i] = 0xbb; \
+ memset_var ( ( dest_var + 1 ), 0, len ); \
+ ok ( dest_var[0] == 0xbb ); \
+ ok ( dest_var[ sizeof ( dest_var ) - 1 ] == 0xbb ); \
+ ok ( memcmp ( ( dest_var + 1 ), zero, len ) == 0 ); \
+ } while ( 0 )
+
+/**
+ * Perform memset() self-tests
+ *
+ */
+static void memset_test_exec ( void ) {
+
+ /* Constant-length tests */
+ MEMSET_TEST_CONSTANT ( 0 );
+ MEMSET_TEST_CONSTANT ( 1 );
+ MEMSET_TEST_CONSTANT ( 2 );
+ MEMSET_TEST_CONSTANT ( 3 );
+ MEMSET_TEST_CONSTANT ( 4 );
+ MEMSET_TEST_CONSTANT ( 5 );
+ MEMSET_TEST_CONSTANT ( 6 );
+ MEMSET_TEST_CONSTANT ( 7 );
+ MEMSET_TEST_CONSTANT ( 8 );
+ MEMSET_TEST_CONSTANT ( 9 );
+ MEMSET_TEST_CONSTANT ( 10 );
+ MEMSET_TEST_CONSTANT ( 11 );
+ MEMSET_TEST_CONSTANT ( 12 );
+ MEMSET_TEST_CONSTANT ( 13 );
+ MEMSET_TEST_CONSTANT ( 14 );
+ MEMSET_TEST_CONSTANT ( 15 );
+ MEMSET_TEST_CONSTANT ( 16 );
+ MEMSET_TEST_CONSTANT ( 17 );
+ MEMSET_TEST_CONSTANT ( 18 );
+ MEMSET_TEST_CONSTANT ( 19 );
+ MEMSET_TEST_CONSTANT ( 20 );
+ MEMSET_TEST_CONSTANT ( 21 );
+ MEMSET_TEST_CONSTANT ( 22 );
+ MEMSET_TEST_CONSTANT ( 23 );
+ MEMSET_TEST_CONSTANT ( 24 );
+ MEMSET_TEST_CONSTANT ( 25 );
+ MEMSET_TEST_CONSTANT ( 26 );
+ MEMSET_TEST_CONSTANT ( 27 );
+ MEMSET_TEST_CONSTANT ( 28 );
+ MEMSET_TEST_CONSTANT ( 29 );
+ MEMSET_TEST_CONSTANT ( 30 );
+ MEMSET_TEST_CONSTANT ( 31 );
+}
+
+/** memset() self-test */
+struct self_test memset_test __self_test = {
+ .name = "memset",
+ .exec = memset_test_exec,
+};
diff --git a/qemu/roms/ipxe/src/tests/ocsp_test.c b/qemu/roms/ipxe/src/tests/ocsp_test.c
index a318c185a..c6d458596 100644
--- a/qemu/roms/ipxe/src/tests/ocsp_test.c
+++ b/qemu/roms/ipxe/src/tests/ocsp_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
@@ -1857,5 +1861,6 @@ struct self_test ocsp_test __self_test = {
};
/* Drag in algorithms required for tests */
+REQUIRING_SYMBOL ( ocsp_test );
REQUIRE_OBJECT ( rsa );
REQUIRE_OBJECT ( sha1 );
diff --git a/qemu/roms/ipxe/src/tests/pccrc_test.c b/qemu/roms/ipxe/src/tests/pccrc_test.c
new file mode 100644
index 000000000..f4ab573ac
--- /dev/null
+++ b/qemu/roms/ipxe/src/tests/pccrc_test.c
@@ -0,0 +1,529 @@
+/*
+ * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of 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.
+ *
+ * This program 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 a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+/** @file
+ *
+ * Peer Content Caching and Retrieval: Content Identification [MS-PCCRC] tests
+ *
+ */
+
+/* Forcibly enable assertions */
+#undef NDEBUG
+
+#include <stdint.h>
+#include <string.h>
+#include <assert.h>
+#include <ipxe/uaccess.h>
+#include <ipxe/pccrc.h>
+#include <ipxe/sha256.h>
+#include <ipxe/sha512.h>
+#include <ipxe/hmac.h>
+#include <ipxe/test.h>
+
+/** Define inline raw data */
+#define DATA(...) { __VA_ARGS__ }
+
+/**
+ * Define an inline content range
+ *
+ * @v START Start offset
+ * @v END End offset
+ * @ret range Content range
+ */
+#define RANGE( START, END ) { .start = START, .end = END }
+
+/**
+ * Define an inline trimmed content range
+ *
+ * @v START Start offset
+ * @v END End offset
+ * @ret trim Trimmed content range
+ */
+#define TRIM( START, END ) { .start = START, .end = END }
+
+/** A content information test */
+struct peerdist_info_test {
+ /** Raw content information */
+ const void *data;
+ /** Length of raw content information */
+ size_t len;
+ /** Expected digest algorithm */
+ struct digest_algorithm *expected_digest;
+ /** Expected digest size */
+ size_t expected_digestsize;
+ /** Expected content range */
+ struct peerdist_range expected_range;
+ /** Expected trimmed content range */
+ struct peerdist_range expected_trim;
+ /** Expected number of segments */
+ unsigned int expected_segments;
+};
+
+/**
+ * Define a content information test
+ *
+ * @v name Test name
+ * @v DATA Raw content information
+ * @v DIGEST Expected digest algorithm
+ * @v DIGESTSIZE Expected digest size
+ * @v RANGE Expected content range
+ * @v TRIM Expected trimmer content range
+ * @v SEGMENTS Expected number of segments
+ * @ret test Content information test
+ *
+ * Raw content information can be obtained from PeerDist-capable web
+ * servers using wget's "--header" option to inject the relevant
+ * PeerDist headers. For example:
+ *
+ * wget --header "Accept-Encoding: peerdist" \
+ * --header "X-P2P-PeerDist: Version=1.0" \
+ * http://peerdist.server.address/test.url -O - | xxd -i -c 11
+ *
+ * Version 1 content information can be retrieved using the headers:
+ *
+ * Accept-Encoding: peerdist
+ * X-P2P-PeerDist: Version=1.0
+ *
+ * Version 2 content information can be retrieved (from compatible
+ * servers) using the headers:
+ *
+ * Accept-Encoding: peerdist
+ * X-P2P-PeerDist: Version=1.1
+ * X-P2P-PeerDistEx: MinContentInformation=2.0, MaxContentInformation=2.0
+ */
+#define PEERDIST_INFO_TEST( name, DATA, DIGEST, DIGESTSIZE, RANGE, \
+ TRIM, SEGMENTS ) \
+ static const uint8_t name ## _data[] = DATA; \
+ static struct peerdist_info_test name = { \
+ .data = name ## _data, \
+ .len = sizeof ( name ## _data ), \
+ .expected_digest = DIGEST, \
+ .expected_digestsize = DIGESTSIZE, \
+ .expected_range = RANGE, \
+ .expected_trim = TRIM, \
+ .expected_segments = SEGMENTS, \
+ }
+
+/** A content information segment test */
+struct peerdist_info_segment_test {
+ /** Segment index */
+ unsigned int index;
+ /** Expected content range */
+ struct peerdist_range expected_range;
+ /** Expected number of blocks */
+ unsigned int expected_blocks;
+ /** Expected block size */
+ size_t expected_blksize;
+ /** Expected segment hash of data */
+ uint8_t expected_hash[PEERDIST_DIGEST_MAX_SIZE];
+ /** Expected segment secret */
+ uint8_t expected_secret[PEERDIST_DIGEST_MAX_SIZE];
+ /** Expected segment identifier */
+ uint8_t expected_id[PEERDIST_DIGEST_MAX_SIZE];
+};
+
+/**
+ * Define a content information segment test
+ *
+ * @v name Test name
+ * @v INDEX Segment index
+ * @v RANGE Expected content range
+ * @v BLOCKS Expected number of blocks
+ * @v BLKSIZE Expected block size
+ * @v HASH Expected segment hash of data
+ * @v SECRET Expected segment secret
+ * @v ID Expected segment identifier
+ * @ret test Content information segment test
+ */
+#define PEERDIST_INFO_SEGMENT_TEST( name, INDEX, RANGE, BLOCKS, \
+ BLKSIZE, HASH, SECRET, ID ) \
+ static struct peerdist_info_segment_test name = { \
+ .index = INDEX, \
+ .expected_range = RANGE, \
+ .expected_blocks = BLOCKS, \
+ .expected_blksize = BLKSIZE, \
+ .expected_hash = HASH, \
+ .expected_secret = SECRET, \
+ .expected_id = ID, \
+ }
+
+/** A content information block test */
+struct peerdist_info_block_test {
+ /** Block index */
+ unsigned int index;
+ /** Expected content range */
+ struct peerdist_range expected_range;
+ /** Expected trimmed content range */
+ struct peerdist_range expected_trim;
+ /** Expected hash of data */
+ uint8_t expected_hash[PEERDIST_DIGEST_MAX_SIZE];
+};
+
+/**
+ * Define a content information block test
+ *
+ * @v name Test name
+ * @v INDEX Block index
+ * @v RANGE Expected content range
+ * @v TRIM Expected trimmed content range
+ * @v HASH Expected hash of data
+ * @ret test Content information block test
+ */
+#define PEERDIST_INFO_BLOCK_TEST( name, INDEX, RANGE, TRIM, HASH ) \
+ static struct peerdist_info_block_test name = { \
+ .index = INDEX, \
+ .expected_range = RANGE, \
+ .expected_trim = TRIM, \
+ .expected_hash = HASH, \
+ }
+
+/**
+ * Define a server passphrase
+ *
+ * @v name Server passphrase name
+ * @v DATA Raw server passphrase
+ *
+ * The server passphrase can be exported from a Windows BranchCache
+ * server using the command:
+ *
+ * netsh branchcache exportkey exported.key somepassword
+ *
+ * and this encrypted exported key can be decrypted using the
+ * oSSL_key_dx or mcrypt_key_dx utilities found in the (prototype)
+ * Prequel project at https://fedorahosted.org/prequel/ :
+ *
+ * oSSL_key_dx exported.key somepassword
+ * or
+ * mcrypt_key_dx exported.key somepassword
+ *
+ * Either command will display both the server passphrase and the
+ * "Server Secret". Note that this latter is the version 1 server
+ * secret (i.e. the SHA-256 of the server passphrase); the
+ * corresponding version 2 server secret can be obtained by
+ * calculating the truncated SHA-512 of the server passphrase.
+ *
+ * We do not know the server passphrase during normal operation. We
+ * use it in the self-tests only to check for typos and other errors
+ * in the test vectors, by checking that the segment secret defined in
+ * a content information segment test is as expected.
+ */
+#define SERVER_PASSPHRASE( name, DATA ) \
+ static uint8_t name[] = DATA
+
+/** Server passphrase used for these test vectors */
+SERVER_PASSPHRASE ( passphrase,
+ DATA ( 0x2a, 0x3d, 0x73, 0xeb, 0x43, 0x5e, 0x9f, 0x2b, 0x8a, 0x34, 0x42,
+ 0x67, 0xe7, 0x46, 0x7a, 0x3c, 0x73, 0x85, 0xc6, 0xe0, 0x55, 0xe2,
+ 0xb4, 0xd3, 0x0d, 0xfe, 0xc7, 0xc3, 0x8b, 0x0e, 0xd7, 0x2c ) );
+
+/** IIS logo (iis-85.png) content information version 1 */
+PEERDIST_INFO_TEST ( iis_85_png_v1,
+ DATA ( 0x00, 0x01, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x7e, 0x85, 0x01, 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0xd8, 0xd9, 0x76, 0x35, 0x4a, 0x48, 0x72, 0xe9, 0x25, 0x76,
+ 0x18, 0x03, 0xf4, 0x58, 0xd9, 0xda, 0xaa, 0x67, 0xf8, 0xe3, 0x1c,
+ 0x63, 0x0f, 0xb7, 0x4e, 0x6a, 0x31, 0x2e, 0xf8, 0xa2, 0x5a, 0xba,
+ 0x11, 0xaf, 0xc0, 0xd7, 0x94, 0x92, 0x43, 0xf9, 0x4f, 0x9c, 0x1f,
+ 0xab, 0x35, 0xd9, 0xfd, 0x1e, 0x33, 0x1f, 0xcf, 0x78, 0x11, 0xa2,
+ 0xe0, 0x1d, 0x35, 0x87, 0xb3, 0x8d, 0x77, 0x0a, 0x29, 0xe2, 0x02,
+ 0x00, 0x00, 0x00, 0x73, 0xc1, 0x8a, 0xb8, 0x54, 0x91, 0x10, 0xf8,
+ 0xe9, 0x0e, 0x71, 0xbb, 0xc3, 0xab, 0x2a, 0xa8, 0xc4, 0x4d, 0x13,
+ 0xf4, 0x92, 0x94, 0x99, 0x25, 0x5b, 0x66, 0x0f, 0x24, 0xec, 0x77,
+ 0x80, 0x0b, 0x97, 0x4b, 0xdd, 0x65, 0x56, 0x7f, 0xde, 0xec, 0xcd,
+ 0xaf, 0xe4, 0x57, 0xa9, 0x50, 0x3b, 0x45, 0x48, 0xf6, 0x6e, 0xd3,
+ 0xb1, 0x88, 0xdc, 0xfd, 0xa0, 0xac, 0x38, 0x2b, 0x09, 0x71, 0x1a,
+ 0xcc ),
+ &sha256_algorithm, 32, RANGE ( 0, 99710 ), TRIM ( 0, 99710 ), 1 );
+
+/** IIS logo (iis-85.png) content information version 1 segment 0 */
+PEERDIST_INFO_SEGMENT_TEST ( iis_85_png_v1_s0, 0,
+ RANGE ( 0, 99710 ), 2, 65536,
+ DATA ( 0xd8, 0xd9, 0x76, 0x35, 0x4a, 0x48, 0x72, 0xe9, 0x25, 0x76, 0x18,
+ 0x03, 0xf4, 0x58, 0xd9, 0xda, 0xaa, 0x67, 0xf8, 0xe3, 0x1c, 0x63,
+ 0x0f, 0xb7, 0x4e, 0x6a, 0x31, 0x2e, 0xf8, 0xa2, 0x5a, 0xba ),
+ DATA ( 0x11, 0xaf, 0xc0, 0xd7, 0x94, 0x92, 0x43, 0xf9, 0x4f, 0x9c, 0x1f,
+ 0xab, 0x35, 0xd9, 0xfd, 0x1e, 0x33, 0x1f, 0xcf, 0x78, 0x11, 0xa2,
+ 0xe0, 0x1d, 0x35, 0x87, 0xb3, 0x8d, 0x77, 0x0a, 0x29, 0xe2 ),
+ DATA ( 0x49, 0x1b, 0x21, 0x7d, 0xbe, 0xe2, 0xb5, 0xf1, 0x2c, 0xa7, 0x9b,
+ 0x01, 0x5e, 0x06, 0xf4, 0xbb, 0xe6, 0x4f, 0x97, 0x45, 0xba, 0xd7,
+ 0x86, 0x7a, 0xef, 0x17, 0xde, 0x59, 0x92, 0x7e, 0xdc, 0xe9 ) );
+
+/** IIS logo (iis-85.png) content information version 1 segment 0 block 0 */
+PEERDIST_INFO_BLOCK_TEST ( iis_85_png_v1_s0_b0, 0,
+ RANGE ( 0, 65536 ),
+ TRIM ( 0, 65536 ),
+ DATA ( 0x73, 0xc1, 0x8a, 0xb8, 0x54, 0x91, 0x10, 0xf8, 0xe9, 0x0e, 0x71,
+ 0xbb, 0xc3, 0xab, 0x2a, 0xa8, 0xc4, 0x4d, 0x13, 0xf4, 0x92, 0x94,
+ 0x99, 0x25, 0x5b, 0x66, 0x0f, 0x24, 0xec, 0x77, 0x80, 0x0b ) );
+
+/** IIS logo (iis-85.png) content information version 1 segment 0 block 1 */
+PEERDIST_INFO_BLOCK_TEST ( iis_85_png_v1_s0_b1, 1,
+ RANGE ( 65536, 99710 ),
+ TRIM ( 65536, 99710 ),
+ DATA ( 0x97, 0x4b, 0xdd, 0x65, 0x56, 0x7f, 0xde, 0xec, 0xcd, 0xaf, 0xe4,
+ 0x57, 0xa9, 0x50, 0x3b, 0x45, 0x48, 0xf6, 0x6e, 0xd3, 0xb1, 0x88,
+ 0xdc, 0xfd, 0xa0, 0xac, 0x38, 0x2b, 0x09, 0x71, 0x1a, 0xcc ) );
+
+/** IIS logo (iis-85.png) content information version 2 */
+PEERDIST_INFO_TEST ( iis_85_png_v2,
+ DATA ( 0x00, 0x02, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x88, 0x00, 0x00, 0x99, 0xde, 0xe0, 0xd0, 0xc3, 0x58,
+ 0xe2, 0x68, 0x4b, 0x62, 0x33, 0x0d, 0x32, 0xb5, 0xf1, 0x97, 0x87,
+ 0x24, 0xa0, 0xd0, 0xa5, 0x2b, 0xdc, 0x5e, 0x78, 0x1f, 0xae, 0x71,
+ 0xff, 0x57, 0xa8, 0xbe, 0x3d, 0xd4, 0x58, 0x03, 0x7e, 0xd4, 0x04,
+ 0x11, 0x6b, 0xb6, 0x16, 0xd9, 0xb1, 0x41, 0x16, 0x08, 0x85, 0x20,
+ 0xc4, 0x7c, 0xdc, 0x50, 0xab, 0xce, 0xa3, 0xfa, 0xe1, 0x88, 0xa9,
+ 0x8e, 0xa2, 0x2d, 0xf3, 0xc0, 0x00, 0x00, 0xeb, 0xa0, 0x33, 0x81,
+ 0xd0, 0xd0, 0xcb, 0x74, 0xf4, 0xb6, 0x13, 0xd8, 0x21, 0x0f, 0x37,
+ 0xf0, 0x02, 0xa0, 0x6f, 0x39, 0x10, 0x58, 0x60, 0x96, 0xa1, 0x30,
+ 0xd3, 0x43, 0x98, 0xc0, 0x8e, 0x66, 0xd7, 0xbc, 0xb8, 0xb6, 0xeb,
+ 0x77, 0x83, 0xe4, 0xf8, 0x07, 0x64, 0x7b, 0x63, 0xf1, 0x46, 0xb5,
+ 0x2f, 0x4a, 0xc8, 0x9c, 0xcc, 0x7a, 0xbf, 0x5f, 0xa1, 0x1a, 0xca,
+ 0xfc, 0x2a, 0xcf, 0x50, 0x28, 0x58, 0x6c ),
+ &sha512_algorithm, 32, RANGE ( 0, 99710 ), TRIM ( 0, 99710 ), 2 );
+
+/** IIS logo (iis-85.png) content information version 2 segment 0 */
+PEERDIST_INFO_SEGMENT_TEST ( iis_85_png_v2_s0, 0,
+ RANGE ( 0, 39390 ), 1, 39390,
+ DATA ( 0xe0, 0xd0, 0xc3, 0x58, 0xe2, 0x68, 0x4b, 0x62, 0x33, 0x0d, 0x32,
+ 0xb5, 0xf1, 0x97, 0x87, 0x24, 0xa0, 0xd0, 0xa5, 0x2b, 0xdc, 0x5e,
+ 0x78, 0x1f, 0xae, 0x71, 0xff, 0x57, 0xa8, 0xbe, 0x3d, 0xd4 ),
+ DATA ( 0x58, 0x03, 0x7e, 0xd4, 0x04, 0x11, 0x6b, 0xb6, 0x16, 0xd9, 0xb1,
+ 0x41, 0x16, 0x08, 0x85, 0x20, 0xc4, 0x7c, 0xdc, 0x50, 0xab, 0xce,
+ 0xa3, 0xfa, 0xe1, 0x88, 0xa9, 0x8e, 0xa2, 0x2d, 0xf3, 0xc0 ),
+ DATA ( 0x33, 0x71, 0xbb, 0xea, 0xdd, 0xb6, 0x23, 0x53, 0xad, 0xce, 0xf9,
+ 0x70, 0xa0, 0x6f, 0xdf, 0x65, 0x00, 0x1e, 0x04, 0x21, 0xf4, 0xc7,
+ 0x10, 0x82, 0x76, 0xb0, 0xc3, 0x7a, 0x9f, 0x9e, 0xc1, 0x0f ) );
+
+/** IIS logo (iis-85.png) content information version 2 segment 0 block 0 */
+PEERDIST_INFO_BLOCK_TEST ( iis_85_png_v2_s0_b0, 0,
+ RANGE ( 0, 39390 ),
+ TRIM ( 0, 39390 ),
+ DATA ( 0xe0, 0xd0, 0xc3, 0x58, 0xe2, 0x68, 0x4b, 0x62, 0x33, 0x0d, 0x32,
+ 0xb5, 0xf1, 0x97, 0x87, 0x24, 0xa0, 0xd0, 0xa5, 0x2b, 0xdc, 0x5e,
+ 0x78, 0x1f, 0xae, 0x71, 0xff, 0x57, 0xa8, 0xbe, 0x3d, 0xd4 ) );
+
+/** IIS logo (iis-85.png) content information version 2 segment 1 */
+PEERDIST_INFO_SEGMENT_TEST ( iis_85_png_v2_s1, 1,
+ RANGE ( 39390, 99710 ), 1, 60320,
+ DATA ( 0x33, 0x81, 0xd0, 0xd0, 0xcb, 0x74, 0xf4, 0xb6, 0x13, 0xd8, 0x21,
+ 0x0f, 0x37, 0xf0, 0x02, 0xa0, 0x6f, 0x39, 0x10, 0x58, 0x60, 0x96,
+ 0xa1, 0x30, 0xd3, 0x43, 0x98, 0xc0, 0x8e, 0x66, 0xd7, 0xbc ),
+ DATA ( 0xb8, 0xb6, 0xeb, 0x77, 0x83, 0xe4, 0xf8, 0x07, 0x64, 0x7b, 0x63,
+ 0xf1, 0x46, 0xb5, 0x2f, 0x4a, 0xc8, 0x9c, 0xcc, 0x7a, 0xbf, 0x5f,
+ 0xa1, 0x1a, 0xca, 0xfc, 0x2a, 0xcf, 0x50, 0x28, 0x58, 0x6c ),
+ DATA ( 0xd7, 0xe9, 0x24, 0x42, 0x5e, 0x8f, 0x4f, 0x88, 0xf0, 0x1d, 0xc6,
+ 0xa9, 0xbb, 0x1b, 0xc3, 0x7b, 0xe1, 0x13, 0xec, 0x79, 0x17, 0xc7,
+ 0x45, 0xd4, 0x96, 0x5c, 0x2b, 0x55, 0xfa, 0x16, 0x3a, 0x6e ) );
+
+/** IIS logo (iis-85.png) content information version 2 segment 1 block 0 */
+PEERDIST_INFO_BLOCK_TEST ( iis_85_png_v2_s1_b0, 0,
+ RANGE ( 39390, 99710 ),
+ TRIM ( 39390, 99710 ),
+ DATA ( 0x33, 0x81, 0xd0, 0xd0, 0xcb, 0x74, 0xf4, 0xb6, 0x13, 0xd8, 0x21,
+ 0x0f, 0x37, 0xf0, 0x02, 0xa0, 0x6f, 0x39, 0x10, 0x58, 0x60, 0x96,
+ 0xa1, 0x30, 0xd3, 0x43, 0x98, 0xc0, 0x8e, 0x66, 0xd7, 0xbc ) );
+
+/**
+ * Report content information test result
+ *
+ * @v test Content information test
+ * @v info Content information to fill in
+ * @v file Test code file
+ * @v line Test code line
+ */
+static void peerdist_info_okx ( struct peerdist_info_test *test,
+ struct peerdist_info *info,
+ const char *file, unsigned int line ) {
+
+ /* Parse content information */
+ okx ( peerdist_info ( virt_to_user ( test->data ), test->len,
+ info ) == 0, file, line );
+
+ /* Verify content information */
+ okx ( info->raw.data == virt_to_user ( test->data ), file, line );
+ okx ( info->raw.len == test->len, file, line );
+ okx ( info->digest == test->expected_digest, file, line );
+ okx ( info->digestsize == test->expected_digestsize, file, line );
+ okx ( info->range.start == test->expected_range.start, file, line );
+ okx ( info->range.end == test->expected_range.end, file, line );
+ okx ( info->trim.start == test->expected_trim.start, file, line );
+ okx ( info->trim.end == test->expected_trim.end, file, line );
+ okx ( info->trim.start >= info->range.start, file, line );
+ okx ( info->trim.end <= info->range.end, file, line );
+ okx ( info->segments == test->expected_segments, file, line );
+}
+#define peerdist_info_ok( test, info ) \
+ peerdist_info_okx ( test, info, __FILE__, __LINE__ )
+
+/**
+ * Report content information segment test result
+ *
+ * @v test Content information segment test
+ * @v info Content information
+ * @v segment Segment information to fill in
+ * @v file Test code file
+ * @v line Test code line
+ */
+static void peerdist_info_segment_okx ( struct peerdist_info_segment_test *test,
+ const struct peerdist_info *info,
+ struct peerdist_info_segment *segment,
+ const char *file, unsigned int line ) {
+ size_t digestsize = info->digestsize;
+
+ /* Parse content information segment */
+ okx ( peerdist_info_segment ( info, segment, test->index ) == 0,
+ file, line );
+
+ /* Verify content information segment */
+ okx ( segment->info == info, file, line );
+ okx ( segment->index == test->index, file, line );
+ okx ( segment->range.start == test->expected_range.start, file, line );
+ okx ( segment->range.end == test->expected_range.end, file, line );
+ okx ( segment->blocks == test->expected_blocks, file, line );
+ okx ( segment->blksize == test->expected_blksize, file, line );
+ okx ( memcmp ( segment->hash, test->expected_hash,
+ digestsize ) == 0, file, line );
+ okx ( memcmp ( segment->secret, test->expected_secret,
+ digestsize ) == 0, file, line );
+ okx ( memcmp ( segment->id, test->expected_id,
+ digestsize ) == 0, file, line );
+}
+#define peerdist_info_segment_ok( test, info, segment ) \
+ peerdist_info_segment_okx ( test, info, segment, __FILE__, __LINE__ )
+
+/**
+ * Report content information block test result
+ *
+ * @v test Content information block test
+ * @v segment Segment information
+ * @v block Block information to fill in
+ * @v file Test code file
+ * @v line Test code line
+ */
+static void
+peerdist_info_block_okx ( struct peerdist_info_block_test *test,
+ const struct peerdist_info_segment *segment,
+ struct peerdist_info_block *block,
+ const char *file, unsigned int line ) {
+ const struct peerdist_info *info = segment->info;
+ size_t digestsize = info->digestsize;
+
+ /* Parse content information block */
+ okx ( peerdist_info_block ( segment, block, test->index ) == 0,
+ file, line );
+
+ /* Verify content information block */
+ okx ( block->segment == segment, file, line );
+ okx ( block->index == test->index, file, line );
+ okx ( block->range.start == test->expected_range.start, file, line );
+ okx ( block->range.end == test->expected_range.end, file, line );
+ okx ( block->trim.start == test->expected_trim.start, file, line );
+ okx ( block->trim.end == test->expected_trim.end, file, line );
+ okx ( memcmp ( block->hash, test->expected_hash,
+ digestsize ) == 0, file, line );
+}
+#define peerdist_info_block_ok( test, segment, block ) \
+ peerdist_info_block_okx ( test, segment, block, __FILE__, __LINE__ )
+
+/**
+ * Report server passphrase test result
+ *
+ * @v test Content information segment test
+ * @v info Content information
+ * @v pass Server passphrase
+ * @v pass_len Length of server passphrase
+ * @v file Test code file
+ * @v line Test code line
+ */
+static void
+peerdist_info_passphrase_okx ( struct peerdist_info_segment_test *test,
+ const struct peerdist_info *info,
+ uint8_t *pass, size_t pass_len,
+ const char *file, unsigned int line ) {
+ struct digest_algorithm *digest = info->digest;
+ uint8_t ctx[digest->ctxsize];
+ uint8_t secret[digest->digestsize];
+ uint8_t expected[digest->digestsize];
+ size_t digestsize = info->digestsize;
+ size_t secretsize = digestsize;
+
+ /* Calculate server secret */
+ digest_init ( digest, ctx );
+ digest_update ( digest, ctx, pass, pass_len );
+ digest_final ( digest, ctx, secret );
+
+ /* Calculate expected segment secret */
+ hmac_init ( digest, ctx, secret, &secretsize );
+ assert ( secretsize == digestsize );
+ hmac_update ( digest, ctx, test->expected_hash, digestsize );
+ hmac_final ( digest, ctx, secret, &secretsize, expected );
+ assert ( secretsize == digestsize );
+
+ /* Verify segment secret */
+ okx ( memcmp ( test->expected_secret, expected, digestsize ) == 0,
+ file, line );
+}
+#define peerdist_info_passphrase_ok( test, info, pass, pass_len ) \
+ peerdist_info_passphrase_okx ( test, info, pass, pass_len, \
+ __FILE__, __LINE__ )
+
+/**
+ * Perform content information self-tests
+ *
+ */
+static void peerdist_info_test_exec ( void ) {
+ struct peerdist_info info;
+ struct peerdist_info_segment segment;
+ struct peerdist_info_block block;
+
+ /* IIS logo (iis-85.png) content information version 1 */
+ peerdist_info_ok ( &iis_85_png_v1, &info );
+ peerdist_info_passphrase_ok ( &iis_85_png_v1_s0, &info,
+ passphrase, sizeof ( passphrase ) );
+ peerdist_info_segment_ok ( &iis_85_png_v1_s0, &info, &segment );
+ peerdist_info_block_ok ( &iis_85_png_v1_s0_b0, &segment, &block );
+ peerdist_info_block_ok ( &iis_85_png_v1_s0_b1, &segment, &block );
+
+ /* IIS logo (iis-85.png) content information version 2 */
+ peerdist_info_ok ( &iis_85_png_v2, &info );
+ peerdist_info_passphrase_ok ( &iis_85_png_v2_s0, &info,
+ passphrase, sizeof ( passphrase ) );
+ peerdist_info_segment_ok ( &iis_85_png_v2_s0, &info, &segment );
+ peerdist_info_block_ok ( &iis_85_png_v2_s0_b0, &segment, &block );
+ peerdist_info_passphrase_ok ( &iis_85_png_v2_s1, &info,
+ passphrase, sizeof ( passphrase ) );
+ peerdist_info_segment_ok ( &iis_85_png_v2_s1, &info, &segment );
+ peerdist_info_block_ok ( &iis_85_png_v2_s1_b0, &segment, &block );
+}
+
+/** Content information self-test */
+struct self_test peerdist_info_test __self_test = {
+ .name = "pccrc",
+ .exec = peerdist_info_test_exec,
+};
diff --git a/qemu/roms/ipxe/src/tests/pixbuf_test.c b/qemu/roms/ipxe/src/tests/pixbuf_test.c
index 15cd33dfd..aaa516bb2 100644
--- a/qemu/roms/ipxe/src/tests/pixbuf_test.c
+++ b/qemu/roms/ipxe/src/tests/pixbuf_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
@@ -53,8 +57,8 @@ void pixbuf_okx ( struct pixel_buffer_test *test, const char *file,
/* Correct image data pointer */
test->image->data = virt_to_user ( ( void * ) test->image->data );
- /* Check that image is detected as PNM */
- okx ( image_probe ( test->image ) == 0, file, line );
+ /* Check that image is detected as correct type */
+ okx ( register_image ( test->image ) == 0, file, line );
okx ( test->image->type == test->type, file, line );
/* Check that a pixel buffer can be created from the image */
@@ -73,4 +77,7 @@ void pixbuf_okx ( struct pixel_buffer_test *test, const char *file,
pixbuf_put ( pixbuf );
}
+
+ /* Unregister image */
+ unregister_image ( test->image );
}
diff --git a/qemu/roms/ipxe/src/tests/pixbuf_test.h b/qemu/roms/ipxe/src/tests/pixbuf_test.h
index 394f7f5fa..d12829d89 100644
--- a/qemu/roms/ipxe/src/tests/pixbuf_test.h
+++ b/qemu/roms/ipxe/src/tests/pixbuf_test.h
@@ -1,7 +1,7 @@
#ifndef _PIXBUF_TEST_H
#define _PIXBUF_TEST_H
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdint.h>
#include <ipxe/refcnt.h>
diff --git a/qemu/roms/ipxe/src/tests/png_test.c b/qemu/roms/ipxe/src/tests/png_test.c
index cf32f2034..e921aa2a6 100644
--- a/qemu/roms/ipxe/src/tests/png_test.c
+++ b/qemu/roms/ipxe/src/tests/png_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
diff --git a/qemu/roms/ipxe/src/tests/pnm_test.c b/qemu/roms/ipxe/src/tests/pnm_test.c
index 26b0c0726..d57fdaaef 100644
--- a/qemu/roms/ipxe/src/tests/pnm_test.c
+++ b/qemu/roms/ipxe/src/tests/pnm_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
diff --git a/qemu/roms/ipxe/src/tests/profile_test.c b/qemu/roms/ipxe/src/tests/profile_test.c
index 9d682bf2b..d2f8df211 100644
--- a/qemu/roms/ipxe/src/tests/profile_test.c
+++ b/qemu/roms/ipxe/src/tests/profile_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
diff --git a/qemu/roms/ipxe/src/tests/pubkey_test.h b/qemu/roms/ipxe/src/tests/pubkey_test.h
index 7678453a9..cd65b8703 100644
--- a/qemu/roms/ipxe/src/tests/pubkey_test.h
+++ b/qemu/roms/ipxe/src/tests/pubkey_test.h
@@ -1,7 +1,7 @@
#ifndef _PUBKEY_TEST_H
#define _PUBKEY_TEST_H
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdint.h>
#include <ipxe/crypto.h>
diff --git a/qemu/roms/ipxe/src/tests/rsa_test.c b/qemu/roms/ipxe/src/tests/rsa_test.c
index 3b32c74bc..c0d05d263 100644
--- a/qemu/roms/ipxe/src/tests/rsa_test.c
+++ b/qemu/roms/ipxe/src/tests/rsa_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
diff --git a/qemu/roms/ipxe/src/tests/setjmp_test.c b/qemu/roms/ipxe/src/tests/setjmp_test.c
new file mode 100644
index 000000000..50ad13f3c
--- /dev/null
+++ b/qemu/roms/ipxe/src/tests/setjmp_test.c
@@ -0,0 +1,171 @@
+/*
+ * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of 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.
+ *
+ * This program 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 a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+/** @file
+ *
+ * setjmp()/longjmp() tests
+ *
+ */
+
+/* Forcibly enable assertions */
+#undef NDEBUG
+
+#include <stddef.h>
+#include <assert.h>
+#include <setjmp.h>
+#include <ipxe/test.h>
+
+/** A setjmp()/longjmp() test */
+struct setjmp_test {
+ /** Jump buffer */
+ jmp_buf env;
+ /** Expected value */
+ int expected;
+ /** Test code file */
+ const char *file;
+ /** Test code line */
+ unsigned int line;
+};
+
+/** Expected jump */
+static struct setjmp_test *jumped;
+
+/**
+ * Report a setjmp() test result
+ *
+ * @v test setjmp()/longjmp() test
+ *
+ * This has to be implemented as a macro since if it were a function
+ * then the context saved by setjmp() would be invalidated when the
+ * function returned.
+ */
+#define setjmp_ok( test ) do { \
+ int value; \
+ /* Sanity check */ \
+ assert ( jumped == NULL ); \
+ /* Initialise test */ \
+ (test)->expected = 0; \
+ (test)->file = __FILE__; \
+ (test)->line = __LINE__; \
+ /* Perform setjmp() */ \
+ value = setjmp ( (test)->env ); \
+ /* Report setjmp()/longjmp() result */ \
+ setjmp_return_ok ( (test), value ); \
+ } while ( 0 )
+
+/**
+ * Report a setjmp()/longjmp() test result
+ *
+ * @v test setjmp()/longjmp() test
+ * @v value Value returned from setjmp()
+ *
+ * This function ends up reporting results from either setjmp() or
+ * longjmp() tests (since calls to longjmp() will return via the
+ * corresponding setjmp()). It therefore uses the test code file and
+ * line stored in the test structure, which will represent the line
+ * from which either setjmp() or longjmp() was called.
+ */
+static void setjmp_return_ok ( struct setjmp_test *test, int value ) {
+
+ /* Determine whether this was reached via setjmp() or longjmp() */
+ if ( value == 0 ) {
+ /* This is the initial call to setjmp() */
+ okx ( test->expected == 0, test->file, test->line );
+ okx ( jumped == NULL, test->file, test->line );
+ } else {
+ /* This is reached via a call to longjmp() */
+ okx ( value == test->expected, test->file, test->line );
+ okx ( jumped == test, test->file, test->line );
+ }
+
+ /* Clear expected jump */
+ jumped = NULL;
+}
+
+/**
+ * Report a longjmp() test result
+ *
+ * @v test setjmp()/longjmp() test
+ * @v file Test code file
+ * @v line Test code line
+ */
+static void longjmp_okx ( struct setjmp_test *test, int value,
+ const char *file, unsigned int line ) {
+
+ /* Record expected value. A zero passed to longjmp() should
+ * result in setjmp() returning a value of one.
+ */
+ test->expected = ( value ? value : 1 );
+
+ /* Record test code file and line */
+ test->file = file;
+ test->line = line;
+
+ /* Record expected jump */
+ jumped = test;
+
+ /* Perform longjmp(). Should return via setjmp_okx() */
+ longjmp ( test->env, value );
+
+ /* longjmp() should never return */
+ assert ( 0 );
+}
+#define longjmp_ok( test, value ) \
+ longjmp_okx ( test, value, __FILE__, __LINE__ )
+
+/**
+ * Perform setjmp()/longjmp() self-tests
+ *
+ */
+static void setjmp_test_exec ( void ) {
+ static struct setjmp_test alpha;
+ static struct setjmp_test beta;
+ static int iteration;
+
+ /* This is one of the very few situations in which the
+ * "for-case" pattern is justified.
+ */
+ for ( iteration = 0 ; iteration < 10 ; iteration++ ) {
+ DBGC ( jumped, "SETJMP test iteration %d\n", iteration );
+ switch ( iteration ) {
+ case 0: setjmp_ok ( &alpha ); break;
+ case 1: setjmp_ok ( &beta ); break;
+ case 2: longjmp_ok ( &alpha, 0 );
+ case 3: longjmp_ok ( &alpha, 1 );
+ case 4: longjmp_ok ( &alpha, 2 );
+ case 5: longjmp_ok ( &beta, 17 );
+ case 6: longjmp_ok ( &beta, 29 );
+ case 7: longjmp_ok ( &alpha, -1 );
+ case 8: longjmp_ok ( &beta, 0 );
+ case 9: longjmp_ok ( &beta, 42 );
+ }
+ }
+}
+
+/** setjmp()/longjmp() self-test */
+struct self_test setjmp_test __self_test = {
+ .name = "setjmp",
+ .exec = setjmp_test_exec,
+};
diff --git a/qemu/roms/ipxe/src/tests/settings_test.c b/qemu/roms/ipxe/src/tests/settings_test.c
index 4ee6a10fa..f7fb35d0d 100644
--- a/qemu/roms/ipxe/src/tests/settings_test.c
+++ b/qemu/roms/ipxe/src/tests/settings_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
@@ -228,6 +232,12 @@ static struct setting test_hexraw_setting = {
.type = &setting_type_hexraw,
};
+/** Test Base64 setting type */
+static struct setting test_base64_setting = {
+ .name = "test_base64",
+ .type = &setting_type_base64,
+};
+
/** Test UUID setting type */
static struct setting test_uuid_setting = {
.name = "test_uuid",
@@ -379,6 +389,15 @@ static void settings_test_exec ( void ) {
0x17, 0x06, 0x39, 0x6b, 0xf4, 0x48, 0x4e ),
"9e4b6eef36b646fe8f1706396bf4484e" );
+ /* "base64" setting type */
+ storef_ok ( &test_settings, &test_base64_setting,
+ "cGFzc6\nNwaHJhc2U= ",
+ RAW ( 0x70, 0x61, 0x73, 0x73, 0xa3, 0x70, 0x68, 0x72, 0x61,
+ 0x73, 0x65 ) );
+ fetchf_ok ( &test_settings, &test_base64_setting,
+ RAW ( 0x80, 0x81, 0x82, 0x83, 0x84, 0x00, 0xff ),
+ "gIGCg4QA/w==" );
+
/* "uuid" setting type (no store capability) */
fetchf_ok ( &test_settings, &test_uuid_setting,
RAW ( 0x1a, 0x6a, 0x74, 0x9d, 0x0e, 0xda, 0x46, 0x1a,0xa8,
@@ -399,3 +418,7 @@ struct self_test settings_test __self_test = {
.name = "settings",
.exec = settings_test_exec,
};
+
+/* Include real IPv6 setting type */
+REQUIRING_SYMBOL ( settings_test );
+REQUIRE_OBJECT ( ipv6 );
diff --git a/qemu/roms/ipxe/src/tests/sha1_test.c b/qemu/roms/ipxe/src/tests/sha1_test.c
index bcf761bdd..9f1d75686 100644
--- a/qemu/roms/ipxe/src/tests/sha1_test.c
+++ b/qemu/roms/ipxe/src/tests/sha1_test.c
@@ -15,87 +15,63 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
* SHA-1 tests
*
+ * NIST test vectors are taken from
+ *
+ * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA1.pdf
+ *
*/
-#include <stdint.h>
+/* Forcibly enable assertions */
+#undef NDEBUG
+
#include <ipxe/sha1.h>
#include <ipxe/test.h>
#include "digest_test.h"
-/** An SHA-1 test vector */
-struct sha1_test_vector {
- /** Test data */
- void *data;
- /** Test data length */
- size_t len;
- /** Expected digest */
- uint8_t digest[SHA1_DIGEST_SIZE];
-};
+/* Empty test vector (digest obtained from "sha1sum /dev/null") */
+DIGEST_TEST ( sha1_empty, &sha1_algorithm, DIGEST_EMPTY,
+ DIGEST ( 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 0x32,
+ 0x55, 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8,
+ 0x07, 0x09 ) );
-/** SHA-1 test vectors */
-static struct sha1_test_vector sha1_test_vectors[] = {
- /* Empty test data
- *
- * Expected digest value obtained from "sha1sum /dev/null"
- */
- { NULL, 0,
- { 0xda, 0x39, 0xa3, 0xee, 0x5e, 0x6b, 0x4b, 0x0d, 0x32, 0x55,
- 0xbf, 0xef, 0x95, 0x60, 0x18, 0x90, 0xaf, 0xd8, 0x07, 0x09 } },
- /* Test data and expected digests taken from the NIST
- * Cryptographic Toolkit Algorithm Examples at
- * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA1.pdf
- */
- { "abc", 3,
- { 0xa9, 0x99, 0x3e, 0x36, 0x47, 0x06, 0x81, 0x6a, 0xba, 0x3e,
- 0x25, 0x71, 0x78, 0x50, 0xc2, 0x6c, 0x9c, 0xd0, 0xd8, 0x9d } },
- { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56,
- { 0x84, 0x98, 0x3e, 0x44, 0x1c, 0x3b, 0xd2, 0x6e, 0xba, 0xae,
- 0x4a, 0xa1, 0xf9, 0x51, 0x29, 0xe5, 0xe5, 0x46, 0x70, 0xf1 } },
-};
+/* NIST test vector "abc" */
+DIGEST_TEST ( sha1_nist_abc, &sha1_algorithm, DIGEST_NIST_ABC,
+ DIGEST ( 0xa9, 0x99, 0x3e, 0x36, 0x47, 0x06, 0x81, 0x6a, 0xba,
+ 0x3e, 0x25, 0x71, 0x78, 0x50, 0xc2, 0x6c, 0x9c, 0xd0,
+ 0xd8, 0x9d ) );
-/** SHA-1 test fragment lists */
-static struct digest_test_fragments sha1_test_fragments[] = {
- { { 0, -1UL, } },
- { { 1, 1, 1, 1, 1, 1, 1, 1 } },
- { { 2, 0, 23, 4, 6, 1, 0 } },
-};
+/* NIST test vector "abc...opq" */
+DIGEST_TEST ( sha1_nist_abc_opq, &sha1_algorithm, DIGEST_NIST_ABC_OPQ,
+ DIGEST ( 0x84, 0x98, 0x3e, 0x44, 0x1c, 0x3b, 0xd2, 0x6e, 0xba,
+ 0xae, 0x4a, 0xa1, 0xf9, 0x51, 0x29, 0xe5, 0xe5, 0x46,
+ 0x70, 0xf1 ) );
/**
* Perform SHA-1 self-test
*
*/
static void sha1_test_exec ( void ) {
- struct digest_algorithm *digest = &sha1_algorithm;
- struct sha1_test_vector *test;
- unsigned long cost;
- unsigned int i;
- unsigned int j;
- /* Correctness test */
- for ( i = 0 ; i < ( sizeof ( sha1_test_vectors ) /
- sizeof ( sha1_test_vectors[0] ) ) ; i++ ) {
- test = &sha1_test_vectors[i];
- /* Test with a single pass */
- digest_ok ( digest, NULL, test->data, test->len, test->digest );
- /* Test with fragment lists */
- for ( j = 0 ; j < ( sizeof ( sha1_test_fragments ) /
- sizeof ( sha1_test_fragments[0] ) ) ; j++ ){
- digest_ok ( digest, &sha1_test_fragments[j],
- test->data, test->len, test->digest );
- }
- }
+ /* Correctness tests */
+ digest_ok ( &sha1_empty );
+ digest_ok ( &sha1_nist_abc );
+ digest_ok ( &sha1_nist_abc_opq );
- /* Speed test */
- cost = digest_cost ( digest );
- DBG ( "SHA1 required %ld cycles per byte\n", cost );
+ /* Speed tests */
+ DBG ( "SHA1 required %ld cycles per byte\n",
+ digest_cost ( &sha1_algorithm ) );
}
/** SHA-1 self-test */
diff --git a/qemu/roms/ipxe/src/tests/sha256_test.c b/qemu/roms/ipxe/src/tests/sha256_test.c
index 06a8cae25..3b4c423fd 100644
--- a/qemu/roms/ipxe/src/tests/sha256_test.c
+++ b/qemu/roms/ipxe/src/tests/sha256_test.c
@@ -15,93 +15,96 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
- * SHA-256 tests
+ * SHA-256 family tests
+ *
+ * NIST test vectors are taken from
+ *
+ * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA256.pdf
+ * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA224.pdf
*
*/
-#include <stdint.h>
+/* Forcibly enable assertions */
+#undef NDEBUG
+
#include <ipxe/sha256.h>
#include <ipxe/test.h>
#include "digest_test.h"
-/** An SHA-256 test vector */
-struct sha256_test_vector {
- /** Test data */
- void *data;
- /** Test data length */
- size_t len;
- /** Expected digest */
- uint8_t digest[SHA256_DIGEST_SIZE];
-};
+/* Empty test vector (digest obtained from "sha256sum /dev/null") */
+DIGEST_TEST ( sha256_empty, &sha256_algorithm, DIGEST_EMPTY,
+ DIGEST ( 0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a,
+ 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae,
+ 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99,
+ 0x1b, 0x78, 0x52, 0xb8, 0x55 ) );
-/** SHA-256 test vectors */
-static struct sha256_test_vector sha256_test_vectors[] = {
- /* Empty test data
- *
- * Expected digest value obtained from "sha256sum /dev/null"
- */
- { NULL, 0,
- { 0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4,
- 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b,
- 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55 } },
- /* Test data and expected digests taken from the NIST
- * Cryptographic Toolkit Algorithm Examples at
- * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA256.pdf
- */
- { "abc", 3,
- { 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41, 0x41, 0x40,
- 0xde, 0x5d, 0xae, 0x22, 0x23, 0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17,
- 0x7a, 0x9c, 0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad } },
- { "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", 56,
- { 0x24, 0x8d, 0x6a, 0x61, 0xd2, 0x06, 0x38, 0xb8, 0xe5, 0xc0, 0x26,
- 0x93, 0x0c, 0x3e, 0x60, 0x39, 0xa3, 0x3c, 0xe4, 0x59, 0x64, 0xff,
- 0x21, 0x67, 0xf6, 0xec, 0xed, 0xd4, 0x19, 0xdb, 0x06, 0xc1 } },
-};
+/* NIST test vector "abc" */
+DIGEST_TEST ( sha256_nist_abc, &sha256_algorithm, DIGEST_NIST_ABC,
+ DIGEST ( 0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea, 0x41,
+ 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23, 0xb0, 0x03,
+ 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c, 0xb4, 0x10, 0xff,
+ 0x61, 0xf2, 0x00, 0x15, 0xad ) );
-/** SHA-256 test fragment lists */
-static struct digest_test_fragments sha256_test_fragments[] = {
- { { 0, -1UL, } },
- { { 1, 1, 1, 1, 1, 1, 1, 1 } },
- { { 2, 0, 23, 4, 6, 1, 0 } },
-};
+/* NIST test vector "abc...opq" */
+DIGEST_TEST ( sha256_nist_abc_opq, &sha256_algorithm, DIGEST_NIST_ABC_OPQ,
+ DIGEST ( 0x24, 0x8d, 0x6a, 0x61, 0xd2, 0x06, 0x38, 0xb8, 0xe5,
+ 0xc0, 0x26, 0x93, 0x0c, 0x3e, 0x60, 0x39, 0xa3, 0x3c,
+ 0xe4, 0x59, 0x64, 0xff, 0x21, 0x67, 0xf6, 0xec, 0xed,
+ 0xd4, 0x19, 0xdb, 0x06, 0xc1 ) );
+
+/* Empty test vector (digest obtained from "sha224sum /dev/null") */
+DIGEST_TEST ( sha224_empty, &sha224_algorithm, DIGEST_EMPTY,
+ DIGEST ( 0xd1, 0x4a, 0x02, 0x8c, 0x2a, 0x3a, 0x2b, 0xc9, 0x47,
+ 0x61, 0x02, 0xbb, 0x28, 0x82, 0x34, 0xc4, 0x15, 0xa2,
+ 0xb0, 0x1f, 0x82, 0x8e, 0xa6, 0x2a, 0xc5, 0xb3, 0xe4,
+ 0x2f ) );
+
+/* NIST test vector "abc" */
+DIGEST_TEST ( sha224_nist_abc, &sha224_algorithm, DIGEST_NIST_ABC,
+ DIGEST ( 0x23, 0x09, 0x7d, 0x22, 0x34, 0x05, 0xd8, 0x22, 0x86,
+ 0x42, 0xa4, 0x77, 0xbd, 0xa2, 0x55, 0xb3, 0x2a, 0xad,
+ 0xbc, 0xe4, 0xbd, 0xa0, 0xb3, 0xf7, 0xe3, 0x6c, 0x9d,
+ 0xa7 ) );
+
+/* NIST test vector "abc...opq" */
+DIGEST_TEST ( sha224_nist_abc_opq, &sha224_algorithm, DIGEST_NIST_ABC_OPQ,
+ DIGEST ( 0x75, 0x38, 0x8b, 0x16, 0x51, 0x27, 0x76, 0xcc, 0x5d,
+ 0xba, 0x5d, 0xa1, 0xfd, 0x89, 0x01, 0x50, 0xb0, 0xc6,
+ 0x45, 0x5c, 0xb4, 0xf5, 0x8b, 0x19, 0x52, 0x52, 0x25,
+ 0x25 ) );
/**
- * Perform SHA-256 self-test
+ * Perform SHA-256 family self-test
*
*/
static void sha256_test_exec ( void ) {
- struct digest_algorithm *digest = &sha256_algorithm;
- struct sha256_test_vector *test;
- unsigned long cost;
- unsigned int i;
- unsigned int j;
- /* Correctness test */
- for ( i = 0 ; i < ( sizeof ( sha256_test_vectors ) /
- sizeof ( sha256_test_vectors[0] ) ) ; i++ ) {
- test = &sha256_test_vectors[i];
- /* Test with a single pass */
- digest_ok ( digest, NULL, test->data, test->len, test->digest );
- /* Test with fragment lists */
- for ( j = 0 ; j < ( sizeof ( sha256_test_fragments ) /
- sizeof ( sha256_test_fragments[0] )); j++ ){
- digest_ok ( digest, &sha256_test_fragments[j],
- test->data, test->len, test->digest );
- }
- }
+ /* Correctness tests */
+ digest_ok ( &sha256_empty );
+ digest_ok ( &sha256_nist_abc );
+ digest_ok ( &sha256_nist_abc_opq );
+ digest_ok ( &sha224_empty );
+ digest_ok ( &sha224_nist_abc );
+ digest_ok ( &sha224_nist_abc_opq );
- /* Speed test */
- cost = digest_cost ( digest );
- DBG ( "SHA256 required %ld cycles per byte\n", cost );
+ /* Speed tests */
+ DBG ( "SHA256 required %ld cycles per byte\n",
+ digest_cost ( &sha256_algorithm ) );
+ DBG ( "SHA224 required %ld cycles per byte\n",
+ digest_cost ( &sha224_algorithm ) );
}
-/** SHA-256 self-test */
+/** SHA-256 family self-test */
struct self_test sha256_test __self_test = {
.name = "sha256",
.exec = sha256_test_exec,
diff --git a/qemu/roms/ipxe/src/tests/sha512_test.c b/qemu/roms/ipxe/src/tests/sha512_test.c
new file mode 100644
index 000000000..be530ebad
--- /dev/null
+++ b/qemu/roms/ipxe/src/tests/sha512_test.c
@@ -0,0 +1,185 @@
+/*
+ * Copyright (C) 2015 Michael Brown <mbrown@fensystems.co.uk>.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or any later version.
+ *
+ * This program 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 a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
+ */
+
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
+
+/** @file
+ *
+ * SHA-512 family tests
+ *
+ * NIST test vectors are taken from
+ *
+ * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA512.pdf
+ * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA384.pdf
+ * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA512_256.pdf
+ * http://csrc.nist.gov/groups/ST/toolkit/documents/Examples/SHA512_224.pdf
+ *
+ */
+
+/* Forcibly enable assertions */
+#undef NDEBUG
+
+#include <ipxe/sha512.h>
+#include <ipxe/test.h>
+#include "digest_test.h"
+
+/* Empty test vector (digest obtained from "sha512sum /dev/null") */
+DIGEST_TEST ( sha512_empty, &sha512_algorithm, DIGEST_EMPTY,
+ DIGEST ( 0xcf, 0x83, 0xe1, 0x35, 0x7e, 0xef, 0xb8, 0xbd, 0xf1,
+ 0x54, 0x28, 0x50, 0xd6, 0x6d, 0x80, 0x07, 0xd6, 0x20,
+ 0xe4, 0x05, 0x0b, 0x57, 0x15, 0xdc, 0x83, 0xf4, 0xa9,
+ 0x21, 0xd3, 0x6c, 0xe9, 0xce, 0x47, 0xd0, 0xd1, 0x3c,
+ 0x5d, 0x85, 0xf2, 0xb0, 0xff, 0x83, 0x18, 0xd2, 0x87,
+ 0x7e, 0xec, 0x2f, 0x63, 0xb9, 0x31, 0xbd, 0x47, 0x41,
+ 0x7a, 0x81, 0xa5, 0x38, 0x32, 0x7a, 0xf9, 0x27, 0xda,
+ 0x3e ) );
+
+/* NIST test vector "abc" */
+DIGEST_TEST ( sha512_nist_abc, &sha512_algorithm, DIGEST_NIST_ABC,
+ DIGEST ( 0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba, 0xcc,
+ 0x41, 0x73, 0x49, 0xae, 0x20, 0x41, 0x31, 0x12, 0xe6,
+ 0xfa, 0x4e, 0x89, 0xa9, 0x7e, 0xa2, 0x0a, 0x9e, 0xee,
+ 0xe6, 0x4b, 0x55, 0xd3, 0x9a, 0x21, 0x92, 0x99, 0x2a,
+ 0x27, 0x4f, 0xc1, 0xa8, 0x36, 0xba, 0x3c, 0x23, 0xa3,
+ 0xfe, 0xeb, 0xbd, 0x45, 0x4d, 0x44, 0x23, 0x64, 0x3c,
+ 0xe8, 0x0e, 0x2a, 0x9a, 0xc9, 0x4f, 0xa5, 0x4c, 0xa4,
+ 0x9f ) );
+
+/* NIST test vector "abc...stu" */
+DIGEST_TEST ( sha512_nist_abc_stu, &sha512_algorithm, DIGEST_NIST_ABC_STU,
+ DIGEST ( 0x8e, 0x95, 0x9b, 0x75, 0xda, 0xe3, 0x13, 0xda, 0x8c,
+ 0xf4, 0xf7, 0x28, 0x14, 0xfc, 0x14, 0x3f, 0x8f, 0x77,
+ 0x79, 0xc6, 0xeb, 0x9f, 0x7f, 0xa1, 0x72, 0x99, 0xae,
+ 0xad, 0xb6, 0x88, 0x90, 0x18, 0x50, 0x1d, 0x28, 0x9e,
+ 0x49, 0x00, 0xf7, 0xe4, 0x33, 0x1b, 0x99, 0xde, 0xc4,
+ 0xb5, 0x43, 0x3a, 0xc7, 0xd3, 0x29, 0xee, 0xb6, 0xdd,
+ 0x26, 0x54, 0x5e, 0x96, 0xe5, 0x5b, 0x87, 0x4b, 0xe9,
+ 0x09 ) );
+
+/* Empty test vector (digest obtained from "sha384sum /dev/null") */
+DIGEST_TEST ( sha384_empty, &sha384_algorithm, DIGEST_EMPTY,
+ DIGEST ( 0x38, 0xb0, 0x60, 0xa7, 0x51, 0xac, 0x96, 0x38, 0x4c,
+ 0xd9, 0x32, 0x7e, 0xb1, 0xb1, 0xe3, 0x6a, 0x21, 0xfd,
+ 0xb7, 0x11, 0x14, 0xbe, 0x07, 0x43, 0x4c, 0x0c, 0xc7,
+ 0xbf, 0x63, 0xf6, 0xe1, 0xda, 0x27, 0x4e, 0xde, 0xbf,
+ 0xe7, 0x6f, 0x65, 0xfb, 0xd5, 0x1a, 0xd2, 0xf1, 0x48,
+ 0x98, 0xb9, 0x5b ) );
+
+/* NIST test vector "abc" */
+DIGEST_TEST ( sha384_nist_abc, &sha384_algorithm, DIGEST_NIST_ABC,
+ DIGEST ( 0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b, 0xb5,
+ 0xa0, 0x3d, 0x69, 0x9a, 0xc6, 0x50, 0x07, 0x27, 0x2c,
+ 0x32, 0xab, 0x0e, 0xde, 0xd1, 0x63, 0x1a, 0x8b, 0x60,
+ 0x5a, 0x43, 0xff, 0x5b, 0xed, 0x80, 0x86, 0x07, 0x2b,
+ 0xa1, 0xe7, 0xcc, 0x23, 0x58, 0xba, 0xec, 0xa1, 0x34,
+ 0xc8, 0x25, 0xa7 ) );
+
+/* NIST test vector "abc...stu" */
+DIGEST_TEST ( sha384_nist_abc_stu, &sha384_algorithm, DIGEST_NIST_ABC_STU,
+ DIGEST ( 0x09, 0x33, 0x0c, 0x33, 0xf7, 0x11, 0x47, 0xe8, 0x3d,
+ 0x19, 0x2f, 0xc7, 0x82, 0xcd, 0x1b, 0x47, 0x53, 0x11,
+ 0x1b, 0x17, 0x3b, 0x3b, 0x05, 0xd2, 0x2f, 0xa0, 0x80,
+ 0x86, 0xe3, 0xb0, 0xf7, 0x12, 0xfc, 0xc7, 0xc7, 0x1a,
+ 0x55, 0x7e, 0x2d, 0xb9, 0x66, 0xc3, 0xe9, 0xfa, 0x91,
+ 0x74, 0x60, 0x39 ) );
+
+/* Empty test vector (digest obtained from "shasum -a 512256 /dev/null") */
+DIGEST_TEST ( sha512_256_empty, &sha512_256_algorithm, DIGEST_EMPTY,
+ DIGEST ( 0xc6, 0x72, 0xb8, 0xd1, 0xef, 0x56, 0xed, 0x28, 0xab,
+ 0x87, 0xc3, 0x62, 0x2c, 0x51, 0x14, 0x06, 0x9b, 0xdd,
+ 0x3a, 0xd7, 0xb8, 0xf9, 0x73, 0x74, 0x98, 0xd0, 0xc0,
+ 0x1e, 0xce, 0xf0, 0x96, 0x7a ) );
+
+/* NIST test vector "abc" */
+DIGEST_TEST ( sha512_256_nist_abc, &sha512_256_algorithm, DIGEST_NIST_ABC,
+ DIGEST ( 0x53, 0x04, 0x8e, 0x26, 0x81, 0x94, 0x1e, 0xf9, 0x9b,
+ 0x2e, 0x29, 0xb7, 0x6b, 0x4c, 0x7d, 0xab, 0xe4, 0xc2,
+ 0xd0, 0xc6, 0x34, 0xfc, 0x6d, 0x46, 0xe0, 0xe2, 0xf1,
+ 0x31, 0x07, 0xe7, 0xaf, 0x23 ) );
+
+/* NIST test vector "abc...stu" */
+DIGEST_TEST ( sha512_256_nist_abc_stu, &sha512_256_algorithm,
+ DIGEST_NIST_ABC_STU,
+ DIGEST ( 0x39, 0x28, 0xe1, 0x84, 0xfb, 0x86, 0x90, 0xf8, 0x40,
+ 0xda, 0x39, 0x88, 0x12, 0x1d, 0x31, 0xbe, 0x65, 0xcb,
+ 0x9d, 0x3e, 0xf8, 0x3e, 0xe6, 0x14, 0x6f, 0xea, 0xc8,
+ 0x61, 0xe1, 0x9b, 0x56, 0x3a ) );
+
+/* Empty test vector (digest obtained from "shasum -a 512224 /dev/null") */
+DIGEST_TEST ( sha512_224_empty, &sha512_224_algorithm, DIGEST_EMPTY,
+ DIGEST ( 0x6e, 0xd0, 0xdd, 0x02, 0x80, 0x6f, 0xa8, 0x9e, 0x25,
+ 0xde, 0x06, 0x0c, 0x19, 0xd3, 0xac, 0x86, 0xca, 0xbb,
+ 0x87, 0xd6, 0xa0, 0xdd, 0xd0, 0x5c, 0x33, 0x3b, 0x84,
+ 0xf4 ) );
+
+/* NIST test vector "abc" */
+DIGEST_TEST ( sha512_224_nist_abc, &sha512_224_algorithm, DIGEST_NIST_ABC,
+ DIGEST ( 0x46, 0x34, 0x27, 0x0f, 0x70, 0x7b, 0x6a, 0x54, 0xda,
+ 0xae, 0x75, 0x30, 0x46, 0x08, 0x42, 0xe2, 0x0e, 0x37,
+ 0xed, 0x26, 0x5c, 0xee, 0xe9, 0xa4, 0x3e, 0x89, 0x24,
+ 0xaa ) );
+
+/* NIST test vector "abc...stu" */
+DIGEST_TEST ( sha512_224_nist_abc_stu, &sha512_224_algorithm,
+ DIGEST_NIST_ABC_STU,
+ DIGEST ( 0x23, 0xfe, 0xc5, 0xbb, 0x94, 0xd6, 0x0b, 0x23, 0x30,
+ 0x81, 0x92, 0x64, 0x0b, 0x0c, 0x45, 0x33, 0x35, 0xd6,
+ 0x64, 0x73, 0x4f, 0xe4, 0x0e, 0x72, 0x68, 0x67, 0x4a,
+ 0xf9 ) );
+
+/**
+ * Perform SHA-512 family self-test
+ *
+ */
+static void sha512_test_exec ( void ) {
+
+ /* Correctness tests */
+ digest_ok ( &sha512_empty );
+ digest_ok ( &sha512_nist_abc );
+ digest_ok ( &sha512_nist_abc_stu );
+ digest_ok ( &sha384_empty );
+ digest_ok ( &sha384_nist_abc );
+ digest_ok ( &sha384_nist_abc_stu );
+ digest_ok ( &sha512_256_empty );
+ digest_ok ( &sha512_256_nist_abc );
+ digest_ok ( &sha512_256_nist_abc_stu );
+ digest_ok ( &sha512_224_empty );
+ digest_ok ( &sha512_224_nist_abc );
+ digest_ok ( &sha512_224_nist_abc_stu );
+
+ /* Speed tests */
+ DBG ( "SHA512 required %ld cycles per byte\n",
+ digest_cost ( &sha512_algorithm ) );
+ DBG ( "SHA384 required %ld cycles per byte\n",
+ digest_cost ( &sha384_algorithm ) );
+ DBG ( "SHA512/256 required %ld cycles per byte\n",
+ digest_cost ( &sha512_256_algorithm ) );
+ DBG ( "SHA512/224 required %ld cycles per byte\n",
+ digest_cost ( &sha512_224_algorithm ) );
+}
+
+/** SHA-512 family self-test */
+struct self_test sha512_test __self_test = {
+ .name = "sha512",
+ .exec = sha512_test_exec,
+};
diff --git a/qemu/roms/ipxe/src/tests/string_test.c b/qemu/roms/ipxe/src/tests/string_test.c
index 3b48d9f3d..4693b5f65 100644
--- a/qemu/roms/ipxe/src/tests/string_test.c
+++ b/qemu/roms/ipxe/src/tests/string_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
@@ -31,7 +35,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <stdint.h>
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
+#include <strings.h>
+#include <ipxe/string.h>
#include <ipxe/test.h>
/**
@@ -63,6 +70,18 @@ static void string_test_exec ( void ) {
ok ( *(strchr ( "Testing", 'g' )) == 'g' );
ok ( strchr ( "Testing", 'x' ) == NULL );
+ /* Test strrchr() */
+ ok ( strrchr ( "", 'a' ) == NULL );
+ ok ( *(strrchr ( "Haystack", 'a' )) == 'a' );
+ ok ( *(strrchr ( "Haystack", 'k' )) == 'k' );
+ ok ( strrchr ( "Haystack", 'x' ) == NULL );
+
+ /* Test memchr() */
+ ok ( memchr ( "", '\0', 0 ) == NULL );
+ ok ( *((uint8_t *)memchr ( "post\0null", 'l', 9 )) == 'l' );
+ ok ( *((uint8_t *)memchr ( "post\0null", '\0', 9 )) == '\0' );
+ ok ( memchr ( "thingy", 'z', 6 ) == NULL );
+
/* Test strcmp() */
ok ( strcmp ( "", "" ) == 0 );
ok ( strcmp ( "Hello", "Hello" ) == 0 );
@@ -78,11 +97,31 @@ static void string_test_exec ( void ) {
ok ( strncmp ( "Goodbye", "Goodbye world", 32 ) != 0 );
ok ( strncmp ( "Goodbye", "Goodbye world", 7 ) == 0 );
+ /* Test strcasecmp() */
+ ok ( strcasecmp ( "", "" ) == 0 );
+ ok ( strcasecmp ( "Uncle Jack", "Uncle jack" ) == 0 );
+ ok ( strcasecmp ( "Uncle Jack", "Uncle" ) != 0 );
+ ok ( strcasecmp ( "Uncle", "Uncle Jack" ) != 0 );
+ ok ( strcasecmp ( "not", "equal" ) != 0 );
+
/* Test memcmp() */
ok ( memcmp ( "", "", 0 ) == 0 );
ok ( memcmp ( "Foo", "Foo", 3 ) == 0 );
ok ( memcmp ( "Foo", "Bar", 3 ) != 0 );
+ /* Test strstr() */
+ {
+ const char haystack[] = "find me!";
+ char *found;
+
+ found = strstr ( haystack, "find" );
+ ok ( found == &haystack[0] );
+ found = strstr ( haystack, "me" );
+ ok ( found == &haystack[5] );
+ found = strstr ( haystack, "me." );
+ ok ( found == NULL );
+ }
+
/* Test memset() */
{
static uint8_t test[7] = { '>', 1, 1, 1, 1, 1, '<' };
@@ -154,6 +193,107 @@ static void string_test_exec ( void ) {
ok ( strcmp ( dup, "hello" ) == 0 );
free ( dup );
}
+
+ /* Test strcpy() */
+ {
+ const char longer[7] = "copyme";
+ const char shorter[3] = "hi";
+ char dest[7];
+ char *copy;
+
+ copy = strcpy ( dest, longer );
+ ok ( copy == dest );
+ ok ( memcmp ( dest, longer, 7 ) == 0 );
+ copy = strcpy ( dest, shorter );
+ ok ( copy == dest );
+ ok ( memcmp ( dest, shorter, 3 ) == 0 );
+ ok ( memcmp ( ( dest + 3 ), ( longer + 3 ), 4 ) == 0 );
+ }
+
+ /* Test strncpy() */
+ {
+ const char src[5] = "copy";
+ const char orig[8] = { 'x', 'x', 'x', 'x', 'x', 'x', 'x', 'x' };
+ const char zero[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+ char dest[8];
+ char *copy;
+
+ memcpy ( dest, orig, sizeof ( dest ) );
+ copy = strncpy ( dest, src, 5 );
+ ok ( copy == dest );
+ ok ( memcmp ( dest, src, 5 ) == 0 );
+ ok ( memcmp ( dest + 5, orig + 5, 3 ) == 0 );
+ memcpy ( dest, orig, sizeof ( dest ) );
+ copy = strncpy ( dest, src, 4 );
+ ok ( copy == dest );
+ ok ( memcmp ( dest, src, 4 ) == 0 );
+ ok ( memcmp ( dest + 4, orig + 4, 4 ) == 0 );
+ memcpy ( dest, orig, sizeof ( dest ) );
+ copy = strncpy ( dest, src, 8 );
+ ok ( copy == dest );
+ ok ( memcmp ( dest, src, 5 ) == 0 );
+ ok ( memcmp ( dest + 5, zero + 5, 3 ) == 0 );
+ memcpy ( dest, orig, sizeof ( dest ) );
+ copy = strncpy ( dest, "", 8 );
+ ok ( copy == dest );
+ ok ( memcmp ( dest, zero, 8 ) == 0 );
+ }
+
+ /* Test strcat() */
+ {
+ char buf[16] = "append";
+ char *dest;
+
+ dest = strcat ( buf, " this" );
+ ok ( dest == buf );
+ ok ( strcmp ( buf, "append this" ) == 0 );
+ }
+
+ /* Test digit_value() */
+ {
+ unsigned int i;
+ char buf[2];
+ for ( i = 0 ; i < 16 ; i++ ) {
+ snprintf ( buf, sizeof ( buf ), "%x", i );
+ ok ( digit_value ( buf[0] ) == i );
+ snprintf ( buf, sizeof ( buf ), "%X", i );
+ ok ( digit_value ( buf[0] ) == i );
+ }
+ ok ( digit_value ( 0 ) >= 16 );
+ ok ( digit_value ( 9 ) >= 16 );
+ ok ( digit_value ( '0' - 1 ) >= 16 );
+ ok ( digit_value ( '9' + 1 ) >= 16 );
+ ok ( digit_value ( 'A' - 1 ) >= 16 );
+ ok ( digit_value ( 'F' + 1 ) >= 16 );
+ ok ( digit_value ( 'a' - 1 ) >= 16 );
+ ok ( digit_value ( 'f' + 1 ) >= 16 );
+ }
+
+ /* Test strtoul() */
+ ok ( strtoul ( "12345", NULL, 0 ) == 12345UL );
+ ok ( strtoul ( " 741", NULL, 10 ) == 741UL );
+ ok ( strtoul ( " 555a", NULL, 0 ) == 555UL );
+ ok ( strtoul ( " 555a", NULL, 16 ) == 0x555aUL );
+ ok ( strtoul ( "-12", NULL, 0 ) == -12UL );
+ ok ( strtoul ( "+3", NULL, 0 ) == 3UL );
+ ok ( strtoul ( "721", NULL, 0 ) == 721UL );
+ ok ( strtoul ( "721", NULL, 8 ) == 0721UL );
+ ok ( strtoul ( "0721", NULL, 0 ) == 0721UL );
+ ok ( strtoul ( "", NULL, 0 ) == 0UL );
+ ok ( strtoul ( "\t0xcAfe", NULL, 0 ) == 0xcafeUL );
+ ok ( strtoul ( "0xffffffff", NULL, 0 ) == 0xffffffffUL );
+ {
+ static const char string[] = "123aHa.world";
+ char *endp;
+ ok ( strtoul ( string, &endp, 0 ) == 123UL );
+ ok ( endp == &string[3] );
+ ok ( strtoul ( string, &endp, 16 ) == 0x123aUL );
+ ok ( endp == &string[4] );
+ ok ( strtoul ( string, &endp, 26 ) ==
+ ( ( ( ( ( 1 * 26 + 2 ) * 26 + 3 ) * 26 + 10 ) * 26
+ + 17 ) * 26 + 10 ) );
+ ok ( endp == &string[6] );
+ }
}
/** String self-test */
diff --git a/qemu/roms/ipxe/src/tests/tcpip_test.c b/qemu/roms/ipxe/src/tests/tcpip_test.c
index 00c88ae32..759f886bc 100644
--- a/qemu/roms/ipxe/src/tests/tcpip_test.c
+++ b/qemu/roms/ipxe/src/tests/tcpip_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
diff --git a/qemu/roms/ipxe/src/tests/test.c b/qemu/roms/ipxe/src/tests/test.c
index c05e72a76..67bd4cf89 100644
--- a/qemu/roms/ipxe/src/tests/test.c
+++ b/qemu/roms/ipxe/src/tests/test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
diff --git a/qemu/roms/ipxe/src/tests/tests.c b/qemu/roms/ipxe/src/tests/tests.c
index 2b4b78c7c..54ce86677 100644
--- a/qemu/roms/ipxe/src/tests/tests.c
+++ b/qemu/roms/ipxe/src/tests/tests.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
@@ -26,6 +30,8 @@ FILE_LICENCE ( GPL2_OR_LATER );
*/
/* Drag in all applicable self-tests */
+PROVIDE_REQUIRING_SYMBOL();
+REQUIRE_OBJECT ( memset_test );
REQUIRE_OBJECT ( memcpy_test );
REQUIRE_OBJECT ( string_test );
REQUIRE_OBJECT ( math_test );
@@ -37,12 +43,14 @@ REQUIRE_OBJECT ( base16_test );
REQUIRE_OBJECT ( settings_test );
REQUIRE_OBJECT ( time_test );
REQUIRE_OBJECT ( tcpip_test );
+REQUIRE_OBJECT ( ipv4_test );
REQUIRE_OBJECT ( ipv6_test );
REQUIRE_OBJECT ( crc32_test );
REQUIRE_OBJECT ( md5_test );
REQUIRE_OBJECT ( sha1_test );
REQUIRE_OBJECT ( sha256_test );
-REQUIRE_OBJECT ( aes_cbc_test );
+REQUIRE_OBJECT ( sha512_test );
+REQUIRE_OBJECT ( aes_test );
REQUIRE_OBJECT ( hmac_drbg_test );
REQUIRE_OBJECT ( hash_df_test );
REQUIRE_OBJECT ( bigint_test );
@@ -56,3 +64,6 @@ REQUIRE_OBJECT ( png_test );
REQUIRE_OBJECT ( dns_test );
REQUIRE_OBJECT ( uri_test );
REQUIRE_OBJECT ( profile_test );
+REQUIRE_OBJECT ( setjmp_test );
+REQUIRE_OBJECT ( pccrc_test );
+REQUIRE_OBJECT ( linebuf_test );
diff --git a/qemu/roms/ipxe/src/tests/time_test.c b/qemu/roms/ipxe/src/tests/time_test.c
index 28acebee6..3bf01dd1d 100644
--- a/qemu/roms/ipxe/src/tests/time_test.c
+++ b/qemu/roms/ipxe/src/tests/time_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
diff --git a/qemu/roms/ipxe/src/tests/uri_test.c b/qemu/roms/ipxe/src/tests/uri_test.c
index 14f1b4ad0..da7fb8abe 100644
--- a/qemu/roms/ipxe/src/tests/uri_test.c
+++ b/qemu/roms/ipxe/src/tests/uri_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
@@ -66,6 +70,8 @@ struct uri_resolve_test {
struct uri_tftp_test {
/** Next-server address */
struct in_addr next_server;
+ /** Port number */
+ unsigned int port;
/** Filename */
const char *filename;
/** URI */
@@ -330,7 +336,7 @@ static void uri_tftp_okx ( struct uri_tftp_test *test, const char *file,
size_t len;
/* Construct URI */
- uri = tftp_uri ( test->next_server, test->filename );
+ uri = tftp_uri ( test->next_server, test->port, test->filename );
okx ( uri != NULL, file, line );
if ( uri ) {
uri_okx ( uri, &test->uri, file, line );
@@ -674,7 +680,7 @@ static struct uri_resolve_test uri_fragment = {
/** TFTP URI with absolute path */
static struct uri_tftp_test uri_tftp_absolute = {
- { .s_addr = htonl ( 0xc0a80002 ) /* 192.168.0.2 */ },
+ { .s_addr = htonl ( 0xc0a80002 ) /* 192.168.0.2 */ }, 0,
"/absolute/path",
{
.scheme = "tftp",
@@ -686,7 +692,7 @@ static struct uri_tftp_test uri_tftp_absolute = {
/** TFTP URI with relative path */
static struct uri_tftp_test uri_tftp_relative = {
- { .s_addr = htonl ( 0xc0a80003 ) /* 192.168.0.3 */ },
+ { .s_addr = htonl ( 0xc0a80003 ) /* 192.168.0.3 */ }, 0,
"relative/path",
{
.scheme = "tftp",
@@ -698,7 +704,7 @@ static struct uri_tftp_test uri_tftp_relative = {
/** TFTP URI with path containing special characters */
static struct uri_tftp_test uri_tftp_icky = {
- { .s_addr = htonl ( 0x0a000006 ) /* 10.0.0.6 */ },
+ { .s_addr = htonl ( 0x0a000006 ) /* 10.0.0.6 */ }, 0,
"C:\\tftpboot\\icky#path",
{
.scheme = "tftp",
@@ -708,6 +714,19 @@ static struct uri_tftp_test uri_tftp_icky = {
"tftp://10.0.0.6/C%3A\\tftpboot\\icky%23path",
};
+/** TFTP URI with custom port */
+static struct uri_tftp_test uri_tftp_port = {
+ { .s_addr = htonl ( 0xc0a80001 ) /* 192.168.0.1 */ }, 4069,
+ "/another/path",
+ {
+ .scheme = "tftp",
+ .host = "192.168.0.1",
+ .port = "4069",
+ .path = "/another/path",
+ },
+ "tftp://192.168.0.1:4069/another/path",
+};
+
/** Current working URI test */
static struct uri_churi_test uri_churi[] = {
{
@@ -842,6 +861,7 @@ static void uri_test_exec ( void ) {
uri_tftp_ok ( &uri_tftp_absolute );
uri_tftp_ok ( &uri_tftp_relative );
uri_tftp_ok ( &uri_tftp_icky );
+ uri_tftp_ok ( &uri_tftp_port );
/* Current working URI tests */
uri_churi_ok ( uri_churi );
diff --git a/qemu/roms/ipxe/src/tests/vsprintf_test.c b/qemu/roms/ipxe/src/tests/vsprintf_test.c
index 11512ec8e..0ad4f1c56 100644
--- a/qemu/roms/ipxe/src/tests/vsprintf_test.c
+++ b/qemu/roms/ipxe/src/tests/vsprintf_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
diff --git a/qemu/roms/ipxe/src/tests/x509_test.c b/qemu/roms/ipxe/src/tests/x509_test.c
index fd39e12d2..658d5247c 100644
--- a/qemu/roms/ipxe/src/tests/x509_test.c
+++ b/qemu/roms/ipxe/src/tests/x509_test.c
@@ -15,9 +15,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
+ *
+ * You can also choose to distribute this program under the terms of
+ * the Unmodified Binary Distribution Licence (as given in the file
+ * COPYING.UBDL), provided that you have satisfied its requirements.
*/
-FILE_LICENCE ( GPL2_OR_LATER );
+FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
/** @file
*
@@ -1105,6 +1109,7 @@ struct self_test x509_test __self_test = {
};
/* Drag in algorithms required for tests */
+REQUIRING_SYMBOL ( x509_test );
REQUIRE_OBJECT ( rsa );
REQUIRE_OBJECT ( sha1 );
REQUIRE_OBJECT ( sha256 );