Library to interface with the Linux kernel crypto API
Project description
Python ifalg
ifalg is a Python 3 library to interface with the Linux kernel crypto API. This is generally slower than using a library like OpenSSL or PyCrypto, but it could be useful if you have cryptographic hardware supported by Linux.
Features
For the moment only skcipher and hash algorithms are supported.
Algorithm metadata is parsed from /proc/crypto
Installation
ifalg should work on any Linux distribution with a modern kernel, in order to use this tool you need to have the folowing options enabled on the kernel:
CONFIG_CRYPTO_USER_API
CONFIG_CRYPTO_USER_API_HASH
CONFIG_CRYPTO_USER_API_SKCIPHER
To install just use pip:
pip install ifalg
Samples
Using a hash algorithm:
>>> from ifalg import Hash >>> hash = Hash('sha1') >>> hash.hexdigest(b'hello world') '2aae6c35c94fcfb415dbe95f408b9ce91ee846ed'
Using a keyed hash algorithm:
>>> from ifalg import Hash >>> hash = Hash('cmac(des3_ede)', key=bytes.fromhex('8aa83bf8cbda10620bc1bf19fbb6cd58bc313d4a371ca8b5')) >>> hash.hexdigest(bytes.fromhex('6bc1bee22e409f96')) '8e8f293136283797'
Encryption and Decryption:
>>> from ifalg import SKCipher >>> cipher = SKCipher('cbc(aes)', key=bytes.fromhex('790afba9cfbc095b682666a6999a38ed'), iv=bytes.fromhex('fb1f88c0f23d6aa6dde475c018d7f482')) >>> msg = bytes.fromhex('4e0c74c8d67862a9732604f62f4ad316') >>> cipherText = cipher.encrypt(msg) >>> cipherText b'\x7ftT$Z\xf4\xe6|\xd2)cA\xf2\x1d\xcb\xa9' >>> plainText = cipher.decrypt(cipherText) >>> plainText b'N\x0ct\xc8\xd6xb\xa9s&\x04\xf6/J\xd3\x16' >>> plainText == msg True
Streaming encryption and decryption:
>>> from ifalg import SKCipherStream >>> stream = SKCipherStream('cbc(aes)', key=bytes.fromhex('790afba9cfbc095b682666a6999a38ed'), iv=bytes.fromhex('fb1f88c0f23d6aa6dde475c018d7f482')) >>> stream.write(b'0123456789abcdef0123456789abcdef') 32 >>> cipherText = stream.read(32)
Contact
For any thoughts about this software, please contact me at manologab@gmail.com.
If you find a bug or have any idea to improve this tool, please use Github’s issues <https://github.com/manologab/python-ifalg/issues>.
License
The MIT License (MIT)
Copyright (c) 2015 Manolo Ramirez T.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file ifalg-0.2.tar.gz
.
File metadata
- Download URL: ifalg-0.2.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4dcdfd5d1344a56f3f5a7964fa9f7b2ef8c20d40b85795999b67509edd6e72b |
|
MD5 | c0f7e7e630c06014331f9ecfb995b768 |
|
BLAKE2b-256 | d023b3fb415d8a0061bd8ee9d497a11e1e1acacbd3136593d443b9972d92a1aa |