ocrypt

module
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

README ΒΆ

Ocrypt - Distributed Password-Based Encryption

Go Reference Go Report Card License

Ocrypt is a modern, distributed password-based encryption library that provides secure, threshold-based secret recovery using multiple servers. It's designed as a drop-in replacement for bcrypt with enhanced security through distributed trust.

✨ Features

  • Simple API: Just 2 functions - Register() and Recover()
  • Distributed Security: Uses multiple servers for threshold-based recovery
  • Password-Based: Familiar bcrypt-style interface
  • Cryptographically Secure: Built on Ed25519, Noise Protocol, and Shamir's Secret Sharing
  • Multi-Server Failover: Automatic failover and load balancing
  • Zero Dependencies: Self-contained cryptographic implementations

πŸš€ Quick Start

package main

import (
    "fmt"
    "log"
    
    "github.com/openadp/ocrypt/ocrypt"
)

func main() {
    // Register a secret (like bcrypt.GenerateFromPassword)
    metadata, err := ocrypt.Register("user123", "myapp", "my-secret-data", "password123")
    if err != nil {
        log.Fatal(err)
    }
    
    fmt.Printf("Secret registered! Metadata: %s\n", metadata)
    
    // Recover the secret (like bcrypt.CompareHashAndPassword)
    secret, err := ocrypt.Recover(metadata, "password123")
    if err != nil {
        log.Fatal(err)
    }
    
    fmt.Printf("Recovered secret: %s\n", secret)
}

πŸ“¦ Installation

go get github.com/openadp/ocrypt

πŸ—οΈ Architecture

Ocrypt consists of several focused packages:

Core Packages
  • ocrypt/ - Simple 2-function API (Register/Recover)
  • client/ - Multi-server client with automatic failover
  • keygen/ - Distributed key generation and recovery
Cryptographic Primitives
  • crypto/ - Ed25519 utilities and OPRF implementations
  • noise/ - Noise Protocol Framework for secure communications
  • sharing/ - Shamir's Secret Sharing implementation

πŸ”§ Advanced Usage

Custom Server Configuration
import "github.com/openadp/ocrypt/keygen"

// Generate encryption key with custom servers
servers := []string{
    "https://server1.example.com",
    "https://server2.example.com", 
    "https://server3.example.com",
}

key, authCodes, err := keygen.GenerateEncryptionKey(
    "filename.txt",
    "user123", 
    5, // max guesses
    2, // threshold (2 of 3 servers needed)
    servers,
)
Multi-Server Client
import "github.com/openadp/ocrypt/client"

// Create client with multiple servers
client := client.NewMultiServerClient(servers, 30*time.Second)

// The client automatically handles:
// - Server discovery and health checks
// - Load balancing and failover
// - Connection pooling
// - Retry logic
Direct Cryptographic Operations
import (
    "github.com/openadp/ocrypt/crypto"
    "github.com/openadp/ocrypt/sharing"
)

// Generate Ed25519 keypair
privateKey, publicKey, err := crypto.GenerateKeypair()

// Create secret shares (3-of-5 threshold)
shares, err := sharing.MakeRandomShares(secret, 5, 3)

// Recover secret from shares
recovered, err := sharing.RecoverSecret(shares[:3])

πŸ”’ Security Features

  • Threshold Cryptography: Requires multiple servers for secret recovery
  • Forward Secrecy: Uses ephemeral keys for each session
  • Authenticated Encryption: All communications are authenticated and encrypted
  • Rate Limiting: Built-in protection against brute force attacks
  • Zero-Knowledge: Servers never see plaintext passwords or secrets

🌐 Server Compatibility

Ocrypt is designed to work with OpenADP servers but can be adapted to other threshold cryptography systems. The protocol is based on:

  • JSON-RPC 2.0 for API communication
  • Noise NK for secure channel establishment
  • Ed25519 for digital signatures
  • Curve25519 for key exchange

πŸ“š Documentation

🀝 Contributing

We welcome contributions! Please see CONTRIBUTING.md for guidelines.

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

Directories ΒΆ

Path Synopsis
Package client provides JSON-RPC client functionality for OpenADP server communication.
Package client provides JSON-RPC client functionality for OpenADP server communication.
Package common provides shared cryptographic primitives and utilities for OpenADP.
Package common provides shared cryptographic primitives and utilities for OpenADP.
Package debug provides deterministic operations for testing and debugging.
Package debug provides deterministic operations for testing and debugging.
examples
basic command
Package ocrypt provides a simple 2-function API for distributed password hashing using OpenADP's Oblivious Pseudo Random Function (OPRF) cryptography.
Package ocrypt provides a simple 2-function API for distributed password hashing using OpenADP's Oblivious Pseudo Random Function (OPRF) cryptography.

Jump to

Keyboard shortcuts

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