hppk

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: GPL-3.0 Imports: 3 Imported by: 0

README

HPPK: Homomorphic Polynomial Public Key

image

GoDoc Go Report Card

Overview

HPPK is an implementation of a Homomorphic Polynomial Public Key (HPPK) system, designed for both Key Encapsulation Mechanisms (KEM) and Digital Signatures (DS). This cryptographic protocol leverages the properties of polynomials to create secure, efficient methods for key exchange and message signing.

The main objectives of HPPK are to provide:

  • Secure key encapsulation: Facilitating the secure exchange of symmetric keys.
  • Robust digital signatures: Ensuring the authenticity and integrity of messages.

For a detailed explanation of the underlying theory and security proofs, please refer to the research paper.

Features

  • Homomorphic Encryption: Allows computations on ciphertexts that result in encrypted outcomes, which match the operations performed on the plaintexts.
  • Polynomial-Based Cryptography: Utilizes polynomials to create robust public and private keys.
  • Efficient Key Encapsulation Mechanism (KEM): Securely exchanges symmetric keys.
  • Strong Digital Signatures (DS): Provides authentication and integrity verification of messages.
  • Scalable and Efficient: Suitable for various applications, ranging from small-scale systems to large, complex networks. image

Installation

To use HPPK, you need to have Go installed. You can download and install Go from the official website.

  1. Clone the repository:

    git clone https://github.com/xtaci/hppk.git
    cd hppk
    
  2. Build the project:

    go build
    

Usage

Generating Keys

To generate a new pair of private and public keys:

package main

import (
    "fmt"
    "github.com/xtaci/hppk"
)

func main() {
    privateKey, err := hppk.GenerateKey(5)
    if err != nil {
        fmt.Println("Error generating keys:", err)
        return
    }
    fmt.Println("Private Key:", privateKey)
    fmt.Println("Public Key:", privateKey.PublicKey)
}
Encryption

To encrypt a message using the public key:

package main

import (
    "fmt"
    "github.com/xtaci/hppk"
)

func main() {
    privKey, err := hppk.GenerateKey(10)
    if err != nil {
        panic(err)
    }
    pubKey := privKey.Public()

    message := []byte("hello world")
    kem, err := hppk.Encrypt(pubKey, message)
    if err != nil {
        panic(err)
    }
    fmt.Printf("Encrypted KEM: %+v\n", kem)
}
Decryption

To decrypt the encrypted values using the private key:

package main

import (
    "fmt"
    "github.com/xtaci/hppk"
)

func main() {
    privKey, err := hppk.GenerateKey(10)
    if err != nil {
        panic(err)
    }
    pubKey := privKey.Public()

    message := []byte("hello world")
    kem, err := hppk.Encrypt(pubKey, message)
    if err != nil {
        panic(err)
    }

    decryptedMessage, err := privKey.Decrypt(kem)
    if err != nil {
        panic(err)
    }
    fmt.Printf("Decrypted Message: %s\n", decryptedMessage)
}
Signing
package main

import (
    "crypto/sha256"
    "fmt"
    "github.com/xtaci/hppk"
)

func main() {
    privKey, err := hppk.GenerateKey(10)
    if err != nil {
        panic(err)
    }

    digest := sha256.Sum256([]byte("hello world"))
    signature, err := privKey.Sign(digest[:])
    if err != nil {
        panic(err)
    }
    fmt.Printf("Signature: %+v\n", signature)
}

Verification
package main

import (
    "crypto/sha256"
    "fmt"
    "github.com/xtaci/hppk"
)

func main() {
    privKey, err := hppk.GenerateKey(10)
    if err != nil {
        panic(err)
    }
    pubKey := privKey.Public()

    digest := sha256.Sum256([]byte("hello world"))
    signature, err := privKey.Sign(digest[:])
    if err != nil {
        panic(err)
    }

    isValid := hppk.VerifySignature(signature, digest[:], pubKey)
    fmt.Printf("Signature valid: %v\n", isValid)
}


Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements, bug fixes, or additional features.

License

This project is licensed under the GPLv3 License. See the LICENSE file for details.

References

For more detailed information, please refer to the research paper.

Acknowledgments

Special thanks to the authors of the research paper for their groundbreaking work on HPPK and its applications in KEM and DS.

Documentation

Overview

