|
iPXE
|
Elliptic curve digital signature algorithm (ECDSA). More...
#include <stdlib.h>#include <errno.h>#include <string.h>#include <ipxe/crypto.h>#include <ipxe/bigint.h>#include <ipxe/hmac_drbg.h>#include <ipxe/ecdsa.h>Go to the source code of this file.
Data Structures | |
| struct | ecdsa_key |
| An ECDSA key. More... | |
| struct | ecdsa_context |
| ECDSA context. More... | |
Macros | |
| #define | EINVAL_POINTSIZE __einfo_error ( EINFO_EINVAL_POINTSIZE ) |
| #define | EINFO_EINVAL_POINTSIZE __einfo_uniqify ( EINFO_EINVAL, 0x01, "Invalid point size" ) |
| #define | EINVAL_KEYSIZE __einfo_error ( EINFO_EINVAL_KEYSIZE ) |
| #define | EINFO_EINVAL_KEYSIZE __einfo_uniqify ( EINFO_EINVAL, 0x02, "Invalid key size" ) |
| #define | EINVAL_COMPRESSION __einfo_error ( EINFO_EINVAL_COMPRESSION ) |
| #define | EINFO_EINVAL_COMPRESSION __einfo_uniqify ( EINFO_EINVAL, 0x03, "Invalid compression") |
| #define | EINVAL_INFINITY __einfo_error ( EINFO_EINVAL_INFINITY ) |
| #define | EINFO_EINVAL_INFINITY __einfo_uniqify ( EINFO_EINVAL, 0x04, "Point is infinity" ) |
| #define | EINVAL_SIGNATURE __einfo_error ( EINFO_EINVAL_SIGNATURE ) |
| #define | EINFO_EINVAL_SIGNATURE __einfo_uniqify ( EINFO_EINVAL, 0x05, "Invalid signature" ) |
Functions | |
| FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
| FILE_SECBOOT (PERMITTED) | |
| static int | ecdsa_parse_key (struct ecdsa_key *key, const struct asn1_cursor *raw) |
| Parse ECDSA key. | |
| static int | ecdsa_parse_signature (struct ecdsa_context *ctx, bigint_element_t *rs0, const struct asn1_cursor *raw) |
| Parse ECDSA signature value. | |
| static int | ecdsa_prepend_signature (struct ecdsa_context *ctx, bigint_element_t *rs0, struct asn1_builder *builder) |
| Prepend ECDSA signature value. | |
| static int | ecdsa_alloc (struct ecdsa_context *ctx) |
| Allocate ECDSA context dynamic storage. | |
| static void | ecdsa_free (struct ecdsa_context *ctx) |
| Free ECDSA context dynamic storage. | |
| static void | ecdsa_init_values (struct ecdsa_context *ctx, struct digest_algorithm *digest, const void *value) |
| Initialise ECDSA values. | |
| static int | ecdsa_init (struct ecdsa_context *ctx, const struct asn1_cursor *key, struct digest_algorithm *digest, const void *value) |
| Initialise ECDSA context. | |
| static void | ecdsa_invert (struct ecdsa_context *ctx, bigint_element_t *val0) |
| Invert ECDSA value. | |
| static int | ecdsa_sign_rs (struct ecdsa_context *ctx) |
| Generate ECDSA "r" and "s" values. | |
| static int | ecdsa_verify_rs (struct ecdsa_context *ctx) |
| Verify ECDSA "r" and "s" values. | |
| static int | ecdsa_sign (struct pubkey_algorithm *pubkey __unused, const struct asn1_cursor *key, struct digest_algorithm *digest, const void *value, struct asn1_builder *signature) |
| Sign digest value using ECDSA. | |
| static int | ecdsa_verify (struct pubkey_algorithm *pubkey __unused, const struct asn1_cursor *key, struct digest_algorithm *digest, const void *value, const struct asn1_cursor *signature) |
| Verify signed digest using ECDSA. | |
| static int | ecdsa_match (struct pubkey_algorithm *pubkey __unused, const struct asn1_cursor *private_key, const struct asn1_cursor *public_key) |
| Check for matching ECDSA public/private key pair. | |
Variables | |
| static uint8_t | oid_ecpublickey [] = { ASN1_OID_ECPUBLICKEY } |
| "ecPublicKey" object identifier | |
| struct asn1_algorithm ecpubkey_algorithm | __asn1_algorithm |
| Generic elliptic curve container algorithm. | |
| struct pubkey_algorithm | ecdsa_algorithm |
| ECDSA public-key algorithm. | |
Elliptic curve digital signature algorithm (ECDSA).
The elliptic curve public key format is documented in RFC 5480. The original private key format is documented in RFC 5915, and the generic container PKCS#8 format documented in RFC 5208.
Definition in file ecdsa.c.
| #define EINVAL_POINTSIZE __einfo_error ( EINFO_EINVAL_POINTSIZE ) |
Definition at line 46 of file ecdsa.c.
Referenced by ecdsa_parse_key().
| #define EINFO_EINVAL_POINTSIZE __einfo_uniqify ( EINFO_EINVAL, 0x01, "Invalid point size" ) |
| #define EINVAL_KEYSIZE __einfo_error ( EINFO_EINVAL_KEYSIZE ) |
Definition at line 50 of file ecdsa.c.
Referenced by ecdsa_parse_key(), and ecdsa_parse_signature().
| #define EINFO_EINVAL_KEYSIZE __einfo_uniqify ( EINFO_EINVAL, 0x02, "Invalid key size" ) |
| #define EINVAL_COMPRESSION __einfo_error ( EINFO_EINVAL_COMPRESSION ) |
Definition at line 54 of file ecdsa.c.
Referenced by ecdsa_parse_key().
| #define EINFO_EINVAL_COMPRESSION __einfo_uniqify ( EINFO_EINVAL, 0x03, "Invalid compression") |
| #define EINVAL_INFINITY __einfo_error ( EINFO_EINVAL_INFINITY ) |
Definition at line 58 of file ecdsa.c.
Referenced by ecdsa_parse_key().
| #define EINFO_EINVAL_INFINITY __einfo_uniqify ( EINFO_EINVAL, 0x04, "Point is infinity" ) |
| #define EINVAL_SIGNATURE __einfo_error ( EINFO_EINVAL_SIGNATURE ) |
Definition at line 62 of file ecdsa.c.
Referenced by ecdsa_verify_rs().
| #define EINFO_EINVAL_SIGNATURE __einfo_uniqify ( EINFO_EINVAL, 0x05, "Invalid signature" ) |
| FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
| FILE_SECBOOT | ( | PERMITTED | ) |
|
static |
Parse ECDSA key.
| rc | Return status code |
Definition at line 141 of file ecdsa.c.
References algorithm, asn1_curve_algorithm(), asn1_enter(), asn1_enter_any(), asn1_enter_bits(), ASN1_EXPLICIT_TAG, ASN1_INTEGER, asn1_invalidate_cursor(), ASN1_OCTET_STRING, ASN1_SEQUENCE, asn1_skip(), asn1_skip_any(), asn1_type(), asn1_cursor::data, DBGC, DBGC_HDA, ECDSA_UNCOMPRESSED, EINVAL_COMPRESSION, EINVAL_INFINITY, EINVAL_KEYSIZE, EINVAL_POINTSIZE, elliptic_is_infinity(), key, asn1_cursor::len, len, memcpy(), NULL, raw, rc, and strerror().
Referenced by ecdsa_init(), and ecdsa_match().
|
static |
Parse ECDSA signature value.
| rc | Return status code |
Definition at line 288 of file ecdsa.c.
References __attribute__, asn1_enter_unsigned(), bigint_init, bigint_is_geq, bigint_is_zero, bigint_t, ctx, asn1_cursor::data, DBGC, DBGC_HDA, EINVAL_KEYSIZE, ERANGE, keysize, asn1_cursor::len, memcpy(), raw, rc, and size.
Referenced by ecdsa_verify().
|
static |
Prepend ECDSA signature value.
| ctx | ECDSA context |
| rs0 | Element 0 of signature "r" or "s" value |
| builder | ASN.1 builder |
| rc | Return status code |
Definition at line 334 of file ecdsa.c.
References __attribute__, ASN1_INTEGER, asn1_prepend(), bigint_done, bigint_t, ctx, data, keysize, len, rc, and size.
Referenced by ecdsa_sign().
|
static |
Allocate ECDSA context dynamic storage.
| ctx | ECDSA context |
| rc | Return status code |
Definition at line 371 of file ecdsa.c.
References bigint_required_size, bigint_t, ctx, ENOMEM, k, elliptic_curve::keysize, keysize, malloc(), elliptic_curve::pointsize, product, r, and size.
Referenced by ecdsa_init().
|
static |
Free ECDSA context dynamic storage.
| ctx | ECDSA context |
Definition at line 425 of file ecdsa.c.
Referenced by ecdsa_init(), ecdsa_sign(), and ecdsa_verify().
|
static |
Initialise ECDSA values.
Definition at line 438 of file ecdsa.c.
References __attribute__, bigint_copy, bigint_grow, bigint_init, bigint_montgomery, bigint_ntoa, bigint_reduce, bigint_subtract, bigint_t, ctx, DBGC2, digest_algorithm::digestsize, elliptic_curve::keysize, digest_algorithm::name, elliptic_curve::order, product, size, and value.
Referenced by ecdsa_init().
|
static |
Initialise ECDSA context.
| rc | Return status code |
Definition at line 498 of file ecdsa.c.
References ctx, ecdsa_alloc(), ecdsa_free(), ecdsa_init_values(), ecdsa_parse_key(), key, rc, and value.
Referenced by ecdsa_sign(), and ecdsa_verify().
|
static |
Invert ECDSA value.
| ctx | ECDSA context |
| val0 | Element 0 of value to invert |
Definition at line 529 of file ecdsa.c.
References __attribute__, bigint_copy, bigint_ladder, bigint_mod_exp_ladder(), bigint_montgomery, bigint_multiply, bigint_t, ctx, product, size, and val.
Referenced by ecdsa_sign_rs(), and ecdsa_verify_rs().
|
static |
Generate ECDSA "r" and "s" values.
| rc | Return status code |
Definition at line 564 of file ecdsa.c.
References __attribute__, elliptic_curve::base, bigint_add, bigint_init, bigint_is_geq, bigint_is_zero, bigint_montgomery, bigint_multiply, bigint_ntoa, bigint_t, ctx, DBGC, DBGC2, ecdsa_invert(), elliptic_multiply(), hmac_drbg_generate(), k, elliptic_curve::keysize, keysize, NULL, elliptic_curve::pointsize, product, r, rc, size, and strerror().
Referenced by ecdsa_sign().
|
static |
Verify ECDSA "r" and "s" values.
| rc | Return status code |
Definition at line 670 of file ecdsa.c.
References __attribute__, elliptic_curve::base, bigint_done, bigint_init, bigint_is_zero, bigint_montgomery, bigint_multiply, bigint_ntoa, bigint_subtract, bigint_t, ctx, DBGC, DBGC2, ecdsa_invert(), EINVAL, EINVAL_SIGNATURE, elliptic_add(), elliptic_is_infinity(), elliptic_multiply(), elliptic_curve::keysize, keysize, elliptic_curve::pointsize, product, r, rc, size, and strerror().
Referenced by ecdsa_verify().
|
static |
Sign digest value using ECDSA.
| pubkey | Public-key algorithm |
| key | Key |
| digest | Digest algorithm |
| value | Digest value |
| signature | Signature |
| rc | Return status code |
Definition at line 778 of file ecdsa.c.
References __unused, ASN1_SEQUENCE, asn1_wrap(), ctx, ecdsa_context::digest, ecdsa_free(), ecdsa_init(), ecdsa_prepend_signature(), ecdsa_sign_rs(), ENOTTY, hmac_drbg_instantiate(), key, rc, signature, and value.
|
static |
Verify signed digest using ECDSA.
| pubkey | Public-key algorithm |
| key | Key |
| digest | Digest algorithm |
| value | Digest value |
| signature | Signature |
| rc | Return status code |
Definition at line 836 of file ecdsa.c.
References __unused, asn1_enter(), ASN1_SEQUENCE, asn1_skip_any(), ctx, ecdsa_free(), ecdsa_init(), ecdsa_parse_signature(), ecdsa_verify_rs(), key, memcpy(), rc, signature, and value.
|
static |
Check for matching ECDSA public/private key pair.
| pubkey | Public-key algorithm |
| private_key | Private key |
| public_key | Public key |
| rc | Return status code |
Definition at line 884 of file ecdsa.c.
References __unused, ecdsa_key::curve, ecdsa_parse_key(), ENOTTY, memcmp(), elliptic_curve::pointsize, ecdsa_key::private, ecdsa_key::public, and rc.
|
static |
"ecPublicKey" object identifier
Definition at line 68 of file ecdsa.c.
| struct asn1_algorithm ecpubkey_algorithm __asn1_algorithm |
Generic elliptic curve container algorithm.
The actual curve to be used is identified via the algorithm parameters, rather than the top-level OID.
| struct pubkey_algorithm ecdsa_algorithm |
ECDSA public-key algorithm.
Definition at line 911 of file ecdsa.c.
Referenced by __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), PUBKEY_SIGN_TEST(), PUBKEY_SIGN_TEST(), PUBKEY_SIGN_TEST(), and PUBKEY_SIGN_TEST().