aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/crypto/weierstrass.c41
-rw-r--r--src/crypto/x25519.c16
-rw-r--r--src/include/ipxe/crypto.h14
-rw-r--r--src/include/ipxe/weierstrass.h9
-rw-r--r--src/tests/elliptic_test.c33
-rw-r--r--src/tests/elliptic_test.h58
-rw-r--r--src/tests/p256_test.c81
-rw-r--r--src/tests/p384_test.c113
8 files changed, 363 insertions, 2 deletions
diff --git a/src/crypto/weierstrass.c b/src/crypto/weierstrass.c
index ecc9699..b19970c 100644
--- a/src/crypto/weierstrass.c
+++ b/src/crypto/weierstrass.c
@@ -953,3 +953,44 @@ int weierstrass_multiply ( struct weierstrass_curve *curve, const void *base,
return 0;
}
+
+/**
+ * Add curve points (as a one-off operation)
+ *
+ * @v curve Weierstrass curve
+ * @v addend Curve point to add
+ * @v augend Curve point to add
+ * @v result Curve point to hold result
+ * @ret rc Return status code
+ */
+int weierstrass_add_once ( struct weierstrass_curve *curve, const void *addend,
+ const void *augend, void *result ) {
+ unsigned int size = curve->size;
+ struct {
+ weierstrass_t ( size ) addend;
+ weierstrass_t ( size ) augend;
+ weierstrass_t ( size ) result;
+ } temp;
+ int rc;
+
+ /* Convert inputs to projective coordinates in Montgomery form */
+ if ( ( rc = weierstrass_init ( curve, &temp.addend, &temp.result,
+ addend ) ) != 0 ) {
+ return rc;
+ }
+ if ( ( rc = weierstrass_init ( curve, &temp.augend, &temp.result,
+ augend ) ) != 0 ) {
+ return rc;
+ }
+
+ /* Add curve points */
+ weierstrass_add ( curve, &temp.augend, &temp.addend, &temp.result );
+
+ /* Convert result back to affine co-ordinates */
+ if ( ( rc = weierstrass_done ( curve, &temp.result, &temp.addend,
+ result ) ) != 0 ) {
+ return rc;
+ }
+
+ return 0;
+}
diff --git a/src/crypto/x25519.c b/src/crypto/x25519.c
index 00a7918..11094ba 100644
--- a/src/crypto/x25519.c
+++ b/src/crypto/x25519.c
@@ -833,6 +833,21 @@ static int x25519_curve_multiply ( const void *base, const void *scalar,
return x25519_key ( base, scalar, result );
}
+/**
+ * Add curve points (as a one-off operation)
+ *
+ * @v addend Curve point to add
+ * @v augend Curve point to add
+ * @v result Curve point to hold result
+ * @ret rc Return status code
+ */
+static int x25519_curve_add ( const void *addend __unused,
+ const void *augend __unused,
+ void *result __unused ) {
+
+ return -ENOTTY;
+}
+
/** X25519 elliptic curve */
struct elliptic_curve x25519_curve = {
.name = "x25519",
@@ -840,4 +855,5 @@ struct elliptic_curve x25519_curve = {
.keysize = sizeof ( struct x25519_value ),
.base = x25519_generator.raw,
.multiply = x25519_curve_multiply,
+ .add = x25519_curve_add,
};
diff --git a/src/include/ipxe/crypto.h b/src/include/ipxe/crypto.h
index 8941ffa..93b718e 100644
--- a/src/include/ipxe/crypto.h
+++ b/src/include/ipxe/crypto.h
@@ -194,6 +194,14 @@ struct elliptic_curve {
*/
int ( * multiply ) ( const void *base, const void *scalar,
void *result );
+ /** Add curve points (as a one-off operation)
+ *
+ * @v addend Curve point to add
+ * @v augend Curve point to add
+ * @v result Curve point to hold result
+ * @ret rc Return status code
+ */
+ int ( * add ) ( const void *addend, const void *augend, void *result );
};
static inline __attribute__ (( always_inline )) void
@@ -305,6 +313,12 @@ elliptic_multiply ( struct elliptic_curve *curve,
return curve->multiply ( base, scalar, result );
}
+static inline __attribute__ (( always_inline )) int
+elliptic_add ( struct elliptic_curve *curve, const void *addend,
+ const void *augend, void *result ) {
+ return curve->add ( addend, augend, result );
+}
+
extern void digest_null_init ( void *ctx );
extern void digest_null_update ( void *ctx, const void *src, size_t len );
extern void digest_null_final ( void *ctx, void *out );
diff --git a/src/include/ipxe/weierstrass.h b/src/include/ipxe/weierstrass.h
index b718886..ca3c216 100644
--- a/src/include/ipxe/weierstrass.h
+++ b/src/include/ipxe/weierstrass.h
@@ -126,6 +126,9 @@ struct weierstrass_curve {
extern int weierstrass_multiply ( struct weierstrass_curve *curve,
const void *base, const void *scalar,
void *result );
+extern int weierstrass_add_once ( struct weierstrass_curve *curve,
+ const void *addend, const void *augend,
+ void *result );
/** Define a Weierstrass curve */
#define WEIERSTRASS_CURVE( _name, _curve, _len, _prime, _a, _b, _base, \
@@ -157,6 +160,11 @@ extern int weierstrass_multiply ( struct weierstrass_curve *curve,
return weierstrass_multiply ( &_name ## _weierstrass, \
base, scalar, result ); \
} \
+ static int _name ## _add ( const void *addend, \
+ const void *augend, void *result) { \
+ return weierstrass_add_once ( &_name ## _weierstrass, \
+ addend, augend, result ); \
+ } \
struct elliptic_curve _curve = { \
.name = #_name, \
.pointsize = ( WEIERSTRASS_AXES * (_len) ), \
@@ -164,6 +172,7 @@ extern int weierstrass_multiply ( struct weierstrass_curve *curve,
.base = (_base), \
.order = (_order), \
.multiply = _name ## _multiply, \
+ .add = _name ## _add, \
}
#endif /* _IPXE_WEIERSTRASS_H */
diff --git a/src/tests/elliptic_test.c b/src/tests/elliptic_test.c
index a226662..5b21ee0 100644
--- a/src/tests/elliptic_test.c
+++ b/src/tests/elliptic_test.c
@@ -118,3 +118,36 @@ void elliptic_multiply_okx ( struct elliptic_multiply_test *test,
okx ( memcmp ( actual, test->expected, test->expected_len ) == 0,
file, line );
}
+
+/**
+ * Report elliptic curve point addition test result
+ *
+ * @v test Elliptic curve point addition test
+ * @v file Test code file
+ * @v line Test code line
+ */
+void elliptic_add_okx ( struct elliptic_add_test *test,
+ const char *file, unsigned int line ) {
+ struct elliptic_curve *curve = test->curve;
+ size_t pointsize = curve->pointsize;
+ uint8_t actual[pointsize];
+ int rc;
+
+ /* Sanity checks */
+ okx ( test->addend_len == pointsize, file, line );
+ okx ( test->augend_len == pointsize, file, line );
+ okx ( ( test->expected_len == pointsize ) || ( ! test->expected_len ),
+ file, line );
+
+ /* Perform point addition */
+ rc = elliptic_add ( curve, test->addend, test->augend, actual );
+ if ( test->expected_len ) {
+ okx ( rc == 0, file, line );
+ } else {
+ okx ( rc != 0, file, line );
+ }
+
+ /* Check expected result */
+ okx ( memcmp ( actual, test->expected, test->expected_len ) == 0,
+ file, line );
+}
diff --git a/src/tests/elliptic_test.h b/src/tests/elliptic_test.h
index 1fcc4b1..eab242f 100644
--- a/src/tests/elliptic_test.h
+++ b/src/tests/elliptic_test.h
@@ -25,6 +25,24 @@ struct elliptic_multiply_test {
size_t expected_len;
};
+/** An elliptic curve point addition test */
+struct elliptic_add_test {
+ /** Elliptic curve */
+ struct elliptic_curve *curve;
+ /** Addend point */
+ const void *addend;
+ /** Length of addend point */
+ size_t addend_len;
+ /** Augend point */
+ const void *augend;
+ /** Length of augend point */
+ size_t augend_len;
+ /** Expected result point */
+ const void *expected;
+ /** Length of expected result point (or 0 to expect failure) */
+ size_t expected_len;
+};
+
/** Define inline base point */
#define BASE(...) { __VA_ARGS__ }
@@ -34,6 +52,12 @@ struct elliptic_multiply_test {
/** Define inline scalar multiple */
#define SCALAR(...) { __VA_ARGS__ }
+/** Define inline addend point */
+#define ADDEND(...) { __VA_ARGS__ }
+
+/** Define inline augend point */
+#define AUGEND(...) { __VA_ARGS__ }
+
/** Define inline expected result point */
#define EXPECTED(...) { __VA_ARGS__ }
@@ -64,10 +88,36 @@ struct elliptic_multiply_test {
.expected_len = sizeof ( name ## _expected ), \
};
+/**
+ * Define an elliptic curve point addition test
+ *
+ * @v name Test name
+ * @v CURVE Elliptic curve
+ * @v ADDEND Addend point
+ * @v AUGEND Augend point
+ * @v EXPECTED Expected result point
+ * @ret test Elliptic curve point multiplication test
+ */
+#define ELLIPTIC_ADD_TEST( name, CURVE, ADDEND, AUGEND, EXPECTED ) \
+ static const uint8_t name ## _addend[] = ADDEND; \
+ static const uint8_t name ## _augend[] = AUGEND; \
+ static const uint8_t name ## _expected[] = EXPECTED; \
+ static struct elliptic_add_test name = { \
+ .curve = CURVE, \
+ .addend = name ## _addend, \
+ .addend_len = sizeof ( name ## _addend ), \
+ .augend = name ## _augend, \
+ .augend_len = sizeof ( name ## _augend ), \
+ .expected = name ## _expected, \
+ .expected_len = sizeof ( name ## _expected ), \
+ };
+
extern void elliptic_curve_okx ( struct elliptic_curve *curve,
const char *file, unsigned int line );
extern void elliptic_multiply_okx ( struct elliptic_multiply_test *test,
const char *file, unsigned int line );
+extern void elliptic_add_okx ( struct elliptic_add_test *test,
+ const char *file, unsigned int line );
/**
* Report an elliptic curve sanity test result
@@ -85,4 +135,12 @@ extern void elliptic_multiply_okx ( struct elliptic_multiply_test *test,
#define elliptic_multiply_ok( test ) \
elliptic_multiply_okx ( test, __FILE__, __LINE__ )
+/**
+ * Report an elliptic curve point addition test result
+ *
+ * @v test Elliptic curve point addition test
+ */
+#define elliptic_add_ok( test ) \
+ elliptic_add_okx ( test, __FILE__, __LINE__ )
+
#endif /* _ELLIPTIC_TEST_H */
diff --git a/src/tests/p256_test.c b/src/tests/p256_test.c
index 8b425f2..b7bbe47 100644
--- a/src/tests/p256_test.c
+++ b/src/tests/p256_test.c
@@ -151,6 +151,80 @@ ELLIPTIC_MULTIPLY_TEST ( invalid_one, &p256_curve,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ),
EXPECTED_FAIL );
+/* http://point-at-infinity.org/ecc/nisttv k=2 + k=2 => k=4 */
+ELLIPTIC_ADD_TEST ( poi_2_2_4, &p256_curve,
+ ADDEND ( 0x7c, 0xf2, 0x7b, 0x18, 0x8d, 0x03, 0x4f, 0x7e,
+ 0x8a, 0x52, 0x38, 0x03, 0x04, 0xb5, 0x1a, 0xc3,
+ 0xc0, 0x89, 0x69, 0xe2, 0x77, 0xf2, 0x1b, 0x35,
+ 0xa6, 0x0b, 0x48, 0xfc, 0x47, 0x66, 0x99, 0x78,
+ 0x07, 0x77, 0x55, 0x10, 0xdb, 0x8e, 0xd0, 0x40,
+ 0x29, 0x3d, 0x9a, 0xc6, 0x9f, 0x74, 0x30, 0xdb,
+ 0xba, 0x7d, 0xad, 0xe6, 0x3c, 0xe9, 0x82, 0x29,
+ 0x9e, 0x04, 0xb7, 0x9d, 0x22, 0x78, 0x73, 0xd1 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/nisttv k=1 + k=n-1 => infinity */
+ELLIPTIC_ADD_TEST ( poi_1_n_1, &p256_curve,
+ ADDEND ( 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47,
+ 0xf8, 0xbc, 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2,
+ 0x77, 0x03, 0x7d, 0x81, 0x2d, 0xeb, 0x33, 0xa0,
+ 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
+ 0x4f, 0xe3, 0x42, 0xe2, 0xfe, 0x1a, 0x7f, 0x9b,
+ 0x8e, 0xe7, 0xeb, 0x4a, 0x7c, 0x0f, 0x9e, 0x16,
+ 0x2b, 0xce, 0x33, 0x57, 0x6b, 0x31, 0x5e, 0xce,
+ 0xcb, 0xb6, 0x40, 0x68, 0x37, 0xbf, 0x51, 0xf5 ),
+ AUGEND ( 0x6b, 0x17, 0xd1, 0xf2, 0xe1, 0x2c, 0x42, 0x47,
+ 0xf8, 0xbc, 0xe6, 0xe5, 0x63, 0xa4, 0x40, 0xf2,
+ 0x77, 0x03, 0x7d, 0x81, 0x2d, 0xeb, 0x33, 0xa0,
+ 0xf4, 0xa1, 0x39, 0x45, 0xd8, 0x98, 0xc2, 0x96,
+ 0xb0, 0x1c, 0xbd, 0x1c, 0x01, 0xe5, 0x80, 0x65,
+ 0x71, 0x18, 0x14, 0xb5, 0x83, 0xf0, 0x61, 0xe9,
+ 0xd4, 0x31, 0xcc, 0xa9, 0x94, 0xce, 0xa1, 0x31,
+ 0x34, 0x49, 0xbf, 0x97, 0xc8, 0x40, 0xae, 0x0a ),
+ EXPECTED_FAIL );
+
/**
* Perform P-256 self-test
*
@@ -160,7 +234,7 @@ static void p256_test_exec ( void ) {
/* Curve sanity test */
elliptic_curve_ok ( &p256_curve );
- /* Tests from http://point-at-infinity.org/ecc/nisttv */
+ /* Multiplication tests from http://point-at-infinity.org/ecc/nisttv */
elliptic_multiply_ok ( &poi_1 );
elliptic_multiply_ok ( &poi_2 );
elliptic_multiply_ok ( &poi_2_20 );
@@ -170,6 +244,11 @@ static void p256_test_exec ( void ) {
/* Invalid point tests */
elliptic_multiply_ok ( &invalid_zero );
elliptic_multiply_ok ( &invalid_one );
+
+ /* Addition tests from http://point-at-infinity.org/ecc/nisttv */
+ elliptic_add_ok ( &poi_2_2_4 );
+ elliptic_add_ok ( &poi_3_5_8 );
+ elliptic_add_ok ( &poi_1_n_1 );
}
/** P-256 self-test */
diff --git a/src/tests/p384_test.c b/src/tests/p384_test.c
index 0b172c6..c67cfbc 100644
--- a/src/tests/p384_test.c
+++ b/src/tests/p384_test.c
@@ -197,6 +197,112 @@ ELLIPTIC_MULTIPLY_TEST ( invalid_one, &p384_curve,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ),
EXPECTED_FAIL );
+/* http://point-at-infinity.org/ecc/nisttv k=2 + k=2 => k=4 */
+ELLIPTIC_ADD_TEST ( poi_2_2_4, &p384_curve,
+ ADDEND ( 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, 0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b, 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 ),
+ EXPECTED_FAIL );
+
/**
* Perform P-384 self-test
*
@@ -206,7 +312,7 @@ static void p384_test_exec ( void ) {
/* Curve sanity test */
elliptic_curve_ok ( &p384_curve );
- /* Tests from http://point-at-infinity.org/ecc/nisttv */
+ /* Multiplication tests from http://point-at-infinity.org/ecc/nisttv */
elliptic_multiply_ok ( &poi_1 );
elliptic_multiply_ok ( &poi_2 );
elliptic_multiply_ok ( &poi_2_20 );
@@ -216,6 +322,11 @@ static void p384_test_exec ( void ) {
/* Invalid point tests */
elliptic_multiply_ok ( &invalid_zero );
elliptic_multiply_ok ( &invalid_one );
+
+ /* Addition tests from http://point-at-infinity.org/ecc/nisttv */
+ elliptic_add_ok ( &poi_2_2_4 );
+ elliptic_add_ok ( &poi_3_5_8 );
+ elliptic_add_ok ( &poi_1_n_1 );
}
/** P-384 self-test */