Maven module :un.api : api-encoding :
Class : un.impl.cryptography.ec.ECCrypt
Extends/Implements : -
Subclasses : -

Elliptic curve cryptographic primitives. The cryptography is based on
the fact that it is reasonably fast to multiply an elliptic curve point by an
integer (k*P), but apparently very hard to recover the integer by
computing the inverse of an elliptic curve point. Thus, if (x) is
a secret key, making the product (x*P) public hopefully won't
expose the secret key. Multiplication is commutative, associative, and
distributive so that x*k*P == k*x*P == (k*x)*P and (x + k)*P == x*P + k*P.
Addition of curve points is commutative and associative, so that
x*P + k*P == k*P + x*P.

This public domain software was written by Stuart D. Gathman
based on a C program written by Paulo S.L.M. Barreto
based on original C++ software written by
George Barwood

THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''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 AUTHORS 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.
@author Stuart D. Gathman


Variables : -
Functions : ECCrypt, makePublicKey, encodeSecret, decodeSecret, sign, verify, main



public void ECCrypt (ECPoint curve_point)


Compute the public key for a private key.
param  privateKey The private key (x).
return  the public key (x*P).
public BigInteger makePublicKey (BigInteger privateKey)


Encode a secret into a public form and a shared value.
@param secret holds a one-time secret multiplier (k).
@param publicKey holds a partner's public key (x*P).
@return the secret multiplier's public form (k*P) in r
and the shared value (k*x*P) in s.
public Pair encodeSecret (BigInteger publicKey, BigInteger secret)


Decode a secret shared value.
@param privateKey holds one's secret key (x).
@param message holds the public form of a partner's secret multiplier (k*P).
@return the shared value (x*k*P).
BigInteger decodeSecret (BigInteger privateKey, BigInteger message)


Compute a signature [r = k*P + c, s = k - r*x] mod m.
The elliptic curve point (P) was supplied
in the constructor. The secret multiplier must be random. For instance,
if you use the same multiplier for two signatures, the secret key (x) can
be recovered by subtracting:
s2 - s1 == (k - r2*x) - (k - r1*x) == (r1 - r2)*x
and x == (s2 - s1)/(r1 - r2).

@param privateKey The secret key (x).
@param secret A one time secret multiplier (k).
@param mac The message authentication code or hash (c).
@return the Pair (r,s).
public Pair sign (BigInteger privateKey, BigInteger secret, BigInteger mac)


Verify a signature [r,s]. Computes r - s*P + r*x*P
== k*P + c - (k-r*x)*P + r*x*P == c mod m,
and compares with mac. The curve point (P)
was supplied in the contructor.
@param publicKey The signers public key (x*P).
@param mac The message authentication code or hash.
@param sig The signature (r,s).
@return true if the signature matches.
public boolean verify (BigInteger publicKey, BigInteger mac, Pair sig)


Test key exchange and signature algorithms.
public void main (String[] argv)