All Projects → mhostetter → galois

mhostetter / galois

Licence: MIT license
A performant NumPy extension for Galois fields and their applications

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to galois

Number-Theory-Python
Python code to implement various number theory, elliptic curve and finite field computations.
Stars: ✭ 85 (-19.81%)
Mutual labels:  finite-fields, elliptic-curves, number-theory
crypto-in-action
algebra arithmetic, finite fields, elliptic curves, zero-knowledge
Stars: ✭ 65 (-38.68%)
Mutual labels:  finite-fields, elliptic-curves
enigma
A fast, native, cryptographic engine for the web
Stars: ✭ 101 (-4.72%)
Mutual labels:  aes, rsa
oseid
Microchip AVR based smartcard/token with ECC and RSA cryptography
Stars: ✭ 17 (-83.96%)
Mutual labels:  aes, rsa
Encrypt
🔒 A set of high-level APIs over PointyCastle for two-way cryptography.
Stars: ✭ 199 (+87.74%)
Mutual labels:  aes, rsa
Jsrsasign
The 'jsrsasign' (RSA-Sign JavaScript Library) is an opensource free cryptography library supporting RSA/RSAPSS/ECDSA/DSA signing/validation, ASN.1, PKCS#1/5/8 private/public key, X.509 certificate, CRL, OCSP, CMS SignedData, TimeStamp, CAdES JSON Web Signature/Token in pure JavaScript.
Stars: ✭ 2,760 (+2503.77%)
Mutual labels:  aes, rsa
cryptotools
No description or website provided.
Stars: ✭ 182 (+71.7%)
Mutual labels:  rsa, elliptic-curves
Hltool
Go 开发常用工具库, Google2步验证客户端,AES加密解密,RSA加密解密,钉钉机器人,邮件发送,JWT生成解析,Log,BoltDB操作,图片操作,json操作,struct序列化
Stars: ✭ 151 (+42.45%)
Mutual labels:  aes, rsa
std-curves
Standard curve database.
Stars: ✭ 53 (-50%)
Mutual labels:  elliptic-curves, elliptic-curve-cryptography
Qt-Secret
Simple encryption library supporting RSA and AES algorithms.
Stars: ✭ 196 (+84.91%)
Mutual labels:  aes, rsa
Encrypt Body Spring Boot Starter
(停止维护,替代品搜索:https://github.com/search?l=Java&q=encrypt&type=Repositories )SpringBoot控制器统一的响应体加密与请求体解密的注解处理方式,支持MD5/SHA/AES/DES/RSA
Stars: ✭ 198 (+86.79%)
Mutual labels:  aes, rsa
Python-SecureHTTP
Make HTTP transmissions more secure via RSA+AES, encrypted communication for C/S architecture.
Stars: ✭ 19 (-82.08%)
Mutual labels:  aes, rsa
Cry
Cross platform PoC ransomware written in Go
Stars: ✭ 179 (+68.87%)
Mutual labels:  aes, rsa
crypto.js
base on crypto module
Stars: ✭ 13 (-87.74%)
Mutual labels:  aes, rsa
Practical Cryptography For Developers Book
Practical Cryptography for Developers: Hashes, MAC, Key Derivation, DHKE, Symmetric and Asymmetric Ciphers, Public Key Cryptosystems, RSA, Elliptic Curves, ECC, secp256k1, ECDH, ECIES, Digital Signatures, ECDSA, EdDSA
Stars: ✭ 2,400 (+2164.15%)
Mutual labels:  aes, elliptic-curves
optiga-trust-m
OPTIGA™ Trust M Software Framework
Stars: ✭ 86 (-18.87%)
Mutual labels:  aes, rsa
Hybrid Crypto Js
RSA+AES hybrid encryption implementation for JavaScript. Works with Node.js, React Native and modern browsers.
Stars: ✭ 87 (-17.92%)
Mutual labels:  aes, rsa
Encryptor4j
Strong encryption for Java simplified
Stars: ✭ 92 (-13.21%)
Mutual labels:  aes, rsa
keystore-idb
In-browser key management with IndexedDB and the Web Crypto API
Stars: ✭ 37 (-65.09%)
Mutual labels:  rsa, elliptic-curves
jh-weapp-demo
微信小程序项目- 实现一些常用效果、封装通用组件和工具类
Stars: ✭ 60 (-43.4%)
Mutual labels:  aes, rsa

Galois: A performant NumPy extension for Galois fields and their applications

The galois library is a Python 3 package that extends NumPy arrays to operate over finite fields.

The user creates a FieldArray subclass using GF = galois.GF(p**m). GF is a subclass of np.ndarray and its constructor x = GF(array_like) mimics the signature of np.array(). The FieldArray x is operated on like any other NumPy array except all arithmetic is performed in $\mathrm{GF}(p^m)$, not $\mathbb{R}$.

Internally, the finite field arithmetic is implemented by replacing NumPy ufuncs. The new ufuncs are written in pure Python and just-in-time compiled with Numba. The ufuncs can be configured to use either lookup tables (for speed) or explicit calculation (for memory savings).

Warning The algorithms implemented in the NumPy ufuncs are not constant-time, but were instead designed for performance. As such, the library could be vulnerable to a side-channel timing attack. This library is not intended for production security, but instead for research & development, reverse engineering, cryptanalysis, experimentation, and general education.

Features

Roadmap

  • Elliptic curves over finite fields
  • Galois ring arrays
  • GPU support

Documentation

The documentation for galois is located at https://mhostetter.github.io/galois/latest/.

Getting Started

The Getting Started guide is intended to assist the user with installing the library, creating two example arrays, and performing basic array arithmetic. See Basic Usage for more detailed discussions and examples.

Install the package

The latest version of galois can be installed from PyPI using pip.

$ python3 -m pip install galois

Import the galois package in Python.

In [1]: import galois

In [2]: galois.__version__
Out[2]: '0.1.1'

Create a FieldArray subclass

Next, create a FieldArray subclass for the specific finite field you'd like to work in. This is created using the galois.GF() class factory. In this example, we are working in $\mathrm{GF}(3^5)$.

In [3]: GF = galois.GF(3**5)

In [4]: print(GF.properties)
Galois Field:
  name: GF(3^5)
  characteristic: 3
  degree: 5
  order: 243
  irreducible_poly: x^5 + 2x + 1
  is_primitive_poly: True
  primitive_element: x

The FieldArray subclass GF is a subclass of np.ndarray that performs all arithmetic in the Galois field $\mathrm{GF}(3^5)$, not in $\mathbb{R}$.

In [5]: issubclass(GF, galois.FieldArray)
Out[5]: True

In [6]: issubclass(GF, np.ndarray)
Out[6]: True

See Array Classes for more details.

Create two FieldArray instances

Next, create a new FieldArray x by passing an ArrayLike object to GF's constructor.

In [7]: x = GF([236, 87, 38, 112]); x
Out[7]: GF([236,  87,  38, 112], order=3^5)

The array x is an instance of FieldArray and also an instance of np.ndarray.

In [8]: isinstance(x, galois.FieldArray)
Out[8]: True

In [9]: isinstance(x, np.ndarray)
Out[9]: True

Create a second FieldArray y by converting an existing NumPy array (without copying it) by invoking .view(). When finished working in the finite field, view it back as a NumPy array with .view(np.ndarray).

# y represents an array created elsewhere in the code
In [10]: y = np.array([109, 17, 108, 224]); y
Out[10]: array([109,  17, 108, 224])

In [11]: y = y.view(GF); y
Out[11]: GF([109,  17, 108, 224], order=3^5)

See Array Creation for more details.

Change the element representation

The display representation of finite field elements can be set to either the integer ("int"), polynomial ("poly"), or power ("power") representation. The default representation is the integer representation since that is natural when working with integer NumPy arrays.

Set the display mode by passing the display keyword argument to galois.GF() or by calling the display() classmethod. Choose whichever element representation is most convenient for you.

# The default representation is the integer representation
In [12]: x
Out[12]: GF([236,  87,  38, 112], order=3^5)

In [13]: GF.display("poly"); x
Out[13]: 
GF([2α^4 + 2α^3 + 2α^2 + 2,               α^4 + 2α,
             α^3 + α^2 + 2,      α^4 + α^3 + α + 1], order=3^5)

In [14]: GF.display("power"); x
Out[14]: GF([α^204,  α^16, α^230,  α^34], order=3^5)

# Reset to the integer representation
In [15]: GF.display("int");

See Element Representation for more details.

Perform array arithmetic

Once you have two Galois field arrays, nearly any arithmetic operation can be performed using normal NumPy arithmetic. The traditional NumPy broadcasting rules apply.

Standard element-wise array arithmetic -- addition, subtraction, multiplication, and division -- are easily preformed.

In [16]: x + y
Out[16]: GF([ 18,  95, 146,   0], order=3^5)

In [17]: x - y
Out[17]: GF([127, 100, 173, 224], order=3^5)

In [18]: x * y
Out[18]: GF([ 21, 241, 179,  82], order=3^5)

In [19]: x / y
Out[19]: GF([ 67,  47, 192,   2], order=3^5)

More complicated arithmetic, like square root and logarithm base $\alpha$, are also supported.

In [20]: np.sqrt(x)
Out[20]: GF([ 51, 135,  40,  16], order=3^5)

In [21]: np.log(x)
Out[21]: array([204,  16, 230,  34])

See Array Arithmetic for more details.

Acknowledgements

The galois library is an extension of, and completely dependent on, NumPy. It also heavily relies on Numba and the LLVM just-in-time compiler for optimizing performance of the finite field arithmetic.

Frank Luebeck's compilation of Conway polynomials and Wolfram's compilation of primitive polynomials are used for efficient polynomial lookup, when possible.

Sage is used extensively for generating test vectors for finite field arithmetic and polynomial arithmetic. SymPy is used to generate some test vectors. Octave is used to generate test vectors for forward error correction codes.

This library would not be possible without all of the other libraries mentioned. Thank you to all their developers!

Citation

If this library was useful to you in your research, please cite us. Following the GitHub citation standards, here is the recommended citation.

BibTeX

@software{Hostetter_Galois_2020,
    title = {{Galois: A performant NumPy extension for Galois fields}},
    author = {Hostetter, Matt},
    month = {11},
    year = {2020},
    url = {https://github.com/mhostetter/galois},
}

APA

Hostetter, M. (2020). Galois: A performant NumPy extension for Galois fields [Computer software]. https://github.com/mhostetter/galois
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].