schmidtsamoa

package module
v0.0.0-...-31ac608 Latest Latest
Warning

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

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

README

Schmidt-Samoa Cryptosystem

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

  • Key Generation
  • Encryption
  • Decryption

Schmidt-Samoa has multiplicative homomorphic encryption property and is an example of Partially Homomorphic Encryption (PHE). Therefore, the multiplication of ciphers results in the product 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/schmidt-samoa

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.

Usage & Examples

LICENSE

MIT License

References

  1. https://en.wikipedia.org/wiki/Schmidt-Samoa_cryptosystem
  2. https://eprint.iacr.org/2005/278.pdf

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLargeCipher = errors.New("schmidt-samoa: cipher is larger than Schmidt Samoa public key size")
View Source
var ErrLargeMessage = errors.New("schmidt-samoa: message is larger than Schmidt Samoa public key size")

Functions

This section is empty.

Types

type PrivateKey

type PrivateKey struct {
	PublicKey
	L  *big.Int
	D  *big.Int
	PQ *big.Int
}

PrivateKey represents a Schmidt-Samoa private key.

func GenerateKey

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

GenerateKey generates Schmidt-Samoa key according to 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.

type PublicKey

type PublicKey struct {
	N *big.Int // modulus N
}

PublicKey represents Schmidt-Samoa 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 modulus N of Public key.

func (*PublicKey) HommorphicEncMultiple

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

HommorphicEncMultiple performs homomorphic operation over two chiphers. Schmidt-Samoa has multiplicative homomorphic property, so resultant cipher contains the product of multiple numbers.

func (*PublicKey) HomomorphicEncTwo

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

HomomorphicEncTwo performs homomorphic operation over two chiphers. Schmidt-Samoa has multiplicative homomorphic property, so resultant cipher contains the product of two numbers.

Jump to

Keyboard shortcuts

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