lib/crypto/mpi/mpi-add.c

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

File Facts

System
Linux kernel
Corpus path
lib/crypto/mpi/mpi-add.c
Extension
.c
Size
2604 bytes
Lines
121
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 (usize != vsize) {
			mpihelp_sub(wp, up, usize, vp, vsize);
			wsize = usize;
			MPN_NORMALIZE(wp, wsize);
			wsign = usign;
		} else if (mpihelp_cmp(up, vp, usize) < 0) {
			mpihelp_sub_n(wp, vp, up, usize);
			wsize = usize;
			MPN_NORMALIZE(wp, wsize);
			if (!usign)
				wsign = 1;
		} else {
			mpihelp_sub_n(wp, up, vp, usize);
			wsize = usize;
			MPN_NORMALIZE(wp, wsize);
			if (usign)
				wsign = 1;
		}
	} else { /* U and V have same sign. Add them. */
		mpi_limb_t cy = mpihelp_add(wp, up, usize, vp, vsize);
		wp[usize] = cy;
		wsize = usize + cy;
		if (usign)
			wsign = 1;
	}

	w->nlimbs = wsize;
	w->sign = wsign;
	return 0;
}
EXPORT_SYMBOL_GPL(mpi_add);

int mpi_sub(MPI w, MPI u, MPI v)
{
	int err;
	MPI vv;

	vv = mpi_copy(v);
	if (!vv)
		return -ENOMEM;

	vv->sign = !vv->sign;
	err = mpi_add(w, u, vv);
	mpi_free(vv);

	return err;
}
EXPORT_SYMBOL_GPL(mpi_sub);

int mpi_addm(MPI w, MPI u, MPI v, MPI m)
{
	return mpi_add(w, u, v) ?:
	       mpi_mod(w, w, m);
}
EXPORT_SYMBOL_GPL(mpi_addm);

int mpi_subm(MPI w, MPI u, MPI v, MPI m)
{
	return mpi_sub(w, u, v) ?:
	       mpi_mod(w, w, m);
}
EXPORT_SYMBOL_GPL(mpi_subm);

Annotation

Implementation Notes