Difference between revisions of "SAGE & cryptology"
m (→sage.crypto) |
|||
Line 157: | Line 157: | ||
*Supports compression. |
*Supports compression. |
||
====Python-GnuTLS==== |
====Python-GnuTLS==== |
||
− | http://pypi.python.org/pypi/python-gnutls/1.1.5 |
+ | http://pypi.python.org/pypi/python-gnutls/1.1.5<br> |
− | API reference built on local machine. |
+ | API reference built on local machine.<br> |
− | Same story as with OpenSSL: C-library + python wrapper |
+ | Same story as with OpenSSL: C-library + python wrapper<br> |
+ | |||
====book==== |
====book==== |
||
[http://echidna.maths.usyd.edu.au/~kohel/tch/Crypto/index.html book written on Cryptography by David Kohel], using SAGE |
[http://echidna.maths.usyd.edu.au/~kohel/tch/Crypto/index.html book written on Cryptography by David Kohel], using SAGE |
Revision as of 20:35, 16 July 2008
Discussions
- this thread in the ML
- this blog and especially this post
- JSAGE
- notes for developers
Docs
- http://www.cryptlib.com/standards-compliance.htm
- Sage Programming Guide
- Sage on Google Groups
Available
sage.crypto
Sage Reference Manual
Constructions in Sage
- sage.crypto.all
- sage.crypto.cipher
- sage.crypto.classical
- sage.crypto.classical_cipher
- hillchipher
- substitutioncipher
- transpositioncipher
- vigenerecipher
- sage.crypto.cryptosystem
- sage.crypto.lfsr
- sage.crypto.mq
- SBox Class: mq.SBOX wiki.sagemath.org
- Small Scale Variants of the AES (SR) Polynomial System Generator mq.sr Reference Manual
PyCrypto
Sage ships PyCryptowhich implements many standard cryptographic algorithms.
It is not really meant for research/education/playing around but for production code but maybe something could be done to have easier access to it from within Sage.
The docstring level documentation is horrible:
sage: import Crypto.Cipher.IDEA sage: Crypto.Cipher.IDEA? x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Manual is available here.
- Hash functions: MD2, MD4, MD5, RIPEMD, SHA256
- All hashing modules share the same interface. After importing a given hashing module, call the new() function to create a new hashing object. You can now feed arbitrary strings into the object with the update() method, and can ask for the hash value at any time by calling the digest() or hexdigest() methods. The new() function can also be passed an optional string parameter that will be immediately hashed into the object's state.[1]
- MD5 example
>>> from Crypto.Hash import MD5 >>> m = MD5.new() >>> m.update('abc') >>> m.digest() '\x90\x01P\x98<\xd2O\xb0\xd6\x96?}(\xe1\x7fr'
- Block encryption algorithms: AES, ARC2, Blowfish, CAST, DES, Triple-DES, IDEA, RC5
- Possibilities: Define a new cipher object after importing the module and define the key, mode (cbc,cfb,ecb or pgp) and possible IV.
The object gives you two methods: 'encrypt()' and 'decrypt()'.
For AES: S-Box not modifiable, LookUp Tables are being used. - AES Example
- Possibilities: Define a new cipher object after importing the module and define the key, mode (cbc,cfb,ecb or pgp) and possible IV.
py> from Crypto.Cipher import AES py> # key has to be 16, 24 or 32 bytes for AES py> crypt = AES.new('abcdefghijklmnop', AES.MODE_ECB) # we're lucky, the string to encrypt is a multiple of 16 in length py> txt = 'ea523a664dabaa4476d31226a1e3bab0' py> c = crypt.encrypt(txt) py> c 'w\x81\xe3\xdd\x066\x9eY\xc7\xce~O\x9e\xfb\xef\xfa\xb5\x8a\xac\x7f\xca\x9fl{\xe5\xfd6\x80\xe3\x81%\xb9' py> crypt.decrypt(c) 'ea523a664dabaa4476d31226a1e3bab0'
- DES Example
>>> from Crypto.Cipher import DES >>> obj=DES.new('abcdefgh', DES.MODE_ECB) >>> plain="Guido van Rossum is a space alien." >>> len(plain) 34 >>> obj.encrypt(plain) Traceback (innermost last): File "<stdin>", line 1, in ? ValueError: Strings for DES must be a multiple of 8 in length >>> ciph=obj.encrypt(plain+'XXXXXX') >>> ciph '\021,\343Nq\214DY\337T\342pA\372\255\311s\210\363,\300j\330\250\312\347\342I\3215w\03561\303dgb/\006' >>> obj.decrypt(ciph) 'Guido van Rossum is a space alien.XXXXXX'
- Stream encryption algorithms: ARC4, simple XOR
- Public-key algorithms: RSA, DSA, ElGamal, qNEW
- Public key Modules
construct(tuple)
generate(size, randfunc, progress_func=None) => public key object - Public key Objects
available methods: canencrypt(), cansign(), decrypt(tuple), encrypt(string, K), hasprivate(), publickey(), sign(string, K), size(), verify(string, signature) - RSA Example: (pycrypt manual)
- Public key Modules
>>> from Crypto.Hash import MD5 >>> from Crypto.PublicKey import RSA >>> RSAkey=RSA.generate(384, randfunc) # This will take a while... >>> hash=MD5.new(plaintext).digest() >>> signature=RSAkey.sign(hash, "") >>> signature # Print what an RSA sig looks like--you don't really care. ('\021\317\313\336\264\315' ...,) >>> RSAkey.verify(hash, signature) # This sig will check out 1 >>> RSAkey.verify(hash[:-1], signature)# This sig will fail 0
- Protocols: All-or-nothing transforms, chaffing/winnowing
- Miscellaneous: RFC1751 module for converting 128-key keys into a set of English words, primality testing
- Crypto.Util.number
GCD(x,y),getPrime(N, randfunc),getRandomNumber(N, randfunc),inverse(u, v),isPrime(N) - Crypto.Util.randpool
The randpool module implements a strong random number generator in the RandomPool class. The internal state consists of a string of random data, which is returned as callers request it. The class keeps track of the number of bits of entropy left, and provides a function to add new random data; this data can be obtained in various ways, such as by using the variance in a user's keystroke timings.
- Crypto.Util.number
- Some demo programs (currently all quite old and outdated)
OpenSSL
Manual Functionality in OpenSLL
- SYMMETRIC CIPHERS
- blowfish(3), cast(3), des(3), idea(3), rc2(3), rc4(3), rc5(3)
- AES is same implementation as in pycrypto
- PUBLIC KEY CRYPTOGRAPHY AND KEY AGREEMENT
- dsa(3), dh(3), rsa(3)
- CERTIFICATES
- x509(3), x509v3(3)
- AUTHENTICATION CODES, HASH FUNCTIONS
- hmac(3), md2(3), md4(3), md5(3), mdc2(3), ripemd(3), sha(3)
- AUXILIARY FUNCTIONS
- err(3), threads(3), rand(3), OPENSSL_VERSION_NUMBER(3)
- INPUT/OUTPUT, DATA ENCODING
- asn1(3), bio(3), evp(3), pem(3), pkcs7(3), pkcs12(3)
- INTERNAL FUNCTIONS
- bn(3), buffer(3), lhash(3), objects(3), stack(3),txt_db(3)
Functionality of OpenSSL in Sage is provided via the PyOpenSSL wrapper. A more complete wrapper is M2Crypto but it is not available as a package for Sage. Still have to try to import it.
PyOpenSSL [2]
- Vooral gericht op SSL en niet op het crypto gedeelte
- X509 objects
- X509Name objects
- X509Req objects
- X509Store objects
- PKey objects
- PKCS7 objects
- PKCS12 objects
- X509Extension objects
- NetscapeSPKI objects
- Looks like less functionality than PyCrypto => PyCrypto seems like a better candidate to adjust, else we would have to extend the PyOpenSSL wrapper AND OpenSSL itself for any wanted extended functionality.
- M2Crypto [3]
- RSA, DSA, DH, HMACs, message digests, symmetric ciphers (including AES).
- SSL functionality to implement clients and servers.
- HTTPS extensions to Python's httplib, urllib, and xmlrpclib.
- Unforgeable HMAC'ing AuthCookies for web session management.
- FTP/TLS client and server.
- S/MIME.
- ZServerSSL: A HTTPS server for Zope.
- ZSmime: An S/MIME messenger for Zope.
- More functionality than the PyOpenSSL wrapper, but not available as a Sage package. Worth importing if it provides extra functionality to PyCrypto.
GnuTLS
Standard package in sage. Mostly for certification and not for basic cryptography
- Support for TLS 1.1, TLS 1.0 and SSL 3.0 protocols
- Since SSL 2.0 is insecure it is not supported.
- TLS 1.2 is supported but disabled by default.
- Support for TLS extensions: server name indication, max record size, opaque PRF input, etc.
- Support for authentication using the SRP protocol.
- Support for authentication using both X.509 certificates and OpenPGP keys.
- Support for TLS Pre-Shared-Keys (PSK) extension.
- Support for Inner Application (TLS/IA) extension.
- Support for X.509 and OpenPGP certificate handling.
- Support for X.509 Proxy Certificates (RFC 3820).
- Supports all the strong encryption algorithms (including SHA-256/384/512), including Camellia (RFC 4132).
- Supports compression.
Python-GnuTLS
http://pypi.python.org/pypi/python-gnutls/1.1.5
API reference built on local machine.
Same story as with OpenSSL: C-library + python wrapper
book
book written on Cryptography by David Kohel, using SAGE
Wishes
- General trac
- sage.crypto: block ciphers
- Someone needs to replace FiniteField_ext_pari with the two NTL implementations (they are much faster).
- elliptic and hyperelliptic curves over finite fields support is rather poor
- algebraic aspects received some attention for the cryptanalysis of symmetric cryptographic algorithms, i.e. the cryptanalyst expresses the cipher as a large set of multivariate polynomials and attempts to solve the system. The most common case over GF(2) is handled by PolyBoRi. This library is the backbone of BooleanPolynomialRing and friends. This class needs testing, documentation, extension and bugfixes. Basically someone should sit down and add all the methods of MPolynomial[Ring]_libsingular to BooleanPolynomial[Ring] which make sense, add a ton of doctests and test the hell out of the library to make sure no SIGSEGVs surprise the user.
- the module sage.crypto.mq is also relevant for the above.
- Univariate polynomials over GF(2) are still implemented via NTL's ZZ_pX class rather than GF2X. This should be changed. Also this ticket has a link to gf2x a very small drop in replacement C library which claimed to be 5x faster than NTL. Though, a formal vote is needed to get it into Sage.
- At the end of the day everything boils down to linear algebra. So if you improve that, everybody wins. Sparse linear algebra mod p is still too slow (Ralf-Phillip Weinmann did some work here wrapping code from eclib), there isn o special implementation for sparse linear algebra over GF(2) (both blackbox and e.g. reduced echelon forms), dense LA over GF(2) needs Strassen multiplication/reduction, dense LA over GF(2^n) should probably get implemented.
The ideal toolbox
This is a lengthy list but it's our Xmas list ;-) We aim to have a toolbox for research/education/playing not production optimizations required. So easy access, reconfigurability and clearness are more important!
Block ciphers
Block cipher algorithms
Make sure the internals are accessible and reconfigurable, particularly the S-BOXes.
Try to make generic constructors such as Feistel cipher, etc
- Serpent
- Twofish
- Idea
- DES, 3DES 112, 168
- AES 128, 196, 256
- Present
Modes of operation
Make sure we can select independently the block cipher encryption/decryption mode and the chaining "encryption/decryption" mode
- Authentication modes
- CMAC
- XCBC
- CBC-MAC
- Authentication+encryption modes
- CCM
- GCM
- Encryption modes
- ECB
- CBC
- CTR
- Disk encryption modes
- LRW
- XTS
Non-keyed hashes
- MDC-2 (ISO 10118-2)
Paddings
- Bit padding (can be done at bit level, others are at byte level)
DD DD DD 80 00 00 00 00
- zeros
DD DD DD 00 00 00 00 00
- PKCS7
DD DD DD 05 05 05 05 05
- ISO 10126
DD DD DD 42 DB 8A 98 05
- ANSI X.923
DD DD DD 00 00 00 00 05
Stream ciphers
Same thing, get the internals accessible and patchable
- RC4
- A5/1 A5/2
- SNOW2 SNOW3G
- SW candidates of eSTREAM:
- HC-128
- RABBIT
- Salsa 20/12
- SOSEMANUK
- HW candidates of eSTREAM:
- F-FCSR
- Grain
- MICKEY
- Trivium
- LFSR
- Shrinking generator
- Self-shrinking generator
One-way functions
- MD5
- SHA family
- Whirlpool
- RipeMD
- MDC-2
- RadioGatún
Ways to transform a block cipher into a hash
- Davies-Meyer
- Matyas-Meyer-Oseas
- Miyaguchi-Preneel
MACs based on hash functions
- HMAC
- NMAC
Key derivation functions
- KDF family
- PBKDF2
Public-key cryptography
ECC
- all coordinate systems
- cf http://www.hyperelliptic.org/EFD/
Others
- RSA (encryption, signature, PKCS#1 v1.5 and v2.1, with and without CTR)
- DSA
- ElGamal
- DH
- XTR
- Paillier
- NTRUE
Pseudo-random generators
- cf NIST
- Mersenne Twister
Cryptanalysis tools
- boolean functions & S-Box
- algebraic degree
- algebraic immunity
- algebraic normal form (ANF)
- non linearity
- resiliency
- Walsh transforms
- cross-correlation
- ECC point counting
- complex multiplication?
- factorisation solver
- discrete log solver
- statistical tests (diehard, FIPS...)
- Field operations: addition, multiplication, inverses (normal and polynomial basis)