pyPhelix:   a Python wrapper for Phelix

Phelix is a highly efficient stream cipher that, in a single pass of the data, both encrypts and generates a hash, a MAC.   Phelix is a 128-bit stream cipher that can accept up to a 256-bit key.

From Bruce Schneier's site:

Phelix is a high-speed stream cipher with a built-in MAC functionality. It is efficient in both hardware and software.   On current Pentium CPUs, Phelix has a per-packet overhead of less than 900 clocks, plus a per-byte cost well under 8 clocks per byte, comparing very favorably with the best AES (encryption-only) implementations, even for small packets.

Phelix was written by Doug Whiting, Bruce Schneier, Stephan Lucks and Frédéric Muller.  It is a slightly modifed version of Helix, and is a phase 2 candidate for the eSTREAM project.   Because Phelix is new, the use of Phelix should be limited to selected, low value assets where throughput is especially critical.   Phelix is in the Public Domain.

UPDATE: Phelix did not advance to Phase 3 of the eSTREAM competition because of a claim that reuse of the nonce could reveal the key.   By definition, nonces are not to be reused so the claim is arguably bogus, but nevertheless, the eSTREAM committee chose to remove Phelix from the competition.   That said, as long as the nonce is not reused, Phelix appears to be a credible and very fast cipher with the added advantage of providing both ciphertext and a hash with a single pass of the data.

pyPhelix is a simple ctypes Python wrapper providing access to Phelix.   It is EXPERIMENTAL software and intended for educational purposes only.   To make experimentation less cumbersome, pyPhelix is freeware.  

 
Usage:

    import pyPhelix
    
    message = 'Kilroy was here!  ...and there, and everywhere.'
    key     = 'myKey'             # do better in real life
    nonce   = 'aNonce'            # do better in real life
    IV      = (nonce+'*'*16)[:16] # force to exactly 128 bits
    
    # encrypt and get MAC
    ph = pyPhelix.Phelix(key, IV)
    ciphertext = ph.encryptBytes(message)
    mac1 = ph.getMAC()
    
    # decrypt and get MAC
    ph2 = pyPhelix.Phelix(key, IV)
    plaintext = ph2.decryptBytes(ciphertext)
    mac2 = ph2.getMAC()

    if plaintext == message and mac2 == mac1:
        print '  *** good ***'
    else:
        print '  *** bad ***'
        
 
Installation:

Download the Phelix ZIP file from either location:
    http://www.ecrypt.eu.org/stream/p2ciphers/phelix/phelix_p2source.zip
    http://www.schneier.com/code/phelix.zip

Compile phelix.c and install as a shared library, not a Python extension.

pyPhelix is available below. Be sure to see README.txt file for more information.

    THIS SOURCE IS PROVIDED WITHOUT WARRANTY OR GUARANTEE OF ANY KIND.  USE AT YOUR OWN RISK.
    source, demos, etc pyPhelix-v0.07.zip

 
References:

      http://www.schneier.com/paper-phelix.html
      http://en.wikipedia.org/wiki/Phelix
      http://www.ecrypt.eu.org/stream/phelixp2.html
      http://www.ecrypt.eu.org/stream/p2ciphers/phelix/phelix_p2.pdf

Larry Bugbee, rev Dec 2008