crypto

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: GPL-2.0 Imports: 16 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

Copyright (C) 2026 by saba <contact me via issue>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

In addition, no derivative work may use the name or imply association with this application without prior consent.

Copyright (C) 2026 by saba <contact me via issue>

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

In addition, no derivative work may use the name or imply association with this application without prior consent.

Index

Constants

This section is empty.

Variables

View Source
var KeyUpdateAfterBytes int64 = 32 << 20 // 32 MiB

KeyUpdateAfterBytes controls automatic key rotation based on plaintext bytes. It is a package var (not config) to enable targeted tests with smaller thresholds.

Functions

func EncodePoint

func EncodePoint(p *edwards25519.Point) string

EncodePoint returns the hex string of the compressed point

func EncodeScalar

func EncodeScalar(s *edwards25519.Scalar) string

EncodeScalar returns the hex string of the scalar

func ParsePrivateScalar

func ParsePrivateScalar(keyHex string) (*edwards25519.Scalar, error)

ParsePrivateScalar parses either a master private scalar (32-byte hex) or a split key (64-byte hex) and returns the corresponding master scalar x.

func RecoverPublicKey

func RecoverPublicKey(keyHex string) (*edwards25519.Point, error)

RecoverPublicKey takes a split private key (r, k) or a master private key (x) and returns the public key P. Input can be: - 32 bytes hex (Master Scalar x) - 64 bytes hex (Split Key r || k)

func SplitPrivateKey

func SplitPrivateKey(x *edwards25519.Scalar) (string, error)

SplitPrivateKey takes a master private key x and returns a new random split key (r, k) such that x = r + k (mod L). Returns hex encoded string of r || k (64 bytes)

Types

type KeyPair

type KeyPair struct {
	Private *edwards25519.Scalar
	Public  *edwards25519.Point
}

KeyPair holds the scalar private key and point public key

func GenerateMasterKey

func GenerateMasterKey() (*KeyPair, error)

GenerateMasterKey generates a random master private key (scalar) and its public key (point)

type RecordConn

type RecordConn struct {
	net.Conn
	// contains filtered or unexported fields
}

RecordConn is a framed AEAD net.Conn with:

  • deterministic per-record nonce (epoch+seq)
  • per-direction key rotation (epoch), driven by plaintext byte counters
  • replay/out-of-order protection within the connection (strict seq check)

Wire format per record:

  • uint16 bodyLen
  • header[12] = epoch(uint32 BE) || seq(uint64 BE) (plaintext)
  • ciphertext = AEAD(header as nonce, plaintext, header as AAD)

func NewRecordConn

func NewRecordConn(c net.Conn, method string, baseSend, baseRecv []byte) (*RecordConn, error)

func (*RecordConn) CloseRead

func (c *RecordConn) CloseRead() error

func (*RecordConn) CloseWrite

func (c *RecordConn) CloseWrite() error

func (*RecordConn) Read

func (c *RecordConn) Read(p []byte) (int, error)

func (*RecordConn) Rekey

func (c *RecordConn) Rekey(baseSend, baseRecv []byte) error

func (*RecordConn) Write

func (c *RecordConn) Write(p []byte) (int, error)

func (*RecordConn) WriteBuffers added in v0.5.1

func (c *RecordConn) WriteBuffers(buffers net.Buffers) (int64, error)

WriteBuffers writes the concatenation of buffers as one plaintext stream. It coalesces small headers with their payload without an intermediate buffer. Neither the slices nor their contents are modified or retained after return.

func (*RecordConn) WriteTo added in v0.5.1

func (c *RecordConn) WriteTo(w io.Writer) (int64, error)

WriteTo forwards authenticated plaintext directly from the record buffer. The read lock keeps that storage alive during each destination Write. A short write leaves the unwritten suffix available to the next Read or WriteTo.

Jump to

Keyboard shortcuts

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