storecrypto

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 18 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package storecrypto defines the versioned, client-side encrypted format used by croc's asynchronous stored transfers.

Index

Constants

View Source
const (
	Version       = 1
	Protocol      = "croc-store-v1"
	ChunkSize     = 4 * 1024 * 1024
	KeySize       = 32
	TransferIDLen = 16
	MaxFiles      = 100
)

Variables

This section is empty.

Functions

func CapabilityVerifier

func CapabilityVerifier(capability []byte) []byte

CapabilityVerifier returns the value stored by the service for a capability.

func DecodeBase64URL

func DecodeBase64URL(value string) ([]byte, error)

DecodeBase64URL decodes a protocol byte string.

func EncodeBase64URL

func EncodeBase64URL(value []byte) string

EncodeBase64URL encodes a protocol byte string.

func EncodedSHA256

func EncodedSHA256(data []byte) string

EncodedSHA256 returns an unpadded URL-safe digest.

func GenerateKey

func GenerateKey() ([]byte, error)

GenerateKey returns a fresh 256-bit transfer key.

func GenerateTransferID

func GenerateTransferID() (string, error)

GenerateTransferID returns a URL-safe identifier containing 128 bits of entropy. Identifiers are public and are not decryption keys.

func OpenChunk

func OpenChunk(master []byte, id string, ref ChunkRef, ciphertext []byte) ([]byte, error)

OpenChunk authenticates and decrypts one file chunk.

func OpenManifestJSON

func OpenManifestJSON(master []byte, id string, ciphertext []byte, maxBytes int64) ([]byte, error)

OpenManifestJSON authenticates and decrypts a manifest, returning its validated JSON representation.

func RedeemCapability

func RedeemCapability(master []byte) ([]byte, error)

RedeemCapability derives a capability that authorizes reading ciphertext but cannot decrypt it.

func SealChunk

func SealChunk(master []byte, id string, ref ChunkRef, plaintext []byte) ([]byte, error)

SealChunk encrypts one file chunk with position-binding associated data.

func SealManifest

func SealManifest(master []byte, id string, manifest Manifest) ([]byte, error)

SealManifest encrypts a validated manifest.

func SealManifestJSON

func SealManifestJSON(master []byte, id string, plaintext []byte) ([]byte, error)

SealManifestJSON validates and encrypts a JSON-encoded manifest.

func ValidateManifest

func ValidateManifest(manifest Manifest, maxBytes int64) error

ValidateManifest rejects malformed or unsafe metadata before any files are created by a receiver.

Types

type ChunkCipher

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

ChunkCipher reuses the derived data key and AEAD across chunks in one transfer. It also supports caller-owned output buffers for the hot path.

func NewChunkCipher

func NewChunkCipher(master []byte) (*ChunkCipher, error)

NewChunkCipher prepares the data cipher for a stored transfer.

func (*ChunkCipher) NonceSize

func (c *ChunkCipher) NonceSize() int

NonceSize returns the prefix reserved before plaintext for SealInPlace.

func (*ChunkCipher) Open

func (c *ChunkCipher) Open(dst []byte, id string, ref ChunkRef, ciphertext []byte) ([]byte, error)

Open authenticates and decrypts a chunk, reusing dst when possible.

func (*ChunkCipher) OpenInPlace

func (c *ChunkCipher) OpenInPlace(id string, ref ChunkRef, ciphertext []byte) ([]byte, error)

OpenInPlace authenticates and decrypts into ciphertext's payload area.

func (*ChunkCipher) Seal

func (c *ChunkCipher) Seal(dst []byte, id string, ref ChunkRef, plaintext []byte) ([]byte, error)

Seal encrypts a chunk, reusing dst when it has sufficient capacity.

func (*ChunkCipher) SealInPlace

func (c *ChunkCipher) SealInPlace(buffer []byte, id string, ref ChunkRef) ([]byte, error)

SealInPlace encrypts plaintext already stored immediately after the nonce prefix in buffer. The ciphertext overwrites that plaintext.

type ChunkRef

type ChunkRef struct {
	ObjectIndex int64
	FileIndex   int64
	FileChunk   int64
	PlainSize   int
}

ChunkRef identifies a chunk and supplies the authenticated context required to decrypt it.

func ChunkRefs

func ChunkRefs(manifest Manifest) []ChunkRef

ChunkRefs returns the authenticated context for every manifest chunk.

type Manifest

type Manifest struct {
	Version   int            `json:"v"`
	ChunkSize int            `json:"cs"`
	Files     []ManifestFile `json:"f"`
}

Manifest is encrypted before it is uploaded. The storage service never sees file names, modification times, sizes, or hashes.

func OpenManifest

func OpenManifest(master []byte, id string, ciphertext []byte, maxBytes int64) (Manifest, error)

OpenManifest authenticates, decrypts, and validates a manifest.

type ManifestFile

type ManifestFile struct {
	Name       string    `json:"n"`
	Size       int64     `json:"s"`
	Modified   time.Time `json:"m"`
	SHA256     string    `json:"h"`
	FirstChunk int       `json:"fc"`
	ChunkCount int       `json:"cc"`
}

ManifestFile describes one regular file in a stored transfer.

type Share

type Share struct {
	Origin    string
	ID        string
	MasterKey []byte
}

Share contains the public storage origin, opaque object ID, and secret master key encoded by a browser URL or CLI token.

func ParseShare

func ParseShare(value string) (Share, error)

ParseShare parses either the canonical browser URL or the CLI token.

func (Share) BrowserURL

func (share Share) BrowserURL() (string, error)

BrowserURL formats a share as a browser-safe fragment URL.

func (Share) CLIToken

func (share Share) CLIToken() (string, error)

CLIToken formats a share as a shell-prompt-friendly token.

Jump to

Keyboard shortcuts

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