Skip to content

Commit

Permalink
qapi/crypto: Rename QCryptoHashAlgorithm to *Algo, and drop 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.

QCryptoHashAlgorithm has a 'prefix' that overrides the generated
enumeration constants' prefix to QCRYPTO_HASH_ALG.

We could simply drop 'prefix', but then the prefix becomes
QCRYPTO_HASH_ALGORITHM, which is rather long.

We could additionally rename the type to QCryptoHashAlg, but I think
the abbreviation "alg" is less than clear.

Rename the type to QCryptoHashAlgo instead.  The prefix becomes to
QCRYPTO_HASH_ALGO.

Signed-off-by: Markus Armbruster <[email protected]>
Acked-by: Daniel P. Berrangé <[email protected]>
Message-ID: <[email protected]>
[Conflicts with merge commit 7bbadc6 resolved]
  • Loading branch information
Markus Armbruster committed Sep 10, 2024
1 parent 5f4059e commit ef834aa
Show file tree
Hide file tree
Showing 54 changed files with 363 additions and 364 deletions.
8 changes: 4 additions & 4 deletions backends/cryptodev-builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,16 +169,16 @@ static int cryptodev_builtin_get_rsa_hash_algo(
{
switch (virtio_rsa_hash) {
case VIRTIO_CRYPTO_RSA_MD5:
return QCRYPTO_HASH_ALG_MD5;
return QCRYPTO_HASH_ALGO_MD5;

case VIRTIO_CRYPTO_RSA_SHA1:
return QCRYPTO_HASH_ALG_SHA1;
return QCRYPTO_HASH_ALGO_SHA1;

case VIRTIO_CRYPTO_RSA_SHA256:
return QCRYPTO_HASH_ALG_SHA256;
return QCRYPTO_HASH_ALGO_SHA256;

case VIRTIO_CRYPTO_RSA_SHA512:
return QCRYPTO_HASH_ALG_SHA512;
return QCRYPTO_HASH_ALGO_SHA512;

default:
error_setg(errp, "Unsupported rsa hash algo: %d", virtio_rsa_hash);
Expand Down
10 changes: 5 additions & 5 deletions backends/cryptodev-lkcf.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ static int cryptodev_lkcf_set_op_desc(QCryptoAkCipherOptions *opts,
if (rsa_opt->padding_alg == QCRYPTO_RSA_PADDING_ALG_PKCS1) {
snprintf(key_desc, desc_len, "enc=%s hash=%s",
QCryptoRSAPaddingAlgorithm_str(rsa_opt->padding_alg),
QCryptoHashAlgorithm_str(rsa_opt->hash_alg));
QCryptoHashAlgo_str(rsa_opt->hash_alg));

} else {
snprintf(key_desc, desc_len, "enc=%s",
Expand All @@ -161,19 +161,19 @@ static int cryptodev_lkcf_set_rsa_opt(int virtio_padding_alg,

switch (virtio_hash_alg) {
case VIRTIO_CRYPTO_RSA_MD5:
opt->hash_alg = QCRYPTO_HASH_ALG_MD5;
opt->hash_alg = QCRYPTO_HASH_ALGO_MD5;
break;

case VIRTIO_CRYPTO_RSA_SHA1:
opt->hash_alg = QCRYPTO_HASH_ALG_SHA1;
opt->hash_alg = QCRYPTO_HASH_ALGO_SHA1;
break;

case VIRTIO_CRYPTO_RSA_SHA256:
opt->hash_alg = QCRYPTO_HASH_ALG_SHA256;
opt->hash_alg = QCRYPTO_HASH_ALGO_SHA256;
break;

case VIRTIO_CRYPTO_RSA_SHA512:
opt->hash_alg = QCRYPTO_HASH_ALG_SHA512;
opt->hash_alg = QCRYPTO_HASH_ALGO_SHA512;
break;

default:
Expand Down
2 changes: 1 addition & 1 deletion block/parallels-ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ parallels_parse_format_extension(BlockDriverState *bs, uint8_t *ext_cluster,
goto fail;
}

ret = qcrypto_hash_bytes(QCRYPTO_HASH_ALG_MD5, (char *)pos, remaining,
ret = qcrypto_hash_bytes(QCRYPTO_HASH_ALGO_MD5, (char *)pos, remaining,
&hash, &hash_len, errp);
if (ret < 0) {
goto fail;
Expand Down
4 changes: 2 additions & 2 deletions block/quorum.c
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ static int quorum_compute_hash(QuorumAIOCB *acb, int i, QuorumVoteValue *hash)
/* XXX - would be nice if we could pass in the Error **
* and propagate that back, but this quorum code is
* restricted to just errno values currently */
if (qcrypto_hash_bytesv(QCRYPTO_HASH_ALG_SHA256,
if (qcrypto_hash_bytesv(QCRYPTO_HASH_ALGO_SHA256,
qiov->iov, qiov->niov,
&data, &len,
NULL) < 0) {
Expand Down Expand Up @@ -1308,7 +1308,7 @@ static BlockDriver bdrv_quorum = {

static void bdrv_quorum_init(void)
{
if (!qcrypto_hash_supports(QCRYPTO_HASH_ALG_SHA256)) {
if (!qcrypto_hash_supports(QCRYPTO_HASH_ALGO_SHA256)) {
/* SHA256 hash support is required for quorum device */
return;
}
Expand Down
6 changes: 3 additions & 3 deletions crypto/afsplit.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ static void qcrypto_afsplit_xor(size_t blocklen,
}


static int qcrypto_afsplit_hash(QCryptoHashAlgorithm hash,
static int qcrypto_afsplit_hash(QCryptoHashAlgo hash,
size_t blocklen,
uint8_t *block,
Error **errp)
Expand Down Expand Up @@ -85,7 +85,7 @@ static int qcrypto_afsplit_hash(QCryptoHashAlgorithm hash,
}


int qcrypto_afsplit_encode(QCryptoHashAlgorithm hash,
int qcrypto_afsplit_encode(QCryptoHashAlgo hash,
size_t blocklen,
uint32_t stripes,
const uint8_t *in,
Expand Down Expand Up @@ -117,7 +117,7 @@ int qcrypto_afsplit_encode(QCryptoHashAlgorithm hash,
}


int qcrypto_afsplit_decode(QCryptoHashAlgorithm hash,
int qcrypto_afsplit_decode(QCryptoHashAlgo hash,
size_t blocklen,
uint32_t stripes,
const uint8_t *in,
Expand Down
14 changes: 7 additions & 7 deletions crypto/akcipher-gcrypt.c.inc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ typedef struct QCryptoGcryptRSA {
QCryptoAkCipher akcipher;
gcry_sexp_t key;
QCryptoRSAPaddingAlgorithm padding_alg;
QCryptoHashAlgorithm hash_alg;
QCryptoHashAlgo hash_alg;
} QCryptoGcryptRSA;

static void qcrypto_gcrypt_rsa_free(QCryptoAkCipher *akcipher)
Expand Down Expand Up @@ -417,7 +417,7 @@ static int qcrypto_gcrypt_rsa_sign(QCryptoAkCipher *akcipher,

err = gcry_sexp_build(&dgst_sexp, NULL,
"(data (flags pkcs1) (hash %s %b))",
QCryptoHashAlgorithm_str(rsa->hash_alg),
QCryptoHashAlgo_str(rsa->hash_alg),
in_len, in);
if (gcry_err_code(err) != 0) {
error_setg(errp, "Failed to build dgst: %s/%s",
Expand Down Expand Up @@ -497,7 +497,7 @@ static int qcrypto_gcrypt_rsa_verify(QCryptoAkCipher *akcipher,

err = gcry_sexp_build(&dgst_sexp, NULL,
"(data (flags pkcs1) (hash %s %b))",
QCryptoHashAlgorithm_str(rsa->hash_alg),
QCryptoHashAlgo_str(rsa->hash_alg),
in2_len, in2);
if (gcry_err_code(err) != 0) {
error_setg(errp, "Failed to build dgst: %s/%s",
Expand Down Expand Up @@ -575,10 +575,10 @@ bool qcrypto_akcipher_supports(QCryptoAkCipherOptions *opts)

case QCRYPTO_RSA_PADDING_ALG_PKCS1:
switch (opts->u.rsa.hash_alg) {
case QCRYPTO_HASH_ALG_MD5:
case QCRYPTO_HASH_ALG_SHA1:
case QCRYPTO_HASH_ALG_SHA256:
case QCRYPTO_HASH_ALG_SHA512:
case QCRYPTO_HASH_ALGO_MD5:
case QCRYPTO_HASH_ALGO_SHA1:
case QCRYPTO_HASH_ALGO_SHA256:
case QCRYPTO_HASH_ALGO_SHA512:
return true;

default:
Expand Down
26 changes: 13 additions & 13 deletions crypto/akcipher-nettle.c.inc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ typedef struct QCryptoNettleRSA {
struct rsa_public_key pub;
struct rsa_private_key priv;
QCryptoRSAPaddingAlgorithm padding_alg;
QCryptoHashAlgorithm hash_alg;
QCryptoHashAlgo hash_alg;
} QCryptoNettleRSA;

static void qcrypto_nettle_rsa_free(QCryptoAkCipher *akcipher)
Expand Down Expand Up @@ -276,19 +276,19 @@ static int qcrypto_nettle_rsa_sign(QCryptoAkCipher *akcipher,

mpz_init(s);
switch (rsa->hash_alg) {
case QCRYPTO_HASH_ALG_MD5:
case QCRYPTO_HASH_ALGO_MD5:
rv = rsa_md5_sign_digest(&rsa->priv, data, s);
break;

case QCRYPTO_HASH_ALG_SHA1:
case QCRYPTO_HASH_ALGO_SHA1:
rv = rsa_sha1_sign_digest(&rsa->priv, data, s);
break;

case QCRYPTO_HASH_ALG_SHA256:
case QCRYPTO_HASH_ALGO_SHA256:
rv = rsa_sha256_sign_digest(&rsa->priv, data, s);
break;

case QCRYPTO_HASH_ALG_SHA512:
case QCRYPTO_HASH_ALGO_SHA512:
rv = rsa_sha512_sign_digest(&rsa->priv, data, s);
break;

Expand Down Expand Up @@ -341,19 +341,19 @@ static int qcrypto_nettle_rsa_verify(QCryptoAkCipher *akcipher,

nettle_mpz_init_set_str_256_u(s, sig_len, sig);
switch (rsa->hash_alg) {
case QCRYPTO_HASH_ALG_MD5:
case QCRYPTO_HASH_ALGO_MD5:
rv = rsa_md5_verify_digest(&rsa->pub, data, s);
break;

case QCRYPTO_HASH_ALG_SHA1:
case QCRYPTO_HASH_ALGO_SHA1:
rv = rsa_sha1_verify_digest(&rsa->pub, data, s);
break;

case QCRYPTO_HASH_ALG_SHA256:
case QCRYPTO_HASH_ALGO_SHA256:
rv = rsa_sha256_verify_digest(&rsa->pub, data, s);
break;

case QCRYPTO_HASH_ALG_SHA512:
case QCRYPTO_HASH_ALGO_SHA512:
rv = rsa_sha512_verify_digest(&rsa->pub, data, s);
break;

Expand Down Expand Up @@ -429,10 +429,10 @@ bool qcrypto_akcipher_supports(QCryptoAkCipherOptions *opts)
switch (opts->u.rsa.padding_alg) {
case QCRYPTO_RSA_PADDING_ALG_PKCS1:
switch (opts->u.rsa.hash_alg) {
case QCRYPTO_HASH_ALG_MD5:
case QCRYPTO_HASH_ALG_SHA1:
case QCRYPTO_HASH_ALG_SHA256:
case QCRYPTO_HASH_ALG_SHA512:
case QCRYPTO_HASH_ALGO_MD5:
case QCRYPTO_HASH_ALGO_SHA1:
case QCRYPTO_HASH_ALGO_SHA256:
case QCRYPTO_HASH_ALGO_SHA512:
return true;

default:
Expand Down
16 changes: 8 additions & 8 deletions crypto/block-luks.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ struct QCryptoBlockLUKS {
QCryptoIVGenAlgorithm ivgen_alg;

/* Hash algorithm used for IV generation*/
QCryptoHashAlgorithm ivgen_hash_alg;
QCryptoHashAlgo ivgen_hash_alg;

/*
* Encryption algorithm used for IV generation.
Expand All @@ -141,7 +141,7 @@ struct QCryptoBlockLUKS {
QCryptoCipherAlgorithm ivgen_cipher_alg;

/* Hash algorithm used in pbkdf2 function */
QCryptoHashAlgorithm hash_alg;
QCryptoHashAlgo hash_alg;

/* Name of the secret that was used to open the image */
char *secret;
Expand Down Expand Up @@ -223,7 +223,7 @@ static int qcrypto_block_luks_name_lookup(const char *name,

#define qcrypto_block_luks_hash_name_lookup(name, errp) \
qcrypto_block_luks_name_lookup(name, \
&QCryptoHashAlgorithm_lookup, \
&QCryptoHashAlgo_lookup, \
"Hash algorithm", \
errp)

Expand Down Expand Up @@ -264,7 +264,7 @@ qcrypto_block_luks_has_format(const uint8_t *buf,
*/
static QCryptoCipherAlgorithm
qcrypto_block_luks_essiv_cipher(QCryptoCipherAlgorithm cipher,
QCryptoHashAlgorithm hash,
QCryptoHashAlgo hash,
Error **errp)
{
size_t digestlen = qcrypto_hash_digest_len(hash);
Expand Down Expand Up @@ -1331,11 +1331,11 @@ qcrypto_block_luks_create(QCryptoBlock *block,
luks_opts.ivgen_alg = QCRYPTO_IVGEN_ALG_PLAIN64;
}
if (!luks_opts.has_hash_alg) {
luks_opts.hash_alg = QCRYPTO_HASH_ALG_SHA256;
luks_opts.hash_alg = QCRYPTO_HASH_ALGO_SHA256;
}
if (luks_opts.ivgen_alg == QCRYPTO_IVGEN_ALG_ESSIV) {
if (!luks_opts.has_ivgen_hash_alg) {
luks_opts.ivgen_hash_alg = QCRYPTO_HASH_ALG_SHA256;
luks_opts.ivgen_hash_alg = QCRYPTO_HASH_ALGO_SHA256;
luks_opts.has_ivgen_hash_alg = true;
}
}
Expand Down Expand Up @@ -1386,13 +1386,13 @@ qcrypto_block_luks_create(QCryptoBlock *block,
cipher_mode = QCryptoCipherMode_str(luks_opts.cipher_mode);
ivgen_alg = QCryptoIVGenAlgorithm_str(luks_opts.ivgen_alg);
if (luks_opts.has_ivgen_hash_alg) {
ivgen_hash_alg = QCryptoHashAlgorithm_str(luks_opts.ivgen_hash_alg);
ivgen_hash_alg = QCryptoHashAlgo_str(luks_opts.ivgen_hash_alg);
cipher_mode_spec = g_strdup_printf("%s-%s:%s", cipher_mode, ivgen_alg,
ivgen_hash_alg);
} else {
cipher_mode_spec = g_strdup_printf("%s-%s", cipher_mode, ivgen_alg);
}
hash_alg = QCryptoHashAlgorithm_str(luks_opts.hash_alg);
hash_alg = QCryptoHashAlgo_str(luks_opts.hash_alg);


if (strlen(cipher_alg) >= QCRYPTO_BLOCK_LUKS_CIPHER_NAME_LEN) {
Expand Down
2 changes: 1 addition & 1 deletion crypto/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ QCryptoIVGen *qcrypto_block_get_ivgen(QCryptoBlock *block)
}


QCryptoHashAlgorithm qcrypto_block_get_kdf_hash(QCryptoBlock *block)
QCryptoHashAlgo qcrypto_block_get_kdf_hash(QCryptoBlock *block)
{
return block->kdfhash;
}
Expand Down
2 changes: 1 addition & 1 deletion crypto/blockpriv.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct QCryptoBlock {
QCryptoIVGen *ivgen;
QemuMutex mutex;

QCryptoHashAlgorithm kdfhash;
QCryptoHashAlgo kdfhash;
size_t niv;
uint64_t payload_offset; /* In bytes */
uint64_t sector_size; /* In bytes */
Expand Down
26 changes: 13 additions & 13 deletions crypto/hash-afalg.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,33 +20,33 @@
#include "hmacpriv.h"

static char *
qcrypto_afalg_hash_format_name(QCryptoHashAlgorithm alg,
qcrypto_afalg_hash_format_name(QCryptoHashAlgo alg,
bool is_hmac,
Error **errp)
{
char *name;
const char *alg_name;

switch (alg) {
case QCRYPTO_HASH_ALG_MD5:
case QCRYPTO_HASH_ALGO_MD5:
alg_name = "md5";
break;
case QCRYPTO_HASH_ALG_SHA1:
case QCRYPTO_HASH_ALGO_SHA1:
alg_name = "sha1";
break;
case QCRYPTO_HASH_ALG_SHA224:
case QCRYPTO_HASH_ALGO_SHA224:
alg_name = "sha224";
break;
case QCRYPTO_HASH_ALG_SHA256:
case QCRYPTO_HASH_ALGO_SHA256:
alg_name = "sha256";
break;
case QCRYPTO_HASH_ALG_SHA384:
case QCRYPTO_HASH_ALGO_SHA384:
alg_name = "sha384";
break;
case QCRYPTO_HASH_ALG_SHA512:
case QCRYPTO_HASH_ALGO_SHA512:
alg_name = "sha512";
break;
case QCRYPTO_HASH_ALG_RIPEMD160:
case QCRYPTO_HASH_ALGO_RIPEMD160:
alg_name = "rmd160";
break;

Expand All @@ -65,7 +65,7 @@ qcrypto_afalg_hash_format_name(QCryptoHashAlgorithm alg,
}

static QCryptoAFAlg *
qcrypto_afalg_hash_hmac_ctx_new(QCryptoHashAlgorithm alg,
qcrypto_afalg_hash_hmac_ctx_new(QCryptoHashAlgo alg,
const uint8_t *key, size_t nkey,
bool is_hmac, Error **errp)
{
Expand Down Expand Up @@ -99,14 +99,14 @@ qcrypto_afalg_hash_hmac_ctx_new(QCryptoHashAlgorithm alg,
}

static QCryptoAFAlg *
qcrypto_afalg_hash_ctx_new(QCryptoHashAlgorithm alg,
qcrypto_afalg_hash_ctx_new(QCryptoHashAlgo alg,
Error **errp)
{
return qcrypto_afalg_hash_hmac_ctx_new(alg, NULL, 0, false, errp);
}

QCryptoAFAlg *
qcrypto_afalg_hmac_ctx_new(QCryptoHashAlgorithm alg,
qcrypto_afalg_hmac_ctx_new(QCryptoHashAlgo alg,
const uint8_t *key, size_t nkey,
Error **errp)
{
Expand All @@ -115,7 +115,7 @@ qcrypto_afalg_hmac_ctx_new(QCryptoHashAlgorithm alg,

static int
qcrypto_afalg_hash_hmac_bytesv(QCryptoAFAlg *hmac,
QCryptoHashAlgorithm alg,
QCryptoHashAlgo alg,
const struct iovec *iov,
size_t niov, uint8_t **result,
size_t *resultlen,
Expand Down Expand Up @@ -173,7 +173,7 @@ qcrypto_afalg_hash_hmac_bytesv(QCryptoAFAlg *hmac,
}

static int
qcrypto_afalg_hash_bytesv(QCryptoHashAlgorithm alg,
qcrypto_afalg_hash_bytesv(QCryptoHashAlgo alg,
const struct iovec *iov,
size_t niov, uint8_t **result,
size_t *resultlen,
Expand Down
Loading

0 comments on commit ef834aa

Please sign in to comment.