summaryrefslogtreecommitdiffstats
path: root/src/tests
Commit message (Collapse)AuthorAgeFilesLines
* [crypto] Allow for zero-length big integer literalsMichael Brown2025-12-291-0/+7
| | | | | | | | | | Ensure that zero-length big integer literals are treated as containing a zero value. Avoid tests on every big integer arithmetic operation by ensuring that bigint_required_size() always returns a non-zero value: the zero-length tests can therefore be restricted to only bigint_init() and bigint_done(). Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [test] Update big integer tests to use okx()Michael Brown2025-12-291-292/+428
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [test] Add test cases for X.509 certificates with ECDSA signaturesMichael Brown2025-12-191-0/+271
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [test] Ensure OID-identified algorithms are present for X.509 testsMichael Brown2025-12-191-3/+2Star
| | | | | | | | | The algorithms required for the X.509 tests are accessed indirectly via their OID-identified algorithms, rather than directly via symbols. Ensure that the required OID-identified algorithm definitions are included regardless of the configuration in config/crypto.h. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [crypto] Add support for ECDSA signaturesMichael Brown2025-12-192-0/+275
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [test] Test verification of constructed signatureMichael Brown2025-12-191-0/+4
| | | | | | | | | | | Some signature schemes (such as ECDSA) allow for non-deterministic signatures. Provide more information in test results by performing verification of the constructed signature even when it does not match the expected test case result: this allows us to distinguish between a bug that is generating invalid signatures and a bug that is generating valid but non-canonical signatures. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [crypto] Allow for an explicit representation of point at infinityMichael Brown2025-12-184-25/+105
| | | | | | | | | | | | | | | ECDSA requires the ability to add two arbitrary curve points, either of which may legitimately be the point at infinity. Update the API so that curves must choose an explicit affine representation for the point at infinity, and provide a method to test for this representation. Multiplication and addition will now allow this representation to be provided as an input, and will not fail if the result is the point at infinity. Callers must explicitly check for the point at infinity where needed (e.g. after computing the ECDHE shared secret curve point). Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [test] Test signature verification independently of signingMichael Brown2025-12-171-13/+17
| | | | | | | | Copy and modify the signature defined within the test case for verification tests, rather than relying on the modifiable signature constructed by the signing portion of the same test. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [crypto] Allow for addition of arbitrary Weierstrass curve pointsMichael Brown2025-12-084-2/+283
| | | | | | | | | | | | | | | ECDSA verification requires the ability to add two arbitrary curve points (as well as the ability to multiply a curve point by a scalar). Add an elliptic curve method to perform arbitrary point addition. Pass in curve points as affine coordinates: this will require some redundant conversions between affine coorfinates and the internal representation as projective coordinates in Montgomery form, but keeps the API as simple as possible. Since we do not expect to perform a high volume of ECDSA signature verifications, these redundant calculations are an acceptable cost for keeping the code simple. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [crypto] Expose the (prime) group order as an elliptic curve propertyMichael Brown2025-12-054-0/+59
| | | | | | | | | | | ECDSA requires knowledge of the group order of the base point, and is defined only for curves with a prime group order (e.g. the NIST curves). Add the group order as an explicit property of an elliptic curve, and add tests to verify that the order is correct. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [test] Allow for elliptic curve tests other than multiplicationMichael Brown2025-12-054-270/+271
| | | | | | | Rename elliptic_ok() to elliptic_multiply_ok() etc, to create namespace for tests of other elliptic curve operations. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [crypto] Expose the base point as an explicit elliptic curve propertyMichael Brown2025-12-051-2/+3
| | | | | | | | Add the generator base point as an explicit property of an elliptic curve, and remove the ability to pass a NULL to elliptic_multiply() to imply the use of the generator base point. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [test] Include key matching in existing public-key testsMichael Brown2025-12-031-0/+8
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [crypto] Construct asymmetric ciphered data using ASN.1 buildersMichael Brown2025-12-022-39/+45
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [crypto] Construct signatures using ASN.1 buildersMichael Brown2025-12-011-15/+15
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [crypto] Pass signatures for verification as ASN.1 cursorsMichael Brown2025-12-012-14/+16
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [libc] Add wcsnlen()Michael Brown2025-08-281-0/+18
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [fdt] Use phandle as device locationMichael Brown2025-08-041-9/+10
| | | | | | | | | | | | | Consumption of phandles will be in the form of locating a functional device (e.g. a GPIO device, or an I2C device, or a reset controller) by phandle, rather than locating the device tree node to which the phandle refers. Repurpose fdt_phandle() to obtain the phandle value (instead of searching by phandle), and record this value as the bus location within the generic device structure. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [fdt] Add ability to locate node by phandleMichael Brown2025-07-221-65/+78
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [init] Show initialisation function names in debug messagesMichael Brown2025-07-152-0/+2
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [iobuf] Ensure I/O buffer data sits within unshared cachelinesMichael Brown2025-07-071-1/+7
| | | | | | | | | | | On platforms where DMA devices are not in the same coherency domain as the CPU cache, we must ensure that DMA I/O buffers do not share cachelines with other data. Align the start and end of I/O buffers to IOB_ZLEN, which is larger than any cacheline size we expect to encounter. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [fdt] Allow paths and aliases to be terminated with separator charactersMichael Brown2025-06-111-0/+7
| | | | | | | | | | | | | | Non-permitted name characters such as a colon are sometimes used to separate alias names or paths from additional metadata, such as the baud rate for a UART in the "/chosen/stdout-path" property. Support the use of such alias names and paths by allowing any character not permitted in a property name to terminate a property or node name match. (This is a very relaxed matching rule that will produce false positive matches on invalid input, but this is unlikely to cause problems in practice.) Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [ipv4] Add support for classless static routesMichael Brown2025-06-101-0/+29
| | | | | | | | | Add support for RFC 3442 classless static routes provided via DHCP option 121. Originally-implemented-by: Hazel Smith <hazel.smith@leicester.ac.uk> Originally-implemented-by: Raphael Pour <raphael.pour@hetzner.com> Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [ipv4] Extend routing mechanism to handle non-default routesMichael Brown2025-06-101-0/+30
| | | | | | | | | | | | | | | | | | | | | | | Extend the definition of an IPv4 routing table entry to allow for the expression of non-default gateways for specified off-link subnets, and of on-link secondary subnets (where we can send directly to the destination address even though our source address is not within the subnet). This more precise definition also allows us to correctly handle routing in the (uncommon for iPXE) case when multiple network interfaces are open concurrently and more than one interface has a default gateway. The common case of a single IPv4 address/netmask and a default gateway now results in two routing table entries. To retain backwards compatibility with existing documentation (and to avoid on-screen clutter), the "route" command prints default gateways on the same line as the locally assigned address. There is therefore no change in output from the "route" command unless explicit additional (off-link or on-link) routes are present. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [ipv4] Add self-tests for IPv4 routingMichael Brown2025-06-101-0/+152
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [test] Add infrastructure for test network devicesMichael Brown2025-06-102-0/+329
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [fdt] Provide ability to locate the parent device nodeMichael Brown2025-05-301-0/+12
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [fdt] Add tests for device tree creationMichael Brown2025-05-301-0/+18
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [tests] Remove prehistoric umalloc() test codeMichael Brown2025-05-151-25/+0Star
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [image] Make image data read-only to most consumersMichael Brown2025-04-305-39/+7Star
| | | | | | | | | | | | | | | | | | | | Almost all image consumers do not need to modify the content of the image. Now that the image data is a pointer type (rather than the opaque userptr_t type), we can rely on the compiler to enforce this at build time. Change the .data field to be a const pointer, so that the compiler can verify that image consumers do not modify the image content. Provide a transparent .rwdata field for consumers who have a legitimate (and now explicit) reason to modify the image content. We do not attempt to impose any runtime restriction on checking whether or not an image is writable. The only existing instances of genuinely read-only images are the various unit test images, and it is acceptable for defective test cases to result in a segfault rather than a runtime error. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [image] Add the concept of a static imageMichael Brown2025-04-304-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | Not all images are allocated via alloc_image(). For example: embedded images, the static images created to hold a runtime command line, and the images used by unit tests are all static structures. Using image_set_cmdline() (via e.g. the "imgargs" command) to set the command-line arguments of a static image will succeed but will leak memory, since nothing will ever free the allocated command line. There are no code paths that can lead to calling image_set_len() on a static image, but there is no safety check against future code paths attempting this. Define a flag IMAGE_STATIC to mark an image as statically allocated, generalise free_image() to also handle freeing dynamically allocated portions of static images (such as the command line), and expose free_image() for use by static images. Define a related flag IMAGE_STATIC_NAME to mark the name as statically allocated. Allow a statically allocated name to be replaced with a dynamically allocated name since this is a potentially valid use case (e.g. if "imgdecrypt --name <name>" is used on an embedded image). Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [test] Separate read-only and writable CMS test imagesMichael Brown2025-04-301-2/+14
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [uaccess] Remove redundant copy_from_user() and copy_to_user()Michael Brown2025-04-304-0/+4
| | | | | | | Remove the now-redundant copy_from_user() and copy_to_user() wrapper functions. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [bofm] Allow BOFM tests to be run without a BOFM-capable device driverMichael Brown2025-04-291-1/+110
| | | | | | | | | | | The BOFM tests are not part of the standard unit test suite, since they are designed to allow for exercising real BOFM driver code outside of the context of a real IBM blade server. Allow for the BOFM tests to be run without a real BOFM driver, by providing a dummy driver for the specified PCI test device. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [peerdist] Remove userptr_t from PeerDist content information parsingMichael Brown2025-04-291-4/+2Star
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [uaccess] Remove trivial uses of userptr_tMichael Brown2025-04-241-3/+2Star
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [umalloc] Remove userptr_t from user memory allocationsMichael Brown2025-04-231-3/+2Star
| | | | | | | | Use standard void pointers for umalloc(), urealloc(), and ufree(), with the "u" prefix retained to indicate that these allocations are made from external ("user") memory rather than from the internal heap. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [acpi] Remove userptr_t from ACPI table parsingMichael Brown2025-04-221-5/+7
| | | | | | | Simplify the ACPI table parsing code by assuming that all table content is fully accessible via pointer dereferences. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [deflate] Remove userptr_t from decompression codeMichael Brown2025-04-223-20/+21
| | | | | | | Simplify the deflate, zlib, and gzip decompression code by assuming that all content is fully accessible via pointer dereferences. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [uaccess] Remove redundant memcpy_user() and related string functionsMichael Brown2025-04-214-11/+8Star
| | | | | | | | | | The memcpy_user(), memmove_user(), memcmp_user(), memset_user(), and strlen_user() functions are now just straightforward wrappers around the corresponding standard library functions. Remove these redundant wrappers. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [fdt] Add fdt_cells() to read cell-based properties such as "reg"Michael Brown2025-04-151-33/+61
| | | | | | | | Add fdt_cells() to read scalar values encoded within a cell array, reimplement fdt_u64() as a wrapper around this, and add fdt_u32() for completeness. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [fdt] Remove concept of a device tree cursorMichael Brown2025-04-141-0/+14
| | | | | | | | Refactor device tree traversal to operate on the basis of describing the token at a given offset, with no separate notion of a device tree cursor. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [fdt] Add basic tests for reading values from a flattened device treeMichael Brown2025-04-142-0/+228
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [cpio] Allow for the construction of pure directoriesMichael Brown2025-03-121-0/+16
| | | | | | | | | | Allow for the possibility of creating empty directories (without having to include a dummy file inside the directory) using a zero-length image and a CPIO filename with a trailing slash, such as: initrd emptyfile /usr/share/oem/ Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [cpio] Fix calculation of name lengths in CPIO headersMichael Brown2025-03-122-0/+264
| | | | | | | | | | | | | Commit 12ea8c4 ("[cpio] Allow for construction of parent directories as needed") introduced a regression in constructing CPIO archive headers for relative paths (e.g. simple filenames with no leading slash). Fix by counting the number of path components rather than the number of path separators, and add some test cases to cover CPIO header construction. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [crypto] Support extracting certificates from EFI signature list imagesMichael Brown2025-03-112-0/+168
| | | | | | | | | | | Add support for the EFI signature list image format (as produced by tools such as efisecdb). The parsing code does not require any EFI boot services functions and so may be enabled even in non-EFI builds. We default to enabling it only for EFI builds. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [crypto] Support direct reduction only for Montgomery constant R^2 mod NMichael Brown2025-02-141-53/+53
| | | | | | | | | | | | | | | | | | | | | | The only remaining use case for direct reduction (outside of the unit tests) is in calculating the constant R^2 mod N used during Montgomery multiplication. The current implementation of direct reduction requires a writable copy of the modulus (to allow for shifting), and both the modulus and the result buffer must be padded to be large enough to hold (R^2 - N), which is twice the size of the actual values involved. For the special case of reducing R^2 mod N (or any power of two mod N), we can run the same algorithm without needing either a writable copy of the modulus or a padded result buffer. The working state required is only two bits larger than the result buffer, and these additional bits may be held in local variables instead. Rewrite bigint_reduce() to handle only this use case, and remove the no longer necessary uses of double-sized big integers. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [crypto] Expose shifted out bit from big integer shiftsMichael Brown2025-02-131-20/+53
| | | | | | | Expose the bit shifted out as a result of shifting a big integer left or right. Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [crypto] Add definitions and tests for the NIST P-384 elliptic curveMichael Brown2025-01-302-0/+223
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>
* [crypto] Add definitions and tests for the NIST P-256 elliptic curveMichael Brown2025-01-282-0/+177
| | | | Signed-off-by: Michael Brown <mcb30@ipxe.org>