credentials: Added void *params to public_key encrypt() and private_key decrypt() methods

This commit is contained in:
Andreas Steffen
2021-11-09 17:58:28 +01:00
parent c8341fca61
commit 4abb29f639
43 changed files with 50 additions and 48 deletions
+1 -1
View File
@@ -90,7 +90,7 @@ METHOD(private_key_t, sign, bool,
METHOD(private_key_t, decrypt, bool,
private_tkm_private_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
void *params, chunk_t crypto, chunk_t *plain)
{
return FALSE;
}
+1 -1
View File
@@ -62,7 +62,7 @@ METHOD(public_key_t, verify, bool,
METHOD(public_key_t, encrypt_, bool,
private_tkm_public_key_t *this, encryption_scheme_t scheme,
chunk_t plain, chunk_t *crypto)
void *params, chunk_t plain, chunk_t *crypto)
{
return FALSE;
}
@@ -388,7 +388,7 @@ METHOD(private_key_t, get_type, key_type_t,
METHOD(private_key_t, decrypt, bool,
private_private_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
void *params, chunk_t crypto, chunk_t *plain)
{
DBG1(DBG_LIB, "private key decryption is currently not supported via JNI");
return FALSE;
@@ -67,12 +67,13 @@ struct private_key_t {
* Decrypt a chunk of data.
*
* @param scheme expected encryption scheme used
* @param params optional parameters required by the specified scheme
* @param crypto chunk containing encrypted data
* @param plain where to allocate decrypted data
* @return TRUE if data decrypted and plaintext allocated
*/
bool (*decrypt)(private_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain);
void *params, chunk_t crypto, chunk_t *plain);
/**
* Get the strength of the key in bits.
@@ -182,12 +182,13 @@ struct public_key_t {
* Encrypt a chunk of data.
*
* @param scheme encryption scheme to use
* @param params optional parameters required by the specified scheme
* @param plain chunk containing plaintext data
* @param crypto where to allocate encrypted data
* @return TRUE if data successfully encrypted
*/
bool (*encrypt)(public_key_t *this, encryption_scheme_t scheme,
chunk_t plain, chunk_t *crypto);
void *params, chunk_t plain, chunk_t *crypto);
/**
* Check if two public keys are equal.
@@ -391,7 +391,7 @@ METHOD(private_key_t, get_type, key_type_t,
METHOD(private_key_t, decrypt, bool,
private_agent_private_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
void *params, chunk_t crypto, chunk_t *plain)
{
DBG1(DBG_LIB, "private key decryption not supported by ssh-agent");
return FALSE;
@@ -538,7 +538,7 @@ METHOD(private_key_t, sign, bool,
METHOD(private_key_t, decrypt, bool,
private_bliss_private_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
void *params, chunk_t crypto, chunk_t *plain)
{
DBG1(DBG_LIB, "encryption scheme %N not supported",
encryption_scheme_names, scheme);
@@ -220,7 +220,7 @@ METHOD(public_key_t, verify, bool,
METHOD(public_key_t, encrypt_, bool,
private_bliss_public_key_t *this, encryption_scheme_t scheme,
chunk_t plain, chunk_t *crypto)
void *params, chunk_t plain, chunk_t *crypto)
{
DBG1(DBG_LIB, "encryption scheme %N not supported",
encryption_scheme_names, scheme);
@@ -168,8 +168,8 @@ START_TEST(test_bliss_sign_fail)
ck_assert(!pubkey->get_fingerprint(pubkey, KEYID_PGPV4, &fp));
/* encryption / decryption operation is not defined for BLISS */
ck_assert(!pubkey->encrypt(pubkey, ENCRYPT_UNKNOWN, chunk_empty, NULL));
ck_assert(!privkey->decrypt(privkey, ENCRYPT_UNKNOWN, chunk_empty, NULL));
ck_assert(!pubkey->encrypt(pubkey, ENCRYPT_UNKNOWN, NULL, chunk_empty, NULL));
ck_assert(!privkey->decrypt(privkey, ENCRYPT_UNKNOWN, NULL, chunk_empty, NULL));
/* sign with invalid signature scheme */
ck_assert(!privkey->sign(privkey, SIGN_UNKNOWN, NULL, msg, &signature));
@@ -141,7 +141,7 @@ METHOD(private_key_t, sign, bool,
METHOD(private_key_t, decrypt, bool,
private_botan_ec_private_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
void *params, chunk_t crypto, chunk_t *plain)
{
DBG1(DBG_LIB, "EC private key decryption not implemented");
return FALSE;
@@ -190,7 +190,7 @@ METHOD(public_key_t, verify, bool,
METHOD(public_key_t, encrypt, bool,
private_botan_ec_public_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
void *params, chunk_t crypto, chunk_t *plain)
{
DBG1(DBG_LIB, "EC public key encryption not implemented");
return FALSE;
@@ -74,7 +74,7 @@ METHOD(private_key_t, sign, bool,
METHOD(private_key_t, decrypt, bool,
private_private_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
void *params, chunk_t crypto, chunk_t *plain)
{
DBG1(DBG_LIB, "EdDSA private key decryption not implemented");
return FALSE;
@@ -82,7 +82,7 @@ METHOD(public_key_t, verify, bool,
METHOD(public_key_t, encrypt, bool,
private_public_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
void *params, chunk_t crypto, chunk_t *plain)
{
DBG1(DBG_LIB, "EdDSA public key encryption not implemented");
return FALSE;
@@ -159,7 +159,7 @@ METHOD(private_key_t, sign, bool,
METHOD(private_key_t, decrypt, bool,
private_botan_rsa_private_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
void *params, chunk_t crypto, chunk_t *plain)
{
botan_pk_op_decrypt_t decrypt_op;
const char *padding;
@@ -139,7 +139,7 @@ METHOD(public_key_t, verify, bool,
METHOD(public_key_t, encrypt, bool,
private_botan_rsa_public_key_t *this, encryption_scheme_t scheme,
chunk_t plain, chunk_t *crypto)
void *params, chunk_t plain, chunk_t *crypto)
{
botan_pk_op_encrypt_t encrypt_op;
botan_rng_t rng;
@@ -113,7 +113,7 @@ end:
METHOD(private_key_t, decrypt, bool,
private_curve25519_private_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
void *params, chunk_t crypto, chunk_t *plain)
{
DBG1(DBG_LIB, "encryption scheme %N not supported", encryption_scheme_names,
scheme);
@@ -139,7 +139,7 @@ METHOD(public_key_t, verify, bool,
METHOD(public_key_t, encrypt_, bool,
private_curve25519_public_key_t *this, encryption_scheme_t scheme,
chunk_t plain, chunk_t *crypto)
void *params, chunk_t plain, chunk_t *crypto)
{
DBG1(DBG_LIB, "encryption scheme %N not supported", encryption_scheme_names,
scheme);
@@ -278,7 +278,7 @@ METHOD(private_key_t, sign, bool,
METHOD(private_key_t, decrypt, bool,
private_gcrypt_rsa_private_key_t *this, encryption_scheme_t scheme,
chunk_t encrypted, chunk_t *plain)
void *params, chunk_t encrypted, chunk_t *plain)
{
gcry_error_t err;
gcry_sexp_t in, out;
@@ -237,7 +237,7 @@ METHOD(public_key_t, verify, bool,
METHOD(public_key_t, encrypt_, bool,
private_gcrypt_rsa_public_key_t *this, encryption_scheme_t scheme,
chunk_t plain, chunk_t *encrypted)
void *params, chunk_t plain, chunk_t *encrypted)
{
gcry_sexp_t in, out;
gcry_error_t err;
@@ -494,7 +494,7 @@ METHOD(private_key_t, sign, bool,
METHOD(private_key_t, decrypt, bool,
private_gmp_rsa_private_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
void *params, chunk_t crypto, chunk_t *plain)
{
chunk_t em, stripped;
bool success = FALSE;
@@ -313,7 +313,7 @@ METHOD(public_key_t, verify, bool,
METHOD(public_key_t, encrypt_, bool,
private_gmp_rsa_public_key_t *this, encryption_scheme_t scheme,
chunk_t plain, chunk_t *crypto)
void *params, chunk_t plain, chunk_t *crypto)
{
chunk_t em;
u_char *pos;
@@ -183,7 +183,7 @@ METHOD(private_key_t, sign, bool,
METHOD(private_key_t, decrypt, bool,
private_openssl_ec_private_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
void *params, chunk_t crypto, chunk_t *plain)
{
DBG1(DBG_LIB, "EC private key decryption not implemented");
return FALSE;
@@ -183,7 +183,7 @@ METHOD(public_key_t, verify, bool,
METHOD(public_key_t, encrypt, bool,
private_openssl_ec_public_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
void *params, chunk_t crypto, chunk_t *plain)
{
DBG1(DBG_LIB, "EC public key encryption not implemented");
return FALSE;
@@ -108,7 +108,7 @@ error:
METHOD(private_key_t, decrypt, bool,
private_private_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
void *params, chunk_t crypto, chunk_t *plain)
{
DBG1(DBG_LIB, "EdDSA private key decryption not implemented");
return FALSE;
@@ -118,7 +118,7 @@ METHOD(public_key_t, verify, bool,
METHOD(public_key_t, encrypt, bool,
private_public_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
void *params, chunk_t crypto, chunk_t *plain)
{
DBG1(DBG_LIB, "encryption scheme %N not supported", encryption_scheme_names,
scheme);
@@ -644,7 +644,7 @@ static bool decrypt(private_openssl_pkcs7_t *this,
{
/* get encryptedKey from internal structure; TODO fixup */
chunk = openssl_asn1_str2chunk(ri->ktri->encryptedKey);
if (private->decrypt(private, ENCRYPT_RSA_PKCS1,
if (private->decrypt(private, ENCRYPT_RSA_PKCS1, NULL,
chunk, &key))
{
private->destroy(private);
@@ -306,7 +306,7 @@ METHOD(private_key_t, sign, bool,
METHOD(private_key_t, decrypt, bool,
private_openssl_rsa_private_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
void *params, chunk_t crypto, chunk_t *plain)
{
int padding, len;
char *decrypted;
@@ -307,7 +307,7 @@ METHOD(public_key_t, verify, bool,
METHOD(public_key_t, encrypt, bool,
private_openssl_rsa_public_key_t *this, encryption_scheme_t scheme,
chunk_t plain, chunk_t *crypto)
void *params, chunk_t plain, chunk_t *crypto)
{
int padding, len;
char *encrypted;
+1 -1
View File
@@ -126,7 +126,7 @@ METHOD(private_key_t, sign_not_allowed, bool,
METHOD(private_key_t, decrypt_not_allowed, bool,
private_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
void *params, chunk_t crypto, chunk_t *plain)
{
DBG1(DBG_LIB, "decryption failed - signature only key");
return FALSE;
@@ -388,7 +388,7 @@ METHOD(private_key_t, sign, bool,
METHOD(private_key_t, decrypt, bool,
private_pkcs11_private_key_t *this, encryption_scheme_t scheme,
chunk_t crypt, chunk_t *plain)
void *params, chunk_t crypt, chunk_t *plain)
{
CK_MECHANISM_PTR mechanism;
CK_SESSION_HANDLE session;
@@ -307,7 +307,7 @@ METHOD(public_key_t, verify, bool,
METHOD(public_key_t, encrypt, bool,
private_pkcs11_public_key_t *this, encryption_scheme_t scheme,
chunk_t plain, chunk_t *crypt)
void *params, chunk_t plain, chunk_t *crypt)
{
CK_MECHANISM_PTR mechanism;
CK_SESSION_HANDLE session;
@@ -137,7 +137,7 @@ static bool decrypt(private_key_t *private, chunk_t key, chunk_t iv, int oid,
DBG1(DBG_LIB, "unsupported content encryption algorithm");
return FALSE;
}
if (!private->decrypt(private, ENCRYPT_RSA_PKCS1, key, &plain_key))
if (!private->decrypt(private, ENCRYPT_RSA_PKCS1, NULL, key, &plain_key))
{
DBG1(DBG_LIB, "symmetric key could not be decrypted with rsa");
return FALSE;
@@ -438,7 +438,7 @@ static bool encrypt_key(certificate_t *cert, chunk_t in, chunk_t *out)
{
return FALSE;
}
if (!key->encrypt(key, ENCRYPT_RSA_PKCS1, in, out))
if (!key->encrypt(key, ENCRYPT_RSA_PKCS1, NULL, in, out))
{
key->destroy(key);
return FALSE;
@@ -207,7 +207,7 @@ METHOD(private_key_t, sign, bool,
METHOD(private_key_t, decrypt, bool,
private_wolfssl_ec_private_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
void *params, chunk_t crypto, chunk_t *plain)
{
DBG1(DBG_LIB, "EC private key decryption not implemented");
return FALSE;
@@ -195,7 +195,7 @@ METHOD(public_key_t, verify, bool,
METHOD(public_key_t, encrypt, bool,
private_wolfssl_ec_public_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
void *params, chunk_t crypto, chunk_t *plain)
{
DBG1(DBG_LIB, "EC public key encryption not implemented");
return FALSE;
@@ -113,7 +113,7 @@ METHOD(private_key_t, sign, bool,
METHOD(private_key_t, decrypt, bool,
private_private_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
void *params, chunk_t crypto, chunk_t *plain)
{
DBG1(DBG_LIB, "EdDSA private key decryption not implemented");
return FALSE;
@@ -114,7 +114,7 @@ METHOD(public_key_t, verify, bool,
METHOD(public_key_t, encrypt, bool,
private_public_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
void *params, chunk_t crypto, chunk_t *plain)
{
DBG1(DBG_LIB, "encryption scheme %N not supported", encryption_scheme_names,
scheme);
@@ -243,7 +243,7 @@ METHOD(private_key_t, sign, bool,
METHOD(private_key_t, decrypt, bool,
private_wolfssl_rsa_private_key_t *this, encryption_scheme_t scheme,
chunk_t crypto, chunk_t *plain)
void *params, chunk_t crypto, chunk_t *plain)
{
int padding, mgf, len;
enum wc_HashType hash;
@@ -218,7 +218,7 @@ METHOD(public_key_t, verify, bool,
METHOD(public_key_t, encrypt, bool,
private_wolfssl_rsa_public_key_t *this, encryption_scheme_t scheme,
chunk_t plain, chunk_t *crypto)
void *params, chunk_t plain, chunk_t *crypto)
{
int padding, mgf, len;
enum wc_HashType hash;
@@ -379,7 +379,7 @@ START_TEST(test_ed25519_gen)
key2->destroy(key2);
/* decryption not supported */
ck_assert(!key->decrypt(key, ENCRYPT_UNKNOWN, msg, NULL));
ck_assert(!key->decrypt(key, ENCRYPT_UNKNOWN, NULL, msg, NULL));
/* wrong signature scheme */
ck_assert(!key->sign(key, SIGN_ED448, NULL, msg, &sig));
@@ -414,7 +414,7 @@ START_TEST(test_ed25519_gen)
pubkey2->destroy(pubkey2);
/* encryption not supported */
ck_assert(!pubkey->encrypt(pubkey, ENCRYPT_UNKNOWN, msg, NULL));
ck_assert(!pubkey->encrypt(pubkey, ENCRYPT_UNKNOWN, NULL, msg, NULL));
/* verify with wrong signature scheme */
ck_assert(!pubkey->verify(pubkey, SIGN_ED448, NULL, msg, sig));
+2 -2
View File
@@ -440,7 +440,7 @@ START_TEST(test_ed448_gen)
key2->destroy(key2);
/* decryption not supported */
ck_assert(!key->decrypt(key, ENCRYPT_UNKNOWN, msg, NULL));
ck_assert(!key->decrypt(key, ENCRYPT_UNKNOWN, NULL, msg, NULL));
/* wrong signature scheme */
ck_assert(!key->sign(key, SIGN_ED25519, NULL, msg, &sig));
@@ -475,7 +475,7 @@ START_TEST(test_ed448_gen)
pubkey2->destroy(pubkey2);
/* encryption not supported */
ck_assert(!pubkey->encrypt(pubkey, ENCRYPT_UNKNOWN, msg, NULL));
ck_assert(!pubkey->encrypt(pubkey, ENCRYPT_UNKNOWN, NULL, msg, NULL));
/* verify with wrong signature scheme */
ck_assert(!pubkey->verify(pubkey, SIGN_ED25519, NULL, msg, sig));
+1 -1
View File
@@ -1628,7 +1628,7 @@ static status_t send_key_exchange_encrypt(private_tls_peer_t *this,
this->alert->add(this->alert, TLS_FATAL, TLS_CERTIFICATE_UNKNOWN);
return NEED_MORE;
}
if (!public->encrypt(public, ENCRYPT_RSA_PKCS1,
if (!public->encrypt(public, ENCRYPT_RSA_PKCS1, NULL,
chunk_from_thing(premaster), &encrypted))
{
public->destroy(public);
+2 -2
View File
@@ -805,8 +805,8 @@ static status_t process_key_exchange_encrypted(private_tls_server_t *this,
rng->destroy(rng);
if (this->private &&
this->private->decrypt(this->private,
ENCRYPT_RSA_PKCS1, encrypted, &decrypted))
this->private->decrypt(this->private, ENCRYPT_RSA_PKCS1, NULL,
encrypted, &decrypted))
{
if (decrypted.len == sizeof(premaster) &&
untoh16(decrypted.ptr) == this->client_version)
+1 -1
View File
@@ -105,7 +105,7 @@ METHOD(private_key_t, sign, bool,
METHOD(private_key_t, decrypt, bool,
private_tpm_private_key_t *this, encryption_scheme_t scheme,
chunk_t crypt, chunk_t *plain)
void *params, chunk_t crypt, chunk_t *plain)
{
return FALSE;
}