crypto/shash.c

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

File Facts

System
Linux kernel
Corpus path
crypto/shash.c
Extension
.c
Size
13821 bytes
Lines
549
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 (*blenp) {
			memcpy(buf + *blenp, data, bs - *blenp);
			nbytes = bs;
			src = buf;
		}

		err = crypto_shash_alg(tfm)->update(desc, src, nbytes);
		if (err < 0)
			return err;

		data += nbytes - err - *blenp;
		len -= nbytes - err - *blenp;
		*blenp = 0;
	}

	if (*blenp || !out) {
		memcpy(buf + *blenp, data, len);
		*blenp += len;
		if (!out)
			return 0;
		data = buf;
		len = *blenp;
	}

finup:
	return crypto_shash_op_and_zero(crypto_shash_alg(tfm)->finup, desc,
					data, len, out);
}
EXPORT_SYMBOL_GPL(crypto_shash_finup);

static int shash_default_digest(struct shash_desc *desc, const u8 *data,
				unsigned int len, u8 *out)
{
	return __crypto_shash_init(desc) ?:
	       crypto_shash_finup(desc, data, len, out);
}

int crypto_shash_digest(struct shash_desc *desc, const u8 *data,
			unsigned int len, u8 *out)
{
	struct crypto_shash *tfm = desc->tfm;

	if (crypto_shash_get_flags(tfm) & CRYPTO_TFM_NEED_KEY)
		return -ENOKEY;

	return crypto_shash_op_and_zero(crypto_shash_alg(tfm)->digest, desc,
					data, len, out);
}
EXPORT_SYMBOL_GPL(crypto_shash_digest);

int crypto_shash_tfm_digest(struct crypto_shash *tfm, const u8 *data,
			    unsigned int len, u8 *out)
{
	SHASH_DESC_ON_STACK(desc, tfm);

	desc->tfm = tfm;
	return crypto_shash_digest(desc, data, len, out);
}
EXPORT_SYMBOL_GPL(crypto_shash_tfm_digest);

static int __crypto_shash_export(struct shash_desc *desc, void *out,
				 int (*export)(struct shash_desc *desc,
					       void *out))
{
	struct crypto_shash *tfm = desc->tfm;
	u8 *buf = shash_desc_ctx(desc);
	unsigned int plen, ss;

	plen = crypto_shash_blocksize(tfm) + 1;
	ss = crypto_shash_statesize(tfm);
	if (crypto_shash_block_only(tfm))
		ss -= plen;
	if (!export) {
		memcpy(out, buf, ss);
		return 0;
	}

	return export(desc, out);
}

int crypto_shash_export_core(struct shash_desc *desc, void *out)
{
	return __crypto_shash_export(desc, out,
				     crypto_shash_alg(desc->tfm)->export_core);
}
EXPORT_SYMBOL_GPL(crypto_shash_export_core);

int crypto_shash_export(struct shash_desc *desc, void *out)
{
	struct crypto_shash *tfm = desc->tfm;

Annotation

Implementation Notes