Skip to content

Commit

Permalink
rsa: fix OSSL_PKEY_PARAM_MAX_SIZE to be more exact
Browse files Browse the repository at this point in the history
Fixes #135
  • Loading branch information
gotthardp committed Jan 5, 2025
1 parent bddb341 commit f45ad13
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
4 changes: 3 additions & 1 deletion docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](http://keepachangelog.com/)

## [1.3.0] - 2024-xx-yy
## [1.3.0] - 2025-01-yy
### Added
- Added support for RSA-OAEP decryption.
- Added Parent to textual information printed by 'openssl pkey -text'.
### Fixed
- Fixed multi-threaded operation, preventing the 'Esys called in bad sequence'
errors (thanks to @Danigaralfo, @famez, and @AndreasFuchsTPM).
- Fixed retrieval of OSSL_PKEY_PARAM_MAX_SIZE for RSA keys. The exact value
is returned instead of a fixed TPM2_MAX_RSA_KEY_BYTES.
- Fixed handling of absent emptyAuth value in the TSS2 PRIVATE KEY file.
- Set authorization value of newly generated keys. This allows users of the
C API to direcly use just generated EVP_PKEY.
Expand Down
3 changes: 2 additions & 1 deletion src/tpm2-provider-keymgmt-rsa.c
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,8 @@ tpm2_rsa_keymgmt_get_params(void *keydata, OSSL_PARAM params[])
return 0;
}
p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_MAX_SIZE);
if (p != NULL && !OSSL_PARAM_set_int(p, TPM2_MAX_RSA_KEY_BYTES))
if (p != NULL && !OSSL_PARAM_set_int(p,
tpm2_rsa_size(&pkey->data.pub.publicArea.unique.rsa)))
return 0;

if (TPM2_PKEY_RSA_SCHEME(pkey) != TPM2_ALG_NULL) {
Expand Down
14 changes: 14 additions & 0 deletions src/tpm2-provider-types.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ tpm2_rsa_scheme_alg_to_name(const TPMI_ALG_RSA_SCHEME alg)
return NULL;
}

int
tpm2_rsa_size(const TPM2B_PUBLIC_KEY_RSA *rsa)
{
BIGNUM *bn;
int ret = TPM2_MAX_RSA_KEY_BYTES;

if (rsa && (bn = BN_bin2bn(rsa->buffer, rsa->size, NULL))) {
ret = BN_num_bytes(bn);
BN_free(bn);
}

return ret;
}

typedef struct {
int nid;
TPM2_ECC_CURVE curve;
Expand Down
3 changes: 3 additions & 0 deletions src/tpm2-provider-types.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ tpm2_rsa_scheme_name_to_alg(const char *name);
const char *
tpm2_rsa_scheme_alg_to_name(const TPMI_ALG_RSA_SCHEME alg);

int
tpm2_rsa_size(const TPM2B_PUBLIC_KEY_RSA *rsa);

TPM2_ECC_CURVE
tpm2_nid_to_ecc_curve(int nid);

Expand Down

0 comments on commit f45ad13

Please sign in to comment.