lib/crypto/mpi/mpi-mul.c

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

File Facts

System
Linux kernel
Corpus path
lib/crypto/mpi/mpi-mul.c
Extension
.c
Size
2533 bytes
Lines
112
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 (wp == up || wp == vp) {
			wp = mpi_alloc_limb_space(wsize);
			if (!wp)
				return -ENOMEM;
			assign_wp = 1;
		} else {
			err = mpi_resize(w, wsize);
			if (err)
				return err;
			wp = w->d;
		}
	} else { /* Make U and V not overlap with W.	*/
		if (wp == up) {
			/* W and U are identical.  Allocate temporary space for U. */
			up = tmp_limb = mpi_alloc_limb_space(usize);
			if (!up)
				return -ENOMEM;
			/* Is V identical too?  Keep it identical with U.  */
			if (wp == vp)
				vp = up;
			/* Copy to the temporary space.  */
			MPN_COPY(up, wp, usize);
		} else if (wp == vp) {
			/* W and V are identical.  Allocate temporary space for V. */
			vp = tmp_limb = mpi_alloc_limb_space(vsize);
			if (!vp)
				return -ENOMEM;
			/* Copy to the temporary space.  */
			MPN_COPY(vp, wp, vsize);
		}
	}

	if (!vsize)
		wsize = 0;
	else {
		err = mpihelp_mul(wp, up, usize, vp, vsize, &cy);
		if (err) {
			if (assign_wp)
				mpi_free_limb_space(wp);
			goto free_tmp_limb;
		}
		wsize -= cy ? 0:1;
	}

	if (assign_wp)
		mpi_assign_limb_space(w, wp, wsize);
	w->nlimbs = wsize;
	w->sign = sign_product;

free_tmp_limb:
	if (tmp_limb)
		mpi_free_limb_space(tmp_limb);
	return err;
}
EXPORT_SYMBOL_GPL(mpi_mul);

int mpi_mulm(MPI w, MPI u, MPI v, MPI m)
{
	return mpi_mul(w, u, v) ?:
	       mpi_tdiv_r(w, w, m);
}
EXPORT_SYMBOL_GPL(mpi_mulm);

Annotation

Implementation Notes