benaloh

package module
v0.0.0-...-61c5a29 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 26, 2021 License: MIT Imports: 4 Imported by: 0

README

Benaloh Cryptosystem

This package is implemented according to the pseudo-code and mathematical notations of the following algorithms of the Benaloh cryptosystem:

  • Key Generation
  • Encryption
  • Decryption

Benaloh has additive homomorphic encryption property and is an example of Partially Homomorphic Encryption (PHE). Therefore, the multiplication of ciphers results in the sum of original numbers.

Moreover, it also supports the following PHE functions:

  • Homomorphic Encryption over two ciphers
  • Homomorphic Encryption over multiple ciphers

Installation

go get -u github.com/Mirzazhar/benaloh

Warning

This package is intendedly designed for education purposes. Of course, it may contain bugs and needs several improvements. Therefore, this package should not be used for production purposes.

Keys generation implementation is not efficient and it takes time to generate keys using large primes. The worst thing, it can generate keys up to the 32-bit size of prime numbers.

Limitations

In this implementation decryption algorithm works by taking the discrete log of a base x to recover original message m. It can only work if the value of R in the key is small. Otherwise, message m can be recovered using Baby-step giant-step algorithm in case of a large value of R.

Usage & Examples

Contribution

  • You can fork this, extend it and contribute back.
  • You can contribute with pull requests.

LICENSE

MIT License

References

  1. https://en.wikipedia.org/wiki/Benaloh_cryptosystem
  2. https://www.microsoft.com/en-us/research/wp-content/uploads/1987/01/thesis.pdf
  3. https://dl.acm.org/doi/pdf/10.1145/3214303

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLargeCipher = errors.New("benaloh: cipher is larger than the public key size")
View Source
var ErrLargeMessage = errors.New("benaloh: message is larger than the public key size")

Functions

This section is empty.

Types

type PrivateKey

type PrivateKey struct {
	PublicKey
	PhiDivR, X *big.Int
}

PrivateKey represents a Benaloh private key.

func GenerateKey

func GenerateKey(random io.Reader, bitsize int) (*PrivateKey, error)

GenerateKey generates the Benaloh private key of the given bit size.

func (*PrivateKey) Decrypt

func (priv *PrivateKey) Decrypt(cipherText []byte) ([]byte, error)

Decrypt decrypts the passed cipher text. It returns an error if cipher text value is larger than modulus N of Public key. Moreover, this works by taking discrete log of a base x to recover original message m. It can only work, if R is small. Otherwise, message can be recovered using Baby-step giant-step algorithm in case of large value of R.

type PublicKey

type PublicKey struct {
	Y, R, N *big.Int
}

PublicKey represents Benaloh public key.

func (*PublicKey) Encrypt

func (pub *PublicKey) Encrypt(plainText []byte) ([]byte, error)

Encrypt encrypts a plain text represented as a byte array. It returns an error if plain text value is larger than R value of Public key.

func (*PublicKey) HommorphicEncMultiple

func (pub *PublicKey) HommorphicEncMultiple(ciphers ...[]byte) ([]byte, error)

HommorphicEncMultiple performs homomorphic operation over two chiphers. Benaloh has additive homomorphic property, so resultant cipher contains the sum of multiple numbers.

func (*PublicKey) HomomorphicEncTwo

func (pub *PublicKey) HomomorphicEncTwo(c1, c2 []byte) ([]byte, error)

HomomorphicEncTwo performs homomorphic operation over two chiphers. Benaloh has additive homomorphic property, so resultant cipher contains the sum of two numbers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL