iPXE
|
RSA public-key cryptography. More...
#include <stdint.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.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.
Macros | |
#define | EACCES_VERIFY __einfo_error ( EINFO_EACCES_VERIFY ) |
#define | EINFO_EACCES_VERIFY __einfo_uniqify ( EINFO_EACCES, 0x01, "RSA signature incorrect" ) |
Functions | |
FILE_LICENCE (GPL2_OR_LATER_OR_UBDL) | |
static struct rsa_digestinfo_prefix * | rsa_find_prefix (struct digest_algorithm *digest) |
Identify RSA prefix. More... | |
static void | rsa_free (struct rsa_context *context) |
Free RSA dynamic storage. More... | |
static int | rsa_alloc (struct rsa_context *context, size_t modulus_len, size_t exponent_len) |
Allocate RSA dynamic storage. More... | |
static int | rsa_parse_integer (struct asn1_cursor *integer, const struct asn1_cursor *raw) |
Parse RSA integer. More... | |
static int | rsa_parse_mod_exp (struct asn1_cursor *modulus, struct asn1_cursor *exponent, const struct asn1_cursor *raw) |
Parse RSA modulus and exponent. More... | |
static int | rsa_init (void *ctx, const void *key, size_t key_len) |
Initialise RSA cipher. More... | |
static size_t | rsa_max_len (void *ctx) |
Calculate RSA maximum output length. More... | |
static void | rsa_cipher (struct rsa_context *context, const void *in, void *out) |
Perform RSA cipher operation. More... | |
static int | rsa_encrypt (void *ctx, const void *plaintext, size_t plaintext_len, void *ciphertext) |
Encrypt using RSA. More... | |
static int | rsa_decrypt (void *ctx, const void *ciphertext, size_t ciphertext_len, void *plaintext) |
Decrypt using RSA. More... | |
static int | rsa_encode_digest (struct rsa_context *context, struct digest_algorithm *digest, const void *value, void *encoded) |
Encode RSA digest. More... | |
static int | rsa_sign (void *ctx, struct digest_algorithm *digest, const void *value, void *signature) |
Sign digest value using RSA. More... | |
static int | rsa_verify (void *ctx, struct digest_algorithm *digest, const void *value, const void *signature, size_t signature_len) |
Verify signed digest value using RSA. More... | |
static void | rsa_final (void *ctx) |
Finalise RSA cipher. More... | |
static int | rsa_match (const void *private_key, size_t private_key_len, const void *public_key, size_t public_key_len) |
Check for matching RSA public/private key pair. More... | |
REQUIRING_SYMBOL (rsa_algorithm) | |
REQUIRE_OBJECT (config_crypto) | |
Variables | |
struct pubkey_algorithm | rsa_algorithm |
RSA public-key algorithm. More... | |
#define EACCES_VERIFY __einfo_error ( EINFO_EACCES_VERIFY ) |
#define EINFO_EACCES_VERIFY __einfo_uniqify ( EINFO_EACCES, 0x01, "RSA signature incorrect" ) |
FILE_LICENCE | ( | GPL2_OR_LATER_OR_UBDL | ) |
|
static |
Identify RSA prefix.
digest | Digest algorithm |
prefix | RSA prefix, or NULL |
Definition at line 57 of file rsa.c.
References digest, for_each_table_entry, NULL, prefix, and RSA_DIGESTINFO_PREFIXES.
Referenced by rsa_encode_digest().
|
static |
Free RSA dynamic storage.
context | RSA context |
Definition at line 72 of file rsa.c.
References rsa_context::dynamic, free, and NULL.
Referenced by rsa_alloc(), rsa_final(), and rsa_init().
|
static |
Allocate RSA dynamic storage.
context | RSA context |
modulus_len | Modulus length |
exponent_len | Exponent length |
rc | Return status code |
Definition at line 86 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_free(), size, rsa_context::size, tmp, and rsa_context::tmp.
Referenced by rsa_init().
|
static |
Parse RSA integer.
integer | Integer to fill in |
raw | ASN.1 cursor |
rc | Return status code |
Definition at line 130 of file rsa.c.
References asn1_enter(), ASN1_INTEGER, asn1_cursor::data, EINVAL, asn1_cursor::len, memcpy(), and raw.
Referenced by rsa_parse_mod_exp().
|
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 159 of file rsa.c.
References asn1_check_algorithm(), asn1_enter(), ASN1_INTEGER, asn1_integral_bit_string(), ASN1_OCTET_STRING, ASN1_SEQUENCE, asn1_skip(), asn1_skip_any(), asn1_type(), bits, asn1_cursor::data, asn1_cursor::len, memcpy(), raw, rc, and rsa_parse_integer().
Referenced by rsa_init(), and rsa_match().
|
static |
Initialise RSA cipher.
ctx | RSA context |
key | Key |
key_len | Length of key |
rc | Return status code |
Definition at line 239 of file rsa.c.
References bigint_init, bigint_t(), ctx, asn1_cursor::data, DBGC, DBGC_HDA, rsa_context::exponent0, rsa_context::exponent_size, key, key_len, asn1_cursor::len, memset(), rsa_context::modulus0, rc, rsa_alloc(), rsa_free(), rsa_parse_mod_exp(), and rsa_context::size.
|
static |
Calculate RSA maximum output length.
ctx | RSA context |
max_len | Maximum output length |
Definition at line 289 of file rsa.c.
References ctx, and rsa_context::max_len.
|
static |
Perform RSA cipher operation.
context | RSA context |
in | Input buffer |
out | Output buffer |
Definition at line 302 of file rsa.c.
References bigint_done, bigint_init, 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_decrypt(), rsa_encrypt(), rsa_sign(), and rsa_verify().
|
static |
Encrypt using RSA.
ctx | RSA context |
plaintext | Plaintext |
plaintext_len | Length of plaintext |
ciphertext | Ciphertext |
ciphertext_len | Length of ciphertext, or negative error |
Definition at line 329 of file rsa.c.
References ctx, DBGC, DBGC_HDA, ERANGE, get_random_nz(), max_len, rsa_context::max_len, memcpy(), rsa_context::output0, rc, rsa_cipher(), and strerror().
|
static |
Decrypt using RSA.
ctx | RSA context |
ciphertext | Ciphertext |
ciphertext_len | Ciphertext length |
plaintext | Plaintext |
plaintext_len | Plaintext length, or negative error |
Definition at line 380 of file rsa.c.
References ctx, DBGC, DBGC_HDA, EINVAL, end, ERANGE, rsa_context::input0, rsa_context::max_len, memchr(), memcpy(), rsa_cipher(), start, and zero.
|
static |
Encode RSA digest.
context | RSA context |
digest | Digest algorithm |
value | Digest value |
encoded | Encoded digest |
rc | Return status code |
Definition at line 439 of file rsa.c.
References assert(), DBGC, DBGC_HDA, digest, digest_algorithm::digestsize, ENOTSUP, ERANGE, max_len, rsa_context::max_len, memcpy(), memset(), digest_algorithm::name, pad_len, prefix, rsa_find_prefix(), and value.
Referenced by rsa_sign(), and rsa_verify().
|
static |
Sign digest value using RSA.
ctx | RSA context |
digest | Digest algorithm |
value | Digest value |
signature | Signature |
signature_len | Signature length, or negative error |
Definition at line 497 of file rsa.c.
References ctx, DBGC, DBGC_HDA, digest, digest_algorithm::digestsize, rsa_context::max_len, digest_algorithm::name, rsa_context::output0, rc, rsa_cipher(), rsa_encode_digest(), signature, and value.
|
static |
Verify signed digest value using RSA.
ctx | RSA context |
digest | Digest algorithm |
value | Digest value |
signature | Signature |
signature_len | Signature length |
rc | Return status code |
Definition at line 531 of file rsa.c.
References ctx, DBGC, DBGC_HDA, digest, digest_algorithm::digestsize, EACCES_VERIFY, ERANGE, rsa_context::input0, rsa_context::max_len, memcmp(), digest_algorithm::name, rsa_context::output0, rc, rsa_cipher(), rsa_encode_digest(), signature, signature_len, and value.
|
static |
Finalise RSA cipher.
ctx | RSA context |
Definition at line 585 of file rsa.c.
References ctx, and rsa_free().
|
static |
Check for matching RSA public/private key pair.
private_key | Private key |
private_key_len | Private key length |
public_key | Public key |
public_key_len | Public key length |
rc | Return status code |
Definition at line 600 of file rsa.c.
References asn1_compare(), asn1_cursor::data, ENOTTY, asn1_cursor::len, private_key, private_key_len, public_key, public_key_len, rc, and rsa_parse_mod_exp().
REQUIRING_SYMBOL | ( | rsa_algorithm | ) |
REQUIRE_OBJECT | ( | config_crypto | ) |
struct pubkey_algorithm rsa_algorithm |
RSA public-key algorithm.
Definition at line 632 of file rsa.c.
Referenced by icert_cert().