diff options
author | Michael Brown <mcb30@ipxe.org> | 2024-01-30 13:26:36 +0000 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2024-01-30 13:26:36 +0000 |
commit | 17135c83fb056f93fe70bdb09dd05ecc08963eed (patch) | |
tree | 37d12a0223ff435890ce730b7467ff908963dcba /src/include/ipxe/crypto.h | |
parent | 27398f136030efb8845c45fbe154e544feefd7e5 (diff) | |
download | ipxe-17135c83fb056f93fe70bdb09dd05ecc08963eed.tar.gz |
[crypto] Add an abstraction of an elliptic curve
Define an abstraction of an elliptic curve with a fixed generator and
one supported operation (scalar multiplication of a curve point).
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/include/ipxe/crypto.h')
-rw-r--r-- | src/include/ipxe/crypto.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/include/ipxe/crypto.h b/src/include/ipxe/crypto.h index a15d5eba0..9ee1c40cb 100644 --- a/src/include/ipxe/crypto.h +++ b/src/include/ipxe/crypto.h @@ -195,6 +195,23 @@ struct pubkey_algorithm { const void *public_key, size_t public_key_len ); }; +/** An elliptic curve */ +struct elliptic_curve { + /** Curve name */ + const char *name; + /** Key size */ + size_t keysize; + /** Multiply scalar by curve point + * + * @v base Base point (or NULL to use generator) + * @v scalar Scalar multiple + * @v result Result point to fill in + * @ret rc Return status code + */ + int ( * multiply ) ( const void *base, const void *scalar, + void *result ); +}; + static inline void digest_init ( struct digest_algorithm *digest, void *ctx ) { digest->init ( ctx ); @@ -302,6 +319,12 @@ static inline int pubkey_match ( struct pubkey_algorithm *pubkey, public_key_len ); } +static inline int elliptic_multiply ( struct elliptic_curve *curve, + const void *base, const void *scalar, + void *result ) { + return curve->multiply ( base, scalar, 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 ); |