Skip to content

nicksrepo/trustmesh-libs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LibCrypto/Nonce = Nonce Implementation


Secure Nonce Management System Design Document

Overview

This document outlines the design and implementation of a secure nonce management system intended for use in distributed systems, ensuring uniqueness, security, and efficient management of nonces. The system includes mechanisms for generating secure nonces, validating their uniqueness, and pruning expired or used nonces to maintain system efficiency.

System Components

Nonce Structure

type Nonce struct {
    Address   string
    Value     uint32
    Hash      []byte
    Timestamp int64
}
  • Address: A unique identifier (e.g., a network address) associated with the nonce.
  • Value: A securely generated random value serving as the nonce.
  • Hash: A cryptographic hash of the nonce value, ensuring integrity.
  • Timestamp: The creation time of the nonce, used for expiry checks.

Secure Nonce Generation

Nonces are generated using a cryptographically secure pseudo-random number generator (CSPRNG) provided by the crypto/rand package in Go. This ensures that nonces are unpredictable and resistant to guessing or brute-force attacks.

func generateSecureNonce() (uint32, error) {
    var nonce uint32
    err := binary.Read(rand.Reader, binary.BigEndian, &nonce)
    if err != nil {
        return 0, err
    }
    return nonce, nil
}

Nonce Storage

Nonces are stored in a thread-safe map, keyed by the associated address, ensuring that there is only one nonce per address.

var (
    nonces      = make(map[string]NonceMapEntry)
    noncesMutex sync.RWMutex
)

Nonce Validation

Nonces are validated by checking their existence in the nonce map and ensuring they have not expired based on their timestamp.

func ValidateNonce(address string, nonce Nonce) bool {
    noncesMutex.RLock()
    defer noncesMutex.RUnlock()

    entry, exists := nonces[address]
    return exists && nonce.Value == entry.Value && bytes.Equal(nonce.Hash, entry.Hash) && time.Now().Unix()-entry.Timestamp <= nonceLifetime
}

Nonce Pruning

To maintain system efficiency, a mechanism for pruning expired nonces based on a predefined lifetime is implemented. This process runs periodically and removes nonces that have surpassed their expiry time.

func pruneExpiredNonces() {
    noncesMutex.Lock()
    defer noncesMutex.Unlock()

    currentTimestamp := time.Now().Unix()
    for address, entry := range nonces {
        if currentTimestamp-entry.Timestamp > nonceLifetime {
            delete(nonces, address)
        }
    }
}

Security Considerations

  • Entropy and Randomness: Ensuring the CSPRNG provides high entropy to prevent nonce predictability.
  • Nonce Length: Using a sufficient nonce length to avoid collisions and enhance security.
  • Expiry and Pruning: Implementing expiry times and regular pruning to mitigate replay attacks and manage storage efficiently.
  • Thread-Safety: Employing mutexes to ensure thread-safe operations on the nonce storage map.

Implementation Notes

  • Concurrency: The system is designed to be thread-safe, allowing concurrent nonce generation, validation, and pruning.
  • Scalability: By pruning expired nonces and optimizing storage, the system remains efficient as usage scales.
  • Extensibility: The design allows for future enhancements, such as integrating more complex validation schemes or updating cryptographic primitives.

Future Work

  • Rate Limiting: Implementing rate limiting for nonce generation and validation to protect against denial-of-service (DoS) attacks.
  • Audit and Monitoring: Establishing mechanisms for auditing nonce usage and monitoring for abnormal patterns that may indicate security issues.

This document serves as a reference for the current design and implementation of the secure nonce management system, providing a foundation for future development and enhancements.

LibCrypto = Enhanced NetworkAddress with Anonymized Geographic Locations


Overview

This update enhances the NetworkAddress structure within the common package to include anonymized geographic locations, ensuring privacy while enabling location-based functionalities. This design incorporates secure cryptographic practices for data handling and communication within distributed systems.

Key Components

NetworkAddress Structure

  • AnonGeoLocation: SafeLatitudeLongitude - Stores anonymized latitude and longitude.
  • LocationKey: kyber.Point - Cryptographic commitment to the AnonGeoLocation.
  • PrivateKey: kyber.Scalar - Node's private key for cryptographic operations.
  • PublicKey: kyber.Point - Node's public key derived from the private key.

Functionalities

NewNetworkAddress(lat, long float64)

  • Initializes a NetworkAddress with anonymized geographic data and cryptographic keys.

PublicKeyBase64() string

  • Returns the public key in Base64 encoded format.

encrypt(data []byte, key []byte) (string, error)

  • Utility for AES-GCM encryption of data.

EncodeToString(secretKey []byte) (string, error)

  • Serializes and encrypts the NetworkAddress, including public key and nonce.

GenerateSharedSecret(peerPublicKey kyber.Point) []byte

  • Generates a shared secret for secure communication.

Security Measures

  • Anonymization: Uses a precision grid for geographic data to maintain user privacy.
  • Cryptographic Commitment: Secures the location data through cryptographic commitments.
  • Secure Key Management: Employs Kyber library for robust cryptographic key generation.
  • AES-GCM Encryption: Ensures the confidentiality and integrity of network address data.

Use Cases

  • Decentralized Applications: Enhances node privacy and security in decentralized networks.
  • Proximity-Based Services: Enables privacy-preserving proximity detection and interaction.
  • Secure Communications: Facilitates encrypted messaging and data exchange between nodes.

Future Enhancements

  • Dynamic Precision: Adjusts anonymization precision based on environmental context.
  • Encoding/Decoding: Improves methods for efficient data serialization and processing.
  • Address Interface: Expands the implementation to cover comprehensive network address interactions.

Anonymizing Geographic Coordinates in Network Addresses


Overview

This document outlines the methodology for incorporating longitude and latitude data into network addresses while preserving anonymity, utilizing cryptographic commitments to maintain privacy.

Objectives

  • Preserve Anonymity: Protect exact geographic locations.
  • Maintain Utility: Retain location-based service capabilities.
  • Efficiency: Ensure system performance is not adversely impacted.

System Components

Geographic Encoding

  • Converts precise coordinates into a numeric grid system, reducing location precision to enhance anonymity.

Cryptographic Commitments

  • Generates secure commitments of the encoded geographic data, allowing nodes to commit to a location without disclosing it.

Zero-Knowledge Proofs (Optional)

  • Facilitates proving geographic proximity without revealing exact locations, ensuring verification without compromising privacy.

Nonce Integration

  • Incorporates geographic commitments into nonce structures, tying anonymized location data to unique network identifiers.

Implementation Steps

  1. Discretize Geographic Data: Map coordinates to a grid system.
  2. Generate Commitments: Securely encapsulate encoded locations.
  3. Integrate with Nonces: Embed location commitments within network address nonces.
  4. (Optional) Implement ZKPs: Develop proofs for proximity verification.

Security and Anonymity

  • Ensures location data is anonymized through discretization and cryptographic commitments, using secure random generation for nonces to prevent predictability.

Use Cases

  • Suited for applications requiring location awareness without compromising user privacy, including decentralized networks and proximity-based services.

Future Enhancements

  • Explore dynamic precision adjustment and further cryptographic methods to improve anonymity and system flexibility.

About

libs for trustmesh network

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages