Skip to content

Commit

Permalink
qapi/crypto: Drop unwanted 'prefix'
Browse files Browse the repository at this point in the history
QAPI's 'prefix' feature can make the connection between enumeration
type and its constants less than obvious.  It's best used with
restraint.

QCryptoAkCipherKeyType has a 'prefix' that overrides the generated
enumeration constants' prefix to QCRYPTO_AKCIPHER_KEY_TYPE.

Drop it.  The prefix becomes QCRYPTO_AK_CIPHER_KEY_TYPE.

Signed-off-by: Markus Armbruster <[email protected]>
Acked-by: Daniel P. Berrangé <[email protected]>
Message-ID: <[email protected]>
  • Loading branch information
Markus Armbruster committed Sep 10, 2024
1 parent 32cfefb commit 5f4059e
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 33 deletions.
4 changes: 2 additions & 2 deletions backends/cryptodev-builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,11 @@ static int cryptodev_builtin_create_akcipher_session(

switch (sess_info->keytype) {
case VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PUBLIC:
type = QCRYPTO_AKCIPHER_KEY_TYPE_PUBLIC;
type = QCRYPTO_AK_CIPHER_KEY_TYPE_PUBLIC;
break;

case VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PRIVATE:
type = QCRYPTO_AKCIPHER_KEY_TYPE_PRIVATE;
type = QCRYPTO_AK_CIPHER_KEY_TYPE_PRIVATE;
break;

default:
Expand Down
6 changes: 3 additions & 3 deletions backends/cryptodev-lkcf.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ static void cryptodev_lkcf_execute_task(CryptoDevLKCFTask *task)
* 2. generally, public key related compution is fast, just compute it with
* thread-pool.
*/
if (session->keytype == QCRYPTO_AKCIPHER_KEY_TYPE_PRIVATE) {
if (session->keytype == QCRYPTO_AK_CIPHER_KEY_TYPE_PRIVATE) {
if (qcrypto_akcipher_export_p8info(&session->akcipher_opts,
session->key, session->keylen,
&p8info, &p8info_len,
Expand Down Expand Up @@ -534,11 +534,11 @@ static int cryptodev_lkcf_create_asym_session(

switch (sess_info->keytype) {
case VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PUBLIC:
sess->keytype = QCRYPTO_AKCIPHER_KEY_TYPE_PUBLIC;
sess->keytype = QCRYPTO_AK_CIPHER_KEY_TYPE_PUBLIC;
break;

case VIRTIO_CRYPTO_AKCIPHER_KEY_TYPE_PRIVATE:
sess->keytype = QCRYPTO_AKCIPHER_KEY_TYPE_PRIVATE;
sess->keytype = QCRYPTO_AK_CIPHER_KEY_TYPE_PRIVATE;
break;

default:
Expand Down
8 changes: 4 additions & 4 deletions crypto/akcipher-gcrypt.c.inc
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ static int qcrypto_gcrypt_parse_rsa_private_key(
const uint8_t *key, size_t keylen, Error **errp)
{
g_autoptr(QCryptoAkCipherRSAKey) rsa_key = qcrypto_akcipher_rsakey_parse(
QCRYPTO_AKCIPHER_KEY_TYPE_PRIVATE, key, keylen, errp);
QCRYPTO_AK_CIPHER_KEY_TYPE_PRIVATE, key, keylen, errp);
gcry_mpi_t n = NULL, e = NULL, d = NULL, p = NULL, q = NULL, u = NULL;
bool compute_mul_inv = false;
int ret = -1;
Expand Down Expand Up @@ -178,7 +178,7 @@ static int qcrypto_gcrypt_parse_rsa_public_key(QCryptoGcryptRSA *rsa,
{

g_autoptr(QCryptoAkCipherRSAKey) rsa_key = qcrypto_akcipher_rsakey_parse(
QCRYPTO_AKCIPHER_KEY_TYPE_PUBLIC, key, keylen, errp);
QCRYPTO_AK_CIPHER_KEY_TYPE_PUBLIC, key, keylen, errp);
gcry_mpi_t n = NULL, e = NULL;
int ret = -1;
gcry_error_t err;
Expand Down Expand Up @@ -540,13 +540,13 @@ static QCryptoGcryptRSA *qcrypto_gcrypt_rsa_new(
rsa->akcipher.driver = &gcrypt_rsa;

switch (type) {
case QCRYPTO_AKCIPHER_KEY_TYPE_PRIVATE:
case QCRYPTO_AK_CIPHER_KEY_TYPE_PRIVATE:
if (qcrypto_gcrypt_parse_rsa_private_key(rsa, key, keylen, errp) != 0) {
goto error;
}
break;

case QCRYPTO_AKCIPHER_KEY_TYPE_PUBLIC:
case QCRYPTO_AK_CIPHER_KEY_TYPE_PUBLIC:
if (qcrypto_gcrypt_parse_rsa_public_key(rsa, key, keylen, errp) != 0) {
goto error;
}
Expand Down
8 changes: 4 additions & 4 deletions crypto/akcipher-nettle.c.inc
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ static int qcrypt_nettle_parse_rsa_private_key(QCryptoNettleRSA *rsa,
Error **errp)
{
g_autoptr(QCryptoAkCipherRSAKey) rsa_key = qcrypto_akcipher_rsakey_parse(
QCRYPTO_AKCIPHER_KEY_TYPE_PRIVATE, key, keylen, errp);
QCRYPTO_AK_CIPHER_KEY_TYPE_PRIVATE, key, keylen, errp);

if (!rsa_key) {
return -1;
Expand Down Expand Up @@ -137,7 +137,7 @@ static int qcrypt_nettle_parse_rsa_public_key(QCryptoNettleRSA *rsa,
Error **errp)
{
g_autoptr(QCryptoAkCipherRSAKey) rsa_key = qcrypto_akcipher_rsakey_parse(
QCRYPTO_AKCIPHER_KEY_TYPE_PUBLIC, key, keylen, errp);
QCRYPTO_AK_CIPHER_KEY_TYPE_PUBLIC, key, keylen, errp);

if (!rsa_key) {
return -1;
Expand Down Expand Up @@ -397,13 +397,13 @@ static QCryptoAkCipher *qcrypto_nettle_rsa_new(
rsa_private_key_init(&rsa->priv);

switch (type) {
case QCRYPTO_AKCIPHER_KEY_TYPE_PRIVATE:
case QCRYPTO_AK_CIPHER_KEY_TYPE_PRIVATE:
if (qcrypt_nettle_parse_rsa_private_key(rsa, key, keylen, errp) != 0) {
goto error;
}
break;

case QCRYPTO_AKCIPHER_KEY_TYPE_PUBLIC:
case QCRYPTO_AK_CIPHER_KEY_TYPE_PUBLIC:
if (qcrypt_nettle_parse_rsa_public_key(rsa, key, keylen, errp) != 0) {
goto error;
}
Expand Down
4 changes: 2 additions & 2 deletions crypto/rsakey-builtin.c.inc
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ QCryptoAkCipherRSAKey *qcrypto_akcipher_rsakey_parse(
size_t keylen, Error **errp)
{
switch (type) {
case QCRYPTO_AKCIPHER_KEY_TYPE_PRIVATE:
case QCRYPTO_AK_CIPHER_KEY_TYPE_PRIVATE:
return qcrypto_builtin_rsa_private_key_parse(key, keylen, errp);

case QCRYPTO_AKCIPHER_KEY_TYPE_PUBLIC:
case QCRYPTO_AK_CIPHER_KEY_TYPE_PUBLIC:
return qcrypto_builtin_rsa_public_key_parse(key, keylen, errp);

default:
Expand Down
4 changes: 2 additions & 2 deletions crypto/rsakey-nettle.c.inc
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,10 @@ QCryptoAkCipherRSAKey *qcrypto_akcipher_rsakey_parse(
size_t keylen, Error **errp)
{
switch (type) {
case QCRYPTO_AKCIPHER_KEY_TYPE_PRIVATE:
case QCRYPTO_AK_CIPHER_KEY_TYPE_PRIVATE:
return qcrypto_nettle_rsa_private_key_parse(key, keylen, errp);

case QCRYPTO_AKCIPHER_KEY_TYPE_PUBLIC:
case QCRYPTO_AK_CIPHER_KEY_TYPE_PUBLIC:
return qcrypto_nettle_rsa_public_key_parse(key, keylen, errp);

default:
Expand Down
1 change: 0 additions & 1 deletion qapi/crypto.json
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,6 @@
# Since: 7.1
##
{ 'enum': 'QCryptoAkCipherKeyType',
'prefix': 'QCRYPTO_AKCIPHER_KEY_TYPE',
'data': ['public', 'private']}

##
Expand Down
2 changes: 1 addition & 1 deletion tests/bench/benchmark-crypto-akcipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static QCryptoAkCipher *create_rsa_akcipher(const uint8_t *priv_key,
opt.alg = QCRYPTO_AKCIPHER_ALG_RSA;
opt.u.rsa.padding_alg = padding;
opt.u.rsa.hash_alg = hash;
return qcrypto_akcipher_new(&opt, QCRYPTO_AKCIPHER_KEY_TYPE_PRIVATE,
return qcrypto_akcipher_new(&opt, QCRYPTO_AK_CIPHER_KEY_TYPE_PRIVATE,
priv_key, keylen, &error_abort);
}

Expand Down
28 changes: 14 additions & 14 deletions tests/unit/test-crypto-akcipher.c
Original file line number Diff line number Diff line change
Expand Up @@ -692,88 +692,88 @@ struct QCryptoAkCipherTestData {
static QCryptoRSAKeyTestData rsakey_test_data[] = {
{
.path = "/crypto/akcipher/rsakey-1024-public",
.key_type = QCRYPTO_AKCIPHER_KEY_TYPE_PUBLIC,
.key_type = QCRYPTO_AK_CIPHER_KEY_TYPE_PUBLIC,
.key = rsa1024_public_key,
.keylen = sizeof(rsa1024_public_key),
.is_valid_key = true,
.exp_key_len = 128,
},
{
.path = "/crypto/akcipher/rsakey-1024-private",
.key_type = QCRYPTO_AKCIPHER_KEY_TYPE_PRIVATE,
.key_type = QCRYPTO_AK_CIPHER_KEY_TYPE_PRIVATE,
.key = rsa1024_private_key,
.keylen = sizeof(rsa1024_private_key),
.is_valid_key = true,
.exp_key_len = 128,
},
{
.path = "/crypto/akcipher/rsakey-2048-public",
.key_type = QCRYPTO_AKCIPHER_KEY_TYPE_PUBLIC,
.key_type = QCRYPTO_AK_CIPHER_KEY_TYPE_PUBLIC,
.key = rsa2048_public_key,
.keylen = sizeof(rsa2048_public_key),
.is_valid_key = true,
.exp_key_len = 256,
},
{
.path = "/crypto/akcipher/rsakey-2048-private",
.key_type = QCRYPTO_AKCIPHER_KEY_TYPE_PRIVATE,
.key_type = QCRYPTO_AK_CIPHER_KEY_TYPE_PRIVATE,
.key = rsa2048_private_key,
.keylen = sizeof(rsa2048_private_key),
.is_valid_key = true,
.exp_key_len = 256,
},
{
.path = "/crypto/akcipher/rsakey-public-lack-elem",
.key_type = QCRYPTO_AKCIPHER_KEY_TYPE_PUBLIC,
.key_type = QCRYPTO_AK_CIPHER_KEY_TYPE_PUBLIC,
.key = rsa_public_key_lack_element,
.keylen = sizeof(rsa_public_key_lack_element),
.is_valid_key = false,
},
{
.path = "/crypto/akcipher/rsakey-private-lack-elem",
.key_type = QCRYPTO_AKCIPHER_KEY_TYPE_PRIVATE,
.key_type = QCRYPTO_AK_CIPHER_KEY_TYPE_PRIVATE,
.key = rsa_private_key_lack_element,
.keylen = sizeof(rsa_private_key_lack_element),
.is_valid_key = false,
},
{
.path = "/crypto/akcipher/rsakey-public-empty-elem",
.key_type = QCRYPTO_AKCIPHER_KEY_TYPE_PUBLIC,
.key_type = QCRYPTO_AK_CIPHER_KEY_TYPE_PUBLIC,
.key = rsa_public_key_empty_element,
.keylen = sizeof(rsa_public_key_empty_element),
.is_valid_key = false,
},
{
.path = "/crypto/akcipher/rsakey-private-empty-elem",
.key_type = QCRYPTO_AKCIPHER_KEY_TYPE_PRIVATE,
.key_type = QCRYPTO_AK_CIPHER_KEY_TYPE_PRIVATE,
.key = rsa_private_key_empty_element,
.keylen = sizeof(rsa_private_key_empty_element),
.is_valid_key = false,
},
{
.path = "/crypto/akcipher/rsakey-public-empty-key",
.key_type = QCRYPTO_AKCIPHER_KEY_TYPE_PUBLIC,
.key_type = QCRYPTO_AK_CIPHER_KEY_TYPE_PUBLIC,
.key = NULL,
.keylen = 0,
.is_valid_key = false,
},
{
.path = "/crypto/akcipher/rsakey-private-empty-key",
.key_type = QCRYPTO_AKCIPHER_KEY_TYPE_PRIVATE,
.key_type = QCRYPTO_AK_CIPHER_KEY_TYPE_PRIVATE,
.key = NULL,
.keylen = 0,
.is_valid_key = false,
},
{
.path = "/crypto/akcipher/rsakey-public-invalid-length-val",
.key_type = QCRYPTO_AKCIPHER_KEY_TYPE_PUBLIC,
.key_type = QCRYPTO_AK_CIPHER_KEY_TYPE_PUBLIC,
.key = rsa_public_key_invalid_length_val,
.keylen = sizeof(rsa_public_key_invalid_length_val),
.is_valid_key = false,
},
{
.path = "/crypto/akcipher/rsakey-public-extra-elem",
.key_type = QCRYPTO_AKCIPHER_KEY_TYPE_PUBLIC,
.key_type = QCRYPTO_AK_CIPHER_KEY_TYPE_PUBLIC,
.key = rsa_public_key_extra_elem,
.keylen = sizeof(rsa_public_key_extra_elem),
.is_valid_key = false,
Expand Down Expand Up @@ -885,12 +885,12 @@ static void test_akcipher(const void *opaque)
return;
}
pub_key = qcrypto_akcipher_new(&data->opt,
QCRYPTO_AKCIPHER_KEY_TYPE_PUBLIC,
QCRYPTO_AK_CIPHER_KEY_TYPE_PUBLIC,
data->pub_key, data->pub_key_len,
&error_abort);
g_assert(pub_key != NULL);
priv_key = qcrypto_akcipher_new(&data->opt,
QCRYPTO_AKCIPHER_KEY_TYPE_PRIVATE,
QCRYPTO_AK_CIPHER_KEY_TYPE_PRIVATE,
data->priv_key, data->priv_key_len,
&error_abort);
g_assert(priv_key != NULL);
Expand Down

0 comments on commit 5f4059e

Please sign in to comment.