diff options
author | Michael Brown <mcb30@ipxe.org> | 2025-01-30 15:35:34 +0000 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2025-01-30 15:35:34 +0000 |
commit | c85de315a601d95a6348c4caf5d3af6b146274b7 (patch) | |
tree | aabf897aa6df9c4cca11fa9b67f1ab7d33dde99e | |
parent | bc5f3dbe3e03bc67a846981c1fb93206f5557283 (diff) | |
download | ipxe-c85de315a601d95a6348c4caf5d3af6b146274b7.tar.gz |
[crypto] Add definitions and tests for the NIST P-384 elliptic curve
Signed-off-by: Michael Brown <mcb30@ipxe.org>
-rw-r--r-- | src/config/config_crypto.c | 5 | ||||
-rw-r--r-- | src/config/crypto.h | 3 | ||||
-rw-r--r-- | src/crypto/mishmash/oid_p384.c | 47 | ||||
-rw-r--r-- | src/crypto/p384.c | 76 | ||||
-rw-r--r-- | src/include/ipxe/asn1.h | 5 | ||||
-rw-r--r-- | src/include/ipxe/p384.h | 19 | ||||
-rw-r--r-- | src/include/ipxe/tls.h | 1 | ||||
-rw-r--r-- | src/tests/p384_test.c | 222 | ||||
-rw-r--r-- | src/tests/tests.c | 1 |
9 files changed, 379 insertions, 0 deletions
diff --git a/src/config/config_crypto.c b/src/config/config_crypto.c index 99acd3076..19d6d032e 100644 --- a/src/config/config_crypto.c +++ b/src/config/config_crypto.c @@ -93,6 +93,11 @@ REQUIRE_OBJECT ( oid_x25519 ); REQUIRE_OBJECT ( oid_p256 ); #endif +/* P-384 */ +#if defined ( CRYPTO_CURVE_P384 ) +REQUIRE_OBJECT ( oid_p384 ); +#endif + /* AES-CBC */ #if defined ( CRYPTO_CIPHER_AES_CBC ) REQUIRE_OBJECT ( oid_aes_cbc ); diff --git a/src/config/crypto.h b/src/config/crypto.h index 5e96be4aa..f2ee9fd0d 100644 --- a/src/config/crypto.h +++ b/src/config/crypto.h @@ -63,6 +63,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); /** P-256 elliptic curve */ #define CRYPTO_CURVE_P256 +/** P-384 elliptic curve */ +#define CRYPTO_CURVE_P384 + /** Margin of error (in seconds) allowed in signed timestamps * * We default to allowing a reasonable margin of error: 12 hours to diff --git a/src/crypto/mishmash/oid_p384.c b/src/crypto/mishmash/oid_p384.c new file mode 100644 index 000000000..968fb45c1 --- /dev/null +++ b/src/crypto/mishmash/oid_p384.c @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2025 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 ); + +#include <byteswap.h> +#include <ipxe/p384.h> +#include <ipxe/asn1.h> +#include <ipxe/tls.h> + +/** "secp384r1" object identifier */ +static uint8_t oid_secp384r1[] = { ASN1_OID_SECP384R1 }; + +/** "secp384r1" OID-identified algorithm */ +struct asn1_algorithm secp384r1_algorithm __asn1_algorithm = { + .name = "secp384r1", + .curve = &p384_curve, + .oid = ASN1_CURSOR ( oid_secp384r1 ), +}; + +/** P-384 named curve */ +struct tls_named_curve tls_secp384r1_named_curve __tls_named_curve ( 01 ) = { + .curve = &p384_curve, + .code = htons ( TLS_NAMED_CURVE_SECP384R1 ), + .format = TLS_POINT_FORMAT_UNCOMPRESSED, + .pre_master_secret_len = P384_LEN, +}; diff --git a/src/crypto/p384.c b/src/crypto/p384.c new file mode 100644 index 000000000..887bf161d --- /dev/null +++ b/src/crypto/p384.c @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2025 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 + * + * NIST P-384 elliptic curve + * + */ + +#include <ipxe/p384.h> + +/** P-384 field prime */ +static const uint8_t p384_prime[P384_LEN] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, + 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xff +}; + +/** P-384 constant "a" */ +static const uint8_t p384_a[P384_LEN] = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, + 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0xff, 0xff, 0xff, 0xfc +}; + +/** P-384 constant "b" */ +static const uint8_t p384_b[P384_LEN] = { + 0xb3, 0x31, 0x2f, 0xa7, 0xe2, 0x3e, 0xe7, 0xe4, 0x98, 0x8e, 0x05, + 0x6b, 0xe3, 0xf8, 0x2d, 0x19, 0x18, 0x1d, 0x9c, 0x6e, 0xfe, 0x81, + 0x41, 0x12, 0x03, 0x14, 0x08, 0x8f, 0x50, 0x13, 0x87, 0x5a, 0xc6, + 0x56, 0x39, 0x8d, 0x8a, 0x2e, 0xd1, 0x9d, 0x2a, 0x85, 0xc8, 0xed, + 0xd3, 0xec, 0x2a, 0xef +}; + +/** P-384 base point */ +static const uint8_t p384_base[ P384_LEN * 2 ] = { + 0xaa, 0x87, 0xca, 0x22, 0xbe, 0x8b, 0x05, 0x37, 0x8e, 0xb1, 0xc7, + 0x1e, 0xf3, 0x20, 0xad, 0x74, 0x6e, 0x1d, 0x3b, 0x62, 0x8b, 0xa7, + 0x9b, 0x98, 0x59, 0xf7, 0x41, 0xe0, 0x82, 0x54, 0x2a, 0x38, 0x55, + 0x02, 0xf2, 0x5d, 0xbf, 0x55, 0x29, 0x6c, 0x3a, 0x54, 0x5e, 0x38, + 0x72, 0x76, 0x0a, 0xb7, 0x36, 0x17, 0xde, 0x4a, 0x96, 0x26, 0x2c, + 0x6f, 0x5d, 0x9e, 0x98, 0xbf, 0x92, 0x92, 0xdc, 0x29, 0xf8, 0xf4, + 0x1d, 0xbd, 0x28, 0x9a, 0x14, 0x7c, 0xe9, 0xda, 0x31, 0x13, 0xb5, + 0xf0, 0xb8, 0xc0, 0x0a, 0x60, 0xb1, 0xce, 0x1d, 0x7e, 0x81, 0x9d, + 0x7a, 0x43, 0x1d, 0x7c, 0x90, 0xea, 0x0e, 0x5f +}; + +/** P-384 elliptic curve */ +WEIERSTRASS_CURVE ( p384, p384_curve, P384_LEN, + p384_prime, p384_a, p384_b, p384_base ); diff --git a/src/include/ipxe/asn1.h b/src/include/ipxe/asn1.h index d503ccf9b..8a7461cd3 100644 --- a/src/include/ipxe/asn1.h +++ b/src/include/ipxe/asn1.h @@ -198,6 +198,11 @@ struct asn1_builder_header { ASN1_OID_INITIAL ( 1, 3 ), ASN1_OID_SINGLE ( 101 ), \ ASN1_OID_SINGLE ( 110 ) +/** ASN.1 OID for secp384r1 (1.3.132.0.34) */ +#define ASN1_OID_SECP384R1 \ + ASN1_OID_INITIAL ( 1, 3 ), ASN1_OID_DOUBLE ( 132 ), \ + ASN1_OID_SINGLE ( 0 ), ASN1_OID_SINGLE ( 34 ) + /** ASN.1 OID for id-aes128-cbc (2.16.840.1.101.3.4.1.2) */ #define ASN1_OID_AES128_CBC \ ASN1_OID_INITIAL ( 2, 16 ), ASN1_OID_DOUBLE ( 840 ), \ diff --git a/src/include/ipxe/p384.h b/src/include/ipxe/p384.h new file mode 100644 index 000000000..f4631b5f2 --- /dev/null +++ b/src/include/ipxe/p384.h @@ -0,0 +1,19 @@ +#ifndef _IPXE_P384_H +#define _IPXE_P384_H + +/** @file + * + * NIST P-384 elliptic curve + * + */ + +FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); + +#include <ipxe/weierstrass.h> + +/** P-384 value length */ +#define P384_LEN ( 384 / 8 ) + +extern struct elliptic_curve p384_curve; + +#endif /* _IPXE_P384_H */ diff --git a/src/include/ipxe/tls.h b/src/include/ipxe/tls.h index 685c62e6d..7abbe4ff9 100644 --- a/src/include/ipxe/tls.h +++ b/src/include/ipxe/tls.h @@ -128,6 +128,7 @@ struct tls_header { /* TLS named curve extension */ #define TLS_NAMED_CURVE 10 #define TLS_NAMED_CURVE_SECP256R1 23 +#define TLS_NAMED_CURVE_SECP384R1 24 #define TLS_NAMED_CURVE_X25519 29 /* TLS signature algorithms extension */ diff --git a/src/tests/p384_test.c b/src/tests/p384_test.c new file mode 100644 index 000000000..101cfc24c --- /dev/null +++ b/src/tests/p384_test.c @@ -0,0 +1,222 @@ +/* + * Copyright (C) 2025 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 + * + * NIST P-384 elliptic curve self-tests + * + */ + +/* Forcibly enable assertions */ +#undef NDEBUG + +#include <ipxe/p384.h> +#include <ipxe/test.h> +#include "elliptic_test.h" + +/* http://point-at-infinity.org/ecc/nisttv k=1 */ +ELLIPTIC_TEST ( poi_1, &p384_curve, BASE_GENERATOR, + SCALAR ( 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, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ), + EXPECTED ( 0xaa, 0x87, 0xca, 0x22, 0xbe, 0x8b, 0x05, 0x37, + 0x8e, 0xb1, 0xc7, 0x1e, 0xf3, 0x20, 0xad, 0x74, + 0x6e, 0x1d, 0x3b, 0x62, 0x8b, 0xa7, 0x9b, 0x98, + 0x59, 0xf7, 0x41, 0xe0, 0x82, 0x54, 0x2a, 0x38, + 0x55, 0x02, 0xf2, 0x5d, 0xbf, 0x55, 0x29, 0x6c, + 0x3a, 0x54, 0x5e, 0x38, 0x72, 0x76, 0x0a, 0xb7, + 0x36, 0x17, 0xde, 0x4a, 0x96, 0x26, 0x2c, 0x6f, + 0x5d, 0x9e, 0x98, 0xbf, 0x92, 0x92, 0xdc, 0x29, + 0xf8, 0xf4, 0x1d, 0xbd, 0x28, 0x9a, 0x14, 0x7c, + 0xe9, 0xda, 0x31, 0x13, 0xb5, 0xf0, 0xb8, 0xc0, + 0x0a, 0x60, 0xb1, 0xce, 0x1d, 0x7e, 0x81, 0x9d, + 0x7a, 0x43, 0x1d, 0x7c, 0x90, 0xea, 0x0e, 0x5f ) ); + +/* http://point-at-infinity.org/ecc/nisttv k=2 */ +ELLIPTIC_TEST ( poi_2, &p384_curve, BASE_GENERATOR, + SCALAR ( 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, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 ), + EXPECTED ( 0x08, 0xd9, 0x99, 0x05, 0x7b, 0xa3, 0xd2, 0xd9, + 0x69, 0x26, 0x00, 0x45, 0xc5, 0x5b, 0x97, 0xf0, + 0x89, 0x02, 0x59, 0x59, 0xa6, 0xf4, 0x34, 0xd6, + 0x51, 0xd2, 0x07, 0xd1, 0x9f, 0xb9, 0x6e, 0x9e, + 0x4f, 0xe0, 0xe8, 0x6e, 0xbe, 0x0e, 0x64, 0xf8, + 0x5b, 0x96, 0xa9, 0xc7, 0x52, 0x95, 0xdf, 0x61, + 0x8e, 0x80, 0xf1, 0xfa, 0x5b, 0x1b, 0x3c, 0xed, + 0xb7, 0xbf, 0xe8, 0xdf, 0xfd, 0x6d, 0xba, 0x74, + 0xb2, 0x75, 0xd8, 0x75, 0xbc, 0x6c, 0xc4, 0x3e, + 0x90, 0x4e, 0x50, 0x5f, 0x25, 0x6a, 0xb4, 0x25, + 0x5f, 0xfd, 0x43, 0xe9, 0x4d, 0x39, 0xe2, 0x2d, + 0x61, 0x50, 0x1e, 0x70, 0x0a, 0x94, 0x0e, 0x80 ) ); + +/* http://point-at-infinity.org/ecc/nisttv k=2 (as base) to k=20 */ +ELLIPTIC_TEST ( poi_2_20, &p384_curve, + BASE ( 0x08, 0xd9, 0x99, 0x05, 0x7b, 0xa3, 0xd2, 0xd9, + 0x69, 0x26, 0x00, 0x45, 0xc5, 0x5b, 0x97, 0xf0, + 0x89, 0x02, 0x59, 0x59, 0xa6, 0xf4, 0x34, 0xd6, + 0x51, 0xd2, 0x07, 0xd1, 0x9f, 0xb9, 0x6e, 0x9e, + 0x4f, 0xe0, 0xe8, 0x6e, 0xbe, 0x0e, 0x64, 0xf8, + 0x5b, 0x96, 0xa9, 0xc7, 0x52, 0x95, 0xdf, 0x61, + 0x8e, 0x80, 0xf1, 0xfa, 0x5b, 0x1b, 0x3c, 0xed, + 0xb7, 0xbf, 0xe8, 0xdf, 0xfd, 0x6d, 0xba, 0x74, + 0xb2, 0x75, 0xd8, 0x75, 0xbc, 0x6c, 0xc4, 0x3e, + 0x90, 0x4e, 0x50, 0x5f, 0x25, 0x6a, 0xb4, 0x25, + 0x5f, 0xfd, 0x43, 0xe9, 0x4d, 0x39, 0xe2, 0x2d, + 0x61, 0x50, 0x1e, 0x70, 0x0a, 0x94, 0x0e, 0x80 ), + SCALAR ( 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, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a ), + EXPECTED ( 0x60, 0x55, 0x08, 0xec, 0x02, 0xc5, 0x34, 0xbc, + 0xee, 0xe9, 0x48, 0x4c, 0x86, 0x08, 0x6d, 0x21, + 0x39, 0x84, 0x9e, 0x2b, 0x11, 0xc1, 0xa9, 0xca, + 0x1e, 0x28, 0x08, 0xde, 0xc2, 0xea, 0xf1, 0x61, + 0xac, 0x8a, 0x10, 0x5d, 0x70, 0xd4, 0xf8, 0x5c, + 0x50, 0x59, 0x9b, 0xe5, 0x80, 0x0a, 0x62, 0x3f, + 0x51, 0x58, 0xee, 0x87, 0x96, 0x2a, 0xc6, 0xb8, + 0x1f, 0x00, 0xa1, 0x03, 0xb8, 0x54, 0x3a, 0x07, + 0x38, 0x1b, 0x76, 0x39, 0xa3, 0xa6, 0x5f, 0x13, + 0x53, 0xae, 0xf1, 0x1b, 0x73, 0x31, 0x06, 0xdd, + 0xe9, 0x2e, 0x99, 0xb7, 0x8d, 0xe3, 0x67, 0xb4, + 0x8e, 0x23, 0x8c, 0x38, 0xda, 0xd8, 0xee, 0xdd ) ); + +/* http://point-at-infinity.org/ecc/nisttv k=112233445566778899 */ +ELLIPTIC_TEST ( poi_mid, &p384_curve, BASE_GENERATOR, + SCALAR ( 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, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x01, 0x8e, 0xbb, 0xb9, 0x5e, 0xed, 0x0e, 0x13 ), + EXPECTED ( 0xa4, 0x99, 0xef, 0xe4, 0x88, 0x39, 0xbc, 0x3a, + 0xbc, 0xd1, 0xc5, 0xce, 0xdb, 0xdd, 0x51, 0x90, + 0x4f, 0x95, 0x14, 0xdb, 0x44, 0xf4, 0x68, 0x6d, + 0xb9, 0x18, 0x98, 0x3b, 0x0c, 0x9d, 0xc3, 0xae, + 0xe0, 0x5a, 0x88, 0xb7, 0x24, 0x33, 0xe9, 0x51, + 0x5f, 0x91, 0xa3, 0x29, 0xf5, 0xf4, 0xfa, 0x60, + 0x3b, 0x7c, 0xa2, 0x8e, 0xf3, 0x1f, 0x80, 0x9c, + 0x2f, 0x1b, 0xa2, 0x4a, 0xae, 0xd8, 0x47, 0xd0, + 0xf8, 0xb4, 0x06, 0xa4, 0xb8, 0x96, 0x85, 0x42, + 0xde, 0x13, 0x9d, 0xb5, 0x82, 0x8c, 0xa4, 0x10, + 0xe6, 0x15, 0xd1, 0x18, 0x2e, 0x25, 0xb9, 0x1b, + 0x11, 0x31, 0xe2, 0x30, 0xb7, 0x27, 0xd3, 0x6a ) ); + +/* http://point-at-infinity.org/ecc/nisttv k=<largest> */ +ELLIPTIC_TEST ( poi_large, &p384_curve, BASE_GENERATOR, + SCALAR ( 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xc7, 0x63, 0x4d, 0x81, 0xf4, 0x37, 0x2d, 0xdf, + 0x58, 0x1a, 0x0d, 0xb2, 0x48, 0xb0, 0xa7, 0x7a, + 0xec, 0xec, 0x19, 0x6a, 0xcc, 0xc5, 0x29, 0x72 ), + EXPECTED ( 0xaa, 0x87, 0xca, 0x22, 0xbe, 0x8b, 0x05, 0x37, + 0x8e, 0xb1, 0xc7, 0x1e, 0xf3, 0x20, 0xad, 0x74, + 0x6e, 0x1d, 0x3b, 0x62, 0x8b, 0xa7, 0x9b, 0x98, + 0x59, 0xf7, 0x41, 0xe0, 0x82, 0x54, 0x2a, 0x38, + 0x55, 0x02, 0xf2, 0x5d, 0xbf, 0x55, 0x29, 0x6c, + 0x3a, 0x54, 0x5e, 0x38, 0x72, 0x76, 0x0a, 0xb7, + 0xc9, 0xe8, 0x21, 0xb5, 0x69, 0xd9, 0xd3, 0x90, + 0xa2, 0x61, 0x67, 0x40, 0x6d, 0x6d, 0x23, 0xd6, + 0x07, 0x0b, 0xe2, 0x42, 0xd7, 0x65, 0xeb, 0x83, + 0x16, 0x25, 0xce, 0xec, 0x4a, 0x0f, 0x47, 0x3e, + 0xf5, 0x9f, 0x4e, 0x30, 0xe2, 0x81, 0x7e, 0x62, + 0x85, 0xbc, 0xe2, 0x84, 0x6f, 0x15, 0xf1, 0xa0 ) ); + +/* Invalid curve point zero */ +ELLIPTIC_TEST ( invalid_zero, &p384_curve, + BASE ( 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, + 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, + 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 ), + SCALAR ( 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, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ), + EXPECTED_FAIL ); + +/* Invalid curve point (base_x, base_y - 1) */ +ELLIPTIC_TEST ( invalid_one, &p384_curve, + BASE ( 0xaa, 0x87, 0xca, 0x22, 0xbe, 0x8b, 0x05, 0x37, + 0x8e, 0xb1, 0xc7, 0x1e, 0xf3, 0x20, 0xad, 0x74, + 0x6e, 0x1d, 0x3b, 0x62, 0x8b, 0xa7, 0x9b, 0x98, + 0x59, 0xf7, 0x41, 0xe0, 0x82, 0x54, 0x2a, 0x38, + 0x55, 0x02, 0xf2, 0x5d, 0xbf, 0x55, 0x29, 0x6c, + 0x3a, 0x54, 0x5e, 0x38, 0x72, 0x76, 0x0a, 0xb7, + 0x36, 0x17, 0xde, 0x4a, 0x96, 0x26, 0x2c, 0x6f, + 0x5d, 0x9e, 0x98, 0xbf, 0x92, 0x92, 0xdc, 0x29, + 0xf8, 0xf4, 0x1d, 0xbd, 0x28, 0x9a, 0x14, 0x7c, + 0xe9, 0xda, 0x31, 0x13, 0xb5, 0xf0, 0xb8, 0xc0, + 0x0a, 0x60, 0xb1, 0xce, 0x1d, 0x7e, 0x81, 0x9d, + 0x7a, 0x43, 0x1d, 0x7c, 0x90, 0xea, 0x0e, 0x5e ), + SCALAR ( 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, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ), + EXPECTED_FAIL ); + +/** + * Perform P-384 self-test + * + */ +static void p384_test_exec ( void ) { + + /* Tests from http://point-at-infinity.org/ecc/nisttv */ + elliptic_ok ( &poi_1 ); + elliptic_ok ( &poi_2 ); + elliptic_ok ( &poi_2_20 ); + elliptic_ok ( &poi_mid ); + elliptic_ok ( &poi_large ); + + /* Invalid point tests */ + elliptic_ok ( &invalid_zero ); + elliptic_ok ( &invalid_one ); +} + +/** P-384 self-test */ +struct self_test p384_test __self_test = { + .name = "p384", + .exec = p384_test_exec, +}; diff --git a/src/tests/tests.c b/src/tests/tests.c index a1659fb29..96687423f 100644 --- a/src/tests/tests.c +++ b/src/tests/tests.c @@ -87,3 +87,4 @@ REQUIRE_OBJECT ( mschapv2_test ); REQUIRE_OBJECT ( uuid_test ); REQUIRE_OBJECT ( editstring_test ); REQUIRE_OBJECT ( p256_test ); +REQUIRE_OBJECT ( p384_test ); |