]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
crypto: sig - Rename crypto_sig_maxsize() to crypto_sig_keysize()
authorLukas Wunner <lukas@wunner.de>
Tue, 10 Sep 2024 14:30:26 +0000 (16:30 +0200)
committerHerbert Xu <herbert@gondor.apana.org.au>
Sat, 5 Oct 2024 05:22:04 +0000 (13:22 +0800)
crypto_sig_maxsize() is a bit of a misnomer as it doesn't return the
maximum signature size, but rather the key size.

Rename it as well as all implementations of the ->max_size callback.
A subsequent commit introduces a crypto_sig_maxsize() function which
returns the actual maximum signature size.

While at it, change the return type of crypto_sig_keysize() from int to
unsigned int for consistency with crypto_akcipher_maxsize().  None of
the callers checks for a negative return value and an error condition
can always be indicated by returning zero.

Signed-off-by: Lukas Wunner <lukas@wunner.de>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Documentation/crypto/api-sig.rst
crypto/asymmetric_keys/public_key.c
crypto/ecdsa-x962.c
crypto/ecdsa.c
crypto/ecrdsa.c
crypto/rsassa-pkcs1.c
crypto/sig.c
crypto/testmgr.c
include/crypto/sig.h

index a96dba66296b70db9e8c087825720a08570a3b47..10dabc87df0294d8884e5e7c8e32ec38a5e8f09b 100644 (file)
@@ -11,4 +11,5 @@ Asymmetric Signature API
    :doc: Generic Public Key Signature API
 
 .. kernel-doc:: include/crypto/sig.h
