common

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2025 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package common provides shared cryptographic primitives and utilities for OpenADP.

Package noise provides Noise-NK protocol implementation for OpenADP.

Index

Constants

This section is empty.

Variables

View Source
var (
	// Base field Z_p where p = 2^255 - 19
	P = new(big.Int)

	// Curve constant d = -121665 * inv(121666) mod p
	D = new(big.Int)

	// Group order q = 2^252 + 27742317777372353535851937790883648493
	Q = new(big.Int)

	// Base point G
	G = &Point4D{}

	// Zero point (neutral element)
	ZeroPoint = &Point4D{}

	// Square root of -1 mod p
	ModpSqrtM1 = new(big.Int)
)

Constants for Ed25519 curve

Functions

func DebugLog added in v0.1.2

func DebugLog(message string)

DebugLog prints a debug message if debug mode is enabled

func DeriveEncKey

func DeriveEncKey(p *Point4D) []byte

DeriveEncKey derives an encryption key from a point

func GenerateKeypair

func GenerateKeypair() (noise.DHKey, error)

GenerateKeypair generates a new X25519 keypair for Noise-NK

func GetDeterministicEphemeralSecret added in v0.1.2

func GetDeterministicEphemeralSecret() []byte

GetDeterministicEphemeralSecret returns a fixed ephemeral secret for reproducible Noise handshakes

func IsDebugModeEnabled added in v0.1.2

func IsDebugModeEnabled() bool

IsDebugModeEnabled returns whether debug mode is currently enabled

func IsValidPoint

func IsValidPoint(p *Point4D) bool

IsValidPoint checks if a point is valid using Ed25519 cofactor clearing

func PointCompress

func PointCompress(p *Point4D) []byte

PointCompress compresses a point to 32 bytes

func PointEqual

func PointEqual(p1, p2 *Point4D) bool

PointEqual checks if two points are equal in projective coordinates

func SecretExpand

func SecretExpand(secret []byte) (*big.Int, error)

SecretExpand expands a 32-byte secret key to a scalar

func SecretToPublic

func SecretToPublic(secret []byte) ([]byte, error)

SecretToPublic converts a private key to its corresponding public key

func SetDebugMode added in v0.1.2

func SetDebugMode(enabled bool)

SetDebugMode enables or disables debug mode for Noise-NK operations

func Sha256Hash

func Sha256Hash(data []byte) []byte

Sha256Hash computes SHA-256 hash of input bytes

func TestNoiseNK

func TestNoiseNK() error

TestNoiseNK runs a basic test of the Noise-NK implementation

func X25519DH

func X25519DH(privateKey, publicKey []byte) ([]byte, error)

X25519DH performs Diffie-Hellman key exchange

func X25519GenerateKeypair

func X25519GenerateKeypair() ([]byte, []byte, error)

X25519GenerateKeypair generates a X25519 keypair

func X25519PublicKeyFromPrivate

func X25519PublicKeyFromPrivate(privateKey []byte) ([]byte, error)

X25519PublicKeyFromPrivate derives public key from private key

Types

type DebugRandomReader added in v0.1.2

type DebugRandomReader struct {
	// contains filtered or unexported fields
}

DebugRandomReader provides deterministic randomness for debug mode

func (*DebugRandomReader) Read added in v0.1.2

func (dr *DebugRandomReader) Read(p []byte) (int, error)

Read implements io.Reader for deterministic randomness

type NoiseNK

type NoiseNK struct {
	// contains filtered or unexported fields
}

NoiseNK represents a Noise-NK protocol handler

func NewNoiseNK

func NewNoiseNK(role string, localStaticKey *noise.DHKey, remoteStaticKey []byte, prologue []byte) (*NoiseNK, error)

NewNoiseNK creates a new Noise-NK endpoint

func (*NoiseNK) Decrypt

func (nk *NoiseNK) Decrypt(ciphertext []byte, associatedData []byte) ([]byte, error)

Decrypt decrypts a message (post-handshake)

func (*NoiseNK) Encrypt

func (nk *NoiseNK) Encrypt(plaintext []byte, associatedData []byte) ([]byte, error)

Encrypt encrypts a message (post-handshake)

func (*NoiseNK) GetHandshakeHash

func (nk *NoiseNK) GetHandshakeHash() []byte

GetHandshakeHash returns the handshake hash for channel binding

func (*NoiseNK) GetPublicKey

func (nk *NoiseNK) GetPublicKey() []byte

GetPublicKey returns this party's static public key as bytes

func (*NoiseNK) GetTransportKeys added in v0.1.2

func (nk *NoiseNK) GetTransportKeys() ([]byte, []byte)

GetTransportKeys returns the actual transport keys for debugging

func (*NoiseNK) IsHandshakeComplete

func (nk *NoiseNK) IsHandshakeComplete() bool

IsHandshakeComplete returns whether the handshake is complete

func (*NoiseNK) ReadHandshakeMessage

func (nk *NoiseNK) ReadHandshakeMessage(message []byte) ([]byte, error)

ReadHandshakeMessage reads and processes a handshake message from the other party

func (*NoiseNK) SetRemotePublicKey

func (nk *NoiseNK) SetRemotePublicKey(remotePublicKey []byte) error

SetRemotePublicKey sets the remote party's static public key and reinitializes handshake

func (*NoiseNK) WriteHandshakeMessage

func (nk *NoiseNK) WriteHandshakeMessage(payload []byte) ([]byte, error)

WriteHandshakeMessage writes the next handshake message

type Point2D

type Point2D struct {
	X, Y *big.Int
}

Point2D represents a 2D point with (x, y) coordinates

func Unexpand

func Unexpand(point *Point4D) *Point2D

Unexpand converts extended 4D coordinates back to 2D point

type Point4D

type Point4D struct {
	X, Y, Z, T *big.Int
}

Point4D represents extended coordinates (X, Y, Z, T)

func Expand

func Expand(point *Point2D) *Point4D

Expand converts a 2D point to extended 4D coordinates

func H

func H(uid, did, bid, pin []byte) *Point4D

H computes the hash function H(UID, DID, BID, pin) -> Point

func PointAdd

func PointAdd(p1, p2 *Point4D) *Point4D

PointAdd adds two points in extended coordinates

func PointDecompress

func PointDecompress(data []byte) (*Point4D, error)

PointDecompress decompresses 32 bytes to a point

func PointMul

func PointMul(s *big.Int, p *Point4D) *Point4D

PointMul computes scalar multiplication: Q = s * P using double-and-add

Jump to

Keyboard shortcuts

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