2001-07-30 09:13:56 +00:00
|
|
|
.\"
|
|
|
|
.\" Copyright (c) 2001 Dima Dorfman.
|
|
|
|
.\" All rights reserved.
|
|
|
|
.\"
|
|
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
|
|
.\" modification, are permitted provided that the following conditions
|
|
|
|
.\" are met:
|
|
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
.\" SUCH DAMAGE.
|
|
|
|
.\"
|
|
|
|
.\" This manual page is based on the mp(3X) manual page from Sun Release
|
|
|
|
.\" 4.1, dated 7 September 1989. It's an old, crufty, and relatively ugly
|
|
|
|
.\" manual page, but it does document what appears to be the "traditional"
|
|
|
|
.\" libmp interface.
|
|
|
|
.\"
|
|
|
|
.\" $FreeBSD$
|
|
|
|
.\"
|
|
|
|
.\" See above for rationale for this date.
|
|
|
|
.Dd September 7, 1989
|
2001-08-21 20:05:39 +00:00
|
|
|
.Dt LIBMP 3
|
2001-07-30 09:13:56 +00:00
|
|
|
.Os
|
|
|
|
.Sh NAME
|
|
|
|
.Nm libmp
|
|
|
|
.Nd traditional BSD multiple precision integer arithmetic library
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
.In mp.h
|
|
|
|
.Pp
|
|
|
|
Function prototypes are given in the main body of the text.
|
|
|
|
.Pp
|
|
|
|
Applications using this interface must be linked with
|
2001-08-09 06:10:46 +00:00
|
|
|
.Fl l Ns Ar mp
|
2001-07-30 09:13:56 +00:00
|
|
|
(this library)
|
|
|
|
and
|
2001-08-09 06:10:46 +00:00
|
|
|
.Fl l Ns Ar crypto
|
|
|
|
.Pq Xr crypto 3 .
|
2001-07-30 09:13:56 +00:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
.Bf -symbolic
|
|
|
|
This interface is obsolete in favor of the
|
|
|
|
.Xr crypto 3
|
|
|
|
.Vt BIGNUM
|
|
|
|
library.
|
|
|
|
.Ef
|
|
|
|
.Pp
|
|
|
|
.Nm
|
|
|
|
is the traditional
|
|
|
|
.Bx
|
|
|
|
multiple precision integer arithmetic library.
|
|
|
|
It has a number of problems,
|
|
|
|
and is unsuitable for use in any programs where reliability is a concern.
|
|
|
|
It is provided here for compatibility only.
|
|
|
|
.Pp
|
|
|
|
These routines perform arithmetic on integers of arbitrary precision
|
|
|
|
stored using the defined type
|
|
|
|
.Vt MINT .
|
|
|
|
Pointers to
|
|
|
|
.Vt MINT
|
|
|
|
are initialized using
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_itom
|
2001-07-30 09:13:56 +00:00
|
|
|
or
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_xtom ,
|
2001-07-30 09:13:56 +00:00
|
|
|
and must be recycled with
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_mfree
|
2001-07-30 09:13:56 +00:00
|
|
|
when they are no longer needed.
|
|
|
|
Routines which store a result in one of their arguments expect that
|
|
|
|
the latter has also been initialized prior to being passed to it.
|
|
|
|
The following routines are defined and implemented:
|
|
|
|
.Pp
|
2001-08-09 06:10:46 +00:00
|
|
|
.Ft "MINT *" Ns
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_itom "short n" ;
|
2001-07-30 09:13:56 +00:00
|
|
|
.Pp
|
2001-08-09 06:10:46 +00:00
|
|
|
.Ft "MINT *" Ns
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_xtom "const char *s" ;
|
2001-07-30 09:13:56 +00:00
|
|
|
.Pp
|
2001-08-09 06:10:46 +00:00
|
|
|
.Ft "char *" Ns
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_mtox "const MINT *mp" ;
|
2001-07-30 09:13:56 +00:00
|
|
|
.Pp
|
|
|
|
.Ft void
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_mfree "MINT *mp" ;
|
2001-07-30 09:13:56 +00:00
|
|
|
.Bd -ragged -offset indent
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_itom
|
2001-07-30 09:13:56 +00:00
|
|
|
returns an
|
|
|
|
.Vt MINT
|
|
|
|
with the value of
|
2001-08-09 06:10:46 +00:00
|
|
|
.Fa n .
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_xtom
|
2001-07-30 09:13:56 +00:00
|
|
|
returns an
|
|
|
|
.Vt MINT
|
|
|
|
with the value of
|
2001-08-09 06:10:46 +00:00
|
|
|
.Fa s ,
|
2001-07-30 09:13:56 +00:00
|
|
|
which is treated to be in hexadecimal.
|
|
|
|
The return values from
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_itom
|
2001-07-30 09:13:56 +00:00
|
|
|
and
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_xtom
|
2001-07-30 09:13:56 +00:00
|
|
|
must be released with
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_mfree
|
2001-07-30 09:13:56 +00:00
|
|
|
when they are no longer needed.
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_mtox
|
2001-07-30 09:13:56 +00:00
|
|
|
returns a null-terminated hexadecimal string having the value of
|
|
|
|
.Fa mp ;
|
|
|
|
its return value must be released with
|
|
|
|
.Fn free
|
2001-08-09 06:10:46 +00:00
|
|
|
.Pq Xr free 3
|
2001-07-30 09:13:56 +00:00
|
|
|
when it is no longer needed.
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
.Ft void
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_madd "const MINT *mp1" "const MINT *mp2" "MINT *rmp" ;
|
2001-07-30 09:13:56 +00:00
|
|
|
.Pp
|
|
|
|
.Ft void
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_msub "const MINT *mp1" "const MINT *mp2" "MINT *rmp" ;
|
2001-07-30 09:13:56 +00:00
|
|
|
.Pp
|
|
|
|
.Ft void
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_mult "const MINT *mp1" "const MINT *mp2" "MINT *rmp" ;
|
2001-07-30 09:13:56 +00:00
|
|
|
.Bd -ragged -offset indent
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_madd ,
|
|
|
|
.Fn mp_msub ,
|
2001-07-30 09:13:56 +00:00
|
|
|
and
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_mult
|
2001-07-30 09:13:56 +00:00
|
|
|
store the sum, difference, or product, respectively, of
|
|
|
|
.Fa mp1
|
|
|
|
and
|
|
|
|
.Fa mp2
|
|
|
|
in
|
|
|
|
.Fa rmp .
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
.Ft void
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_mdiv "const MINT *nmp" "const MINT *dmp" "MINT *qmp" "MINT *rmp" ;
|
2001-07-30 09:13:56 +00:00
|
|
|
.Pp
|
|
|
|
.Ft void
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_sdiv "const MINT *nmp" "short d" "MINT *qmp" "short *ro" ;
|
2001-07-30 09:13:56 +00:00
|
|
|
.Bd -ragged -offset indent
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_mdiv
|
2001-07-30 09:13:56 +00:00
|
|
|
computes the quotient and remainder of
|
|
|
|
.Fa nmp
|
|
|
|
and
|
|
|
|
.Fa dmp
|
|
|
|
and stores the result in
|
|
|
|
.Fa qmp
|
|
|
|
and
|
|
|
|
.Fa rmp ,
|
|
|
|
respectively.
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_sdiv
|
2001-07-30 09:13:56 +00:00
|
|
|
is similar to
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_mdiv
|
2001-07-30 09:13:56 +00:00
|
|
|
except the divisor
|
|
|
|
.Fa ( dmp
|
|
|
|
or
|
|
|
|
.Fa d )
|
|
|
|
and remainder
|
|
|
|
.Fa ( rmp
|
|
|
|
or
|
|
|
|
.Fa ro )
|
|
|
|
are ordinary integers.
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
.Ft void
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_pow "const MINT *bmp" "const MINT *emp" "const MINT *mmp" "MINT *rmp" ;
|
2001-07-30 09:13:56 +00:00
|
|
|
.Pp
|
|
|
|
.Ft void
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_rpow "const MINT *bmp" "short e" "MINT *rmp" ;
|
2001-07-30 09:13:56 +00:00
|
|
|
.Bd -ragged -offset indent
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_rpow
|
2001-07-30 09:13:56 +00:00
|
|
|
computes the result of
|
|
|
|
.Fa bmp
|
|
|
|
raised to the
|
|
|
|
.Fa emp Ns th
|
|
|
|
power and reduced modulo
|
|
|
|
.Fa mmp ;
|
|
|
|
the result is stored in
|
|
|
|
.Fa rmp .
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_pow
|
2001-07-30 09:13:56 +00:00
|
|
|
computes the result of
|
|
|
|
.Fa bmp
|
|
|
|
raised to the
|
|
|
|
.Fa e Ns th
|
|
|
|
power and stores the result in
|
|
|
|
.Fa rmp .
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
.Ft void
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_min "MINT *mp" ;
|
2001-07-30 09:13:56 +00:00
|
|
|
.Pp
|
|
|
|
.Ft void
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_mout "const MINT *mp" ;
|
2001-07-30 09:13:56 +00:00
|
|
|
.Bd -ragged -offset indent
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_min
|
2001-07-30 09:13:56 +00:00
|
|
|
reads a line from standard input, tries to interpret it as a decimal
|
|
|
|
number, and if successful, stores the result in
|
|
|
|
.Fa mp .
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_mout
|
2001-07-30 09:13:56 +00:00
|
|
|
prints the value, in decimal, of
|
|
|
|
.Fa mp
|
|
|
|
to standard output (without a trailing newline).
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
.Ft void
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_gcd "const MINT *mp1" "const MINT *mp2" "MINT *rmp" ;
|
2001-07-30 09:13:56 +00:00
|
|
|
.Bd -ragged -offset indent
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_gcd
|
2001-07-30 09:13:56 +00:00
|
|
|
computes the greatest common divisor of
|
|
|
|
.Fa mp1
|
|
|
|
and
|
|
|
|
.Fa mp2
|
2001-08-09 06:10:46 +00:00
|
|
|
and stores the result in
|
2001-07-30 09:13:56 +00:00
|
|
|
.Fa rmp .
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
.Ft int
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_mcmp "const MINT *mp1" "const MINT *mp2" ;
|
2001-07-30 09:13:56 +00:00
|
|
|
.Bd -ragged -offset indent
|
|
|
|
.Fa mcmp
|
|
|
|
compares the values of
|
|
|
|
.Fa mp1
|
|
|
|
and
|
|
|
|
.Fa mp2
|
|
|
|
and returns
|
|
|
|
0 if the two values are equal,
|
|
|
|
a value greater than 0 if
|
|
|
|
.Fa mp1
|
|
|
|
is greater than
|
|
|
|
.Fa mp2 ,
|
|
|
|
and a value less than 0 if
|
|
|
|
.Fa mp2
|
|
|
|
is greater than
|
|
|
|
.Fa mp1 .
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
.Ft void
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_move "const MINT *smp" "MINT *tmp" ;
|
2001-07-30 09:13:56 +00:00
|
|
|
.Bd -ragged -offset indent
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_move
|
2001-07-30 09:13:56 +00:00
|
|
|
copies the value of
|
|
|
|
.Fa smp
|
|
|
|
to
|
|
|
|
.Fa tmp
|
|
|
|
(both values must be initialized).
|
|
|
|
.Ed
|
|
|
|
.Pp
|
|
|
|
.Ft void
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_msqrt "const MINT *nmp" "MINT *xmp" "MINT *rmp" ;
|
2001-07-30 09:13:56 +00:00
|
|
|
.Bd -ragged -offset indent
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_msqrt
|
2001-07-30 09:13:56 +00:00
|
|
|
computes the square root and remainder of
|
|
|
|
.Fa nmp
|
|
|
|
and stores them in
|
|
|
|
.Fa xmp
|
|
|
|
and
|
|
|
|
.Fa rmp ,
|
|
|
|
respectively.
|
|
|
|
.Ed
|
|
|
|
.Sh IMPLEMENTATION NOTES
|
|
|
|
This version of
|
|
|
|
.Nm
|
|
|
|
is implemented in terms of the
|
|
|
|
.Xr crypto 3
|
|
|
|
.Vt BIGNUM
|
|
|
|
library.
|
|
|
|
.Sh DIAGNOSTICS
|
|
|
|
Running out of memory or illegal operations result in error messages
|
|
|
|
on standard error and a call to
|
|
|
|
.Xr abort 3 .
|
|
|
|
.Sh SEE ALSO
|
|
|
|
.Xr abort 3 ,
|
2003-08-30 05:35:46 +00:00
|
|
|
.Xr bn 3 ,
|
2001-07-30 09:13:56 +00:00
|
|
|
.Xr crypto 3 ,
|
|
|
|
.Xr free 3 ,
|
2001-08-09 06:10:46 +00:00
|
|
|
.Xr malloc 3 ,
|
|
|
|
.Xr math 3
|
2001-07-30 09:13:56 +00:00
|
|
|
.Sh HISTORY
|
|
|
|
A
|
|
|
|
.Nm
|
|
|
|
library appeared in
|
|
|
|
.Bx 4.3 .
|
|
|
|
.Fx 2.2
|
|
|
|
shipped with a
|
|
|
|
.Nm
|
|
|
|
implemented in terms of
|
|
|
|
.Nm libgmp .
|
|
|
|
This implementation appeared in
|
|
|
|
.Fx 5.0 .
|
|
|
|
.Sh BUGS
|
|
|
|
Errors are reported via output to standard error and abnormal
|
|
|
|
program termination instead of via return values.
|
|
|
|
The application cannot control this behavior.
|
|
|
|
.Pp
|
|
|
|
It is not clear whether the string returned by
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_mtox
|
2001-07-30 09:13:56 +00:00
|
|
|
may be written to by the caller.
|
|
|
|
This implementation allows it, but others may not.
|
|
|
|
Ideally,
|
2009-02-26 21:43:15 +00:00
|
|
|
.Fn mp_mtox
|
2001-07-30 09:13:56 +00:00
|
|
|
would take a pointer to a buffer to fill in.
|
|
|
|
.Pp
|
|
|
|
It is not clear whether using the same variable as both source and
|
|
|
|
destination in a single invocation is permitted.
|
|
|
|
Some of the calls in this implementation allow this, while others
|
|
|
|
do not.
|