Documentation ¶
Overview ¶
Package sodium is a wrapper for https://github.com/jedisct1/libsodium
Most of the functions is a method to the "Bytes" type. They are grouped below:
Signature ¶
Sender sign a message with its SecretKey and the receiver can verify the Signature by sender's PublicKey
type SignKP struct { PublicKey SignPublicKey SecretKey SignSecretKey } func MakeSignKP() SignKP func SeedSignKP(seed SignSeed) SignKP func (k SignSecretKey) PublicKey() SignPublicKey func (k SignSecretKey) Seed() SignSeed //SignKP can be converted to BoxKP //It is recommended to use separate keys for signing and encrytion. func (p SignKP) ToBox() BoxKP func (k SignSecretKey) ToBox() BoxSecretKey func (k SignPublicKey) ToBox() BoxPublicKey //Message + Signature func (b Bytes) Sign(key SignSecretKey) (sm Bytes) func (b Bytes) SignOpen(key SignPublicKey) (m Bytes, err error) //Detached Signature func (b Bytes) SignDetached(key SignSecretKey) (sig Signature) func (b Bytes) SignVerifyDetached(sig Signature, key SignPublicKey) (err error)
(Ed25519)
//for multi-part messages that can't fit in memory func NewSignState() *SignState func (s *SignState) Update(b []byte) func (s *SignState) Sign(key SignSecretKey) Signature func (s *SignState) Verify(sig Signature, key SignPublicKey) (err error)
(Ed25519ph)
Anonymous Public Key Encryption ¶
An anonymous can encrypt a message with an ephemeral key pair and reveiver's PublicKey. The receiver can decrypt the message with its SecretKey. Only the receiver is authenticated.
type BoxKP struct { PublicKey BoxPublicKey SecretKey BoxSecretKey } func MakeBoxKP() BoxKP func SeedBoxKP(seed BoxSeed) BoxKP func (b Bytes) SealedBox(pk BoxPublicKey) (cm Bytes) func (b Bytes) SealedBoxOpen(kp BoxKP) (m Bytes, err error)
(X25519-XSalsa20-Poly1305)
Authenticated Public Key Encryption ¶
Authenticated Box can be used to pass encrypt message from a known sender to a known receiver. The sender and the receiver are both authenticated to each other.
A one-time shared nonce is also generated and passed to protect the key pairs and messages.
type BoxKP struct { PublicKey BoxPublicKey SecretKey BoxSecretKey } func MakeBoxKP() BoxKP func SeedBoxKP(seed BoxSeed) BoxKP func (b *BoxNonce) Next() //All-in-one box func (b Bytes) Box(n BoxNonce, pk BoxPublicKey, sk BoxSecretKey) (c Bytes) func (b Bytes) BoxOpen(n BoxNonce, pk BoxPublicKey, sk BoxSecretKey) (m Bytes, err error) //Detached MAC func (b Bytes) BoxDetached(n BoxNonce, pk BoxPublicKey, sk BoxSecretKey) (mac BoxMAC, c Bytes) func (b Bytes) BoxOpenDetached(mac BoxMAC, n BoxNonce, pk BoxPublicKey, sk BoxSecretKey) (c Bytes, err error)
(X25519-XSalsa20-Poly1305)
Key Exchanging ¶
Server and Client exchange their public key and calculates a common session key with their own secret key.
type KXKP struct { PublicKey KXPublicKey SecretKey KXSecretKey } func MakeKXKP() KXKP func SeedKXKP(seed KXSeed) KXKP type KXSessionKeys struct { Rx KXSessionKey Tx KXSessionKey } // session keys for client func (kp KXKP) ClientSessionKeys(server_pk KXPublicKey) (*KXSessionKeys, error) // session keys for server func (kp KXKP) ServerSessionKeys(client_pk KXPublicKey) (*KXSessionKeys, error) { // client's rx == server's tx // client's tx == server's rx
(rx || tx = BLAKE2B-512(p.n || client_pk || server_pk))
Secret Key Authentication ¶
One holder of a secret key authenticates the message with MAC.
//Holders of the key can generate a MAC for the message. func (b Bytes) Auth(key MACKey) (mac MAC) //Holders of the key can verify the message's authenticity. func (b Bytes) AuthVerify(mac MAC, key MACKey) (err error)
(HMAC-SHA512256)
Secret Key Encryption ¶
Use a secret key and a nonce to protect the key, messages could be encrypted into a SecretBox. The encrypted data's intergrity is checked when decryption.
func (n *SecretBoxNonce) Next() //encrypted message + MAC. func (b Bytes) SecretBox(n SecretBoxNonce, k SecretBoxKey) (c Bytes) func (b Bytes) SecretBoxOpen(n SecretBoxNonce, k SecretBoxKey) (m Bytes, err error) //Detached version has a separate MAC. func (b Bytes) SecretBoxDetached(n SecretBoxNonce, k SecretBoxKey) (c Bytes, mac SecretBoxMAC) func (b Bytes) SecretBoxOpenDetached(mac SecretBoxMAC, n SecretBoxNonce, k SecretBoxKey) (m Bytes, err error)
(XSalsa20-Poly1305)
Authenticated Encryption with Additional Data ¶
Use a secret key and a nonce to protect the key, messages could be encrypted. Optional additional data and the message is authenticited with an authentication tag. Both intergrity and authenticity is checked when decryption. The decryption would not be performed unless the authentication tag is verified.
func MakeAEADCPKey() AEADCPKey func (n *AEADCPNonce) Next() //encrypted message + MAC. func (b Bytes) AEADCPEncrypt(ad Bytes, n AEADCPNonce, k AEADCPKey) (c Bytes) func (b Bytes) AEADCPDecrypt(ad Bytes, n AEADCPNonce, k AEADCPKey) (m Bytes, err error) func (b Bytes) AEADCPVerify(ad Bytes, n AEADCPNonce, k AEADCPKey) (err error) //Detached version has a separate MAC. func (b Bytes) AEADCPEncryptDetached(ad Bytes, n AEADCPNonce, k AEADCPKey) (c Bytes, mac AEADCPMAC) func (b Bytes) AEADCPDecryptDetached(mac AEADCPMAC, ad Bytes, n AEADCPNonce, k AEADCPKey) (m Bytes, err error) func (b Bytes) AEADCPVerifyDetached(mac AEADCPMAC, ad Bytes, n AEADCPNonce, k AEADCPKey) (err error)
AEADCP* (ChaCha20-Poly1305_IETF) AEADXCP* (XChaCha20-Poly1305_IETF)
Secret Key Streaming Encryption ¶
High-level streaming API that use AEAD construct. Using `SecretStreamTag_Sync` to indicate the end of message. And this is useful for application to parse the message earlier. Rekeying is automatic. However using `SecretStreamTag_Rekey` explicitly ask for rekeying. Typical usage is sending chunks with `SecretStreamTag_Message`.
func MakeSecretStreamXCPKey() SecretStreamXCPKey //decoder func MakeSecretStreamXCPDecoder(key SecretStreamXCPKey, in io.Reader, header SecretStreamXCPHeader) (SecretStreamDecoder, error) func (e *SecretStreamXCPDecoder) Read(b []byte) (n int, err error) func (e *SecretStreamXCPDecoder) SetAdditionData(ad []byte) func (e SecretStreamXCPDecoder) Tag() SecretStreamTag //encoder func MakeSecretStreamXCPEncoder(key SecretStreamXCPKey, out io.Writer) SecretStreamEncoder func (e *SecretStreamXCPEncoder) Close() error func (e SecretStreamXCPEncoder) Header() SecretStreamXCPHeader func (e *SecretStreamXCPEncoder) SetAdditionData(ad []byte) func (e *SecretStreamXCPEncoder) SetTag(t SecretStreamTag) func (e *SecretStreamXCPEncoder) Write(b []byte) (n int, err error) func (e *SecretStreamXCPEncoder) WriteAndClose(b []byte) (n int, err error)
XCP (XChaCha20-Poly1305_IETF)
Key Derivation ¶
Deriving subkeys from a single high-entropy key
func MakeMasterKey() MasterKey func MakeKeyContext(s string) KeyContext func (m MasterKey) Derive(length int, id uint64, context KeyContext) SubKey
KDF (BLAKE2B)
Index ¶
- Constants
- Variables
- func MemCmp(buff1, buff2 Bytes, length int) int
- func MemZero(buff1 Bytes)
- func NewGenericHash(outlen int) hash.Hash
- func NewGenericHashDefault() hash.Hash
- func NewGenericHashDefaultKeyed(key GenericHashKey) hash.Hash
- func NewGenericHashKeyed(outlen int, key GenericHashKey) hash.Hash
- func Randomize(k Typed)
- type AEADCPKey
- type AEADCPMAC
- type AEADCPNonce
- type AEADXCPKey
- type AEADXCPMAC
- type AEADXCPNonce
- type BoxKP
- type BoxMAC
- type BoxNonce
- type BoxPublicKey
- type BoxSecretKey
- type BoxSeed
- type Bytes
- func (b Bytes) AEADCPDecrypt(ad Bytes, n AEADCPNonce, k AEADCPKey) (m Bytes, err error)
- func (b Bytes) AEADCPDecryptDetached(mac AEADCPMAC, ad Bytes, n AEADCPNonce, k AEADCPKey) (m Bytes, err error)
- func (b Bytes) AEADCPEncrypt(ad Bytes, n AEADCPNonce, k AEADCPKey) (c Bytes)
- func (b Bytes) AEADCPEncryptDetached(ad Bytes, n AEADCPNonce, k AEADCPKey) (c Bytes, mac AEADCPMAC)
- func (b Bytes) AEADCPVerify(ad Bytes, n AEADCPNonce, k AEADCPKey) (err error)
- func (b Bytes) AEADCPVerifyDetached(mac AEADCPMAC, ad Bytes, n AEADCPNonce, k AEADCPKey) (err error)
- func (b Bytes) AEADXCPDecrypt(ad Bytes, n AEADXCPNonce, k AEADXCPKey) (m Bytes, err error)
- func (b Bytes) AEADXCPDecryptDetached(mac AEADXCPMAC, ad Bytes, n AEADXCPNonce, k AEADXCPKey) (m Bytes, err error)
- func (b Bytes) AEADXCPEncrypt(ad Bytes, n AEADXCPNonce, k AEADXCPKey) (c Bytes)
- func (b Bytes) AEADXCPEncryptDetached(ad Bytes, n AEADXCPNonce, k AEADXCPKey) (c Bytes, mac AEADXCPMAC)
- func (b Bytes) AEADXCPVerify(ad Bytes, n AEADXCPNonce, k AEADXCPKey) (err error)
- func (b Bytes) AEADXCPVerifyDetached(mac AEADXCPMAC, ad Bytes, n AEADXCPNonce, k AEADXCPKey) (err error)
- func (b Bytes) Auth(key MACKey) (mac MAC)
- func (b Bytes) AuthVerify(mac MAC, key MACKey) (err error)
- func (b Bytes) Box(n BoxNonce, pk BoxPublicKey, sk BoxSecretKey) (c Bytes)
- func (b Bytes) BoxDetached(n BoxNonce, pk BoxPublicKey, sk BoxSecretKey) (mac BoxMAC, c Bytes)
- func (b Bytes) BoxOpen(n BoxNonce, pk BoxPublicKey, sk BoxSecretKey) (m Bytes, err error)
- func (b Bytes) BoxOpenDetached(mac BoxMAC, n BoxNonce, pk BoxPublicKey, sk BoxSecretKey) (m Bytes, err error)
- func (b Bytes) Length() int
- func (b Bytes) SealedBox(pk BoxPublicKey) (cm Bytes)
- func (b Bytes) SealedBoxOpen(kp BoxKP) (m Bytes, err error)
- func (b Bytes) SecretBox(n SecretBoxNonce, k SecretBoxKey) (c Bytes)
- func (b Bytes) SecretBoxDetached(n SecretBoxNonce, k SecretBoxKey) (c Bytes, mac SecretBoxMAC)
- func (b Bytes) SecretBoxOpen(n SecretBoxNonce, k SecretBoxKey) (m Bytes, err error)
- func (b Bytes) SecretBoxOpenDetached(mac SecretBoxMAC, n SecretBoxNonce, k SecretBoxKey) (m Bytes, err error)
- func (b Bytes) Shorthash(key ShortHashKey) (out Bytes)
- func (b Bytes) Sign(key SignSecretKey) (sm Bytes)
- func (b Bytes) SignDetached(key SignSecretKey) (sig Signature)
- func (b Bytes) SignOpen(key SignPublicKey) (m Bytes, err error)
- func (b Bytes) SignVerifyDetached(sig Signature, key SignPublicKey) (err error)
- type GenericHash
- type GenericHashKey
- type KXKP
- type KXPublicKey
- type KXSecretKey
- type KXSeed
- type KXSessionKey
- type KXSessionKeys
- type KeyContext
- type MAC
- type MACKey
- type MasterKey
- type Nonce
- type PWHashSalt
- type PWHashStr
- type Scalar
- type ScalarMult
- type SecretBoxKey
- type SecretBoxMAC
- type SecretBoxNonce
- type SecretStreamDecoder
- type SecretStreamEncoder
- type SecretStreamTag
- type SecretStreamXCPDecoder
- type SecretStreamXCPEncoder
- func (e *SecretStreamXCPEncoder) Close() error
- func (e SecretStreamXCPEncoder) Header() SecretStreamXCPHeader
- func (e *SecretStreamXCPEncoder) SetAdditionData(ad []byte)
- func (e *SecretStreamXCPEncoder) SetTag(t SecretStreamTag)
- func (e *SecretStreamXCPEncoder) Write(b []byte) (n int, err error)
- func (e *SecretStreamXCPEncoder) WriteAndClose(b []byte) (n int, err error)
- type SecretStreamXCPHeader
- type SecretStreamXCPKey
- type ShortHash
- type ShortHashKey
- type SignKP
- type SignPublicKey
- type SignSecretKey
- type SignSeed
- type SignState
- type Signature
- type SubKey
- type Typed
Examples ¶
- BoxSecretKey.PublicKey
- Bytes.AEADCPEncrypt
- Bytes.AEADCPEncryptDetached
- Bytes.AEADCPVerify
- Bytes.AEADCPVerifyDetached
- Bytes.AEADXCPEncrypt
- Bytes.AEADXCPEncryptDetached
- Bytes.AEADXCPVerify
- Bytes.AEADXCPVerifyDetached
- Bytes.Auth
- Bytes.Box
- Bytes.BoxDetached
- Bytes.SealedBox
- Bytes.SecretBox
- Bytes.SecretBoxDetached
- Bytes.Shorthash
- Bytes.SignDetached
- MakeKXKP
- MasterKey.Derive
- NewGenericHashKeyed
- NewSignState
- PWHashStore
- SecretStreamXCPDecoder.Read
- SecretStreamXCPEncoder.Header
- SecretStreamXCPEncoder.Write
- SecretStreamXCPEncoder.WriteAndClose
- SeedBoxKP
- SeedSignKP
- SignKP.ToBox
Constants ¶
const ( // normal message chunk SecretStreamTag_Message = iota // message boundary, the last chunk of message SecretStreamTag_Sync // explicity rekeying SecretStreamTag_Rekey )
Variables ¶
var ( CryptoKDFBytesMin = int(C.crypto_kdf_bytes_min()) CryptoKDFBytesMax = int(C.crypto_kdf_bytes_max()) CryptoKDFContextBytes = int(C.crypto_kdf_contextbytes()) )
var ( CryptoPWHashOpsLimitInteractive = int(C.crypto_pwhash_opslimit_interactive()) CryptoPWHashMemLimitInteractive = int(C.crypto_pwhash_memlimit_interactive()) CryptoPWHashOpsLimitModerate = int(C.crypto_pwhash_opslimit_moderate()) CryptoPWHashMemLimitModerate = int(C.crypto_pwhash_memlimit_moderate()) CryptoPWHashOpsLimitSensitive = int(C.crypto_pwhash_opslimit_sensitive()) CryptoPWHashMemLimitSensitive = int(C.crypto_pwhash_memlimit_sensitive()) )
var ( RuntimeHasNeon = bool(C.sodium_runtime_has_neon() != 0) RuntimeHasSse2 = bool(C.sodium_runtime_has_sse2() != 0) RuntimeHasSse3 = bool(C.sodium_runtime_has_sse3() != 0) )
var ( ErrAuth = errors.New("sodium: Message forged") ErrOpenBox = errors.New("sodium: Can't open box") ErrOpenSign = errors.New("sodium: Signature forged") ErrDecryptAEAD = errors.New("sodium: Can't decrypt message") ErrPassword = errors.New("sodium: Password not matched") ErrInvalidKey = errors.New("sodium: Invalid key") ErrInvalidHeader = errors.New("sodium: Invalid header") ErrDecryptSS = errors.New("sodium: Can't decrypt stream") ErrInvalidState = errors.New("sodium: Invalid state") ErrUnknown = errors.New("sodium: Unknown") )
Functions ¶
func NewGenericHash ¶
Unkeyed version, output length should between 16 (128-bit) to 64 (512-bit).
func NewGenericHashDefault ¶
Unkeyed version with default output length.
func NewGenericHashDefaultKeyed ¶
func NewGenericHashDefaultKeyed(key GenericHashKey) hash.Hash
Keyed version with default output length.
func NewGenericHashKeyed ¶
func NewGenericHashKeyed(outlen int, key GenericHashKey) hash.Hash
Keyed version, output length in bytes should between 16 (128-bit) to 64 (512-bit).
Example ¶
kp := MakeBoxKP() key := GenericHashKey{kp.SecretKey.Bytes} h := NewGenericHashKeyed(48, key) h.Write(m) sh := h.Sum(nil) he := NewGenericHash(48) he.Write(m) she := he.Sum(nil) fmt.Println(len(sh)) fmt.Println(len(she)) fmt.Println((MemCmp(sh, she, len(sh))) == 0)
Output: 48 48 false
Types ¶
type AEADCPKey ¶
type AEADCPKey struct {
Bytes
}
func MakeAEADCPKey ¶ added in v1.0.14
func MakeAEADCPKey() AEADCPKey
type AEADCPNonce ¶
type AEADCPNonce struct {
Bytes
}
func (*AEADCPNonce) Next ¶
func (n *AEADCPNonce) Next()
func (AEADCPNonce) Size ¶
func (AEADCPNonce) Size() int
type AEADXCPKey ¶ added in v1.0.14
type AEADXCPKey struct {
Bytes
}
func MakeAEADXCPKey ¶ added in v1.0.14
func MakeAEADXCPKey() AEADXCPKey
func (AEADXCPKey) Size ¶ added in v1.0.14
func (AEADXCPKey) Size() int
type AEADXCPMAC ¶ added in v1.0.14
type AEADXCPMAC struct {
Bytes
}
func (AEADXCPMAC) Size ¶ added in v1.0.14
func (AEADXCPMAC) Size() int
type AEADXCPNonce ¶ added in v1.0.14
type AEADXCPNonce struct {
Bytes
}
func (*AEADXCPNonce) Next ¶ added in v1.0.14
func (n *AEADXCPNonce) Next()
func (AEADXCPNonce) Size ¶ added in v1.0.14
func (AEADXCPNonce) Size() int
type BoxKP ¶
type BoxKP struct { PublicKey BoxPublicKey SecretKey BoxSecretKey }
func SeedBoxKP ¶
SeedBoxKP generates a keypair for signing from a BoxSeed.
The same pair of keys will be generated with the same 'seed'
Example ¶
seed := BoxSeed{} Randomize(&seed) kp1 := SeedBoxKP(seed) kp2 := SeedBoxKP(seed) s1 := kp1.SecretKey s2 := kp2.SecretKey fmt.Println(MemCmp(s1.Bytes, s2.Bytes, s1.Length()) == 0)
Output: true
type BoxPublicKey ¶
type BoxPublicKey struct {
Bytes
}
func (BoxPublicKey) Size ¶
func (k BoxPublicKey) Size() int
type BoxSecretKey ¶
type BoxSecretKey struct {
Bytes
}
func (BoxSecretKey) PublicKey ¶
func (k BoxSecretKey) PublicKey() BoxPublicKey
PublicKey calculates public key from BoxSecretKey.
Example ¶
kp := MakeBoxKP() pk := kp.SecretKey.PublicKey() fmt.Println(MemCmp(kp.PublicKey.Bytes, pk.Bytes, pk.Length()) == 0)
Output: true
func (BoxSecretKey) Size ¶
func (k BoxSecretKey) Size() int
type Bytes ¶
type Bytes []byte
Bytes warppers around []byte.
func (Bytes) AEADCPDecrypt ¶
AEADCPDecrypt decrypts message with AEADCPKey, and AEADCPNonce. The appended authenticated tag is verified with additional data 'ad' before decryption.
It returns an error if decryption failed.
func (Bytes) AEADCPDecryptDetached ¶
func (b Bytes) AEADCPDecryptDetached(mac AEADCPMAC, ad Bytes, n AEADCPNonce, k AEADCPKey) (m Bytes, err error)
AEADCPDecryptDetached decrypts message with AEADCPKey, and AEADCPNonce. The separated authenticated tag is verified with additional data 'ad' before decryption.
It returns an error if decryption failed.
func (Bytes) AEADCPEncrypt ¶
func (b Bytes) AEADCPEncrypt(ad Bytes, n AEADCPNonce, k AEADCPKey) (c Bytes)
AEADCPEncrypt encrypts message with AEADCPKey, and AEADCPNonce. Message then authenticated with additional data 'ad'. Authentication tag is append to the encrypted data.
Example ¶
key := MakeAEADCPKey() n := AEADCPNonce{} Randomize(&n) ad := Bytes(`addtional data`) e := m.AEADCPEncrypt(ad, n, key) md, err := e.AEADCPDecrypt(ad, n, key) fmt.Println(err) fmt.Println(MemCmp(md, m, m.Length()) == 0)
Output: <nil> true
func (Bytes) AEADCPEncryptDetached ¶
AEADCPEncryptDetached encrypts message with AEADCPKey, and AEADCPNonce. Message then authenticated with additional data 'ad'. Authentication tag is separated saved as 'mac'.
Example ¶
key := MakeAEADCPKey() n := AEADCPNonce{} Randomize(&n) ad := Bytes(`addtional data`) e, mac := m.AEADCPEncryptDetached(ad, n, key) md, err := e.AEADCPDecryptDetached(mac, ad, n, key) fmt.Println(err) fmt.Println(MemCmp(md, m, m.Length()) == 0)
Output: <nil> true
func (Bytes) AEADCPVerify ¶
func (b Bytes) AEADCPVerify(ad Bytes, n AEADCPNonce, k AEADCPKey) (err error)
AEADCPVerify decrypts message with AEADCPKey, and AEADCPNonce without writing decrypted data. The appended authenticated tag is verified with additional data 'ad' before decryption.
It returns an error if decryption failed.
Example ¶
key := MakeAEADCPKey() n := AEADCPNonce{} Randomize(&n) ad := Bytes(`addtional data`) e := m.AEADCPEncrypt(ad, n, key) err := e.AEADCPVerify(ad, n, key) fmt.Println(err)
Output: <nil>
func (Bytes) AEADCPVerifyDetached ¶
func (b Bytes) AEADCPVerifyDetached(mac AEADCPMAC, ad Bytes, n AEADCPNonce, k AEADCPKey) (err error)
AEADCPVerifyDetached decrypts message with AEADCPKey, and AEADCPNonce without writing decrypted data. The separated authenticated tag is verified with additional data 'ad' before decryption.
It returns an error if decryption failed.
Example ¶
key := MakeAEADCPKey() n := AEADCPNonce{} Randomize(&n) ad := Bytes(`addtional data`) e, mac := m.AEADCPEncryptDetached(ad, n, key) err := e.AEADCPVerifyDetached(mac, ad, n, key) fmt.Println(err)
Output: <nil>
func (Bytes) AEADXCPDecrypt ¶ added in v1.0.14
func (b Bytes) AEADXCPDecrypt(ad Bytes, n AEADXCPNonce, k AEADXCPKey) (m Bytes, err error)
AEADXCPDecrypt decrypts message with AEADXCPKey, and AEADXCPNonce. The appended authenticated tag is verified with additional data 'ad' before decryption.
It returns an error if decryption failed.
func (Bytes) AEADXCPDecryptDetached ¶ added in v1.0.14
func (b Bytes) AEADXCPDecryptDetached(mac AEADXCPMAC, ad Bytes, n AEADXCPNonce, k AEADXCPKey) (m Bytes, err error)
AEADXCPDecryptDetached decrypts message with AEADXCPKey, and AEADXCPNonce. The separated authenticated tag is verified with additional data 'ad' before decryption.
It returns an error if decryption failed.
func (Bytes) AEADXCPEncrypt ¶ added in v1.0.14
func (b Bytes) AEADXCPEncrypt(ad Bytes, n AEADXCPNonce, k AEADXCPKey) (c Bytes)
AEADXCPEncrypt encrypts message with AEADXCPKey, and AEADXCPNonce. Message then authenticated with additional data 'ad'. Authentication tag is append to the encrypted data.
Example ¶
key := MakeAEADXCPKey() n := AEADXCPNonce{} Randomize(&n) ad := Bytes(`addtional data`) e := m.AEADXCPEncrypt(ad, n, key) md, err := e.AEADXCPDecrypt(ad, n, key) fmt.Println(err) fmt.Println(MemCmp(md, m, m.Length()) == 0)
Output: <nil> true
func (Bytes) AEADXCPEncryptDetached ¶ added in v1.0.14
func (b Bytes) AEADXCPEncryptDetached(ad Bytes, n AEADXCPNonce, k AEADXCPKey) (c Bytes, mac AEADXCPMAC)
AEADXCPEncryptDetached encrypts message with AEADXCPKey, and AEADXCPNonce. Message then authenticated with additional data 'ad'. Authentication tag is separated saved as 'mac'.
Example ¶
key := MakeAEADXCPKey() n := AEADXCPNonce{} Randomize(&n) ad := Bytes(`addtional data`) e, mac := m.AEADXCPEncryptDetached(ad, n, key) md, err := e.AEADXCPDecryptDetached(mac, ad, n, key) fmt.Println(err) fmt.Println(MemCmp(md, m, m.Length()) == 0)
Output: <nil> true
func (Bytes) AEADXCPVerify ¶ added in v1.0.14
func (b Bytes) AEADXCPVerify(ad Bytes, n AEADXCPNonce, k AEADXCPKey) (err error)
AEADXCPVerify decrypts message with AEADXCPKey, and AEADXCPNonce without writing decrypted data. The appended authenticated tag is verified with additional data 'ad' before decryption.
It returns an error if decryption failed.
Example ¶
key := MakeAEADXCPKey() n := AEADXCPNonce{} Randomize(&n) ad := Bytes(`addtional data`) e := m.AEADXCPEncrypt(ad, n, key) err := e.AEADXCPVerify(ad, n, key) fmt.Println(err)
Output: <nil>
func (Bytes) AEADXCPVerifyDetached ¶ added in v1.0.14
func (b Bytes) AEADXCPVerifyDetached(mac AEADXCPMAC, ad Bytes, n AEADXCPNonce, k AEADXCPKey) (err error)
AEADXCPVerifyDetached decrypts message with AEADXCPKey, and AEADXCPNonce without writing decrypted data. The separated authenticated tag is verified with additional data 'ad' before decryption.
It returns an error if decryption failed.
Example ¶
key := MakeAEADXCPKey() n := AEADXCPNonce{} Randomize(&n) ad := Bytes(`addtional data`) e, mac := m.AEADXCPEncryptDetached(ad, n, key) err := e.AEADXCPVerifyDetached(mac, ad, n, key) fmt.Println(err)
Output: <nil>
func (Bytes) Auth ¶
Auth generates a MAC for the message with the secret 'key'.
Example ¶
key := MACKey{} Randomize(&key) mac := m.Auth(key) err := m.AuthVerify(mac, key) fmt.Println(err)
Output: <nil>
func (Bytes) AuthVerify ¶
AuthVerify verifies a messagee with MAC and the secret 'key'.
It returns an error if verification failed.
func (Bytes) Box ¶
func (b Bytes) Box(n BoxNonce, pk BoxPublicKey, sk BoxSecretKey) (c Bytes)
Box puts message into an authenticated encrypted box using sender's SecretKey and receiver's PublicKey, with a shared one-time nonce is used for each message.
Example ¶
rkp := MakeBoxKP() skp := MakeBoxKP() n := BoxNonce{} Randomize(&n) bc := m.Box(n, rkp.PublicKey, skp.SecretKey) bom, err := bc.BoxOpen(n, skp.PublicKey, rkp.SecretKey) fmt.Println(err) fmt.Println(MemCmp(bom, m, m.Length()) == 0)
Output: <nil> true
func (Bytes) BoxDetached ¶
func (b Bytes) BoxDetached(n BoxNonce, pk BoxPublicKey, sk BoxSecretKey) (mac BoxMAC, c Bytes)
BoxDetached encodes message into an encrypted message using sender's SecretKey and receiver's PublicKey, with a shared one-time nonce is used for each message.
Detached MAC is return along with encrypted message for authentication.
Example ¶
rkp := MakeBoxKP() skp := MakeBoxKP() n := BoxNonce{} Randomize(&n) mac, bcd := m.BoxDetached(n, rkp.PublicKey, skp.SecretKey) bomd, err := bcd.BoxOpenDetached(mac, n, skp.PublicKey, rkp.SecretKey) fmt.Println(err) fmt.Println(MemCmp(bomd, m, m.Length()) == 0)
Output: <nil> true
func (Bytes) BoxOpen ¶
func (b Bytes) BoxOpen(n BoxNonce, pk BoxPublicKey, sk BoxSecretKey) (m Bytes, err error)
BoxOpen reads message from an authenticated encrypted box using receiver's SecretKey and sender's PublicKey with a shared one-time nonce
It returns an error if opening failed.
func (Bytes) BoxOpenDetached ¶
func (b Bytes) BoxOpenDetached(mac BoxMAC, n BoxNonce, pk BoxPublicKey, sk BoxSecretKey) (m Bytes, err error)
BoxOpenDetached decodes message from an encrypted message along with a MAC for authentication, and using receiver's SecretKey and sender's PublicKey with a shared one-time nonce.
It returns an error if opening failed.
func (Bytes) SealedBox ¶
func (b Bytes) SealedBox(pk BoxPublicKey) (cm Bytes)
SealedBox puts message into a sealed box using receiver's PublicKey and an ephemeral key pair of which the SecretKey is destroyed on sender's side right after encryption, and the PublicKey is packed with the Box to the receiver.
The receiver can open the box but can not verify the identity of the sender.
Example ¶
kp := MakeBoxKP() n := BoxNonce{} Randomize(&n) c := m.SealedBox(kp.PublicKey) om, err := c.SealedBoxOpen(kp) fmt.Println(err) fmt.Println(MemCmp(om, m, m.Length()) == 0)
Output: <nil> true
func (Bytes) SealedBoxOpen ¶
SealedBoxOpen reads message from a sealed box using its key pair and ephemeral public packed in the Box.
It returns an error if opening failed.
func (Bytes) SecretBox ¶
func (b Bytes) SecretBox(n SecretBoxNonce, k SecretBoxKey) (c Bytes)
SecretBox use a SecretBoxNonce and a SecretBoxKey to encrypt a message.
Example ¶
key := SecretBoxKey{} Randomize(&key) n := SecretBoxNonce{} Randomize(&n) c := m.SecretBox(n, key) md, err := c.SecretBoxOpen(n, key) fmt.Println(err) fmt.Println(MemCmp(md, m, m.Length()) == 0)
Output: <nil> true
func (Bytes) SecretBoxDetached ¶
func (b Bytes) SecretBoxDetached(n SecretBoxNonce, k SecretBoxKey) (c Bytes, mac SecretBoxMAC)
SecretBoxDetached use a SecretBoxNonce and a SecretBoxKey to encrypt a message. A separate MAC is returned.
Example ¶
key := SecretBoxKey{} Randomize(&key) n := SecretBoxNonce{} Randomize(&n) c, mac := m.SecretBoxDetached(n, key) md, err := c.SecretBoxOpenDetached(mac, n, key) fmt.Println(err) fmt.Println(MemCmp(md, m, m.Length()) == 0)
Output: <nil> true
func (Bytes) SecretBoxOpen ¶
func (b Bytes) SecretBoxOpen(n SecretBoxNonce, k SecretBoxKey) (m Bytes, err error)
SecretBoxOpen opens a SecretBox using SecretBoxKey and SecretBoxNonce.
It returns an error if opening failed.
func (Bytes) SecretBoxOpenDetached ¶
func (b Bytes) SecretBoxOpenDetached(mac SecretBoxMAC, n SecretBoxNonce, k SecretBoxKey) (m Bytes, err error)
SecretBoxOpenDetached opens a SecretBox using SecretBoxKey and SecretBoxNonce. with a separate MAC.
It returns an error if opening failed.
func (Bytes) Shorthash ¶
func (b Bytes) Shorthash(key ShortHashKey) (out Bytes)
Shorthash use a secret key and input to produce a ShortHash. It is protective to short input. And it's output is also too short to be collision-resistent, however it can be used in hash table, Bloom filter or generate MAC for interactive protocol.
Example ¶
key := ShortHashKey{} Randomize(&key) m := Bytes(`short message`) hash := m.Shorthash(key) fmt.Println(hash.Length())
Output: 8
func (Bytes) Sign ¶
func (b Bytes) Sign(key SignSecretKey) (sm Bytes)
Sign returns 'sm': signature+message
func (Bytes) SignDetached ¶
func (b Bytes) SignDetached(key SignSecretKey) (sig Signature)
SignDetached signs the message with 'key' and returns only the signature.
Example ¶
kp := MakeSignKP() sm := m.Sign(kp.SecretKey) om, err := sm.SignOpen(kp.PublicKey) sig := m.SignDetached(kp.SecretKey) fmt.Println(err) fmt.Println(MemCmp(om, m, m.Length()) == 0) fmt.Println(MemCmp(sig.Bytes, sm, sig.Length()) == 0) err = m.SignVerifyDetached(sig, kp.PublicKey) fmt.Println(err)
Output: <nil> true true <nil>
func (Bytes) SignOpen ¶
func (b Bytes) SignOpen(key SignPublicKey) (m Bytes, err error)
SignOpen returns message 'm' from signature+message, verified by 'key'.
It returns an error if verification failed.
func (Bytes) SignVerifyDetached ¶
func (b Bytes) SignVerifyDetached(sig Signature, key SignPublicKey) (err error)
SignVerifyDetached verifies the message and its detached 'sig' with 'key'.
It returns an error if verification failed.
type GenericHash ¶
type GenericHash struct {
// contains filtered or unexported fields
}
GenericHash provides a BLAKE2b (RFC7693) hash, in interface of hash.Hash.
The Hash's and key's size can be any between 16 bytes (128 bits) to 64 bytes (512 bits) based on different application.
func (GenericHash) Size ¶
func (g GenericHash) Size() int
Output length in bytes.
Implements hash.Hash
func (*GenericHash) Sum ¶
func (g *GenericHash) Sum(b []byte) []byte
Return appended the Sum after b.
Implements hash.Hash.
NOTE: Repeated call is allowed. But can't call Write() after Sum(). The underlying state is freed. It MUST be Reset() to use it again after calling Sum(). This behaviour is inconsistent with the definition of hash.Hash.
type GenericHashKey ¶
type GenericHashKey struct {
Bytes
}
func (GenericHashKey) Size ¶
func (GenericHashKey) Size() int
type KXKP ¶
type KXKP struct { PublicKey KXPublicKey SecretKey KXSecretKey }
func MakeKXKP ¶
func MakeKXKP() KXKP
MakeKXKP generates a keypair for signing
Example ¶
skp := MakeKXKP() ckp := MakeKXKP() sss, _ := skp.ServerSessionKeys(ckp.PublicKey) css, _ := ckp.ClientSessionKeys(skp.PublicKey) fmt.Println(MemCmp(sss.Tx.Bytes, css.Rx.Bytes, sss.Tx.Size()) == 0) fmt.Println(MemCmp(sss.Rx.Bytes, css.Tx.Bytes, sss.Rx.Size()) == 0) fmt.Println(MemCmp(sss.Tx.Bytes, sss.Rx.Bytes, sss.Tx.Size()) == 0) fmt.Println(MemCmp(css.Tx.Bytes, css.Rx.Bytes, css.Tx.Size()) == 0)
Output: true true false false
func SeedKXKP ¶
SeedKXKP generates a keypair for exchanging from a KXSeed.
The same pair of keys will be generated with the same 'seed'
func (KXKP) ClientSessionKeys ¶
func (kp KXKP) ClientSessionKeys(server_pk KXPublicKey) (*KXSessionKeys, error)
ClientSessionKeys calculates Rx (for receving) and Tx (for sending) session keys with server's public key. return error when server_pk is not acceptable.
func (KXKP) ServerSessionKeys ¶
func (kp KXKP) ServerSessionKeys(client_pk KXPublicKey) (*KXSessionKeys, error)
ServerSessionKeys calculates Rx (for receving) and Tx (for sending) session keys with client's public key. return error when client_pk is not acceptable.
type KXPublicKey ¶
type KXPublicKey struct {
Bytes
}
func (KXPublicKey) Size ¶
func (k KXPublicKey) Size() int
type KXSecretKey ¶
type KXSecretKey struct {
Bytes
}
func (KXSecretKey) Size ¶
func (k KXSecretKey) Size() int
type KXSessionKey ¶
type KXSessionKey struct {
Bytes
}
func (KXSessionKey) Size ¶
func (k KXSessionKey) Size() int
type KXSessionKeys ¶
type KXSessionKeys struct { Rx KXSessionKey Tx KXSessionKey }
type KeyContext ¶
type KeyContext string
KeyContext is a CryptoKDFContextBytes length string indicating the context for the key. e.g. "username"
func MakeKeyContext ¶
func MakeKeyContext(s string) KeyContext
func (KeyContext) Length ¶
func (k KeyContext) Length() int
func (KeyContext) Size ¶
func (KeyContext) Size() int
type MAC ¶
type MAC struct {
Bytes
}
MAC stores Message Authentication Code produced by HMAC-SHA512256.
type MasterKey ¶
type MasterKey struct {
Bytes
}
MasterKey for deriving SubKeys
func (MasterKey) Derive ¶
func (m MasterKey) Derive(length int, id uint64, context KeyContext) SubKey
Derive SubKey from the MasterKey length should be between CryptoKDFBytesMin and CryptoKDFBytesMax
Example ¶
mk := MakeMasterKey() context := MakeKeyContext("testblablabla") // only first CryptoKDFContextBytes is used fmt.Println(context) sk := mk.Derive(CryptoKDFBytesMin, 0, context) fmt.Println(sk.Length() == CryptoKDFBytesMin)
Output: testblab true
type Nonce ¶
type Nonce interface { Typed Next() //Next unused nonce }
Nonce is used to protect secret key. It is important to not use the same nonce for a given key.
type PWHashSalt ¶
type PWHashSalt struct {
Bytes
}
PWHashSalt implements the Typed interface
func (PWHashSalt) Size ¶
func (s PWHashSalt) Size() int
type PWHashStr ¶
type PWHashStr struct {
// contains filtered or unexported fields
}
PWHashStr implements the Typed interface
func LoadPWHashStr ¶
func PWHashStore ¶
PWHashStore use moderate profile to pack hashed password into PWHashStr.
Example ¶
s := PWHashStore("test") str := s.Value() // str for store t := LoadPWHashStr(str) // load from storage err := t.PWHashVerify("test") fmt.Println(err)
Output: <nil>
func PWHashStoreInteractive ¶
PWHashStoreInteractive use interactive profile to pack hashed password into PWHashStr.
func PWHashStoreSensitive ¶
PWHashStoreSensitive use sensitive profile to pack hashed password into PWHashStr.
func (PWHashStr) PWHashVerify ¶
PWHashVerify verifies password.
type Scalar ¶
type Scalar struct {
Bytes
}
func CryptoScalarmultBase ¶
CryptoScalarmultBase calculates BoxPublicKey 'q' from BoxSecertKey 'n'.
type ScalarMult ¶
type ScalarMult struct {
Bytes
}
ScalarMult is the mulitiplication of two Scalar, used to calculate shared key from BoxSecertKey and other end's BoxPublicKey.
func CryptoScalarmult ¶
func CryptoScalarmult(n, p Scalar) (q ScalarMult)
CryptoScalarmult calculates common key 'q' from private key 'n' and other's public key 'p'
func (ScalarMult) Size ¶
func (s ScalarMult) Size() int
type SecretBoxKey ¶
type SecretBoxKey struct {
Bytes
}
func (SecretBoxKey) Size ¶
func (s SecretBoxKey) Size() int
type SecretBoxMAC ¶
type SecretBoxMAC struct {
Bytes
}
func (SecretBoxMAC) Size ¶
func (s SecretBoxMAC) Size() int
type SecretBoxNonce ¶
type SecretBoxNonce struct {
Bytes
}
func (*SecretBoxNonce) Next ¶
func (n *SecretBoxNonce) Next()
func (SecretBoxNonce) Size ¶
func (n SecretBoxNonce) Size() int
type SecretStreamDecoder ¶ added in v1.0.14
type SecretStreamDecoder interface { io.Reader SetAdditionData(ad []byte) Tag() SecretStreamTag }
func MakeSecretStreamXCPDecoder ¶ added in v1.0.14
func MakeSecretStreamXCPDecoder(key SecretStreamXCPKey, in io.Reader, header SecretStreamXCPHeader) (SecretStreamDecoder, error)
type SecretStreamEncoder ¶ added in v1.0.14
type SecretStreamEncoder interface { io.WriteCloser Header() SecretStreamXCPHeader SetAdditionData(ad []byte) SetTag(SecretStreamTag) WriteAndClose(b []byte) (n int, err error) }
func MakeSecretStreamXCPEncoder ¶ added in v1.0.14
func MakeSecretStreamXCPEncoder(key SecretStreamXCPKey, out io.Writer) SecretStreamEncoder
type SecretStreamTag ¶ added in v1.0.14
type SecretStreamTag uint8
SecretStreamTag can be set to encoder for modify stream state or can be get from decoder
type SecretStreamXCPDecoder ¶ added in v1.0.14
type SecretStreamXCPDecoder struct {
// contains filtered or unexported fields
}
func (*SecretStreamXCPDecoder) Read ¶ added in v1.0.14
func (e *SecretStreamXCPDecoder) Read(b []byte) (n int, err error)
Read decrypts the message with length len(b) and save in b. It returns io.EOF when receiving a closing signal
Example ¶
key := MakeSecretStreamXCPKey() var buf bytes.Buffer encoder := MakeSecretStreamXCPEncoder(key, &buf) encoder.SetTag(SecretStreamTag_Rekey) encoder.Write([]byte("test")) encoder.Close() var err error reader := bytes.NewReader(buf.Bytes()) decoder, err := MakeSecretStreamXCPDecoder(key, reader, encoder.Header()) fmt.Println(err == nil) chunk := make([]byte, 4) for { var n int n, err = decoder.Read(chunk) fmt.Println(n) if n > 0 { fmt.Println(string(chunk)) fmt.Println(decoder.Tag() == SecretStreamTag_Rekey) } else { fmt.Println(err == io.EOF) break } }
Output: true 4 test true 0 true
func (*SecretStreamXCPDecoder) SetAdditionData ¶ added in v1.0.14
func (e *SecretStreamXCPDecoder) SetAdditionData(ad []byte)
func (SecretStreamXCPDecoder) Tag ¶ added in v1.0.14
func (e SecretStreamXCPDecoder) Tag() SecretStreamTag
type SecretStreamXCPEncoder ¶ added in v1.0.14
type SecretStreamXCPEncoder struct {
// contains filtered or unexported fields
}
func (*SecretStreamXCPEncoder) Close ¶ added in v1.0.14
func (e *SecretStreamXCPEncoder) Close() error
Write encrypts the closing signal and write to the wrapped io.Writer and then close it
func (SecretStreamXCPEncoder) Header ¶ added in v1.0.14
func (e SecretStreamXCPEncoder) Header() SecretStreamXCPHeader
Header get the header from encoder
Example ¶
key := MakeSecretStreamXCPKey() var buf bytes.Buffer encoder := MakeSecretStreamXCPEncoder(key, &buf) b := encoder.Header().Bytes fmt.Println(b.Length())
Output: 24
func (*SecretStreamXCPEncoder) SetAdditionData ¶ added in v1.0.14
func (e *SecretStreamXCPEncoder) SetAdditionData(ad []byte)
func (*SecretStreamXCPEncoder) SetTag ¶ added in v1.0.14
func (e *SecretStreamXCPEncoder) SetTag(t SecretStreamTag)
func (*SecretStreamXCPEncoder) Write ¶ added in v1.0.14
func (e *SecretStreamXCPEncoder) Write(b []byte) (n int, err error)
Write encrypts the b as a message and write to the wrapped io.Writer
Example ¶
key := MakeSecretStreamXCPKey() var buf bytes.Buffer encoder := MakeSecretStreamXCPEncoder(key, &buf) encoder.SetTag(SecretStreamTag_Sync) encoder.Write([]byte("test")) encoder.Close() fmt.Println(buf.Len())
Output: 38
func (*SecretStreamXCPEncoder) WriteAndClose ¶ added in v1.0.14
func (e *SecretStreamXCPEncoder) WriteAndClose(b []byte) (n int, err error)
Write encrypts the b as a message and write to the wrapped io.Writer and then write the closing signal
Example ¶
key := MakeSecretStreamXCPKey() var buf bytes.Buffer encoder := MakeSecretStreamXCPEncoder(key, &buf) encoder.SetTag(SecretStreamTag_Sync) encoder.WriteAndClose([]byte("test")) fmt.Println(buf.Len())
Output: 21
type SecretStreamXCPHeader ¶ added in v1.0.14
type SecretStreamXCPHeader struct {
Bytes
}
SecretStreamXCPHeader generated by encoder and can be transferred in plain text. It must set to decoder before decoding
func (SecretStreamXCPHeader) Size ¶ added in v1.0.14
func (SecretStreamXCPHeader) Size() int
type SecretStreamXCPKey ¶ added in v1.0.14
type SecretStreamXCPKey struct {
Bytes
}
func MakeSecretStreamXCPKey ¶ added in v1.0.14
func MakeSecretStreamXCPKey() SecretStreamXCPKey
MakeSecretStreamXCPKey initilize the key
func (SecretStreamXCPKey) Size ¶ added in v1.0.14
func (SecretStreamXCPKey) Size() int
type ShortHashKey ¶
type ShortHashKey struct {
Bytes
}
func (ShortHashKey) Size ¶
func (s ShortHashKey) Size() int
type SignKP ¶
type SignKP struct { PublicKey SignPublicKey SecretKey SignSecretKey }
func SeedSignKP ¶
SeedSignKP generates a keypair for signing from a SignSeed.
The same pair of keys will be generated with the same 'seed'
Example ¶
seed := SignSeed{} Randomize(&seed) kp1 := SeedSignKP(seed) kp2 := SeedSignKP(seed) s1 := kp1.SecretKey s2 := kp2.SecretKey s := s1.Seed() pk1 := s1.PublicKey() fmt.Println(MemCmp(s1.Bytes, s2.Bytes, s1.Length()) == 0) fmt.Println(MemCmp(s.Bytes, seed.Bytes, seed.Length()) == 0) fmt.Println(MemCmp(pk1.Bytes, kp1.PublicKey.Bytes, pk1.Length()) == 0)
Output: true true true
func (SignKP) ToBox ¶
ToBox converts a pair of signing key into a pair of box key - ed25519 to curve25519 - returns BoxKP.
Example ¶
skp := MakeSignKP() bkp := skp.ToBox() rkp := MakeBoxKP() sb := skp.SecretKey.ToBox() pb := skp.PublicKey.ToBox() fmt.Println(MemCmp(bkp.SecretKey.Bytes, sb.Bytes, bkp.SecretKey.Length()) == 0) fmt.Println(MemCmp(bkp.PublicKey.Bytes, pb.Bytes, bkp.PublicKey.Length()) == 0) n := BoxNonce{} Randomize(&n) bc := m.Box(n, rkp.PublicKey, bkp.SecretKey) bom, err := bc.BoxOpen(n, bkp.PublicKey, rkp.SecretKey) fmt.Println(err) fmt.Println(MemCmp(bom, m, m.Length()) == 0)
Output: true true <nil> true
type SignPublicKey ¶
type SignPublicKey struct {
Bytes
}
func (SignPublicKey) Size ¶
func (k SignPublicKey) Size() int
func (SignPublicKey) ToBox ¶
func (k SignPublicKey) ToBox() BoxPublicKey
ToBox converts a signing public key into a box public key - ed25519 to curve25519 - returns BoxPublicKey.
type SignSecretKey ¶
type SignSecretKey struct {
Bytes
}
func (SignSecretKey) PublicKey ¶
func (k SignSecretKey) PublicKey() SignPublicKey
PublicKey extracts the SignPublicKey from the SignSecretKey.
func (SignSecretKey) Seed ¶
func (k SignSecretKey) Seed() SignSeed
Seed extracts the seed used when generating the key pair.
func (SignSecretKey) Size ¶
func (k SignSecretKey) Size() int
func (SignSecretKey) ToBox ¶
func (k SignSecretKey) ToBox() BoxSecretKey
ToBox converts a signing secret key into a box secret key - ed25519 to curve25519 - returns BoxSecretKey.
type SignState ¶
type SignState struct {
// contains filtered or unexported fields
}
func NewSignState ¶ added in v1.0.14
func NewSignState() *SignState
NewSignState creates an empty state for multi-part messages that can't fit in memory.
Example ¶
kp := MakeSignKP() s_a := NewSignState() s_a.Update(m) siga := s_a.Sign(kp.SecretKey) s_b := NewSignState() s_b.Update(m) err := s_b.Verify(siga, kp.PublicKey) fmt.Println(err)
Output: <nil>
func (*SignState) Sign ¶
func (s *SignState) Sign(key SignSecretKey) Signature
Sign a signature for the current state.
The underlying state is freed after this call.