iPXE
der_test.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 *
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26/** @file
27 *
28 * DER self-tests
29 *
30 */
31
32/* Forcibly enable assertions */
33#undef NDEBUG
34
35#include <string.h>
36#include <assert.h>
37#include <ipxe/test.h>
38#include <ipxe/der.h>
39#include "asn1_test.h"
40
41/** Define inline data */
42#define DATA(...) { __VA_ARGS__ }
43
44/** Define inline expected digest */
45#define DIGEST(...) { { __VA_ARGS__ } }
46
47/** 32-bit RSA private key */
48ASN1 ( rsa32, &der_image_type,
49 DATA ( 0x30, 0x2c, 0x02, 0x01, 0x00, 0x02, 0x05, 0x00, 0xb7, 0x56,
50 0x5c, 0xb1, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x04, 0x66,
51 0xa4, 0xc4, 0x35, 0x02, 0x03, 0x00, 0xda, 0x9f, 0x02, 0x03,
52 0x00, 0xd6, 0xaf, 0x02, 0x02, 0x01, 0x59, 0x02, 0x02, 0x4e,
53 0xe1, 0x02, 0x03, 0x00, 0xa6, 0x5a ),
54 DIGEST ( 0x82, 0x66, 0x24, 0xd9, 0xc3, 0x98, 0x1e, 0x5e, 0x56, 0xed,
55 0xd0, 0xd0, 0x2a, 0x5e, 0x9c, 0x3a, 0x58, 0xdf, 0x76, 0x0d ) );
56
57/** 64-bit RSA private key */
58ASN1 ( rsa64, &der_image_type,
59 DATA ( 0x30, 0x3e, 0x02, 0x01, 0x00, 0x02, 0x09, 0x00, 0xa1, 0xba,
60 0xb5, 0x70, 0x00, 0x89, 0xc0, 0x43, 0x02, 0x03, 0x01, 0x00,
61 0x01, 0x02, 0x08, 0x43, 0x98, 0xc6, 0x3c, 0x5f, 0xdc, 0x98,
62 0x01, 0x02, 0x05, 0x00, 0xcf, 0x91, 0x1c, 0x5d, 0x02, 0x05,
63 0x00, 0xc7, 0x77, 0x85, 0x1f, 0x02, 0x05, 0x00, 0xbc, 0xb3,
64 0x33, 0x91, 0x02, 0x04, 0x1b, 0xf9, 0x38, 0x13, 0x02, 0x04,
65 0x19, 0xf2, 0x58, 0x86 ),
66 DIGEST ( 0xee, 0x17, 0x32, 0x31, 0xf0, 0x3d, 0xfd, 0xaa, 0x9b, 0x47,
67 0xaf, 0x7b, 0x4b, 0x52, 0x0b, 0xb1, 0xab, 0x25, 0x3f, 0x11 ) );
68
69/**
70 * Perform DER self-test
71 *
72 */
73static void der_test_exec ( void ) {
74
75 /* Perform tests */
76 asn1_ok ( &rsa32 );
77 asn1_ok ( &rsa64 );
78}
79
80/** DER self-test */
81struct self_test der_test __self_test = {
82 .name = "der",
83 .exec = der_test_exec,
84};
#define DATA(...)
Define inline data.
Definition acpi_test.c:74
#define asn1_ok(test)
Report ASN.1 test result.
Definition asn1_test.h:72
#define ASN1(_name, _type, _file,...)
Define an ASN.1 test.
Definition asn1_test.h:44
Assertions.
DER image format.
static void der_test_exec(void)
Perform DER self-test.
Definition der_test.c:73
#define DIGEST(...)
Define inline expected digest.
Definition der_test.c:45
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
String functions.
A self-test set.
Definition test.h:15
Self-test infrastructure.
#define __self_test
Declare a self-test.
Definition test.h:32