crypto/lskcipher.c

Source file repositories/reference/linux-study-clean/crypto/lskcipher.c

File Facts

System
Linux kernel
Corpus path
crypto/lskcipher.c
Extension
.c
Size
16172 bytes
Lines
588
Domain
Kernel Services
Bucket
crypto
Inferred role
Kernel Services: exported/initcall integration point
Status
integration implementation candidate

Why This File Exists

Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.

Dependency Surface

Detected Declarations

Annotated Snippet

if (ret) {
			crypto_unregister_lskciphers(algs, i);
			return ret;
		}
	}

	return 0;
}
EXPORT_SYMBOL_GPL(crypto_register_lskciphers);

void crypto_unregister_lskciphers(struct lskcipher_alg *algs, int count)
{
	int i;

	for (i = count - 1; i >= 0; --i)
		crypto_unregister_lskcipher(&algs[i]);
}
EXPORT_SYMBOL_GPL(crypto_unregister_lskciphers);

int lskcipher_register_instance(struct crypto_template *tmpl,
				struct lskcipher_instance *inst)
{
	int err;

	if (WARN_ON(!inst->free))
		return -EINVAL;

	err = lskcipher_prepare_alg(&inst->alg);
	if (err)
		return err;

	return crypto_register_instance(tmpl, lskcipher_crypto_instance(inst));
}
EXPORT_SYMBOL_GPL(lskcipher_register_instance);

static int lskcipher_setkey_simple(struct crypto_lskcipher *tfm, const u8 *key,
				   unsigned int keylen)
{
	struct crypto_lskcipher *cipher = lskcipher_cipher_simple(tfm);

	crypto_lskcipher_clear_flags(cipher, CRYPTO_TFM_REQ_MASK);
	crypto_lskcipher_set_flags(cipher, crypto_lskcipher_get_flags(tfm) &
				   CRYPTO_TFM_REQ_MASK);
	return crypto_lskcipher_setkey(cipher, key, keylen);
}

static int lskcipher_init_tfm_simple(struct crypto_lskcipher *tfm)
{
	struct lskcipher_instance *inst = lskcipher_alg_instance(tfm);
	struct crypto_lskcipher **ctx = crypto_lskcipher_ctx(tfm);
	struct crypto_lskcipher_spawn *spawn;
	struct crypto_lskcipher *cipher;

	spawn = lskcipher_instance_ctx(inst);
	cipher = crypto_spawn_lskcipher(spawn);
	if (IS_ERR(cipher))
		return PTR_ERR(cipher);

	*ctx = cipher;
	return 0;
}

static void lskcipher_exit_tfm_simple(struct crypto_lskcipher *tfm)
{
	struct crypto_lskcipher **ctx = crypto_lskcipher_ctx(tfm);

	crypto_free_lskcipher(*ctx);
}

static void lskcipher_free_instance_simple(struct lskcipher_instance *inst)
{
	crypto_drop_lskcipher(lskcipher_instance_ctx(inst));
	kfree(inst);
}

/**
 * lskcipher_alloc_instance_simple - allocate instance of simple block cipher
 *
 * Allocate an lskcipher_instance for a simple block cipher mode of operation,
 * e.g. cbc or ecb.  The instance context will have just a single crypto_spawn,
 * that for the underlying cipher.  The {min,max}_keysize, ivsize, blocksize,
 * alignmask, and priority are set from the underlying cipher but can be
 * overridden if needed.  The tfm context defaults to
 * struct crypto_lskcipher *, and default ->setkey(), ->init(), and
 * ->exit() methods are installed.
 *
 * @tmpl: the template being instantiated
 * @tb: the template parameters
 *
 * Return: a pointer to the new instance, or an ERR_PTR().  The caller still

Annotation

Implementation Notes