Package hppk implements the Hierarchical Polynomial Public Key (HPPK) cryptosystem.

HPPK introduces a novel Homomorphic Polynomial Public Key for Key Encapsulation Mechanism (KEM) and Digital Signatures (DS). By exploiting the inherent partial homomorphic properties of the modular multiplicative permutations, HPPK offers a robust symmetric encryption mechanism for asymmetric cryptography, independent of NP-hard problems. The seamless integration of KEM and DS within HPPK results in compact key sizes, cipher sizes, and signature sizes, demonstrating exceptional performance across various cryptographic operations

Index

Constants

View Source
const (
	ERR_MSG_ORDER           = "order must be at least 5"
	ERR_MSG_NULL_ENCRYPTION = "encrypted values cannot be null"
	ERR_MSG_DATA_EXCEEDED   = "the secret to encrypt is not in the GF(p)"
	ERR_MSG_INVALID_PUBKEY  = "public key is invalid"
	ERR_MSG_INVALID_KEM     = "invalid kem value"
	ERR_MSG_INVALID_PRIME   = "invalid prime number"
)

Error messages for various conditions.

View Source
const DefaultPrime = "" /* 617-byte string literal not displayed */

DefaultPrime is a large prime number used in cryptographic operations.

Variables

This section is empty.

Functions

func VerifySignature

func VerifySignature(sig *Signature, digest []byte, pub *PublicKey) bool

VerifySignature verifies the signature of the message digest using the public key and default prime

func VerifySignatureWithPrime added in v1.0.4

func VerifySignatureWithPrime(sig *Signature, digest []byte, pub *PublicKey, prime *big.Int) bool

VerifySignature verifies the signature of the message digest using the public key and given prime

Types

type KEM added in v1.0.5

type KEM struct {
	P *big.Int
	Q *big.Int
}

KEM represents the Encapsulated Key in the HPPK protocol.

func Encrypt added in v1.0.2

func Encrypt(pub *PublicKey, msg []byte) (kem *KEM, err error)

Encrypt encrypts a message using the given public key and default prime number.

func EncryptWithPrime added in v1.0.4

func EncryptWithPrime(pub *PublicKey, msg []byte, prime *big.Int) (kem *KEM, err error)

Encrypt encrypts a message using the given public key and custom prime number.

type PrivateKey

type PrivateKey struct {
	Prime     *big.Int // Prime number used for cryptographic operations
	R1, S1    *big.Int // r1 and s1 are coprimes
	R2, S2    *big.Int // r2 and s2 are coprimes
	F0, F1    *big.Int // f(x) = f1x + f0
	H0, H1    *big.Int // h(x) = h1x + h0
	PublicKey          // Embedding PublicKey structure
}

PrivateKey represents a private key in the HPPK protocol.

func GenerateKey

func GenerateKey(order int) (*PrivateKey, error)

GenerateKey generates a new HPPK private key with the given order and default prime number.

func (*PrivateKey) Decrypt

func (priv *PrivateKey) Decrypt(kem *KEM) (secret *big.Int, err error)

Decrypt decrypts the encrypted values P and Q using the private key.

func (*PrivateKey) Order added in v1.0.6

func (priv *PrivateKey) Order() int

Order returns the polynomial order of the private key.

func (*PrivateKey) Public added in v1.0.4

func (priv *PrivateKey) Public() *PublicKey

Public returns the public key of the private key.

func (*PrivateKey) Sign

func (priv *PrivateKey) Sign(digest []byte) (sign *Signature, err error)

Sign the message digest, returning a signature.

type PublicKey

type PublicKey struct {
	P []*big.Int // Coefficients of the polynomial P(x)
	Q []*big.Int // Coefficients of the polynomial Q(x)
}

PublicKey represents a public key in the HPPK protocol.

type Signature

type Signature struct {
	Beta               *big.Int   // a randomly choosen number from Fp
	F, H               *big.Int   // F & H is calculated from the private key
	S1Verify, S2Verify *big.Int   // S1Verify := beta * s1 mod p, S2Verify := beta * s2 mod p
	U, V               []*big.Int // U = ⌊ R*P /S1 ⌋, V = ⌊ R*Q /S2 ⌋
	K                  int        // R = 2^K
}

Signature represents a digital signature in the HPPK protocol.

Jump to

Keyboard shortcuts

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