lib/crypto/mpi/mpi-bit.c

Source file repositories/reference/linux-study-clean/lib/crypto/mpi/mpi-bit.c

File Facts

System
Linux kernel
Corpus path
lib/crypto/mpi/mpi-bit.c
Extension
.c
Size
4039 bytes
Lines
178
Domain
Kernel Services
Bucket
lib
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 (nlimbs >= x->nlimbs) {
			x->nlimbs = 0;
			return 0;
		}

		if (nlimbs) {
			for (i = 0; i < x->nlimbs - nlimbs; i++)
				x->d[i] = x->d[i+nlimbs];
			x->d[i] = 0;
			x->nlimbs -= nlimbs;
		}
		if (x->nlimbs && nbits)
			mpihelp_rshift(x->d, x->d, x->nlimbs, nbits);
	} else if (nlimbs) {
		/* Copy and shift by more or equal bits than in a limb. */
		xsize = a->nlimbs;
		x->sign = a->sign;
		err = RESIZE_IF_NEEDED(x, xsize);
		if (err)
			return err;
		x->nlimbs = xsize;
		for (i = 0; i < a->nlimbs; i++)
			x->d[i] = a->d[i];
		x->nlimbs = i;

		if (nlimbs >= x->nlimbs) {
			x->nlimbs = 0;
			return 0;
		}

		for (i = 0; i < x->nlimbs - nlimbs; i++)
			x->d[i] = x->d[i+nlimbs];
		x->d[i] = 0;
		x->nlimbs -= nlimbs;

		if (x->nlimbs && nbits)
			mpihelp_rshift(x->d, x->d, x->nlimbs, nbits);
	} else {
		/* Copy and shift by less than bits in a limb.  */
		xsize = a->nlimbs;
		x->sign = a->sign;
		err = RESIZE_IF_NEEDED(x, xsize);
		if (err)
			return err;
		x->nlimbs = xsize;

		if (xsize) {
			if (nbits)
				mpihelp_rshift(x->d, a->d, x->nlimbs, nbits);
			else {
				/* The rshift helper function is not specified for
				 * NBITS==0, thus we do a plain copy here.
				 */
				for (i = 0; i < x->nlimbs; i++)
					x->d[i] = a->d[i];
			}
		}
	}
	MPN_NORMALIZE(x->d, x->nlimbs);

	return 0;
}
EXPORT_SYMBOL_GPL(mpi_rshift);

Annotation

Implementation Notes