|
iPXE
|
RSA public-key cryptography. More...
#include <byteswap.h>#include <stdint.h>#include <stdlib.h>#include <stdarg.h>#include <string.h>#include <strings.h>#include <errno.h>#include <ipxe/asn1.h>#include <ipxe/crypto.h>#include <ipxe/bigint.h>#include <ipxe/random_nz.h>#include <ipxe/rsa.h>Go to the source code of this file.
Data Structures | |
| struct | rsa_context |
| An RSA context. More... | |
Macros | |
| #define | EACCES_VERIFY __einfo_error ( EINFO_EACCES_VERIFY ) |
| #define | EINFO_EACCES_VERIFY __einfo_uniqify ( EINFO_EACCES, 0x01, "RSA signature incorrect" ) |
Typedefs | |
| typedef int | rsa_encode_t(struct rsa_context *context, struct digest_algorithm *digest, const void *value, const void *reference, void *encoded) |
| Encode digest. | |
Functions | |
| FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
| FILE_SECBOOT (PERMITTED) | |
| static struct rsa_digestinfo_prefix * | rsa_find_prefix (struct digest_algorithm *digest) |
| Identify RSA prefix. | |
| static void | rsa_free (struct rsa_context *context) |
| Free RSA dynamic storage. | |
| static int | rsa_alloc (struct rsa_context *context, size_t modulus_len, size_t exponent_len) |
| Allocate RSA dynamic storage. | |
| static int | rsa_parse_mod_exp (struct asn1_cursor *modulus, struct asn1_cursor *exponent, const struct asn1_cursor *raw) |
| Parse RSA modulus and exponent. | |
| static int | rsa_init (struct rsa_context *context, const struct asn1_cursor *key) |
| Initialise RSA cipher. | |
| static int | rsa_cipher (struct rsa_context *context, const void *in, void *out) |
| Perform RSA cipher operation. | |
| static int | rsa_pkcs1_encrypt (struct pubkey_algorithm *pubkey __unused, const struct asn1_cursor *key, const struct asn1_cursor *plaintext, struct asn1_builder *ciphertext) |
| Encrypt using RSA PKCS#1. | |
| static int | rsa_pkcs1_decrypt (struct pubkey_algorithm *pubkey __unused, const struct asn1_cursor *key, const struct asn1_cursor *ciphertext, struct asn1_builder *plaintext) |
| Decrypt using RSA PKCS#1. | |
| static int | rsa_pkcs1_encode (struct rsa_context *context, struct digest_algorithm *digest, const void *value, const void *reference __unused, void *encoded) |
| Encode digest using RSA PKCS#1. | |
| static void | rsa_xor_mask (struct digest_algorithm *digest, void *ctx, void *out, const void *seed, void *xor, size_t len) |
| Apply RSA PSS mask generation function. | |
| static int | rsa_pss_encode (struct rsa_context *context, struct digest_algorithm *digest, const void *value, const void *reference, void *encoded) |
| Encode digest using RSA PSS. | |
| static int | rsa_sign (struct pubkey_algorithm *pubkey, const struct asn1_cursor *key, struct digest_algorithm *digest, const void *value, struct asn1_builder *signature) |
| Sign digest value using RSA. | |
| static int | rsa_verify (struct pubkey_algorithm *pubkey, const struct asn1_cursor *key, struct digest_algorithm *digest, const void *value, const struct asn1_cursor *signature) |
| Verify signed digest value using RSA. | |
| static int | rsa_match (struct pubkey_algorithm *pubkey __unused, const struct asn1_cursor *private_key, const struct asn1_cursor *public_key) |
| Check for matching RSA public/private key pair. | |
| REQUIRING_SYMBOL (rsa_algorithm) | |
| REQUIRE_OBJECT (config_crypto) | |
Variables | |
| int(* | rsa_get_random )(void *data, size_t len) = get_random_nz |
| Generate random data. | |
| struct pubkey_algorithm | rsa_algorithm |
| RSA public-key algorithm. | |
| struct pubkey_algorithm | rsa_pss_algorithm |
| RSA-PSS public-key algorithm. | |
RSA public-key cryptography.
RSA is documented in RFC 3447 and updated in RFC 8017.
Definition in file rsa.c.
| #define EACCES_VERIFY __einfo_error ( EINFO_EACCES_VERIFY ) |
Definition at line 48 of file rsa.c.
Referenced by rsa_verify().
| #define EINFO_EACCES_VERIFY __einfo_uniqify ( EINFO_EACCES, 0x01, "RSA signature incorrect" ) |
| typedef int rsa_encode_t(struct rsa_context *context, struct digest_algorithm *digest, const void *value, const void *reference, void *encoded) |
| FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
| FILE_SECBOOT | ( | PERMITTED | ) |
|
static |
Identify RSA prefix.
| digest | Digest algorithm |
| prefix | RSA prefix, or NULL |
Definition at line 102 of file rsa.c.
References rsa_digestinfo_prefix::digest, for_each_table_entry, NULL, prefix, and RSA_DIGESTINFO_PREFIXES.
Referenced by rsa_pkcs1_encode().
|
inlinestatic |
Free RSA dynamic storage.
| context | RSA context |
Definition at line 117 of file rsa.c.
References rsa_context::dynamic, and zfree().
Referenced by rsa_init(), rsa_pkcs1_decrypt(), rsa_pkcs1_encrypt(), rsa_sign(), and rsa_verify().
|
static |
Allocate RSA dynamic storage.
| context | RSA context |
| modulus_len | Modulus length |
| exponent_len | Exponent length |
| rc | Return status code |
Definition at line 130 of file rsa.c.
References __attribute__, bigint_mod_exp_tmp_len, bigint_required_size, bigint_t, rsa_context::dynamic, ENOMEM, rsa_context::exponent0, rsa_context::exponent_size, rsa_context::input0, malloc(), rsa_context::max_len, rsa_context::modulus0, rsa_context::output0, rsa_context::size, size, rsa_context::tmp, and tmp.
Referenced by rsa_init().
|
static |
Parse RSA modulus and exponent.
| modulus | Modulus to fill in |
| exponent | Exponent to fill in |
| raw | ASN.1 cursor |
| rc | Return status code |
Definition at line 171 of file rsa.c.
References asn1_check_algorithm(), asn1_enter(), asn1_enter_bits(), asn1_enter_unsigned(), ASN1_INTEGER, ASN1_OCTET_STRING, ASN1_SEQUENCE, asn1_skip(), asn1_skip_any(), asn1_type(), memcpy(), NULL, raw, and rc.
Referenced by rsa_init(), and rsa_match().
|
static |
Initialise RSA cipher.
| context | RSA context |
| key | Key |
| rc | Return status code |
Definition at line 248 of file rsa.c.
References bigint_init, bigint_t, asn1_cursor::data, DBGC, DBGC_HDA, EINVAL, rsa_context::exponent0, rsa_context::exponent_size, fls, key, asn1_cursor::len, rsa_context::mask, memset(), rsa_context::modulus0, rc, rsa_alloc(), rsa_free(), rsa_parse_mod_exp(), and rsa_context::size.
Referenced by rsa_pkcs1_decrypt(), rsa_pkcs1_encrypt(), rsa_sign(), and rsa_verify().
|
static |
Perform RSA cipher operation.
| canonical | Input was in canonical form |
Definition at line 306 of file rsa.c.
References bigint_done, bigint_init, bigint_is_geq, bigint_mod_exp, bigint_t, rsa_context::exponent0, rsa_context::exponent_size, in, rsa_context::input0, rsa_context::max_len, rsa_context::modulus0, out, rsa_context::output0, rsa_context::size, and rsa_context::tmp.
Referenced by rsa_pkcs1_decrypt(), rsa_pkcs1_encrypt(), rsa_sign(), and rsa_verify().
|
static |
Encrypt using RSA PKCS#1.
| pubkey | Public-key algorithm |
| key | Key |
| plaintext | Plaintext |
| ciphertext | Ciphertext |
| ciphertext_len | Length of ciphertext, or negative error |
Definition at line 338 of file rsa.c.
References __unused, asn1_grow(), assert, asn1_builder::data, asn1_cursor::data, DBGC, DBGC_HDA, key, asn1_cursor::len, rsa_context::max_len, memcpy(), rsa_context::output0, rc, rsa_cipher(), rsa_free(), rsa_get_random, rsa_init(), and strerror().
|
static |
Decrypt using RSA PKCS#1.
| pubkey | Public-key algorithm |
| key | Key |
| ciphertext | Ciphertext |
| plaintext | Plaintext |
| rc | Return status code |
Definition at line 417 of file rsa.c.
References __unused, asn1_grow(), asn1_builder::data, asn1_cursor::data, DBGC, DBGC_HDA, EINVAL, end, ERANGE, rsa_context::input0, key, asn1_cursor::len, len, rsa_context::max_len, memchr(), memcpy(), pad, rc, rsa_cipher(), rsa_free(), rsa_init(), and start.
|
static |
Encode digest using RSA PKCS#1.
| context | RSA context |
| digest | Digest algorithm |
| value | Digest value |
| reference | Reference encoded digest (or NULL) |
| encoded | Encoded digest |
| rc | Return status code |
Definition at line 514 of file rsa.c.
References __unused, assert, DBGC, DBGC_HDA, rsa_digestinfo_prefix::digest, digest_algorithm::digestsize, ENOTSUP, ERANGE, rsa_context::max_len, memcpy(), memset(), digest_algorithm::name, prefix, rsa_find_prefix(), and value.
|
static |
Apply RSA PSS mask generation function.
| digest | Digest algorithm |
| ctx | Digest context buffer |
| out | Digest output buffer |
| seed | Mask seed |
| xor | XOR buffer |
| len | Length of XOR buffer |
Definition at line 576 of file rsa.c.
References ctx, rsa_digestinfo_prefix::digest, digest_final(), digest_init(), digest_update(), digest_algorithm::digestsize, htonl, len, ntohl, out, and xor().
Referenced by rsa_pss_encode().
|
static |
Encode digest using RSA PSS.
| context | RSA context |
| digest | Digest algorithm |
| value | Digest value |
| reference | Reference encoded digest (or NULL) |
| encoded | Encoded digest |
| rc | Return status code |
Definition at line 612 of file rsa.c.
References assert, ctx, digest_algorithm::ctxsize, DBGC, DBGC_HDA, rsa_digestinfo_prefix::digest, digest_final(), digest_init(), digest_update(), digest_algorithm::digestsize, ERANGE, hash, head, rsa_context::mask, rsa_context::max_len, memcpy(), memset(), digest_algorithm::name, out, rc, rsa_get_random, rsa_xor_mask(), strerror(), and value.
|
static |
Sign digest value using RSA.
| pubkey | Public-key algorithm |
| key | Key |
| digest | Digest algorithm |
| value | Digest value |
| signature | Signature |
| rc | Return status code |
Definition at line 697 of file rsa.c.
References asn1_grow(), assert, DBGC, DBGC_HDA, digest_algorithm::digestsize, key, rsa_context::max_len, digest_algorithm::name, NULL, pubkey_algorithm::priv, rc, rsa_cipher(), rsa_free(), rsa_init(), signature, and value.
|
static |
Verify signed digest value using RSA.
| pubkey | Public-key algorithm |
| key | Key |
| digest | Digest algorithm |
| value | Digest value |
| signature | Signature |
| rc | Return status code |
Definition at line 751 of file rsa.c.
References DBGC, DBGC_HDA, digest_algorithm::digestsize, EACCES_VERIFY, ERANGE, rsa_context::input0, key, rsa_context::max_len, memcmp(), digest_algorithm::name, rsa_context::output0, pubkey_algorithm::priv, rc, rsa_cipher(), rsa_free(), rsa_init(), signature, and value.
|
static |
Check for matching RSA public/private key pair.
| pubkey | Public-key algorithm |
| private_key | Private key |
| public_key | Public key |
| rc | Return status code |
Definition at line 836 of file rsa.c.
References __unused, asn1_compare(), ENOTTY, rc, and rsa_parse_mod_exp().
| REQUIRING_SYMBOL | ( | rsa_algorithm | ) |
References rsa_algorithm.
| REQUIRE_OBJECT | ( | config_crypto | ) |
| int(* rsa_get_random) (void *data, size_t len) | ( | void * | data, |
| size_t | len ) = get_random_nz |
Generate random data.
Definition at line 93 of file rsa.c.
Referenced by rsa_pkcs1_encrypt(), rsa_pss_encode(), and rsa_test_exec().
| struct pubkey_algorithm rsa_algorithm |
RSA public-key algorithm.
Definition at line 861 of file rsa.c.
Referenced by __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), __tls_cipher_suite(), icert_cert(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), and REQUIRING_SYMBOL().
| struct pubkey_algorithm rsa_pss_algorithm |
RSA-PSS public-key algorithm.
Definition at line 872 of file rsa.c.
Referenced by PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), PUBKEY_TEST(), and PUBKEY_TEST().