-   :functions: crypto_alloc_sig crypto_free_sig crypto_sig_set_pubkey crypto_sig_set_privkey crypto_sig_maxsize crypto_sig_sign crypto_sig_verify
+   :functions: crypto_alloc_sig crypto_free_sig crypto_sig_set_pubkey crypto_sig_set_privkey crypto_sig_keysize crypto_sig_sign crypto_sig_verify
+
index cc6d48cafa2b3deb5243f97cba8607e69b1072c9..8bf5aa329c260f1992eecbf34cd26bb330d4c809 100644 (file)
@@ -201,7 +201,7 @@ static int software_key_query(const struct kernel_pkey_params *params,
                if (ret < 0)
                        goto error_free_tfm;
 
-               len = crypto_sig_maxsize(sig);
+               len = crypto_sig_keysize(sig);
 
                info->supported_ops = KEYCTL_SUPPORTS_VERIFY;
                if (pkey->key_is_private)
@@ -332,7 +332,7 @@ static int software_key_eds_op(struct kernel_pkey_params *params,
                if (ret)
                        goto error_free_tfm;
 
-               ksz = crypto_sig_maxsize(sig);
+               ksz = crypto_sig_keysize(sig);
        } else {
                tfm = crypto_alloc_akcipher(alg_name, 0, 0);
                if (IS_ERR(tfm)) {
index 022e654c075d5925aa66f058c097a94976fd1030..8a15232dfa770d23f9c6157bf75c808bc6a08cd2 100644 (file)
@@ -81,7 +81,7 @@ static int ecdsa_x962_verify(struct crypto_sig *tfm,
        struct ecdsa_x962_signature_ctx sig_ctx;
        int err;
 
-       sig_ctx.ndigits = DIV_ROUND_UP(crypto_sig_maxsize(ctx->child),
+       sig_ctx.ndigits = DIV_ROUND_UP(crypto_sig_keysize(ctx->child),
                                       sizeof(u64));
 
        err = asn1_ber_decoder(&ecdsasignature_decoder, &sig_ctx, src, slen);
@@ -92,11 +92,11 @@ static int ecdsa_x962_verify(struct crypto_sig *tfm,
                                 digest, dlen);
 }
 
-static unsigned int ecdsa_x962_max_size(struct crypto_sig *tfm)
+static unsigned int ecdsa_x962_key_size(struct crypto_sig *tfm)
 {
        struct ecdsa_x962_ctx *ctx = crypto_sig_ctx(tfm);
 
-       return crypto_sig_maxsize(ctx->child);
+       return crypto_sig_keysize(ctx->child);
 }
 
 static int ecdsa_x962_set_pub_key(struct crypto_sig *tfm,
@@ -179,7 +179,7 @@ static int ecdsa_x962_create(struct crypto_template *tmpl, struct rtattr **tb)
        inst->alg.exit = ecdsa_x962_exit_tfm;
 
        inst->alg.verify = ecdsa_x962_verify;
-       inst->alg.max_size = ecdsa_x962_max_size;
+       inst->alg.key_size = ecdsa_x962_key_size;
        inst->alg.set_pub_key = ecdsa_x962_set_pub_key;
 
        inst->free = ecdsa_x962_free;
index 1f7c29468a864e9d49dc4d7fa93be23265360b9f..6cb0a6ce9de199ac109fa02fc5a05814615551c1 100644 (file)
@@ -162,7 +162,7 @@ static void ecdsa_exit_tfm(struct crypto_sig *tfm)
        ecdsa_ecc_ctx_deinit(ctx);
 }
 
-static unsigned int ecdsa_max_size(struct crypto_sig *tfm)
+static unsigned int ecdsa_key_size(struct crypto_sig *tfm)
 {
        struct ecc_ctx *ctx = crypto_sig_ctx(tfm);
 
@@ -179,7 +179,7 @@ static int ecdsa_nist_p521_init_tfm(struct crypto_sig *tfm)
 static struct sig_alg ecdsa_nist_p521 = {
        .verify = ecdsa_verify,
        .set_pub_key = ecdsa_set_pub_key,
-       .max_size = ecdsa_max_size,
+       .key_size = ecdsa_key_size,
        .init = ecdsa_nist_p521_init_tfm,
        .exit = ecdsa_exit_tfm,
        .base = {
@@ -201,7 +201,7 @@ static int ecdsa_nist_p384_init_tfm(struct crypto_sig *tfm)
 static struct sig_alg ecdsa_nist_p384 = {
        .verify = ecdsa_verify,
        .set_pub_key = ecdsa_set_pub_key,
-       .max_size = ecdsa_max_size,
+       .key_size = ecdsa_key_size,
        .init = ecdsa_nist_p384_init_tfm,
        .exit = ecdsa_exit_tfm,
        .base = {
@@ -223,7 +223,7 @@ static int ecdsa_nist_p256_init_tfm(struct crypto_sig *tfm)
 static struct sig_alg ecdsa_nist_p256 = {
        .verify = ecdsa_verify,
        .set_pub_key = ecdsa_set_pub_key,
-       .max_size = ecdsa_max_size,
+       .key_size = ecdsa_key_size,
        .init = ecdsa_nist_p256_init_tfm,
        .exit = ecdsa_exit_tfm,
        .base = {
@@ -245,7 +245,7 @@ static int ecdsa_nist_p192_init_tfm(struct crypto_sig *tfm)
 static struct sig_alg ecdsa_nist_p192 = {
        .verify = ecdsa_verify,
        .set_pub_key = ecdsa_set_pub_key,
-       .max_size = ecdsa_max_size,
+       .key_size = ecdsa_key_size,
        .init = ecdsa_nist_p192_init_tfm,
        .exit = ecdsa_exit_tfm,
        .base = {
index 7383dd11089b080fc42e073525a6d9421b91bae4..f981b31f4249718ab7bb4ae4e469960b47daf21b 100644 (file)
@@ -241,7 +241,7 @@ static int ecrdsa_set_pub_key(struct crypto_sig *tfm, const void *key,
        return 0;
 }
 
-static unsigned int ecrdsa_max_size(struct crypto_sig *tfm)
+static unsigned int ecrdsa_key_size(struct crypto_sig *tfm)
 {
        struct ecrdsa_ctx *ctx = crypto_sig_ctx(tfm);
 
@@ -259,7 +259,7 @@ static void ecrdsa_exit_tfm(struct crypto_sig *tfm)
 static struct sig_alg ecrdsa_alg = {
        .verify         = ecrdsa_verify,
        .set_pub_key    = ecrdsa_set_pub_key,
-       .max_size       = ecrdsa_max_size,
+       .key_size       = ecrdsa_key_size,
        .exit           = ecrdsa_exit_tfm,
        .base = {
                .cra_name        = "ecrdsa",
index b291ec0944a262e0dc805d4e66323abee1ace4a6..9c28f1c628264a7e4bcdef038977a6c3995568e9 100644 (file)
@@ -302,7 +302,7 @@ static int rsassa_pkcs1_verify(struct crypto_sig *tfm,
        return 0;
 }
 
-static unsigned int rsassa_pkcs1_max_size(struct crypto_sig *tfm)
+static unsigned int rsassa_pkcs1_key_size(struct crypto_sig *tfm)
 {
        struct rsassa_pkcs1_ctx *ctx = crypto_sig_ctx(tfm);
 
@@ -419,7 +419,7 @@ static int rsassa_pkcs1_create(struct crypto_template *tmpl, struct rtattr **tb)
 
        inst->alg.sign = rsassa_pkcs1_sign;
        inst->alg.verify = rsassa_pkcs1_verify;
-       inst->alg.max_size = rsassa_pkcs1_max_size;
+       inst->alg.key_size = rsassa_pkcs1_key_size;
        inst->alg.set_pub_key = rsassa_pkcs1_set_pub_key;
        inst->alg.set_priv_key = rsassa_pkcs1_set_priv_key;
 
index 84d0ea9fd73bb9dbbc18e00dbe27b79a26907a39..7a3521bee29a4c7c2808fc2ba616ca206b14a44e 100644 (file)
@@ -125,7 +125,7 @@ int crypto_register_sig(struct sig_alg *alg)
                alg->set_priv_key = sig_default_set_key;
        if (!alg->set_pub_key)
                return -EINVAL;
-       if (!alg->max_size)
+       if (!alg->key_size)
                return -EINVAL;
 
        sig_prepare_alg(alg);
index 5760615e27b1be605806f70a6eac12fed6b9f2f7..9d6774c5a463d4a798afaa72cf3d32e69ebd0628 100644 (file)
@@ -4340,7 +4340,7 @@ static int test_sig_one(struct crypto_sig *tfm, const struct sig_testvec *vecs)
        if (vecs->public_key_vec)
                return 0;
 
-       sig_size = crypto_sig_maxsize(tfm);
+       sig_size = crypto_sig_keysize(tfm);
        if (sig_size < vecs->c_size) {
                pr_err("alg: sig: invalid maxsize %u\n", sig_size);
                return -EINVAL;
index bbc902642bf5aced5f15b468d7fdaf8e251dd6ac..a3ef17c5f72f66bd5018a1b097c4a747e5a058a6 100644 (file)
@@ -32,7 +32,7 @@ struct crypto_sig {
  * @set_priv_key: Function invokes the algorithm specific set private key
  *             function, which knows how to decode and interpret
  *             the BER encoded private key and parameters. Optional.
- * @max_size:  Function returns key size. Mandatory.
+ * @key_size:  Function returns key size. Mandatory.
  * @init:      Initialize the cryptographic transformation object.
  *             This function is used to initialize the cryptographic
  *             transformation object. This function is called only once at
@@ -58,7 +58,7 @@ struct sig_alg {
                           const void *key, unsigned int keylen);
        int (*set_priv_key)(struct crypto_sig *tfm,
                            const void *key, unsigned int keylen);
-       unsigned int (*max_size)(struct crypto_sig *tfm);
+       unsigned int (*key_size)(struct crypto_sig *tfm);
        int (*init)(struct crypto_sig *tfm);
        void (*exit)(struct crypto_sig *tfm);
 
@@ -121,20 +121,20 @@ static inline void crypto_free_sig(struct crypto_sig *tfm)
 }
 
 /**
- * crypto_sig_maxsize() - Get len for output buffer
+ * crypto_sig_keysize() - Get key size
  *
- * Function returns the dest buffer size required for a given key.
+ * Function returns the key size in bytes.
  * Function assumes that the key is already set in the transformation. If this
- * function is called without a setkey or with a failed setkey, you will end up
+ * function is called without a setkey or with a failed setkey, you may end up
  * in a NULL dereference.
  *
  * @tfm:       signature tfm handle allocated with crypto_alloc_sig()
  */
-static inline int crypto_sig_maxsize(struct crypto_sig *tfm)
+static inline unsigned int crypto_sig_keysize(struct crypto_sig *tfm)
 {
        struct sig_alg *alg = crypto_sig_alg(tfm);
 
-       return alg->max_size(tfm);
+       return alg->key_size(tfm);
 }
 
 /**