Table of Contents

Class: ecc src/ecc.py

This is the Elliptic Curve Cryptography base class. Used for generating and receiving Diffie-Hellman values, along with Nyberg-Rueppel signature and verification.

Sample usage:

                >>> from ecc.ecc import ecc
                >>> e,f=ecc(1),ecc(2)
                >>> e_pub_key, f_pub_key = e.publicKey(), f.publicKey()

                >>> # Key Exchange
                >>> secret1 = e.DH_recv(f_pub_key)
                >>> secret2 = f.DH_recv(e_pub_key)
                >>> secret1 == secret2
                1

                >>> # Signing / Verification
                >>> msg = "Hello World!"
                >>> sig = e.sign(msg)
                >>> f.verify(msg,e_pub_key,sig)
                1

                >>> # Tamper with the message
                >>> msg += 'a'
                >>> f.verify(msg,e_pub_key,sig)
                0

This class implements Public Key algorithms whose security draws from the intractability of the Elliptic Curve Discrete Logarithm Problem (ECDLP). This particular implementation uses a 113 bit curve of type II with an optimal normal basis and the form:

                E: y^2 + xy = x^3 + x^2 + 1

This module, concepts, and underlying C code relies heavily on the work of Michael Rosing, and his book, Implementing Elliptic Curve Cryptography.

Methods   
DH_recv
__init__
makeKeypair
publicKey
sign
verify
  DH_recv 
DH_recv ( self,  inVal )

Returns the mutually shared secret when provided with inVal, the other party's two-element tuple containing the binary representation of their public key. The key derivation scheme is Diffie-Hellman.

Exceptions   
RuntimeError( "Cannot call DH_recv on a non-DH keypair" )
TypeError( "inVal is not a tuple of size 2" )
  __init__ 
__init__ (
        self,
        entropy=None,
        mode='DH',
        )

Constructor. Provide an arbitrary integer of cryptographically secure entropy to be used in generating a random secret key. Examples of good sources include CSPRNGs and /dev/random. mode determines how the public key is generated. Possible values are DH for Diffie-Hellman and ECKGP for the Elliptic Curve Key Generation Protocol. ECKGP mode cannot be used for any of the Diffie-Hellman routines.

  makeKeypair 
makeKeypair (
        self,
        entropy,
        mode='DH',
        )

Makes a keypair for use as descibed for the constructor.

Exceptions   
TypeError( "entropy must be an integer" )
TypeError( "mode must be either DH or ECKGP" )
  publicKey 
publicKey ( self )

Returns a two element tuple containing the values to be exchanged during the Diffie-Hellman Key Agreement protocol or used in verification. Essentially this is a small binary representation of your public key, which constitutes a given point (x,y) on the public curve.

Exceptions   
RuntimeError( "No keypair has yet been created." )
  sign 
sign ( self,  message )

This method will cryptographically sign the string message to prevent it from being tampered with. Signing scheme is Nyberg-Rueppel. The method returns a two element tuple of binary values representing the signature.

Exceptions   
TypeError( "message must be a non-zero length string" )
  verify 
verify (
        self,
        message,
        public_key,
        signature,
        )

This method will verify that the string message has not been tampered with. Returns true or false. signature is the tuple produced by the original signing of message.

Exceptions   
TypeError( "message must be a non-zero length string" )
TypeError( "public_key is not a tuple" )
TypeError( "signature is not a tuple" )

Table of Contents

This document was automatically generated on Thu Nov 29 10:42:16 2001 by HappyDoc version r1_6_1