dppk

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: GPL-3.0 Imports: 3 Imported by: 0

README

GoDoc Go Report Card CreatedAt

A Deterministic Polynomial Public Key Algorithm over a Prime Galois Field GF(p)

DPPK is an Key encapsulation mechanism, a.k.a. - KEM

Overview

The ancient Vieta’s formulas reveal the relationships between the coefficients of an nth-degree polynomial and its roots. It has been surprisingly found that there exists a hidden secret for a potential public key exchange: decoupling the product of all roots (or the constant term) from the summations of root products (or coefficients) of a polynomial to establish a keypair.

Deterministic Polynomial Public Key (DPPK)

Key Principles

  1. Factorization Dependency: The DPPK algorithm is built on the fact that a polynomial cannot be factorized without its constant term.
  2. Keypair Construction: The keypair generator combines a base polynomial, which can be eliminated during decryption, with two solvable polynomials to create two entangled polynomials.
    • Public Key: Formed by the coefficient vectors of the entangled polynomials.
    • Private Key: Composed of the constant terms of the entangled polynomials and the two solvable polynomials.

Security Mechanism

  • By only publishing the coefficients of the polynomials without their constant terms, polynomial factoring techniques for private key extraction are greatly restricted.
  • The time complexity for private key extraction from the public key is:
    • Classical Attacks: Super-exponential difficulty $O(p^2)$.
    • Quantum Attacks: Exponential difficulty $O(p)$.
  • In comparison, the complexity for the Polynomial Factoring Problem (PFP) is:
    • Classical Attacks: $O(n\sqrt{p})$.
    • Quantum Attacks: $O(\sqrt{p})$, matching the complexity level of Grover’s search algorithm.

Keypair Generation and Encryption/Decryption

  • The central idea for keypair construction arises from Vieta’s formulas by decoupling the coefficients of a polynomial into two categories:

    • Private: From its constant term.
    • Public: From the coefficients of the indeterminate $x$.
  • DPPK uses two entangled generic polynomials based on a common base polynomial $B_n(x)$ with two solvable polynomials $u(x)$ and $v(x)$:

    • Public Key: All coefficients of the entangled polynomials.
    • Private Key: Their constant terms and the two solvable polynomials.

Security Analysis

  • Deterministic Time Complexity:
    • Classical Attacks: $O(\sqrt{p})$ (super-exponential difficulty).
    • Quantum Attacks: $O(p)$ (exponential difficulty).

Installation

To install DPPK, use:

go get -u github.com/xtaci/dppk

Examples

Keypair Generation
package main

import (
    "github.com/xtaci/dppk"
    "log"
)

func main() {
    // Generate key for Alice
    alice, err := dppk.GenerateKey(10)
    if err != nil {
        log.Fatal(err)
    }

    // Generate key for Bob
    bob, err := dppk.GenerateKey(10)
    if err != nil {
        log.Fatal(err)
    }

    log.Println("Alice's Public Key:", alice.PublicKey)
    log.Println("Bob's Public Key:", bob.PublicKey)
}

Encryption
package main

import (
    "github.com/xtaci/dppk"
    "log"
)

func main() {
    // Assume alice and bob have already generated their keys
    alice, _ := dppk.GenerateKey(10)
    bob, _ := dppk.GenerateKey(10)

    // Secret message
    secret := []byte("hello quantum")

    // Bob encrypts the message for Alice
    kem, err := dppk.Encrypt(&alice.PublicKey, secret)
    if err != nil {
        log.Fatal(err)
    }

    log.Printf("KEM: %+v\n", kem)
}

Decryption
package main

import (
    "github.com/xtaci/dppk"
    "log"
)

func main() {
    // Assume alice and bob have already generated their keys and bob has encrypted a message
    alice, _ := dppk.GenerateKey(10)
    bob, _ := dppk.GenerateKey(10)
    secret := []byte("hello quantum")
    kem, _ := dppk.Encrypt(&alice.PublicKey, secret)

    // Alice decrypts the message
    plaintext, err := alice.DecryptMessage(kem)
    if err != nil {
        log.Fatal(err)
    }

    log.Println("Recovered message:", string(plaintext))
}

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 DPPK.

Documentation

Overview

Package dppk implements the Deterministic Polynomial Public Key (DPPK) algorithm.

The ancient Vieta’s formulas reveal the relationships between coefficients of an nth-degree polynomial and its roots. It is surprisingly found that there exists a hidden secret for a potential public key exchange: decoupling the product of all roots or constant term from summations of root products or coefficients of a polynomial to establish a keypair. The proposed deterministic polynomial public key algorithm or DPPK is built on the fact that a polynomial cannot be factorized without its constant term.

DPPK allows the keypair generator to combine a base polynomial, eliminable during the decryption, with two solvable polynomials and creates two entangled polynomials. Two coefficient vectors of the entangled polynomials form a public key, and their constant terms, together with the two solvable polynomials, form the private key. By only publishing coefficients of polynomials without their constant terms, we greatly restrict polynomial factoring techniques for the private key extraction.

Index

Constants

View Source
const (
	ERR_MSG_ORDER         = "order must be at least 5"
	ERR_MSG_NULL_ENCRYPT  = "encrypted values cannot be null"
	ERR_MSG_DATA_EXCEEDED = "the secret to encrypt is not in the GF(p)"
	ERR_MSG_VU_PUBLICKEY  = "VU in public key is not equal"
)
View Source
const DefaultPrime = "" /* 515-byte string literal not displayed */

DefaultPrime is the default prime number used in the DPPK protocol.

Variables

This section is empty.

Functions

func RecoverMessage added in v1.1.0

func RecoverMessage(candidate *big.Int) ([]byte, error)

RecoverMessage converts a decrypted root into the original plaintext.

Types

type KEM added in v1.0.7

type KEM struct {
	Ps *big.Int
	Qs *big.Int
}

KEM represents a Key Encapsulation Mechanism in the DPPK protocol.

func Encrypt added in v1.0.4

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

type PrivateKey

type PrivateKey struct {
	S0             *big.Int // Initial secret value
	A0, A1, B0, B1 *big.Int // Coefficients for the polynomials
	PublicKey
}

PrivateKey represents a private key in the DPPK protocol.

func GenerateKey

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

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

func GenerateKeyWithPrime added in v1.0.3

func GenerateKeyWithPrime(order int, strPrime string) (*PrivateKey, error)

GenerateKey generates a new DPPK private key with the given order and prime number the prime number is a string formatted in base 10

func (*PrivateKey) Decrypt

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

Decrypt decrypts the encrypted values Ps and Qs using the private key.

func (*PrivateKey) DecryptMessage added in v1.1.0

func (priv *PrivateKey) DecryptMessage(kem *KEM) ([]byte, error)

DecryptMessage returns the plaintext message embedded in the ciphertext. It tries both candidate roots and returns the first one that matches the expected secret encoding marker.

func (*PrivateKey) Public added in v1.0.6

func (priv *PrivateKey) Public() *PublicKey

Public returns the public key of the private key.

type PublicKey

type PublicKey struct {
	Prime   *big.Int
	VectorU []*big.Int // Coefficients for polynomial U
	VectorV []*big.Int // Coefficients for polynomial V
}

PublicKey represents a public key in the DPPK protocol.

func (*PublicKey) Equal added in v1.0.6

func (pub *PublicKey) Equal(other *PublicKey) bool

Equal checks if two public keys are equal.

func (*PublicKey) Order added in v1.0.6

func (pub *PublicKey) Order() int

Order returns the order of the public key.

Jump to

Keyboard shortcuts

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