[
  {
    "path": "LICENSE",
    "content": "/*\n * Copyright (c) 2015\n * GoKillers \n *\n * Permission to use, copy, modify, and/or distribute this software for any\n * purpose with or without fee is hereby granted, provided that the above\n * copyright notice and this permission notice appear in all copies.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\" AND THE AUTHOR DISCLAIMS ALL WARRANTIES\n * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF\n * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR\n * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES\n * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN\n * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF\n * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n */\n\n"
  },
  {
    "path": "README.md",
    "content": "!This code requires an independent audit check!\n\nlibsodium-go\n============\nA binding library made in Go for the popular portable cryptography library [Sodium](https://download.libsodium.org/doc/).\n\n\nPurpose\n-------\nThe goal of this binding library is to make use of Sodium in a more Go friendly matter.  And of course making it easier to make secure software.\n\nTeam (as of now...)\n----------------\n<ul>\n<li>Stephen Chavez (@redragonx)</li>\n<li>Graham Smith (@neuegram)</li>\n</ul>\n\nContributors\n------------\nSilkeh\n\nHow to build\n------------\nFor linux, this should be easy since there's pkg-config support. Please make sure libsodium is installed on your system first.\n\nPre-setup:\n1. Please install Libsodium here https://download.libsodium.org/doc/installation/index.html\n2. `sudo ldconfig`\n3. `sudo apt-get install pkg-config`\n\nInstall libsodium-go:\n1. `go get -d github.com/GoKillers/libsodium-go`\n2. `cd $GOPATH/src/github.com/GoKillers/libsodium-go`\n3. `./build.sh`\n\nFor Windows, this requires a little more work.\n\n1. Download and install pkg-config for [win32](http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/) or [win64](http://ftp.gnome.org/pub/gnome/binaries/win64/dependencies/)\n2. Add a system or user variable PKG_CONFIG_PATH pointing to a folder containing pkg-config files, including libsodium\n3. `go get -d github.com/GoKillers/libsodium-go`\n4. `cd %GOPATH%/src/github.com/GoKillers/libsodium-go`\n5. `build.bat`\n\nLicense\n---------\nCopyright 2015 - GoKillers\n"
  },
  {
    "path": "build.bat",
    "content": "go build ./..."
  },
  {
    "path": "build.sh",
    "content": "#!/bin/sh\nexec go build ./..."
  },
  {
    "path": "crypto/aead/aes256gcm/crypto_aead_aes256gcm.go",
    "content": "// Package aes256gcm contains the libsodium bindings for AES256-GCM.\npackage aes256gcm\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport \"github.com/GoKillers/libsodium-go/support\"\n\n// Sodium should always be initialised\nfunc init() {\n\tC.sodium_init()\n}\n\n// Sizes of nonces, key and mac.\nconst (\n\tKeyBytes   int = C.crypto_aead_aes256gcm_KEYBYTES  // Size of a secret key in bytes\n\tNSecBytes  int = C.crypto_aead_aes256gcm_NSECBYTES // Size of a secret nonce in bytes\n\tNonceBytes int = C.crypto_aead_aes256gcm_NPUBBYTES // Size of a nonce in bytes\n\tABytes     int = C.crypto_aead_aes256gcm_ABYTES    // Size of an authentication tag in bytes\n)\n\n// IsAvailable returns true if AES256 is available on the current CPU\nfunc IsAvailable() bool {\n\treturn C.crypto_aead_aes256gcm_is_available() != 0\n}\n\n// GenerateKey generates a secret key\nfunc GenerateKey() *[KeyBytes]byte {\n\tk := new([KeyBytes]byte)\n\tC.crypto_aead_aes256gcm_keygen((*C.uchar)(&k[0]))\n\treturn k\n}\n\n// Encrypt a message `m` with additional data `ad` using a nonce `npub` and a secret key `k`.\n// A ciphertext (including authentication tag) and encryption status are returned.\nfunc Encrypt(m, ad []byte, nonce *[NonceBytes]byte, k *[KeyBytes]byte) (c []byte) {\n\tsupport.NilPanic(k == nil, \"secret key\")\n\tsupport.NilPanic(nonce == nil, \"nonce\")\n\n\tc = make([]byte, len(m)+ABytes)\n\n\tC.crypto_aead_aes256gcm_encrypt(\n\t\t(*C.uchar)(support.BytePointer(c)),\n\t\t(*C.ulonglong)(nil),\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(&nonce[0]),\n\t\t(*C.uchar)(&k[0]))\n\n\treturn\n}\n\n// Decrypt and verify a ciphertext `c` using additional data `ad`, nonce `npub` and secret key `k`.\n// Returns the decrypted message and verification status.\nfunc Decrypt(c, ad []byte, nonce *[NonceBytes]byte, k *[KeyBytes]byte) (m []byte, err error) {\n\tsupport.NilPanic(k == nil, \"secret key\")\n\tsupport.NilPanic(nonce == nil, \"nonce\")\n\tsupport.CheckSizeMin(c, ABytes, \"ciphertext\")\n\n\tm = make([]byte, len(c)-ABytes)\n\n\texit := C.crypto_aead_aes256gcm_decrypt(\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(*C.ulonglong)(nil),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(&c[0]),\n\t\t(C.ulonglong)(len(c)),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(&nonce[0]),\n\t\t(*C.uchar)(&k[0]))\n\n\tif exit != 0 {\n\t\terr = &support.VerificationError{}\n\t}\n\n\treturn\n}\n\n// EncryptDetached encrypts a message `m` with additional data `ad` using\n// a nonce `npub` and a secret key `k`.\n// A ciphertext, authentication tag and encryption status are returned.\nfunc EncryptDetached(m, ad []byte, nonce *[NonceBytes]byte, k *[KeyBytes]byte) (c, mac []byte) {\n\tsupport.NilPanic(k == nil, \"secret key\")\n\tsupport.NilPanic(nonce == nil, \"nonce\")\n\n\tc = make([]byte, len(m))\n\tmac = make([]byte, ABytes)\n\n\tC.crypto_aead_aes256gcm_encrypt_detached(\n\t\t(*C.uchar)(support.BytePointer(c)),\n\t\t(*C.uchar)(&mac[0]),\n\t\t(*C.ulonglong)(nil),\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(&nonce[0]),\n\t\t(*C.uchar)(&k[0]))\n\n\treturn\n}\n\n// DecryptDetached decrypts and verifies a ciphertext `c` with authentication tag `mac`\n// using additional data `ad`, nonce `npub` and secret key `k`.\n// Returns the decrypted message and verification status.\nfunc DecryptDetached(c, mac, ad []byte, nonce *[NonceBytes]byte, k *[KeyBytes]byte) (m []byte, err error) {\n\tsupport.NilPanic(k == nil, \"secret key\")\n\tsupport.NilPanic(nonce == nil, \"nonce\")\n\tsupport.CheckSize(mac, ABytes, \"mac\")\n\n\tm = make([]byte, len(c))\n\n\texit := C.crypto_aead_aes256gcm_decrypt_detached(\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(support.BytePointer(c)),\n\t\t(C.ulonglong)(len(c)),\n\t\t(*C.uchar)(&mac[0]),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(&nonce[0]),\n\t\t(*C.uchar)(&k[0]))\n\n\tif exit != 0 {\n\t\terr = &support.VerificationError{}\n\t}\n\n\treturn\n}\n"
  },
  {
    "path": "crypto/aead/aes256gcm/crypto_aead_aes256gcm_test.go",
    "content": "package aes256gcm\n\nimport (\n\t\"bytes\"\n\t\"github.com/google/gofuzz\"\n\t\"testing\"\n)\n\nvar testCount = 100000\n\ntype TestData struct {\n\tMessage []byte\n\tAd      []byte\n\tKey     [KeyBytes]byte\n\tNonce   [NonceBytes]byte\n}\n\nfunc Test(t *testing.T) {\n\t// Skip the test if unsupported on this platform\n\tif !IsAvailable() {\n\t\tt.Skip(\"The CPU does not support this implementation of AES256GCM.\")\n\t}\n\n\t// Test the key generation\n\tif *GenerateKey() == ([KeyBytes]byte{}) {\n\t\tt.Error(\"Generated key is zero\")\n\t}\n\n\t// Test the length of NSecBytes\n\tif NSecBytes != 0 {\n\t\tt.Errorf(\"NSecBytes is %v but should be %v\", NSecBytes, 0)\n\t}\n\n\t// Fuzzing\n\tf := fuzz.New()\n\n\t// Run tests\n\tfor i := 0; i < testCount; i++ {\n\t\tvar c, m, ec, mac []byte\n\t\tvar err error\n\t\tvar test TestData\n\n\t\t// Fuzz the test struct\n\t\tf.Fuzz(&test)\n\n\t\t// Detached encryption test\n\t\tc, mac = EncryptDetached(test.Message, test.Ad, &test.Nonce, &test.Key)\n\n\t\t// Encryption test\n\t\tec = Encrypt(test.Message, test.Ad, &test.Nonce, &test.Key)\n\t\tif !bytes.Equal(ec, append(c, mac...)) {\n\t\t\tt.Errorf(\"Encryption failed for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\n\t\t// Detached decryption test\n\t\tm, err = DecryptDetached(c, mac, test.Ad, &test.Nonce, &test.Key)\n\t\tif err != nil || !bytes.Equal(m, test.Message) {\n\t\t\tt.Errorf(\"Detached decryption failed for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\n\t\t// Decryption test\n\t\tm, err = Decrypt(ec, test.Ad, &test.Nonce, &test.Key)\n\t\tif err != nil || !bytes.Equal(m, test.Message) {\n\t\t\tt.Errorf(\"Decryption failed for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\n\t\t// Failed detached decryption test\n\t\tmac = make([]byte, ABytes)\n\t\tm, err = DecryptDetached(c, mac, test.Ad, &test.Nonce, &test.Key)\n\t\tif err == nil {\n\t\t\tt.Errorf(\"Detached decryption unexpectedly succeeded for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\n\t\t// Failed decryption test\n\t\tcopy(ec[len(m):], mac)\n\t\tm, err = Decrypt(ec, test.Ad, &test.Nonce, &test.Key)\n\t\tif err == nil {\n\t\t\tt.Errorf(\"Decryption unexpectedly succeeded for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\t}\n\tt.Logf(\"Completed %v tests\", testCount)\n}\n"
  },
  {
    "path": "crypto/aead/chacha20poly1305/crypto_aead_chacha20poly1305.go",
    "content": "// Package chacha20poly1305 contains the libsodium bindings for ChaCha20-Poly1305.\npackage chacha20poly1305\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport \"github.com/GoKillers/libsodium-go/support\"\n\n// Sodium should always be initialised\nfunc init() {\n\tC.sodium_init()\n}\n\n// Sizes of nonces, key and mac.\nconst (\n\tKeyBytes   int = C.crypto_aead_chacha20poly1305_KEYBYTES  // Size of a secret key in bytes\n\tNSecBytes  int = C.crypto_aead_chacha20poly1305_NSECBYTES // Size of a secret nonce in bytes\n\tNonceBytes int = C.crypto_aead_chacha20poly1305_NPUBBYTES // Size of a nonce in bytes\n\tABytes     int = C.crypto_aead_chacha20poly1305_ABYTES    // Size of an authentication tag in bytes\n)\n\n// GenerateKey generates a secret key\nfunc GenerateKey() *[KeyBytes]byte {\n\tk := new([KeyBytes]byte)\n\tC.crypto_aead_chacha20poly1305_keygen((*C.uchar)(&k[0]))\n\treturn k\n}\n\n// Encrypt a message `m` with additional data `ad` using a nonce `npub` and a secret key `k`.\n// A ciphertext (including authentication tag) and encryption status are returned.\nfunc Encrypt(m, ad []byte, nonce *[NonceBytes]byte, k *[KeyBytes]byte) (c []byte) {\n\tsupport.NilPanic(k == nil, \"secret key\")\n\tsupport.NilPanic(nonce == nil, \"nonce\")\n\n\tc = make([]byte, len(m)+ABytes)\n\n\tC.crypto_aead_chacha20poly1305_encrypt(\n\t\t(*C.uchar)(support.BytePointer(c)),\n\t\t(*C.ulonglong)(nil),\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(&nonce[0]),\n\t\t(*C.uchar)(&k[0]))\n\n\treturn\n}\n\n// Decrypt and verify a ciphertext `c` using additional data `ad`, nonce `npub` and secret key `k`.\n// Returns the decrypted message and verification status.\nfunc Decrypt(c, ad []byte, nonce *[NonceBytes]byte, k *[KeyBytes]byte) (m []byte, err error) {\n\tsupport.NilPanic(k == nil, \"secret key\")\n\tsupport.NilPanic(nonce == nil, \"nonce\")\n\tsupport.CheckSizeMin(c, ABytes, \"ciphertext\")\n\n\tm = make([]byte, len(c)-ABytes)\n\n\texit := C.crypto_aead_chacha20poly1305_decrypt(\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(*C.ulonglong)(nil),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(&c[0]),\n\t\t(C.ulonglong)(len(c)),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(&nonce[0]),\n\t\t(*C.uchar)(&k[0]))\n\n\tif exit != 0 {\n\t\terr = &support.VerificationError{}\n\t}\n\n\treturn\n}\n\n// EncryptDetached encrypts a message `m` with additional data `ad` using\n// a nonce `npub` and a secret key `k`.\n// A ciphertext, authentication tag and encryption status are returned.\nfunc EncryptDetached(m, ad []byte, nonce *[NonceBytes]byte, k *[KeyBytes]byte) (c, mac []byte) {\n\tsupport.NilPanic(k == nil, \"secret key\")\n\tsupport.NilPanic(nonce == nil, \"nonce\")\n\n\tc = make([]byte, len(m))\n\tmac = make([]byte, ABytes)\n\n\tC.crypto_aead_chacha20poly1305_encrypt_detached(\n\t\t(*C.uchar)(support.BytePointer(c)),\n\t\t(*C.uchar)(&mac[0]),\n\t\t(*C.ulonglong)(nil),\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(&nonce[0]),\n\t\t(*C.uchar)(&k[0]))\n\n\treturn\n}\n\n// DecryptDetached decrypts and verifies a ciphertext `c` with authentication tag `mac`\n// using additional data `ad`, nonce `npub` and secret key `k`.\n// Returns the decrypted message and verification status.\nfunc DecryptDetached(c, mac, ad []byte, nonce *[NonceBytes]byte, k *[KeyBytes]byte) (m []byte, err error) {\n\tsupport.NilPanic(k == nil, \"secret key\")\n\tsupport.NilPanic(nonce == nil, \"nonce\")\n\tsupport.CheckSize(mac, ABytes, \"mac\")\n\n\tm = make([]byte, len(c))\n\n\texit := C.crypto_aead_chacha20poly1305_decrypt_detached(\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(support.BytePointer(c)),\n\t\t(C.ulonglong)(len(c)),\n\t\t(*C.uchar)(&mac[0]),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(&nonce[0]),\n\t\t(*C.uchar)(&k[0]))\n\n\tif exit != 0 {\n\t\terr = &support.VerificationError{}\n\t}\n\n\treturn\n}\n"
  },
  {
    "path": "crypto/aead/chacha20poly1305/crypto_aead_chacha20poly1305_test.go",
    "content": "package chacha20poly1305\n\nimport (\n\t\"bytes\"\n\t\"github.com/google/gofuzz\"\n\t\"testing\"\n)\n\nvar testCount = 100000\n\ntype TestData struct {\n\tMessage []byte\n\tAd      []byte\n\tKey     [KeyBytes]byte\n\tNonce   [NonceBytes]byte\n}\n\nfunc Test(t *testing.T) {\n\t// Test the key generation\n\tif *GenerateKey() == ([KeyBytes]byte{}) {\n\t\tt.Error(\"Generated key is zero\")\n\t}\n\n\t// Test the length of NSecBytes\n\tif NSecBytes != 0 {\n\t\tt.Errorf(\"NSecBytes is %v but should be %v\", NSecBytes, 0)\n\t}\n\n\t// Fuzzing\n\tf := fuzz.New()\n\n\t// Run tests\n\tfor i := 0; i < testCount; i++ {\n\t\tvar c, m, ec, mac []byte\n\t\tvar err error\n\t\tvar test TestData\n\n\t\t// Fuzz the test struct\n\t\tf.Fuzz(&test)\n\n\t\t// Detached encryption test\n\t\tc, mac = EncryptDetached(test.Message, test.Ad, &test.Nonce, &test.Key)\n\n\t\t// Encryption test\n\t\tec = Encrypt(test.Message, test.Ad, &test.Nonce, &test.Key)\n\t\tif !bytes.Equal(ec, append(c, mac...)) {\n\t\t\tt.Errorf(\"Encryption failed for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\n\t\t// Detached decryption test\n\t\tm, err = DecryptDetached(c, mac, test.Ad, &test.Nonce, &test.Key)\n\t\tif err != nil || !bytes.Equal(m, test.Message) {\n\t\t\tt.Errorf(\"Detached decryption failed for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\n\t\t// Decryption test\n\t\tm, err = Decrypt(ec, test.Ad, &test.Nonce, &test.Key)\n\t\tif err != nil || !bytes.Equal(m, test.Message) {\n\t\t\tt.Errorf(\"Decryption failed for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\n\t\t// Failed detached decryption test\n\t\tmac = make([]byte, ABytes)\n\t\tm, err = DecryptDetached(c, mac, test.Ad, &test.Nonce, &test.Key)\n\t\tif err == nil {\n\t\t\tt.Errorf(\"Detached decryption unexpectedly succeeded for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\n\t\t// Failed decryption test\n\t\tcopy(ec[len(m):], mac)\n\t\tm, err = Decrypt(ec, test.Ad, &test.Nonce, &test.Key)\n\t\tif err == nil {\n\t\t\tt.Errorf(\"Decryption unexpectedly succeeded for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\t}\n\tt.Logf(\"Completed %v tests\", testCount)\n}\n"
  },
  {
    "path": "crypto/aead/chacha20poly1305ietf/crypto_aead_chacha20poly1305_ietf.go",
    "content": "// Package chacha20poly1305ietf contains the libsodium bindings for the IETF variant of ChaCha20-Poly1305.\npackage chacha20poly1305ietf\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport \"github.com/GoKillers/libsodium-go/support\"\n\n// Sodium should always be initialised\nfunc init() {\n\tC.sodium_init()\n}\n\n// Sizes of nonces, key and mac.\nconst (\n\tKeyBytes   int = C.crypto_aead_chacha20poly1305_ietf_KEYBYTES  // Size of a secret key in bytes\n\tNSecBytes  int = C.crypto_aead_chacha20poly1305_ietf_NSECBYTES // Size of a secret nonce in bytes\n\tNonceBytes int = C.crypto_aead_chacha20poly1305_ietf_NPUBBYTES // Size of a nonce in bytes\n\tABytes     int = C.crypto_aead_chacha20poly1305_ietf_ABYTES    // Size of an authentication tag in bytes\n)\n\n// GenerateKey generates a secret key\nfunc GenerateKey() *[KeyBytes]byte {\n\tk := new([KeyBytes]byte)\n\tC.crypto_aead_chacha20poly1305_ietf_keygen((*C.uchar)(&k[0]))\n\treturn k\n}\n\n// Encrypt a message `m` with additional data `ad` using a nonce `npub` and a secret key `k`.\n// A ciphertext (including authentication tag) and encryption status are returned.\nfunc Encrypt(m, ad []byte, nonce *[NonceBytes]byte, k *[KeyBytes]byte) (c []byte) {\n\tsupport.NilPanic(k == nil, \"secret key\")\n\tsupport.NilPanic(nonce == nil, \"nonce\")\n\n\tc = make([]byte, len(m)+ABytes)\n\n\tC.crypto_aead_chacha20poly1305_ietf_encrypt(\n\t\t(*C.uchar)(support.BytePointer(c)),\n\t\t(*C.ulonglong)(nil),\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(&nonce[0]),\n\t\t(*C.uchar)(&k[0]))\n\n\treturn\n}\n\n// Decrypt and verify a ciphertext `c` using additional data `ad`, nonce `npub` and secret key `k`.\n// Returns the decrypted message and verification status.\nfunc Decrypt(c, ad []byte, nonce *[NonceBytes]byte, k *[KeyBytes]byte) (m []byte, err error) {\n\tsupport.NilPanic(k == nil, \"secret key\")\n\tsupport.NilPanic(nonce == nil, \"nonce\")\n\tsupport.CheckSizeMin(c, ABytes, \"ciphertext\")\n\n\tm = make([]byte, len(c)-ABytes)\n\n\texit := C.crypto_aead_chacha20poly1305_ietf_decrypt(\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(*C.ulonglong)(nil),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(&c[0]),\n\t\t(C.ulonglong)(len(c)),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(&nonce[0]),\n\t\t(*C.uchar)(&k[0]))\n\n\tif exit != 0 {\n\t\terr = &support.VerificationError{}\n\t}\n\n\treturn\n}\n\n// EncryptDetached encrypts a message `m` with additional data `ad` using\n// a nonce `npub` and a secret key `k`.\n// A ciphertext, authentication tag and encryption status are returned.\nfunc EncryptDetached(m, ad []byte, nonce *[NonceBytes]byte, k *[KeyBytes]byte) (c, mac []byte) {\n\tsupport.NilPanic(k == nil, \"secret key\")\n\tsupport.NilPanic(nonce == nil, \"nonce\")\n\n\tc = make([]byte, len(m))\n\tmac = make([]byte, ABytes)\n\n\tC.crypto_aead_chacha20poly1305_ietf_encrypt_detached(\n\t\t(*C.uchar)(support.BytePointer(c)),\n\t\t(*C.uchar)(&mac[0]),\n\t\t(*C.ulonglong)(nil),\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(&nonce[0]),\n\t\t(*C.uchar)(&k[0]))\n\n\treturn\n}\n\n// DecryptDetached decrypts and verifies a ciphertext `c` with authentication tag `mac`\n// using additional data `ad`, nonce `npub` and secret key `k`.\n// Returns the decrypted message and verification status.\nfunc DecryptDetached(c, mac, ad []byte, nonce *[NonceBytes]byte, k *[KeyBytes]byte) (m []byte, err error) {\n\tsupport.NilPanic(k == nil, \"secret key\")\n\tsupport.NilPanic(nonce == nil, \"nonce\")\n\tsupport.CheckSize(mac, ABytes, \"mac\")\n\n\tm = make([]byte, len(c))\n\n\texit := C.crypto_aead_chacha20poly1305_ietf_decrypt_detached(\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(support.BytePointer(c)),\n\t\t(C.ulonglong)(len(c)),\n\t\t(*C.uchar)(&mac[0]),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(&nonce[0]),\n\t\t(*C.uchar)(&k[0]))\n\n\tif exit != 0 {\n\t\terr = &support.VerificationError{}\n\t}\n\n\treturn\n}\n"
  },
  {
    "path": "crypto/aead/chacha20poly1305ietf/crypto_aead_chacha20poly1305_ietf_test.go",
    "content": "package chacha20poly1305ietf\n\nimport (\n\t\"bytes\"\n\t\"github.com/google/gofuzz\"\n\t\"testing\"\n)\n\nvar testCount = 100000\n\ntype TestData struct {\n\tMessage []byte\n\tAd      []byte\n\tKey     [KeyBytes]byte\n\tNonce   [NonceBytes]byte\n}\n\nfunc Test(t *testing.T) {\n\t// Test the key generation\n\tif *GenerateKey() == ([KeyBytes]byte{}) {\n\t\tt.Error(\"Generated key is zero\")\n\t}\n\n\t// Test the length of NSecBytes\n\tif NSecBytes != 0 {\n\t\tt.Errorf(\"NSecBytes is %v but should be %v\", NSecBytes, 0)\n\t}\n\n\t// Fuzzing\n\tf := fuzz.New()\n\n\t// Run tests\n\tfor i := 0; i < testCount; i++ {\n\t\tvar c, m, ec, mac []byte\n\t\tvar err error\n\t\tvar test TestData\n\n\t\t// Fuzz the test struct\n\t\tf.Fuzz(&test)\n\n\t\t// Detached encryption test\n\t\tc, mac = EncryptDetached(test.Message, test.Ad, &test.Nonce, &test.Key)\n\n\t\t// Encryption test\n\t\tec = Encrypt(test.Message, test.Ad, &test.Nonce, &test.Key)\n\t\tif !bytes.Equal(ec, append(c, mac...)) {\n\t\t\tt.Errorf(\"Encryption failed for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\n\t\t// Detached decryption test\n\t\tm, err = DecryptDetached(c, mac, test.Ad, &test.Nonce, &test.Key)\n\t\tif err != nil || !bytes.Equal(m, test.Message) {\n\t\t\tt.Errorf(\"Detached decryption failed for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\n\t\t// Decryption test\n\t\tm, err = Decrypt(ec, test.Ad, &test.Nonce, &test.Key)\n\t\tif err != nil || !bytes.Equal(m, test.Message) {\n\t\t\tt.Errorf(\"Decryption failed for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\n\t\t// Failed detached decryption test\n\t\tmac = make([]byte, ABytes)\n\t\tm, err = DecryptDetached(c, mac, test.Ad, &test.Nonce, &test.Key)\n\t\tif err == nil {\n\t\t\tt.Errorf(\"Detached decryption unexpectedly succeeded for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\n\t\t// Failed decryption test\n\t\tcopy(ec[len(m):], mac)\n\t\tm, err = Decrypt(ec, test.Ad, &test.Nonce, &test.Key)\n\t\tif err == nil {\n\t\t\tt.Errorf(\"Decryption unexpectedly succeeded for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\t}\n\tt.Logf(\"Completed %v tests\", testCount)\n}\n"
  },
  {
    "path": "crypto/aead/crypto_aead.go",
    "content": "// Package aead contains bindings for authenticated encryption with additional data.\npackage aead\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport \"crypto/cipher\"\n\n// Sodium should always be initialised\nfunc init() {\n\tC.sodium_init()\n}\n\n// AEAD is and extended version of cipher.AEAD\ntype AEAD interface {\n\tcipher.AEAD\n\n\t// SealDetached encrypts and authenticates plaintext, authenticates the\n\t// additional data and appends the result to dst, returning the updated\n\t// slice and the authentication code (mac) separately.\n\t// The nonce must be NonceSize() bytes long and unique for all time, for a given key.\n\t// The mac is Overhead() bytes long.\n\t//\n\t// The plaintext and dst may alias exactly or not at all. To reuse\n\t// plaintext's storage for the encrypted output, use plaintext[:0] as dst.\n\tSealDetached(dst, nonce, plaintext, additionalData []byte) ([]byte, []byte)\n\n\t// OpenDetached decrypts a ciphertext, authenticates the additional data using\n\t// the autentication code (mac) and, if successful, appends the resulting plaintext\n\t// to dst, returning the updated slice. The nonce must be NonceSize()\n\t// bytes long and both it and the additional data must match the\n\t// value passed to Seal.\n\t//\n\t// The ciphertext and dst may alias exactly or not at all. To reuse\n\t// ciphertext's storage for the decrypted output, use ciphertext[:0] as dst.\n\t//\n\t// Even if the function fails, the contents of dst, up to its capacity,\n\t// may be overwritten.\n\tOpenDetached(dst, nonce, ciphertext, mac, additionalData []byte) ([]byte, error)\n}\n\n// appendSlices appends a slice with a number of empty bytes and\n// returns the new slice and a slice pointing to the empty data.\nfunc appendSlices(in []byte, n int) ([]byte, []byte) {\n\tslice := append(in, make([]byte, n)...)\n\treturn slice, slice[len(in):]\n}\n"
  },
  {
    "path": "crypto/aead/crypto_aead_aes256gcm.go",
    "content": "package aead\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport (\n\t\"github.com/GoKillers/libsodium-go/crypto/aead/aes256gcm\"\n\t\"github.com/GoKillers/libsodium-go/support\"\n\t\"unsafe\"\n)\n\n// AES256GCM state struct\ntype AES256GCM struct {\n\t// Represents crypto_aead_aes256gcm_state, which must be 16 byte aligned.\n\t// This is not enforced by Go, so 16 extra bytes are allocated and\n\t// the 512 aligned bytes in them are used.\n\tstate1 [512 + 16]byte\n}\n\n// NewAES256GCM returns a AES256GCM cipher for an AES256 key.\nfunc NewAES256GCM(k *[aes256gcm.KeyBytes]byte) AEAD {\n\tsupport.NilPanic(k == nil, \"key\")\n\n\tctx := new(AES256GCM)\n\n\tC.crypto_aead_aes256gcm_beforenm(\n\t\tctx.state(),\n\t\t(*C.uchar)(&k[0]))\n\n\treturn ctx\n}\n\n// state returns a pointer to the space allocated for the state\nfunc (a *AES256GCM) state() *C.crypto_aead_aes256gcm_state {\n\tvar offset uintptr\n\tmod := uintptr(unsafe.Pointer(&a.state1)) % 16\n\n\tif mod == 0 {\n\t\toffset = mod\n\t} else {\n\t\toffset = 16 - mod\n\t}\n\n\treturn (*C.crypto_aead_aes256gcm_state)(unsafe.Pointer(&a.state1[offset]))\n}\n\n// NonceSize returns the size of the nonce for Seal() and Open()\nfunc (a *AES256GCM) NonceSize() int {\n\treturn aes256gcm.NonceBytes\n}\n\n// Overhead returns the size of the MAC overhead for Seal() and Open()\nfunc (a *AES256GCM) Overhead() int {\n\treturn aes256gcm.ABytes\n}\n\n// Seal encrypts plaintext using nonce and additional data and appends it to a destination.\n// See aead.AEAD for details.\nfunc (a *AES256GCM) Seal(dst, nonce, plaintext, additionalData []byte) (ret []byte) {\n\tsupport.CheckSize(nonce, a.NonceSize(), \"nonce\")\n\n\tret, c := appendSlices(dst, len(plaintext)+a.Overhead())\n\n\tC.crypto_aead_aes256gcm_encrypt_afternm(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.ulonglong)(nil),\n\t\t(*C.uchar)(support.BytePointer(plaintext)),\n\t\t(C.ulonglong)(len(plaintext)),\n\t\t(*C.uchar)(support.BytePointer(additionalData)),\n\t\t(C.ulonglong)(len(additionalData)),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(&nonce[0]),\n\t\ta.state())\n\n\treturn\n}\n\n// Open decrypts a ciphertext using a nonce and additional data and appends the result to a destination.\n// See aead.AEAD for details.\nfunc (a *AES256GCM) Open(dst, nonce, ciphertext, additionalData []byte) (ret []byte, err error) {\n\tsupport.CheckSize(nonce, a.NonceSize(), \"nonce\")\n\tsupport.CheckSizeMin(ciphertext, a.Overhead(), \"ciphertext\")\n\n\tret, m := appendSlices(dst, len(ciphertext)-a.Overhead())\n\n\texit := C.crypto_aead_aes256gcm_decrypt_afternm(\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(*C.ulonglong)(nil),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(&ciphertext[0]),\n\t\t(C.ulonglong)(len(ciphertext)),\n\t\t(*C.uchar)(support.BytePointer(additionalData)),\n\t\t(C.ulonglong)(len(additionalData)),\n\t\t(*C.uchar)(&nonce[0]),\n\t\ta.state())\n\n\tif exit != 0 {\n\t\terr = &support.VerificationError{}\n\t}\n\n\treturn\n}\n\n// SealDetached encrypts plaintext using nonce and additional data and appends it to a destination.\n// See aead.AEAD for details.\nfunc (a *AES256GCM) SealDetached(dst, nonce, plaintext, additionalData []byte) (ret, mac []byte) {\n\tsupport.CheckSize(nonce, a.NonceSize(), \"nonce\")\n\n\tret, c := appendSlices(dst, len(plaintext))\n\tmac = make([]byte, a.Overhead())\n\n\tC.crypto_aead_aes256gcm_encrypt_detached_afternm(\n\t\t(*C.uchar)(support.BytePointer(c)),\n\t\t(*C.uchar)(&mac[0]),\n\t\t(*C.ulonglong)(nil),\n\t\t(*C.uchar)(support.BytePointer(plaintext)),\n\t\t(C.ulonglong)(len(plaintext)),\n\t\t(*C.uchar)(support.BytePointer(additionalData)),\n\t\t(C.ulonglong)(len(additionalData)),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(&nonce[0]),\n\t\ta.state())\n\n\treturn\n}\n\n// OpenDetached decrypts a ciphertext using a nonce, mac and additional data and appends the result to a destination.\n// See aead.AEAD for details.\nfunc (a *AES256GCM) OpenDetached(dst, nonce, ciphertext, mac, additionalData []byte) (ret []byte, err error) {\n\tsupport.CheckSize(nonce, a.NonceSize(), \"nonce\")\n\tsupport.CheckSize(mac, a.Overhead(), \"mac\")\n\n\tret, m := appendSlices(dst, len(ciphertext))\n\n\texit := C.crypto_aead_aes256gcm_decrypt_detached_afternm(\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(support.BytePointer(ciphertext)),\n\t\t(C.ulonglong)(len(ciphertext)),\n\t\t(*C.uchar)(&mac[0]),\n\t\t(*C.uchar)(support.BytePointer(additionalData)),\n\t\t(C.ulonglong)(len(additionalData)),\n\t\t(*C.uchar)(&nonce[0]),\n\t\ta.state())\n\n\tif exit != 0 {\n\t\terr = &support.VerificationError{}\n\t}\n\n\treturn\n}\n"
  },
  {
    "path": "crypto/aead/crypto_aead_aes256gcm_test.go",
    "content": "package aead\n\nimport (\n\t\"bytes\"\n\t\"github.com/GoKillers/libsodium-go/crypto/aead/aes256gcm\"\n\t\"github.com/google/gofuzz\"\n\t\"testing\"\n)\n\nvar testCount = 100000\n\ntype TestData struct {\n\tMessage []byte\n\tAd      []byte\n\tDst     []byte\n\tKey     [aes256gcm.KeyBytes]byte\n\tNonce   [aes256gcm.NonceBytes]byte\n}\n\nfunc Test(t *testing.T) {\n\t// Skip the test if unsupported on this platform\n\tif !aes256gcm.IsAvailable() {\n\t\tt.Skip(\"The CPU does not support this implementation of AES256GCM.\")\n\t}\n\n\t// Fuzzing\n\tf := fuzz.New()\n\n\t// Run tests\n\tfor i := 0; i < testCount; i++ {\n\t\tvar c, m, ec, mac []byte\n\t\tvar err error\n\t\tvar test TestData\n\n\t\t// Fuzz the test struct\n\t\tf.Fuzz(&test)\n\n\t\t// Create a key context\n\t\tctx := NewAES256GCM(&test.Key)\n\n\t\t// Detached encryption test\n\t\tc, mac = ctx.SealDetached(test.Dst, test.Nonce[:], test.Message, test.Ad)\n\n\t\t// Check if dst was prepended\n\t\tif !bytes.Equal(c[:len(test.Dst)], test.Dst) {\n\t\t\tt.Error(\"dst was not prepended\")\n\t\t\tt.FailNow()\n\t\t}\n\n\t\t// Encryption test\n\t\tec = ctx.Seal(test.Dst, test.Nonce[:], test.Message, test.Ad)\n\t\tif !bytes.Equal(ec, append(c, mac...)) {\n\t\t\tt.Errorf(\"Encryption failed for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\n\t\t// Detached decryption test\n\t\tm, err = ctx.OpenDetached(test.Dst, test.Nonce[:], c[len(test.Dst):], mac, test.Ad)\n\t\tif err != nil || !bytes.Equal(m[len(test.Dst):], test.Message) {\n\t\t\tt.Errorf(\"Detached decryption failed for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\n\t\t// Check if dst was prepended\n\t\tif !bytes.Equal(m[:len(test.Dst)], test.Dst) {\n\t\t\tt.Error(\"dst was not prepended\")\n\t\t\tt.FailNow()\n\t\t}\n\n\t\t// Decryption test\n\t\tm, err = ctx.Open(test.Dst, test.Nonce[:], ec[len(test.Dst):], test.Ad)\n\t\tif err != nil || !bytes.Equal(m[len(test.Dst):], test.Message) {\n\t\t\tt.Errorf(\"Decryption failed for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\n\t\t// Failed detached decryption test\n\t\tmac = make([]byte, ctx.Overhead())\n\t\tm, err = ctx.OpenDetached(test.Dst, test.Nonce[:], c[len(test.Dst):], mac, test.Ad)\n\t\tif err == nil {\n\t\t\tt.Errorf(\"Detached decryption unexpectedly succeeded for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\n\t\t// Failed decryption test\n\t\tcopy(ec[len(test.Dst)+len(m):], mac)\n\t\tm, err = ctx.Open(test.Dst, test.Nonce[:], ec[len(test.Dst):], test.Ad)\n\t\tif err == nil {\n\t\t\tt.Errorf(\"Decryption unexpectedly succeeded for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\t}\n\n\tt.Logf(\"Completed %v tests\", testCount)\n}\n"
  },
  {
    "path": "crypto/aead/xchacha20poly1305ietf/crypto_aead_xchacha20poly1305_ietf.go",
    "content": "// Package xchacha20poly1305ietf contains the libsodium bindings for the IETF variant of XChaCha20-Poly1305.\npackage xchacha20poly1305ietf\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport \"github.com/GoKillers/libsodium-go/support\"\n\n// Sodium should always be initialised\nfunc init() {\n\tC.sodium_init()\n}\n\n// Sizes of nonces, key and mac.\nconst (\n\tKeyBytes   int = C.crypto_aead_xchacha20poly1305_ietf_KEYBYTES  // Size of a secret key in bytes\n\tNSecBytes  int = C.crypto_aead_xchacha20poly1305_ietf_NSECBYTES // Size of a secret nonce in bytes\n\tNonceBytes int = C.crypto_aead_xchacha20poly1305_ietf_NPUBBYTES // Size of a nonce in bytes\n\tABytes     int = C.crypto_aead_xchacha20poly1305_ietf_ABYTES    // Size of an authentication tag in bytes\n)\n\n// GenerateKey generates a secret key\nfunc GenerateKey() *[KeyBytes]byte {\n\tk := new([KeyBytes]byte)\n\tC.crypto_aead_xchacha20poly1305_ietf_keygen((*C.uchar)(&k[0]))\n\treturn k\n}\n\n// Encrypt a message `m` with additional data `ad` using a nonce `npub` and a secret key `k`.\n// A ciphertext (including authentication tag) and encryption status are returned.\nfunc Encrypt(m, ad []byte, nonce *[NonceBytes]byte, k *[KeyBytes]byte) (c []byte) {\n\tsupport.NilPanic(k == nil, \"secret key\")\n\tsupport.NilPanic(nonce == nil, \"nonce\")\n\n\tc = make([]byte, len(m)+ABytes)\n\n\tC.crypto_aead_xchacha20poly1305_ietf_encrypt(\n\t\t(*C.uchar)(support.BytePointer(c)),\n\t\t(*C.ulonglong)(nil),\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(&nonce[0]),\n\t\t(*C.uchar)(&k[0]))\n\n\treturn\n}\n\n// Decrypt and verify a ciphertext `c` using additional data `ad`, nonce `npub` and secret key `k`.\n// Returns the decrypted message and verification status.\nfunc Decrypt(c, ad []byte, nonce *[NonceBytes]byte, k *[KeyBytes]byte) (m []byte, err error) {\n\tsupport.NilPanic(k == nil, \"secret key\")\n\tsupport.NilPanic(nonce == nil, \"nonce\")\n\tsupport.CheckSizeMin(c, ABytes, \"ciphertext\")\n\n\tm = make([]byte, len(c)-ABytes)\n\n\texit := C.crypto_aead_xchacha20poly1305_ietf_decrypt(\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(*C.ulonglong)(nil),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(&c[0]),\n\t\t(C.ulonglong)(len(c)),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(&nonce[0]),\n\t\t(*C.uchar)(&k[0]))\n\n\tif exit != 0 {\n\t\terr = &support.VerificationError{}\n\t}\n\n\treturn\n}\n\n// EncryptDetached encrypts a message `m` with additional data `ad` using\n// a nonce `npub` and a secret key `k`.\n// A ciphertext, authentication tag and encryption status are returned.\nfunc EncryptDetached(m, ad []byte, nonce *[NonceBytes]byte, k *[KeyBytes]byte) (c, mac []byte) {\n\tsupport.NilPanic(k == nil, \"secret key\")\n\tsupport.NilPanic(nonce == nil, \"nonce\")\n\n\tc = make([]byte, len(m))\n\tmac = make([]byte, ABytes)\n\n\tC.crypto_aead_xchacha20poly1305_ietf_encrypt_detached(\n\t\t(*C.uchar)(support.BytePointer(c)),\n\t\t(*C.uchar)(&mac[0]),\n\t\t(*C.ulonglong)(nil),\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(&nonce[0]),\n\t\t(*C.uchar)(&k[0]))\n\n\treturn\n}\n\n// DecryptDetached decrypts and verifies a ciphertext `c` with authentication tag `mac`\n// using additional data `ad`, nonce `npub` and secret key `k`.\n// Returns the decrypted message and verification status.\nfunc DecryptDetached(c, mac, ad []byte, nonce *[NonceBytes]byte, k *[KeyBytes]byte) (m []byte, err error) {\n\tsupport.NilPanic(k == nil, \"secret key\")\n\tsupport.NilPanic(nonce == nil, \"nonce\")\n\tsupport.CheckSize(mac, ABytes, \"mac\")\n\n\tm = make([]byte, len(c))\n\n\texit := C.crypto_aead_xchacha20poly1305_ietf_decrypt_detached(\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(support.BytePointer(c)),\n\t\t(C.ulonglong)(len(c)),\n\t\t(*C.uchar)(&mac[0]),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(&nonce[0]),\n\t\t(*C.uchar)(&k[0]))\n\n\tif exit != 0 {\n\t\terr = &support.VerificationError{}\n\t}\n\n\treturn\n}\n"
  },
  {
    "path": "crypto/aead/xchacha20poly1305ietf/crypto_aead_xchacha20poly1305_ietf_test.go",
    "content": "package xchacha20poly1305ietf\n\nimport (\n\t\"bytes\"\n\t\"github.com/google/gofuzz\"\n\t\"testing\"\n)\n\nvar testCount = 100000\n\ntype TestData struct {\n\tMessage []byte\n\tAd      []byte\n\tKey     [KeyBytes]byte\n\tNonce   [NonceBytes]byte\n}\n\nfunc Test(t *testing.T) {\n\t// Test the key generation\n\tif *GenerateKey() == ([KeyBytes]byte{}) {\n\t\tt.Error(\"Generated key is zero\")\n\t}\n\n\t// Test the length of NSecBytes\n\tif NSecBytes != 0 {\n\t\tt.Errorf(\"NSecBytes is %v but should be %v\", NSecBytes, 0)\n\t}\n\n\t// Fuzzing\n\tf := fuzz.New()\n\n\t// Run tests\n\tfor i := 0; i < testCount; i++ {\n\t\tvar c, m, ec, mac []byte\n\t\tvar err error\n\t\tvar test TestData\n\n\t\t// Fuzz the test struct\n\t\tf.Fuzz(&test)\n\n\t\t// Detached encryption test\n\t\tc, mac = EncryptDetached(test.Message, test.Ad, &test.Nonce, &test.Key)\n\n\t\t// Encryption test\n\t\tec = Encrypt(test.Message, test.Ad, &test.Nonce, &test.Key)\n\t\tif !bytes.Equal(ec, append(c, mac...)) {\n\t\t\tt.Errorf(\"Encryption failed for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\n\t\t// Detached decryption test\n\t\tm, err = DecryptDetached(c, mac, test.Ad, &test.Nonce, &test.Key)\n\t\tif err != nil || !bytes.Equal(m, test.Message) {\n\t\t\tt.Errorf(\"Detached decryption failed for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\n\t\t// Decryption test\n\t\tm, err = Decrypt(ec, test.Ad, &test.Nonce, &test.Key)\n\t\tif err != nil || !bytes.Equal(m, test.Message) {\n\t\t\tt.Errorf(\"Decryption failed for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\n\t\t// Failed detached decryption test\n\t\tmac = make([]byte, ABytes)\n\t\tm, err = DecryptDetached(c, mac, test.Ad, &test.Nonce, &test.Key)\n\t\tif err == nil {\n\t\t\tt.Errorf(\"Detached decryption unexpectedly succeeded for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\n\t\t// Failed decryption test\n\t\tcopy(ec[len(m):], mac)\n\t\tm, err = Decrypt(ec, test.Ad, &test.Nonce, &test.Key)\n\t\tif err == nil {\n\t\t\tt.Errorf(\"Decryption unexpectedly succeeded for %+v\", test)\n\t\t\tt.FailNow()\n\t\t}\n\t}\n\tt.Logf(\"Completed %v tests\", testCount)\n}\n"
  },
  {
    "path": "cryptoaead/crypto_aead_aes256gcm.go",
    "content": "package cryptoaead\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport (\n\t\"github.com/GoKillers/libsodium-go/support\"\n\t\"unsafe\"\n)\n\nfunc CryptoAEADAES256GCMIsAvailable() bool {\n\tC.sodium_init()\n\treturn int(C.crypto_aead_aes256gcm_is_available()) != 0\n}\n\nfunc CryptoAEADAES256GCMKeyBytes() int {\n\treturn int(C.crypto_aead_aes256gcm_keybytes())\n}\n\nfunc CryptoAEADAES256GCMNSecBytes() int {\n\treturn int(C.crypto_aead_aes256gcm_nsecbytes())\n}\n\nfunc CryptoAEADAES256GCMNPubBytes() int {\n\treturn int(C.crypto_aead_aes256gcm_npubbytes())\n}\n\nfunc CryptoAEADAES256GCMABytes() int {\n\treturn int(C.crypto_aead_aes256gcm_abytes())\n}\n\nfunc CryptoAEADAES256GCMStateBytes() int {\n\treturn int(C.crypto_aead_aes256gcm_statebytes())\n}\n\nfunc CryptoAEADAES256GCMEncrypt(m, ad, npub, k []byte) ([]byte, int) {\n\tsupport.CheckSize(k, CryptoAEADAES256GCMKeyBytes(), \"secret key\")\n\tsupport.CheckSize(npub, CryptoAEADAES256GCMNPubBytes(), \"public nonce\")\n\n\tc := make([]byte, len(m)+CryptoAEADAES256GCMABytes())\n\tcLen := C.ulonglong(len(c))\n\n\texit := int(C.crypto_aead_aes256gcm_encrypt(\n\t\t(*C.uchar)(support.BytePointer(c)),\n\t\t(*C.ulonglong)(&cLen),\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(&npub[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoAEADAES256GCMDecrypt(c, ad, npub, k []byte) ([]byte, int) {\n\tsupport.CheckSize(k, CryptoAEADAES256GCMKeyBytes(), \"secret key\")\n\tsupport.CheckSize(npub, CryptoAEADAES256GCMNPubBytes(), \"public nonce\")\n\tsupport.CheckSizeMin(c, CryptoAEADAES256GCMABytes(), \"ciphertext\")\n\n\tm := make([]byte, len(c)-CryptoAEADAES256GCMABytes())\n\tmLen := (C.ulonglong)(len(m))\n\n\texit := int(C.crypto_aead_aes256gcm_decrypt(\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(*C.ulonglong)(&mLen),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(&c[0]),\n\t\t(C.ulonglong)(len(c)),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(&npub[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn m, exit\n}\n\nfunc CryptoAEADAES256GCMEncryptDetached(m, ad, npub, k []byte) ([]byte, []byte, int) {\n\tsupport.CheckSize(k, CryptoAEADAES256GCMKeyBytes(), \"secret key\")\n\tsupport.CheckSize(npub, CryptoAEADAES256GCMNPubBytes(), \"public nonce\")\n\n\tc := make([]byte, len(m))\n\tmac := make([]byte , CryptoAEADAES256GCMABytes())\n\tmacLen := C.ulonglong(len(c))\n\n\texit := int(C.crypto_aead_aes256gcm_encrypt_detached(\n\t\t(*C.uchar)(support.BytePointer(c)),\n\t\t(*C.uchar)(&mac[0]),\n\t\t(*C.ulonglong)(&macLen),\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(&npub[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, mac, exit\n}\n\nfunc CryptoAEADAES256GCMDecryptDetached(c, mac, ad, npub, k []byte) ([]byte, int) {\n\tsupport.CheckSize(k, CryptoAEADAES256GCMKeyBytes(), \"secret key\")\n\tsupport.CheckSize(npub, CryptoAEADAES256GCMNPubBytes(), \"public nonce\")\n\tsupport.CheckSize(mac, CryptoAEADAES256GCMABytes(), \"mac\")\n\n\tm := make([]byte, len(c))\n\n\texit := int(C.crypto_aead_aes256gcm_decrypt_detached(\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(support.BytePointer(c)),\n\t\t(C.ulonglong)(len(c)),\n\t\t(*C.uchar)(&mac[0]),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(&npub[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn m, exit\n}\n\nfunc CryptoAEADAES256GCMBeforeNM(k []byte) ([]byte, int) {\n\tsupport.CheckSize(k, CryptoAEADAES256GCMKeyBytes(), \"secret key\")\n\n\tctx := support.AlignedSlice(CryptoAEADAES256GCMStateBytes(), 16)\n\n\texit := int(C.crypto_aead_aes256gcm_beforenm(\n\t\t(*C.crypto_aead_aes256gcm_state)(unsafe.Pointer(&ctx[0])),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn ctx, exit\n}\n\nfunc CryptoAEADAES256GCMEncryptAfterNM(m, ad, npub, ctx []byte) ([]byte, int) {\n\tsupport.CheckSize(ctx, CryptoAEADAES256GCMStateBytes(), \"context\")\n\tsupport.CheckSize(npub, CryptoAEADAES256GCMNPubBytes(), \"public nonce\")\n\n\tc := make([]byte, len(m)+CryptoAEADAES256GCMABytes())\n\tcLen := C.ulonglong(len(c))\n\n\texit := int(C.crypto_aead_aes256gcm_encrypt_afternm(\n\t\t(*C.uchar)(support.BytePointer(c)),\n\t\t(*C.ulonglong)(&cLen),\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(&npub[0]),\n\t\t(*[512]C.uchar)(unsafe.Pointer(&ctx[0]))))\n\n\treturn c, exit\n}\n\nfunc CryptoAEADAES256GCMDecryptAfterNM(c, ad, npub, ctx []byte) ([]byte, int) {\n\tsupport.CheckSize(ctx, CryptoAEADAES256GCMStateBytes(), \"context\")\n\tsupport.CheckSize(npub, CryptoAEADAES256GCMNPubBytes(), \"public nonce\")\n\tsupport.CheckSizeMin(c, CryptoAEADAES256GCMABytes(), \"ciphertext\")\n\n\tm := make([]byte, len(c)-CryptoAEADAES256GCMABytes())\n\tmLen := (C.ulonglong)(len(m))\n\n\texit := int(C.crypto_aead_aes256gcm_decrypt_afternm(\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(*C.ulonglong)(&mLen),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(&c[0]),\n\t\t(C.ulonglong)(len(c)),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(&npub[0]),\n\t\t(*[512]C.uchar)(unsafe.Pointer(&ctx[0]))))\n\n\treturn m, exit\n}\n\nfunc CryptoAEADAES256GCMEncryptDetachedAfterNM(m, ad, npub, ctx []byte) ([]byte, []byte, int) {\n\tsupport.CheckSize(ctx, CryptoAEADAES256GCMStateBytes(), \"context\")\n\tsupport.CheckSize(npub, CryptoAEADAES256GCMNPubBytes(), \"public nonce\")\n\n\tc := make([]byte, len(m))\n\tmac := make([]byte , CryptoAEADAES256GCMABytes())\n\tmacLen := C.ulonglong(len(c))\n\n\texit := int(C.crypto_aead_aes256gcm_encrypt_detached_afternm(\n\t\t(*C.uchar)(support.BytePointer(c)),\n\t\t(*C.uchar)(&mac[0]),\n\t\t(*C.ulonglong)(&macLen),\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(&npub[0]),\n\t\t(*[512]C.uchar)(unsafe.Pointer(&ctx[0]))))\n\n\treturn c, mac, exit\n}\n\nfunc CryptoAEADAES256GCMDecryptDetachedAfterNM(c, mac, ad, npub, ctx []byte) ([]byte, int) {\n\tsupport.CheckSize(ctx, CryptoAEADAES256GCMStateBytes(), \"context\")\n\tsupport.CheckSize(npub, CryptoAEADAES256GCMNPubBytes(), \"public nonce\")\n\tsupport.CheckSize(mac, CryptoAEADAES256GCMABytes(), \"mac\")\n\n\tm := make([]byte, len(c))\n\n\texit := int(C.crypto_aead_aes256gcm_decrypt_detached_afternm(\n\t\t(*C.uchar)(support.BytePointer(m)),\n\t\t(*C.uchar)(nil),\n\t\t(*C.uchar)(support.BytePointer(c)),\n\t\t(C.ulonglong)(len(c)),\n\t\t(*C.uchar)(&mac[0]),\n\t\t(*C.uchar)(support.BytePointer(ad)),\n\t\t(C.ulonglong)(len(ad)),\n\t\t(*C.uchar)(&npub[0]),\n\t\t(*[512]C.uchar)(unsafe.Pointer(&ctx[0]))))\n\n\treturn m, exit\n}\n\nfunc CryptoAEADAES256GCMKeyGen() []byte {\n\tk := make([]byte, CryptoAEADAES256GCMKeyBytes())\n\tC.crypto_aead_aes256gcm_keygen((*C.uchar)(&k[0]))\n\treturn k\n}\n"
  },
  {
    "path": "cryptoaead/crypto_aead_aes256gcm_test.go",
    "content": "package cryptoaead\n\nimport (\n\t\"testing\"\n\t\"bytes\"\n\t\"github.com/google/gofuzz\"\n)\n\nvar testCount = 100000\n\ntype Test struct {\n\tMessage    []byte\n\tAd         []byte\n\tKey        [32]byte\n\tNonce      [12]byte\n\tCiphertext []byte\n\tMac        []byte\n}\n\nfunc TestCryptoAEADAES256GCM(t *testing.T) {\n\t// Skip the test if unsupported on this platform\n\tif !CryptoAEADAES256GCMIsAvailable() {\n\t\tt.Skip(\"The CPU does not support this implementation of AES256GCM.\")\n\t}\n\n\t// Test the key generation\n\tif len(CryptoAEADAES256GCMKeyGen()) != CryptoAEADAES256GCMKeyBytes() {\n\t\tt.Error(\"Generated key has the wrong length\")\n\t}\n\n\t// Test the length of NSecBytes\n\tif CryptoAEADAES256GCMNSecBytes() != 0 {\n\t\tt.Errorf(\"CryptoAEADAES256GCMNSecBytes is %v but should be %v\", CryptoAEADAES256GCMNSecBytes(), 0)\n\t}\n\n\t// Fuzzing\n\tf := fuzz.New()\n\n\t// Run tests\n\tfor i := 0; i < testCount; i++ {\n\t\tvar c, m, ec, mac []byte\n\t\tvar err int\n\t\tvar test Test\n\n\t\t// Fuzz the test struct\n\t\tf.Fuzz(&test)\n\n\t\t// Create a key context\n\t\tctx, err := CryptoAEADAES256GCMBeforeNM(test.Key[:])\n\t\tif err != 0 {\n\t\t\tt.Error(\"Context creation failed for %+v\", test)\n\t\t}\n\n\t\t// Detached encryption test\n\t\ttest.Ciphertext, test.Mac, err = CryptoAEADAES256GCMEncryptDetached(test.Message, test.Ad, test.Nonce[:], test.Key[:])\n\t\tif err != 0 {\n\t\t\tt.Errorf(\"Detached encryption failed for %+v\", test)\n\t\t}\n\n\t\t// Detached encryption with context\n\t\tc, mac, err = CryptoAEADAES256GCMEncryptDetachedAfterNM(test.Message, test.Ad, test.Nonce[:], ctx)\n\t\tif err != 0 || !bytes.Equal(c, test.Ciphertext) || !bytes.Equal(mac, test.Mac) {\n\t\t\tt.Errorf(\"Detached encryption with context failed for %+v\", test)\n\t\t}\n\n\t\t// Encryption test\n\t\tec, err = CryptoAEADAES256GCMEncrypt(test.Message, test.Ad, test.Nonce[:], test.Key[:])\n\t\tif err != 0 || !bytes.Equal(ec, append(test.Ciphertext, test.Mac...)) {\n\t\t\tt.Errorf(\"Encryption failed for %+v\", test)\n\t\t}\n\n\t\t// Encryption with context\n\t\tec, err = CryptoAEADAES256GCMEncryptAfterNM(test.Message, test.Ad, test.Nonce[:], ctx)\n\t\tif err != 0 || !bytes.Equal(ec, append(test.Ciphertext, test.Mac...)) {\n\t\t\tt.Errorf(\"Encryption with context failed for %+v\", test)\n\t\t}\n\n\t\t// Detached decryption test\n\t\tm, err = CryptoAEADAES256GCMDecryptDetached(c, mac, test.Ad, test.Nonce[:], test.Key[:])\n\t\tif err != 0 || !bytes.Equal(m, test.Message) {\n\t\t\tt.Errorf(\"Detached decryption failed for %+v\", test)\n\t\t}\n\n\t\t// Detached decryption with context test\n\t\tm, err = CryptoAEADAES256GCMDecryptDetachedAfterNM(c, mac, test.Ad, test.Nonce[:], ctx)\n\t\tif err != 0 || !bytes.Equal(m, test.Message) {\n\t\t\tt.Errorf(\"Detached decryption with context failed for %+v\", test)\n\t\t}\n\n\t\t// Decryption test\n\t\tm, err = CryptoAEADAES256GCMDecrypt(ec, test.Ad, test.Nonce[:], test.Key[:])\n\t\tif err != 0 || !bytes.Equal(m, test.Message) {\n\t\t\tt.Errorf(\"Decryption failed for %+v\", test)\n\t\t}\n\n\t\t// Decryption with context test\n\t\tm, err = CryptoAEADAES256GCMDecryptAfterNM(ec, test.Ad, test.Nonce[:], ctx)\n\t\tif err != 0 || !bytes.Equal(m, test.Message) {\n\t\t\tt.Errorf(\"Decryption with context failed for %+v\", test)\n\t\t}\n\t}\n\tt.Logf(\"Completed %v tests\", testCount)\n}\n"
  },
  {
    "path": "cryptoauth/crypto_auth.go",
    "content": "package cryptoauth\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport \"github.com/GoKillers/libsodium-go/support\"\n\nfunc CryptoAuthBytes() int {\n\treturn int(C.crypto_auth_bytes())\n}\n\nfunc CryptoAuthKeyBytes() int {\n\treturn int(C.crypto_auth_keybytes())\n}\n\nfunc CryptoAuthPrimitive() string {\n\treturn C.GoString(C.crypto_auth_primitive())\n}\n\nfunc CryptoAuth(in []byte, key []byte) ([]byte, int) {\n\tsupport.CheckSize(key, CryptoAuthKeyBytes(), \"key\")\n\tinlen := len(in)\n\tout := make([]byte, inlen + CryptoAuthBytes())\n\n\texit := int(C.crypto_auth(\n\t\t(*C.uchar)(&out[0]),\n\t\t(*C.uchar)(&in[0]),\n\t\t(C.ulonglong)(inlen),\n\t\t(*C.uchar)(&key[0])))\n\n\t\treturn out, exit\n}\n\nfunc CryptoAuthVerify(hmac []byte, in []byte, key []byte) int {\n\tsupport.CheckSize(key, CryptoAuthKeyBytes(), \"key\")\n\tinlen := len(in)\n\n\texit := int(C.crypto_auth_verify(\n\t\t(*C.uchar)(&hmac[0]),\n\t\t(*C.uchar)(&in[0]),\n\t\t(C.ulonglong)(inlen),\n\t\t(*C.uchar)(&key[0])))\n\n\t\treturn exit\n}\n"
  },
  {
    "path": "cryptoauth/hmacsha256/authHMAC256Api.go",
    "content": "package authhmac256api\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\n\nfunc CryptoAuthHMAC256Bytes() int {\n\treturn int(C.crypto_auth_hmacsha256_bytes())\n}\n\nfunc CryptoAuthHMAC256BKeyBytes() int {\n\treturn int(C.crypto_auth_hmacsha256_keybytes())\n}\n\nfunc CryptoAuthHMAC256StateBytes() int {\n\treturn int(C.crypto_auth_hmacsha256_statebytes())\n}\n"
  },
  {
    "path": "cryptoauth/hmacsha512/authHMAC512Api.go",
    "content": "package authhmac512api\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\n\nfunc CryptoAuthHMAC512Bytes() int {\n\treturn int(C.crypto_auth_hmacsha512_bytes())\n}\n\nfunc CryptoAuthHMAC512BKeyBytes() int {\n\treturn int(C.crypto_auth_hmacsha512_keybytes())\n}\n\nfunc CryptoAuthHMAC512StateBytes() int {\n\treturn int(C.crypto_auth_hmacsha512_statebytes())\n}\n"
  },
  {
    "path": "cryptoauth/hmacsha512/cp/hmacHMACSHA512.go",
    "content": "package hmachmacsha512\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\n\nfunc CryptoAuthHMACSHA512Init(state *C.struct_crypto_auth_hmacsha512_state, key []byte, keylen int) (*C.struct_crypto_auth_hmacsha512_state, int) {\n\texit := int(C.crypto_auth_hmacsha512_init(\n\t\t(state),\n\t\t(*C.uchar)(&key[0]),\n\t\t(C.size_t)(keylen)))\n\n\treturn state, exit\n\n}\n"
  },
  {
    "path": "cryptobox/crypto_box.go",
    "content": "package cryptobox\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport \"github.com/GoKillers/libsodium-go/support\"\n\nfunc CryptoBoxSeedBytes() int {\n\treturn int(C.crypto_box_seedbytes())\n}\n\nfunc CryptoBoxPublicKeyBytes() int {\n\treturn int(C.crypto_box_publickeybytes())\n}\n\nfunc CryptoBoxSecretKeyBytes() int {\n\treturn int(C.crypto_box_secretkeybytes())\n}\n\nfunc CryptoBoxNonceBytes() int {\n\treturn int(C.crypto_box_noncebytes())\n}\n\nfunc CryptoBoxMacBytes() int {\n\treturn int(C.crypto_box_macbytes())\n}\n\nfunc CryptoBoxPrimitive() string {\n\treturn C.GoString(C.crypto_box_primitive())\n}\n\nfunc CryptoBoxBeforeNmBytes() int {\n\treturn int(C.crypto_box_beforenmbytes())\n}\n\nfunc CryptoBoxZeroBytes() int {\n\treturn int(C.crypto_box_zerobytes())\n}\n\nfunc CryptoBoxBoxZeroBytes() int {\n\treturn int(C.crypto_box_boxzerobytes())\n}\n\nfunc CryptoBoxSeedKeyPair(seed []byte) ([]byte, []byte, int) {\n\tsupport.CheckSize(seed, CryptoBoxSeedBytes(), \"seed\")\n\tsk := make([]byte, CryptoBoxSecretKeyBytes())\n\tpk := make([]byte, CryptoBoxPublicKeyBytes())\n\texit := int(C.crypto_box_seed_keypair(\n\t\t(*C.uchar)(&pk[0]),\n\t\t(*C.uchar)(&sk[0]),\n\t\t(*C.uchar)(&seed[0])))\n\n\treturn sk, pk, exit\n}\n\nfunc CryptoBoxKeyPair() ([]byte, []byte, int) {\n\tsk := make([]byte, CryptoBoxSecretKeyBytes())\n\tpk := make([]byte, CryptoBoxPublicKeyBytes())\n\texit := int(C.crypto_box_keypair(\n\t\t(*C.uchar)(&pk[0]),\n\t\t(*C.uchar)(&sk[0])))\n\n\treturn sk, pk, exit\n}\n\nfunc CryptoBoxBeforeNm(pk []byte, sk []byte) ([]byte, int) {\n\tsupport.CheckSize(pk, CryptoBoxPublicKeyBytes(), \"public key\")\n\tsupport.CheckSize(sk, CryptoBoxSecretKeyBytes(), \"sender's secret key\")\n\tk := make([]byte, CryptoBoxBeforeNmBytes())\n\texit := int(C.crypto_box_beforenm(\n\t\t(*C.uchar)(&k[0]),\n\t\t(*C.uchar)(&pk[0]),\n\t\t(*C.uchar)(&sk[0])))\n\n\treturn k, exit\n}\n\nfunc CryptoBox(m []byte, n []byte, pk []byte, sk []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoBoxNonceBytes(), \"nonce\")\n\tsupport.CheckSize(pk, CryptoBoxPublicKeyBytes(), \"public key\")\n\tsupport.CheckSize(sk, CryptoBoxSecretKeyBytes(), \"sender's secret key\")\n\tc := make([]byte, len(m))\n\texit := int(C.crypto_box(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&pk[0]),\n\t\t(*C.uchar)(&sk[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoBoxOpen(c []byte, n []byte, pk []byte, sk []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoBoxNonceBytes(), \"nonce\")\n\tsupport.CheckSize(pk, CryptoBoxPublicKeyBytes(), \"public key\")\n\tsupport.CheckSize(sk, CryptoBoxPublicKeyBytes(), \"secret key\")\n\tm := make([]byte, len(c))\n\texit := int(C.crypto_box_open(\n\t\t(*C.uchar)(&m[0]),\n\t\t(*C.uchar)(&c[0]),\n\t\t(C.ulonglong)(len(c)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&pk[0]),\n\t\t(*C.uchar)(&sk[0])))\n\n\treturn m, exit\n}\n\nfunc CryptoBoxAfterNm(m []byte, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoBoxNonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoBoxBeforeNmBytes(), \"shared secret key\")\n\tc := make([]byte, len(m))\n\texit := int(C.crypto_box_afternm(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoBoxOpenAfterNm(c []byte, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoBoxNonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoBoxBeforeNmBytes(), \"shared secret key\")\n\tm := make([]byte, len(c))\n\texit := int(C.crypto_box_open_afternm(\n\t\t(*C.uchar)(&m[0]),\n\t\t(*C.uchar)(&c[0]),\n\t\t(C.ulonglong)(len(c)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn m, exit\n}\n"
  },
  {
    "path": "cryptobox/crypto_box_easy.go",
    "content": "package cryptobox\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport \"github.com/GoKillers/libsodium-go/support\"\n\nfunc CryptoBoxDetachedAfterNm(mac []byte, m []byte, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(mac, CryptoBoxMacBytes(), \"mac\")\n\tsupport.CheckSize(n, CryptoBoxNonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoBoxBeforeNmBytes(), \"shared secret key\")\n\tc := make([]byte, len(m)+CryptoBoxMacBytes())\n\texit := int(C.crypto_box_detached_afternm(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&mac[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoBoxDetached(mac []byte, m []byte, n []byte, pk []byte, sk []byte) ([]byte, int) {\n\tsupport.CheckSize(mac, CryptoBoxMacBytes(), \"mac\")\n\tsupport.CheckSize(n, CryptoBoxNonceBytes(), \"nonce\")\n\tsupport.CheckSize(pk, CryptoBoxPublicKeyBytes(), \"public key\")\n\tsupport.CheckSize(sk, CryptoBoxSecretKeyBytes(), \"sender's secret key\")\n\tc := make([]byte, len(m)+CryptoBoxMacBytes())\n\texit := int(C.crypto_box_detached(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&mac[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&pk[0]),\n\t\t(*C.uchar)(&sk[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoBoxEasyAfterNm(m []byte, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoBoxNonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoBoxBeforeNmBytes(), \"shared secret key\")\n\tc := make([]byte, len(m)+CryptoBoxMacBytes())\n\texit := int(C.crypto_box_easy_afternm(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoBoxEasy(m []byte, n []byte, pk []byte, sk []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoBoxNonceBytes(), \"nonce\")\n\tsupport.CheckSize(pk, CryptoBoxPublicKeyBytes(), \"public key\")\n\tsupport.CheckSize(sk, CryptoBoxSecretKeyBytes(), \"secret key\")\n\tc := make([]byte, len(m)+CryptoBoxMacBytes())\n\texit := int(C.crypto_box_easy(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&pk[0]),\n\t\t(*C.uchar)(&sk[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoBoxOpenDetachedAfterNm(c []byte, mac []byte, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(mac, CryptoBoxMacBytes(), \"mac\")\n\tsupport.CheckSize(n, CryptoBoxNonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoBoxBeforeNmBytes(), \"shared secret key\")\n\tm := make([]byte, len(c)-CryptoBoxMacBytes())\n\texit := int(C.crypto_box_open_detached_afternm(\n\t\t(*C.uchar)(&m[0]),\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&mac[0]),\n\t\t(C.ulonglong)(len(c)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn m, exit\n}\n\nfunc CryptoBoxOpenDetached(c []byte, mac []byte, n []byte, pk []byte, sk []byte) ([]byte, int) {\n\tsupport.CheckSize(mac, CryptoBoxMacBytes(), \"mac\")\n\tsupport.CheckSize(n, CryptoBoxNonceBytes(), \"nonce\")\n\tsupport.CheckSize(pk, CryptoBoxPublicKeyBytes(), \"public key\")\n\tsupport.CheckSize(sk, CryptoBoxSecretKeyBytes(), \"secret key\")\n\tm := make([]byte, len(c)-CryptoBoxMacBytes())\n\texit := int(C.crypto_box_open_detached(\n\t\t(*C.uchar)(&m[0]),\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&mac[0]),\n\t\t(C.ulonglong)(len(c)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&pk[0]),\n\t\t(*C.uchar)(&sk[0])))\n\n\treturn m, exit\n}\n\nfunc CryptoBoxOpenEasyAfterNm(c []byte, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoBoxNonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoBoxBeforeNmBytes(), \"shared secret key\")\n\tm := make([]byte, len(c)-CryptoBoxMacBytes())\n\texit := int(C.crypto_box_open_easy_afternm(\n\t\t(*C.uchar)(&m[0]),\n\t\t(*C.uchar)(&c[0]),\n\t\t(C.ulonglong)(len(c)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn m, exit\n}\n\nfunc CryptoBoxOpenEasy(c []byte, n []byte, pk []byte, sk []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoBoxNonceBytes(), \"nonce\")\n\tsupport.CheckSize(pk, CryptoBoxPublicKeyBytes(), \"public key\")\n\tsupport.CheckSize(sk, CryptoBoxSecretKeyBytes(), \"secret key\")\n\tm := make([]byte, len(c)-CryptoBoxMacBytes())\n\texit := int(C.crypto_box_open_easy(\n\t\t(*C.uchar)(&m[0]),\n\t\t(*C.uchar)(&c[0]),\n\t\t(C.ulonglong)(len(c)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&pk[0]),\n\t\t(*C.uchar)(&sk[0])))\n\n\treturn m, exit\n}\n"
  },
  {
    "path": "cryptobox/crypto_box_seal.go",
    "content": "package cryptobox\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport \"github.com/GoKillers/libsodium-go/support\"\n\nfunc CryptoBoxSeal(m []byte, pk []byte) ([]byte, int) {\n\tsupport.CheckSize(pk, CryptoBoxPublicKeyBytes(), \"public key\")\n\tc := make([]byte, len(m)+CryptoBoxSealBytes())\n\texit := int(C.crypto_box_seal(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&pk[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoBoxSealOpen(c []byte, pk []byte, sk []byte) ([]byte, int) {\n\tsupport.CheckSize(pk, CryptoBoxPublicKeyBytes(), \"public key\")\n\tsupport.CheckSize(sk, CryptoBoxSecretKeyBytes(), \"secret key\")\n\tm := make([]byte, len(c)-CryptoBoxSealBytes())\n\texit := int(C.crypto_box_seal_open(\n\t\t(*C.uchar)(&m[0]),\n\t\t(*C.uchar)(&c[0]),\n\t\t(C.ulonglong)(len(c)),\n\t\t(*C.uchar)(&pk[0]),\n\t\t(*C.uchar)(&sk[0])))\n\n\treturn m, exit\n}\n\nfunc CryptoBoxSealBytes() int {\n\treturn int(C.crypto_box_sealbytes())\n}\n"
  },
  {
    "path": "cryptobox/crypto_box_seal_test.go",
    "content": "package cryptobox\n\nimport \"testing\"\n\nfunc TestCryptoBoxSeal(t *testing.T) {\n\tsk, pk, exit := CryptoBoxKeyPair()\n\tif exit != 0 {\n\t\tt.Fatalf(\"CryptoBoxKeyPair failed: %v\", exit)\n\t}\n\ttestStr := \"test string 12345678901234567890123456789012345678901234567890\"\n\tcipherText, exit := CryptoBoxSeal([]byte(testStr), pk)\n\tif exit != 0 {\n\t\tt.Fatalf(\"CryptoBoxSeal failed: %v\", exit)\n\t}\n\tplaintext, exit := CryptoBoxSealOpen(cipherText, pk, sk)\n\tif exit != 0 {\n\t\tt.Fatalf(\"CryptoBoxSealOpen failed: %v\", exit)\n\t}\n\tif string(plaintext) != testStr {\n\t\tt.Fatalf(\"Bad plaintext: %#v\", plaintext)\n\t}\n}\n"
  },
  {
    "path": "cryptogenerichash/crypto_generichash.go",
    "content": "package generichash\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport (\n\t\"github.com/GoKillers/libsodium-go/support\"\n\t\"unsafe\"\n)\n\nfunc CryptoGenericHashBytesMin() int {\n\treturn int(C.crypto_generichash_bytes_min())\n}\n\nfunc CryptoGenericHashBytesMax() int {\n\treturn int(C.crypto_generichash_bytes_max())\n}\n\nfunc CryptoGenericHashBytes() int {\n\treturn int(C.crypto_generichash_bytes())\n}\n\nfunc CryptoGenericHashKeyBytesMin() int {\n\treturn int(C.crypto_generichash_keybytes_min())\n}\n\nfunc CryptoGenericHashKeyBytesMax() int {\n\treturn int(C.crypto_generichash_keybytes_max())\n}\n\nfunc CryptoGenericHashKeyBytes() int {\n\treturn int(C.crypto_generichash_keybytes())\n}\n\nfunc CryptoGenericHashPrimitive() string {\n\treturn C.GoString(C.crypto_generichash_primitive())\n}\n\nfunc CryptoGenericHashStateBytes() int {\n\treturn int(C.crypto_generichash_statebytes())\n}\n\n// I took care of the typedef confusions. This should work okay.\nfunc CryptoGenericHash(outlen int, in []byte, key []byte) ([]byte, int) {\n\tsupport.CheckIntInRange(outlen, CryptoGenericHashBytesMin(), CryptoGenericHashBytesMax(), \"out\")\n\n\t// Check size of key only if actually given\n\tif len(key) > 0 {\n\t\tsupport.CheckSizeInRange(key, CryptoGenericHashKeyBytesMin(), CryptoGenericHashKeyBytesMax(), \"key\")\n\t}\n\n\tout := make([]byte, outlen)\n\texit := int(C.crypto_generichash(\n\t\t(*C.uchar)(&out[0]),\n\t\t(C.size_t)(outlen),\n\t\t(*C.uchar)(support.BytePointer(in)),\n\t\t(C.ulonglong)(len(in)),\n\t\t(*C.uchar)(support.BytePointer(key)),\n\t\t(C.size_t)(len(key))))\n\n\treturn out, exit\n}\n\n// I took care of the typedef confusions. This should work okay.\nfunc CryptoGenericHashInit(key []byte, outlen int) (*C.struct_crypto_generichash_blake2b_state, int) {\n\tsupport.CheckIntInRange(outlen, CryptoGenericHashBytesMin(), CryptoGenericHashBytesMax(), \"out\")\n\n\t// Check size of key only if actually given\n\tif len(key) > 0 {\n\t\tsupport.CheckSizeInRange(key, CryptoGenericHashKeyBytesMin(), CryptoGenericHashKeyBytesMax(), \"key\")\n\t}\n\n\tstate := (*C.struct_crypto_generichash_blake2b_state)(\n\t\tunsafe.Pointer(&support.AlignedSlice(CryptoGenericHashStateBytes(), 64)[0]))\n\n\texit := int(C.crypto_generichash_init(\n\t\tstate,\n\t\t(*C.uchar)(support.BytePointer(key)),\n\t\t(C.size_t)(len(key)),\n\t\t(C.size_t)(outlen)))\n\n\treturn state, exit\n}\n\n// I took care of the typedef confusions. This should work okay.\nfunc CryptoGenericHashUpdate(state *C.struct_crypto_generichash_blake2b_state, in []byte) (*C.struct_crypto_generichash_blake2b_state, int) {\n\texit := int(C.crypto_generichash_update(\n\t\tstate,\n\t\t(*C.uchar)(support.BytePointer(in)),\n\t\t(C.ulonglong)(len(in))))\n\n\treturn state, exit\n}\n\nfunc CryptoGenericHashFinal(state *C.struct_crypto_generichash_blake2b_state, outlen int) (*C.struct_crypto_generichash_blake2b_state, []byte, int) {\n\tsupport.CheckIntInRange(outlen, CryptoGenericHashBytesMin(), CryptoGenericHashBytesMax(), \"out\")\n\tout := make([]byte, outlen)\n\texit := int(C.crypto_generichash_final(\n\t\tstate,\n\t\t(*C.uchar)(&out[0]),\n\t\t(C.size_t)(outlen)))\n\n\treturn state, out, exit\n}\n"
  },
  {
    "path": "cryptohash/crypto_hash.go",
    "content": "package cryptohash\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\n\nfunc CryptoHashBytes() int {\n\treturn int(C.crypto_hash_bytes())\n}\n\nfunc CryptoHashPrimitive() string {\n\treturn C.GoString(C.crypto_hash_primitive())\n}\n\nfunc CryptoHash(in []byte) ([]byte, int) {\n\tout := make([]byte, CryptoHashBytes())\n\texit := int(C.crypto_hash(\n\t\t(*C.uchar)(&out[0]),\n\t\t(*C.uchar)(&in[0]),\n\t\t(C.ulonglong)(len(in))))\n\n\treturn out, exit\n}\n"
  },
  {
    "path": "cryptokdf/crypto_kdf.go",
    "content": "package cryptokdf\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport \"github.com/GoKillers/libsodium-go/support\"\n\nfunc CryptoKdfKeybytes() int {\n\treturn int(C.crypto_kdf_keybytes())\n}\n\nfunc CryptoKdfContextbytes() int {\n\treturn int(C.crypto_kdf_contextbytes())\n}\n\nfunc CryptoKdfBytesMin() int {\n\treturn int(C.crypto_kdf_bytes_min())\n}\n\nfunc CryptoKdfBytesMax() int {\n\treturn int(C.crypto_kdf_bytes_max())\n}\n\nfunc CryptoKdfKeygen() []byte {\n\tk := make([]byte, CryptoKdfKeybytes())\n\tC.crypto_kdf_keygen((*C.uchar)(&k[0]))\n\treturn k\n}\n\nfunc CryptoKdfDeriveFromKey(l int, i uint64, c string, k []byte) ([]byte, int) {\n\tsupport.CheckSize(k, CryptoKdfKeybytes(), \"keybytes\")\n\tsupport.CheckSize([]byte(c), CryptoKdfContextbytes(), \"contextbytes\")\n\tsupport.CheckIntInRange(l, CryptoKdfBytesMin(), CryptoKdfBytesMax(), \"subkey_len\")\n\tout := make([]byte, l)\n\n\texit := int(C.crypto_kdf_derive_from_key(\n\t\t(*C.uchar)(&out[0]),\n\t\t(C.size_t)(l),\n\t\t(C.uint64_t)(i),\n\t\tC.CString(c),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn out, exit\n}\n"
  },
  {
    "path": "cryptosecretbox/crypto_secretbox.go",
    "content": "package secretbox\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport \"github.com/GoKillers/libsodium-go/support\"\n\nfunc CryptoSecretBoxKeyBytes() int {\n\treturn int(C.crypto_secretbox_keybytes())\n}\n\nfunc CryptoSecretBoxNonceBytes() int {\n\treturn int(C.crypto_secretbox_noncebytes())\n}\n\nfunc CryptoSecretBoxZeroBytes() int {\n\treturn int(C.crypto_secretbox_zerobytes())\n}\n\nfunc CryptoSecretBoxBoxZeroBytes() int {\n\treturn int(C.crypto_secretbox_boxzerobytes())\n}\n\nfunc CryptoSecretBoxMacBytes() int {\n\treturn int(C.crypto_secretbox_macbytes())\n}\n\nfunc CryptoSecretBoxPrimitive() string {\n\treturn C.GoString(C.crypto_secretbox_primitive())\n}\n\nfunc CryptoSecretBox(m []byte, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoSecretBoxNonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoSecretBoxKeyBytes(), \"key\")\n\tc := make([]byte, len(m)+CryptoSecretBoxMacBytes())\n\texit := int(C.crypto_secretbox(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoSecretBoxOpen(c []byte, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoSecretBoxNonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoSecretBoxKeyBytes(), \"key\")\n\tm := make([]byte, len(c)-CryptoSecretBoxMacBytes())\n\texit := int(C.crypto_secretbox_open(\n\t\t(*C.uchar)(&m[0]),\n\t\t(*C.uchar)(&c[0]),\n\t\t(C.ulonglong)(len(c)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn m, exit\n}\n"
  },
  {
    "path": "cryptosecretbox/crypto_secretbox_easy.go",
    "content": "package secretbox\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport \"github.com/GoKillers/libsodium-go/support\"\n\nfunc CryptoSecretBoxDetached(m []byte, n []byte, k []byte) ([]byte, []byte, int) {\n\tsupport.CheckSize(n, CryptoSecretBoxNonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoSecretBoxKeyBytes(), \"key\")\n\tc := make([]byte, len(m))\n\tmac := make([]byte, CryptoSecretBoxMacBytes())\n\texit := int(C.crypto_secretbox_detached(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&mac[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, mac, exit\n}\n\nfunc CryptoSecretBoxOpenDetached(c []byte, mac []byte, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(mac, CryptoSecretBoxMacBytes(), \"mac\")\n\tsupport.CheckSize(n, CryptoSecretBoxNonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoSecretBoxKeyBytes(), \"key\")\n\tm := make([]byte, len(c))\n\texit := int(C.crypto_secretbox_open_detached(\n\t\t(*C.uchar)(&m[0]),\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&mac[0]),\n\t\t(C.ulonglong)(len(c)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn m, exit\n}\n\nfunc CryptoSecretBoxEasy(m []byte, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoSecretBoxNonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoSecretBoxKeyBytes(), \"key\")\n\tc := make([]byte, len(m)+CryptoSecretBoxMacBytes())\n\texit := int(C.crypto_secretbox_easy(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoSecretBoxOpenEasy(c []byte, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoSecretBoxNonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoSecretBoxKeyBytes(), \"key\")\n\tm := make([]byte, len(c)-CryptoSecretBoxMacBytes())\n\texit := int(C.crypto_secretbox_open_easy(\n\t\t(*C.uchar)(&m[0]),\n\t\t(*C.uchar)(&c[0]),\n\t\t(C.ulonglong)(len(c)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn m, exit\n}\n"
  },
  {
    "path": "cryptosign/crypto_sign.go",
    "content": "package cryptosign\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport \"github.com/GoKillers/libsodium-go/cryptobox\"\nimport \"github.com/GoKillers/libsodium-go/support\"\n\nfunc CryptoSignBytes() int {\n\treturn int(C.crypto_sign_bytes())\n}\n\nfunc CryptoSignSeedBytes() int {\n\treturn int(C.crypto_sign_seedbytes())\n}\n\nfunc CryptoSignPublicKeyBytes() int {\n\treturn int(C.crypto_sign_publickeybytes())\n}\n\nfunc CryptoSignSecretKeyBytes() int {\n\treturn int(C.crypto_sign_secretkeybytes())\n}\n\nfunc CryptoSignPrimitive() string {\n\treturn C.GoString(C.crypto_sign_primitive())\n}\n\nfunc CryptoSignSeedKeyPair(seed []byte) ([]byte, []byte, int) {\n\tsupport.CheckSize(seed, CryptoSignSeedBytes(), \"seed\")\n\tsk := make([]byte, CryptoSignSecretKeyBytes())\n\tpk := make([]byte, CryptoSignPublicKeyBytes())\n\texit := int(C.crypto_sign_seed_keypair(\n\t\t(*C.uchar)(&pk[0]),\n\t\t(*C.uchar)(&sk[0]),\n\t\t(*C.uchar)(&seed[0])))\n\n\treturn sk, pk, exit\n}\n\nfunc CryptoSignKeyPair() ([]byte, []byte, int) {\n\tsk := make([]byte, CryptoSignSecretKeyBytes())\n\tpk := make([]byte, CryptoSignPublicKeyBytes())\n\texit := int(C.crypto_sign_keypair(\n\t\t(*C.uchar)(&pk[0]),\n\t\t(*C.uchar)(&sk[0])))\n\n\treturn sk, pk, exit\n}\n\nfunc CryptoSign(m []byte, sk []byte) ([]byte, int) {\n\tsupport.CheckSize(sk, CryptoSignSecretKeyBytes(), \"secret key\")\n\tsm := make([]byte, len(m)+CryptoSignBytes())\n\tvar actualSmSize C.ulonglong\n\n\texit := int(C.crypto_sign(\n\t\t(*C.uchar)(&sm[0]),\n\t\t(&actualSmSize),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&sk[0])))\n\n\treturn sm[:actualSmSize], exit\n}\n\nfunc CryptoSignOpen(sm []byte, pk []byte) ([]byte, int) {\n\tsupport.CheckSize(pk, CryptoSignPublicKeyBytes(), \"public key\")\n\tm := make([]byte, len(sm)-CryptoSignBytes())\n\tvar actualMSize C.ulonglong\n\n\texit := int(C.crypto_sign_open(\n\t\t(*C.uchar)(&m[0]),\n\t\t(&actualMSize),\n\t\t(*C.uchar)(&sm[0]),\n\t\t(C.ulonglong)(len(sm)),\n\t\t(*C.uchar)(&pk[0])))\n\n\treturn m[:actualMSize], exit\n}\n\nfunc CryptoSignDetached(m []byte, sk []byte) ([]byte, int) {\n\tsupport.CheckSize(sk, CryptoSignSecretKeyBytes(), \"secret key\")\n\tsig := make([]byte, CryptoSignBytes())\n\tvar actualSigSize C.ulonglong\n\n\texit := int(C.crypto_sign_detached(\n\t\t(*C.uchar)(&sig[0]),\n\t\t(&actualSigSize),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&sk[0])))\n\n\treturn sig[:actualSigSize], exit\n}\n\nfunc CryptoSignVerifyDetached(sig []byte, m []byte, pk []byte) int {\n\tsupport.CheckSize(sig, CryptoSignBytes(), \"signature\")\n\tsupport.CheckSize(pk, CryptoSignPublicKeyBytes(), \"public key\")\n\n\treturn int(C.crypto_sign_verify_detached(\n\t\t(*C.uchar)(&sig[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&pk[0])))\n}\n\nfunc CryptoSignEd25519PkToCurve25519(pkEd25519 []byte) ([]byte, int) {\n\tsupport.CheckSize(pkEd25519, CryptoSignPublicKeyBytes(), \"public key\")\n\tpkCurve25519 := make([]byte, cryptobox.CryptoBoxPublicKeyBytes())\n\n\texit := int(C.crypto_sign_ed25519_pk_to_curve25519(\n\t\t(*C.uchar)(&pkCurve25519[0]),\n\t\t(*C.uchar)(&pkEd25519[0])))\n\n\treturn pkCurve25519, exit\n}\n\nfunc CryptoSignEd25519SkToCurve25519(skEd25519 []byte) ([]byte, int) {\n\tsupport.CheckSize(skEd25519, CryptoSignSecretKeyBytes(), \"secret key\")\n\tskCurve25519 := make([]byte, cryptobox.CryptoBoxSecretKeyBytes())\n\n\texit := int(C.crypto_sign_ed25519_sk_to_curve25519(\n\t\t(*C.uchar)(&skCurve25519[0]),\n\t\t(*C.uchar)(&skEd25519[0])))\n\n\treturn skCurve25519, exit\n}\n"
  },
  {
    "path": "cryptostream/crypto_stream.go",
    "content": "package cryptostream\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport \"github.com/GoKillers/libsodium-go/support\"\n\nfunc CryptoStreamKeyBytes() int {\n\treturn int(C.crypto_stream_keybytes())\n}\n\nfunc  CryptoStreamNonceBytes() int {\n\treturn int(C.crypto_stream_noncebytes())\n}\n\nfunc CryptoStreamPrimitive() string {\n\treturn C.GoString(C.crypto_stream_primitive())\n}\n\nfunc CryptoStream(clen int, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoStreamNonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoStreamKeyBytes(), \"key\")\n\treturn CryptoStreamXSalsa20(clen, n, k)\n}\n\nfunc CryptoStreamXOR(m []byte, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoStreamNonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoStreamKeyBytes(), \"key\")\n\treturn CryptoStreamXSalsa20XOR(m, n, k)\n}\n"
  },
  {
    "path": "cryptostream/crypto_stream_chacha20.go",
    "content": "package cryptostream\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport \"github.com/GoKillers/libsodium-go/support\"\n\nfunc CryptoStreamChaCha20KeyBytes() int {\n\treturn int(C.crypto_stream_chacha20_keybytes())\n}\n\nfunc CryptoStreamChaCha20NonceBytes() int {\n\treturn int(C.crypto_stream_chacha20_noncebytes())\n}\n\nfunc CryptoStreamChaCha20(clen int, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoStreamChaCha20NonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoStreamChaCha20KeyBytes(), \"key\")\n\tc := make([]byte, clen)\n\texit := int(C.crypto_stream_chacha20(\n\t\t(*C.uchar)(&c[0]),\n\t\t(C.ulonglong)(clen),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoStreamChaCha20XOR(m []byte, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoStreamChaCha20NonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoStreamChaCha20KeyBytes(), \"key\")\n\tc := make([]byte, len(m))\n\texit := int(C.crypto_stream_chacha20_xor(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoStreamChaCha20XORIC(m []byte, n []byte, ic uint64, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoStreamChaCha20NonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoStreamChaCha20KeyBytes(), \"key\")\n\n\tc := make([]byte, len(m))\n\texit := int(C.crypto_stream_chacha20_xor_ic(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(C.uint64_t)(ic),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoStreamChaCha20Keygen() []byte {\n\tc := make([]byte, CryptoStreamChaCha20KeyBytes())\n\tC.crypto_stream_chacha20_keygen((*C.uchar)(&c[0]))\n\treturn c\n}\n\nfunc CryptoStreamChaCha20IETFKeyBytes() int {\n\treturn int(C.crypto_stream_chacha20_ietf_keybytes())\n}\n\nfunc CryptoStreamChaCha20IETFNonceBytes() int {\n\treturn int(C.crypto_stream_chacha20_ietf_noncebytes())\n}\n\nfunc CryptoStreamChaCha20IETF(clen int, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoStreamChaCha20IETFNonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoStreamChaCha20IETFKeyBytes(), \"key\")\n\tc := make([]byte, clen)\n\texit := int(C.crypto_stream_chacha20_ietf(\n\t\t(*C.uchar)(&c[0]),\n\t\t(C.ulonglong)(clen),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoStreamChaCha20IETFXOR(m []byte, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoStreamChaCha20IETFNonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoStreamChaCha20IETFKeyBytes(), \"key\")\n\tc := make([]byte, len(m))\n\texit := int(C.crypto_stream_chacha20_ietf_xor(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoStreamChaCha20IETFXORIC(m []byte, n []byte, ic uint32, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoStreamChaCha20IETFNonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoStreamChaCha20IETFKeyBytes(), \"key\")\n\n\tc := make([]byte, len(m))\n\texit := int(C.crypto_stream_chacha20_ietf_xor_ic(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(C.uint32_t)(ic),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoStreamChaCha20IETFKeygen() []byte {\n\tc := make([]byte, CryptoStreamChaCha20IETFKeyBytes())\n\tC.crypto_stream_chacha20_ietf_keygen((*C.uchar)(&c[0]))\n\treturn c\n}\n"
  },
  {
    "path": "cryptostream/crypto_stream_salsa20.go",
    "content": "package cryptostream\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport \"github.com/GoKillers/libsodium-go/support\"\n\nfunc CryptoStreamSalsa20KeyBytes() int {\n\treturn int(C.crypto_stream_salsa20_keybytes())\n}\n\nfunc CryptoStreamSalsa20NonceBytes() int {\n\treturn int(C.crypto_stream_salsa20_noncebytes())\n}\n\nfunc CryptoStreamSalsa20(clen int, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoStreamSalsa20NonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoStreamSalsa20KeyBytes(), \"key\")\n\tc := make([]byte, clen)\n\texit := int(C.crypto_stream_salsa20(\n\t\t(*C.uchar)(&c[0]),\n\t\t(C.ulonglong)(clen),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoStreamSalsa20XOR(m []byte, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoStreamSalsa20NonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoStreamSalsa20KeyBytes(), \"key\")\n\tc := make([]byte, len(m))\n\texit := int(C.crypto_stream_salsa20_xor(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoStreamSalsa20XORIC(m []byte, n []byte, ic uint64, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoStreamSalsa20NonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoStreamSalsa20KeyBytes(), \"key\")\n\n\tc := make([]byte, len(m))\n\texit := int(C.crypto_stream_salsa20_xor_ic(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(C.uint64_t)(ic),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoStreamSalsa20Keygen() []byte {\n\tc := make([]byte, CryptoStreamSalsa20KeyBytes())\n\tC.crypto_stream_salsa20_keygen((*C.uchar)(&c[0]))\n\treturn c\n}\n"
  },
  {
    "path": "cryptostream/crypto_stream_salsa2012.go",
    "content": "package cryptostream\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport \"github.com/GoKillers/libsodium-go/support\"\n\nfunc CryptoStreamSalsa2012KeyBytes() int {\n\treturn int(C.crypto_stream_salsa2012_keybytes())\n}\n\nfunc CryptoStreamSalsa2012NonceBytes() int {\n\treturn int(C.crypto_stream_salsa2012_noncebytes())\n}\n\nfunc CryptoStreamSalsa2012(clen int, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoStreamSalsa2012NonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoStreamSalsa2012KeyBytes(), \"key\")\n\tc := make([]byte, clen)\n\texit := int(C.crypto_stream_salsa2012(\n\t\t(*C.uchar)(&c[0]),\n\t\t(C.ulonglong)(clen),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoStreamSalsa2012XOR(m []byte, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoStreamSalsa2012NonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoStreamSalsa2012KeyBytes(), \"key\")\n\tc := make([]byte, len(m))\n\texit := int(C.crypto_stream_salsa2012_xor(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoStreamSalsa2012Keygen() []byte {\n\tc := make([]byte, CryptoStreamSalsa2012KeyBytes())\n\tC.crypto_stream_salsa2012_keygen((*C.uchar)(&c[0]))\n\treturn c\n}\n"
  },
  {
    "path": "cryptostream/crypto_stream_salsa208.go",
    "content": "package cryptostream\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport \"github.com/GoKillers/libsodium-go/support\"\n\nfunc CryptoStreamSalsa208KeyBytes() int {\n\treturn int(C.crypto_stream_salsa208_keybytes())\n}\n\nfunc CryptoStreamSalsa208NonceBytes() int {\n\treturn int(C.crypto_stream_salsa208_noncebytes())\n}\n\nfunc CryptoStreamSalsa208(clen int, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoStreamSalsa208NonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoStreamSalsa208KeyBytes(), \"key\")\n\tc := make([]byte, clen)\n\texit := int(C.crypto_stream_salsa208(\n\t\t(*C.uchar)(&c[0]),\n\t\t(C.ulonglong)(clen),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoStreamSalsa208XOR(m []byte, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoStreamSalsa208NonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoStreamSalsa208KeyBytes(), \"key\")\n\tc := make([]byte, len(m))\n\texit := int(C.crypto_stream_salsa208_xor(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoStreamSalsa208Keygen() []byte {\n\tc := make([]byte, CryptoStreamSalsa208KeyBytes())\n\tC.crypto_stream_salsa208_keygen((*C.uchar)(&c[0]))\n\treturn c\n}\n"
  },
  {
    "path": "cryptostream/crypto_stream_xchacha20.go",
    "content": "package cryptostream\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport \"github.com/GoKillers/libsodium-go/support\"\n\nfunc CryptoStreamXChaCha20KeyBytes() int {\n\treturn int(C.crypto_stream_xchacha20_keybytes())\n}\n\nfunc CryptoStreamXChaCha20NonceBytes() int {\n\treturn int(C.crypto_stream_xchacha20_noncebytes())\n}\n\nfunc CryptoStreamXChaCha20(clen int, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoStreamXChaCha20NonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoStreamXChaCha20KeyBytes(), \"key\")\n\tc := make([]byte, clen)\n\texit := int(C.crypto_stream_xchacha20(\n\t\t(*C.uchar)(&c[0]),\n\t\t(C.ulonglong)(clen),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoStreamXChaCha20XOR(m []byte, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoStreamXChaCha20NonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoStreamXChaCha20KeyBytes(), \"key\")\n\tc := make([]byte, len(m))\n\texit := int(C.crypto_stream_xchacha20_xor(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoStreamXChaCha20XORIC(m []byte, n []byte, ic uint64, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoStreamXChaCha20NonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoStreamXChaCha20KeyBytes(), \"key\")\n\n\tc := make([]byte, len(m))\n\texit := int(C.crypto_stream_xchacha20_xor_ic(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(C.uint64_t)(ic),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoStreamXChaCha20Keygen() []byte {\n\tc := make([]byte, CryptoStreamXChaCha20KeyBytes())\n\tC.crypto_stream_xchacha20_keygen((*C.uchar)(&c[0]))\n\treturn c\n}\n"
  },
  {
    "path": "cryptostream/crypto_stream_xsalsa20.go",
    "content": "package cryptostream\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport \"github.com/GoKillers/libsodium-go/support\"\n\nfunc CryptoStreamXSalsa20KeyBytes() int {\n\treturn int(C.crypto_stream_xsalsa20_keybytes())\n}\n\nfunc CryptoStreamXSalsa20NonceBytes() int {\n\treturn int(C.crypto_stream_xsalsa20_noncebytes())\n}\n\nfunc CryptoStreamXSalsa20(clen int, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoStreamXSalsa20NonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoStreamXSalsa20KeyBytes(), \"key\")\n\tc := make([]byte, clen)\n\texit := int(C.crypto_stream_xsalsa20(\n\t\t(*C.uchar)(&c[0]),\n\t\t(C.ulonglong)(clen),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoStreamXSalsa20XOR(m []byte, n []byte, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoStreamXSalsa20NonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoStreamXSalsa20KeyBytes(), \"key\")\n\tc := make([]byte, len(m))\n\texit := int(C.crypto_stream_xsalsa20_xor(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoStreamXSalsa20XORIC(m []byte, n []byte, ic uint64, k []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoStreamXSalsa20NonceBytes(), \"nonce\")\n\tsupport.CheckSize(k, CryptoStreamXSalsa20KeyBytes(), \"key\")\n\n\tc := make([]byte, len(m))\n\texit := int(C.crypto_stream_xsalsa20_xor_ic(\n\t\t(*C.uchar)(&c[0]),\n\t\t(*C.uchar)(&m[0]),\n\t\t(C.ulonglong)(len(m)),\n\t\t(*C.uchar)(&n[0]),\n\t\t(C.uint64_t)(ic),\n\t\t(*C.uchar)(&k[0])))\n\n\treturn c, exit\n}\n\nfunc CryptoStreamXSalsa20Keygen() []byte {\n\tc := make([]byte, CryptoStreamXSalsa20KeyBytes())\n\tC.crypto_stream_xsalsa20_keygen((*C.uchar)(&c[0]))\n\treturn c\n}\n"
  },
  {
    "path": "randombytes/randombytes.go",
    "content": "package randombytes\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport \"github.com/GoKillers/libsodium-go/support\"\nimport \"unsafe\"\n\n// RandomBytesSeedBytes returns the number of bytes required\n// for seeding RandomBytesBufDeterministic.\nfunc RandomBytesSeedBytes() int {\n\treturn int(C.randombytes_seedbytes())\n}\n\n// RandomBytes returns a specified number of random bytes.\n// It is essentially a wrapper around RandomBytesBuf for convenience.\n// Note that this behaviour is different than in NaCl and libsodium,\n// where this function behaves the same as RandomBytesBuf.\nfunc RandomBytes(size int) []byte {\n\tbuf := make([]byte, size)\n\tRandomBytesBuf(buf)\n\treturn buf\n}\n\n// RandomBytesBuf fills a buffer with random bytes.\nfunc RandomBytesBuf(buf []byte) {\n\tif len(buf) > 0 {\n\t\tC.randombytes_buf(unsafe.Pointer(&buf[0]), C.size_t(len(buf)))\n\t}\n}\n\n// RandomBytesBufDeterministic fills a buffer with bytes that are\n// indistinguishable from random bytes without knowing seed.\nfunc RandomBytesBufDeterministic(buf []byte, seed []byte) {\n\tsupport.CheckSize(seed, RandomBytesSeedBytes(), \"seed\")\n\tif len(buf) > 0 {\n\t\tC.randombytes_buf_deterministic(\n\t\t\tunsafe.Pointer(&buf[0]),\n\t\t\tC.size_t(len(buf)),\n\t\t\t(*C.uchar)(&seed[0]))\n\t}\n}\n\n// RandomBytesRandom returns a random 32 bit unsigned integer.\nfunc RandomBytesRandom() uint32 {\n\treturn uint32(C.randombytes_random())\n}\n\n// RandomBytesUniform returns a random number between 0 and an upper bound.\n// The generated bytes have a uniform distribution between 0 and the upper bound.\nfunc RandomBytesUniform(upperBound uint32) uint32 {\n\treturn uint32(C.randombytes_uniform(C.uint32_t(upperBound)))\n}\n\n// RandomBytesStir reseeds the random number generator.\nfunc RandomBytesStir() {\n\tC.randombytes_stir()\n}\n\n// RandomBytesClose deallocates the resources used by the random number generator.\nfunc RandomBytesClose() {\n\tC.randombytes_close()\n}\n\n// RandomBytesSetImplementation sets the implementation of the random number generator.\nfunc RandomBytesSetImplementation(impl *C.struct_randombytes_implementation) int {\n\treturn int(C.randombytes_set_implementation(impl))\n}\n\n// RandomBytesImplementationName returns the name of the random number\n// generator that is being used.\nfunc RandomBytesImplementationName() string {\n\treturn C.GoString(C.randombytes_implementation_name())\n}\n\n// RandomBytesSalsa20Implementation contains a pointer to C.randombytes_salsa20_implementation\n// This means that it can be used as an argument to RandomBytesSetImplementation\nvar RandomBytesSalsa20Implementation *C.struct_randombytes_implementation = &C.randombytes_salsa20_implementation\n\n// RandomBytesSysRandomImplementation contains a pointer to C.randombytes_sysrandom_implementation\n// This means that it can be used as an argument to RandomBytesSetImplementation\nvar RandomBytesSysRandomImplementation *C.struct_randombytes_implementation = &C.randombytes_sysrandom_implementation\n"
  },
  {
    "path": "scalarmult/crypto_scalarmult.go",
    "content": "package scalarmult\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\nimport \"github.com/GoKillers/libsodium-go/support\"\n\nfunc CryptoScalarmultBytes() int {\n\treturn int(C.crypto_scalarmult_bytes())\n}\n\nfunc CryptoScalarmultScalarBytes() int {\n\treturn int(C.crypto_scalarmult_scalarbytes())\n}\n\nfunc CryptoScalarmultPrimitive() string {\n\treturn C.GoString(C.crypto_scalarmult_primitive())\n}\n\nfunc CryptoScalarmultBase(n []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoScalarmultScalarBytes(), \"secret key\")\n\tq := make([]byte, CryptoScalarmultBytes())\n\tvar exit C.int\n\n\texit = C.crypto_scalarmult_base(\n\t\t(*C.uchar)(&q[0]),\n\t\t(*C.uchar)(&n[0]))\n\n\treturn q, int(exit)\n}\n\nfunc CryptoScalarMult(n []byte, p []byte) ([]byte, int) {\n\tsupport.CheckSize(n, CryptoScalarmultScalarBytes(), \"secret key\")\n\tsupport.CheckSize(p, CryptoScalarmultScalarBytes(), \"public key\")\n\tq := make([]byte, CryptoScalarmultBytes())\n\tvar exit C.int\n\texit = C.crypto_scalarmult(\n\t\t(*C.uchar)(&q[0]),\n\t\t(*C.uchar)(&n[0]),\n\t\t(*C.uchar)(&p[0]))\n\n\treturn q, int(exit)\n\n}\n"
  },
  {
    "path": "sodium/core.go",
    "content": "package sodium\n\nimport \"fmt\"\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\n\nfunc Init() {\n\tresult := int(C.sodium_init())\n\tif result != 0 {\n\t\tpanic(fmt.Sprintf(\"Sodium initialization failed, result code %d.\",\n\t\t\tresult))\n\t}\n}\n"
  },
  {
    "path": "sodium/runtime.go",
    "content": "package sodium\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\n\nfunc RuntimeHasNeon() bool {\n\treturn C.sodium_runtime_has_neon() != 0\n}\n\nfunc RuntimeHasSse2() bool {\n\treturn C.sodium_runtime_has_sse2() != 0\n}\n\nfunc RuntimeHasSse3() bool {\n\treturn C.sodium_runtime_has_sse3() != 0\n}\n"
  },
  {
    "path": "sodium/utils.go",
    "content": "package sodium\n\nimport \"fmt\"\nimport \"unsafe\"\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\n\nfunc MemZero(buff1 []byte) {\n\tif len(buff1) > 0 {\n\t\tC.sodium_memzero(unsafe.Pointer(&buff1[0]), C.size_t(len(buff1)))\n\t}\n}\n\nfunc MemCmp(buff1, buff2 []byte, length int) int {\n\tif length >= len(buff1) || length >= len(buff2) {\n\t\tpanic(fmt.Sprintf(\"Attempt to compare more bytes (%d) than provided \"+\n\t\t\t\"(%d, %d)\", length, len(buff1), len(buff2)))\n\t}\n\treturn int(C.sodium_memcmp(unsafe.Pointer(&buff1[0]),\n\t\tunsafe.Pointer(&buff2[0]),\n\t\tC.size_t(length)))\n}\n\nfunc Bin2hex(bin []byte) string {\n\tmaxlen := len(bin)*2 + 1\n\tbinPtr := (*C.uchar)(unsafe.Pointer(&bin[0]))\n\tbuf := (*C.char)(C.malloc(C.size_t(maxlen)))\n\tdefer C.free(unsafe.Pointer(buf))\n\n\tC.sodium_bin2hex(buf, C.size_t(maxlen), binPtr, C.size_t(len(bin)))\n\n\treturn C.GoString(buf)\n}\n"
  },
  {
    "path": "sodium/version.go",
    "content": "package sodium\n\n// #cgo pkg-config: libsodium\n// #include <stdlib.h>\n// #include <sodium.h>\nimport \"C\"\n\n// VersionString returns the libsodium version string\nfunc VersionString() string {\n\treturn C.GoString(C.sodium_version_string())\n}\n\n// LibraryVersionMajor returns the library major version number\nfunc LibraryVersionMajor() int {\n\treturn int(C.sodium_library_version_major())\n}\n\n// LibraryVersionMinor returns the library minor version number\nfunc LibraryVersionMinor() int {\n\treturn int(C.sodium_library_version_minor())\n}\n\n// LibraryMinimal returns true for a minimal build\nfunc LibraryMinimal() bool {\n\treturn int(C.sodium_library_minimal()) != 0\n}\n"
  },
  {
    "path": "sodium/version_test.go",
    "content": "package sodium\n\nimport (\n\t\"testing\"\n\t\"strings\"\n)\n\nfunc TestSodiumVersion(t *testing.T) {\n\tstr := VersionString()\n\tmaj := LibraryVersionMajor()\n\tmin := LibraryVersionMinor()\n\tslm := LibraryMinimal()\n\n\tt.Logf(\"Sodium version: %s\\n\", str)\n\tt.Logf(\"Sodium library version: %v.%v\", maj, min)\n\tt.Logf(\"Minimal: %v\", slm)\n\n\tversion := strings.Split(VersionString(), \".\")\n\tif len(version) != 3 {\n\t\tt.Error(\"Sodium version should consist of three components\")\n\t}\n\n\tif maj <= 0 || maj > 100 {\n\t\tt.Errorf(\"Suspicious library version major: %v\", maj)\n\t}\n\n\tif min <= 0 || min > 100 {\n\t\tt.Errorf(\"Suspicious library version minor: %v\", min)\n\t}\n}\n"
  },
  {
    "path": "support/error.go",
    "content": "package support\n\nimport \"strconv\"\n\n// KeySizeError is an error that occurs when a key has an incorrect length.\ntype KeySizeError int\n\nfunc (k KeySizeError) Error() string {\n\treturn \"invalid key size \" + strconv.Itoa(int(k))\n}\n\n// NonceSizeError is an error that occurs when a nonce has an incorrect length.\ntype NonceSizeError int\n\nfunc (k NonceSizeError) Error() string {\n\treturn \"invalid nonce size \" + strconv.Itoa(int(k))\n}\n\n// NilPointerError is an error that occurs when a pointer is a nil pointer\ntype NilPointerError string\n\nfunc (k NilPointerError) Error() string {\n\treturn string(k) + \" is a nil pointer\"\n}\n\n// VerificationError is an error that occurs when the verification of\n// a signature or authentication tag fails.\ntype VerificationError struct {}\n\nfunc (k VerificationError) Error() string {\n\treturn \"verification failed\"\n}\n"
  },
  {
    "path": "support/support.go",
    "content": "// Package support implements support functions and errors that are used by by other libsodium-go packages.\npackage support\n\nimport (\n\t\"fmt\"\n\t\"unsafe\"\n)\n\n// CheckSize checks if the length of a byte slice is equal to the expected length,\n// and panics when this is not the case.\nfunc CheckSize(buf []byte, expected int, descrip string) {\n\tif len(buf) != expected {\n\t\tpanic(fmt.Sprintf(\"Incorrect %s buffer size, expected (%d), got (%d).\", descrip, expected, len(buf)))\n\t}\n}\n\n// CheckSizeMin checks if the length of a byte slice is greater or equal than a minimum length,\n// and panics when this is not the case.\nfunc CheckSizeMin(buf []byte, min int, descrip string) {\n\tif len(buf) < min {\n\t\tpanic(fmt.Sprintf(\"Incorrect %s buffer size, expected (>%d), got (%d).\", descrip, min, len(buf)))\n\t}\n}\n\n// CheckIntInRange checks if the size of an integer is between a lower and upper boundaries.\nfunc CheckIntInRange(n int, min int, max int, descrip string) {\n\tif n < min || n > max {\n\t\tpanic(fmt.Sprintf(\"Incorrect %s size, expected (%d - %d), got (%d).\", descrip, min, max, n))\n\t}\n}\n\n// CheckSizeInRange checks if the length of a byte slice is between a lower and upper boundaries.\nfunc CheckSizeInRange(buf []byte, min int, max int, descrip string) {\n\tif len(buf) < min || len(buf) > max {\n\t\tpanic(fmt.Sprintf(\"Incorrect %s buffer size, expected (%d - %d), got (%d).\", descrip, min, max, len(buf)))\n\t}\n}\n\n// CheckSizeGreaterOrEqual checks if the length of a byte slice is greater or equal to that of a second byte slice.\nfunc CheckSizeGreaterOrEqual(a, b []byte, aDescription, bDescription string) {\n\tif len(a) < len(b) {\n\t\tpanic(fmt.Sprintf(\"%s smaller than %s\", aDescription, bDescription))\n\t}\n}\n\n// NilPanic is a shorthand that results in a panic when called with true.\nfunc NilPanic(t bool, description string) {\n\tif t {\n\t\tpanic(description + \" is a nil pointer\")\n\t}\n}\n\n// BytePointer returns a pointer to the start of a byte slice, or nil when the slice is empty.\nfunc BytePointer(b []byte) *uint8 {\n\tif len(b) > 0 {\n\t\treturn &b[0]\n\t} else {\n\t\treturn nil\n\t}\n}\n\n// AlignedSlice returns a memory aligned slice\nfunc AlignedSlice(size, alignment int) []byte {\n\tslice := make([]byte, size+alignment)\n\toffset := alignment - int(uintptr(unsafe.Pointer(&slice[0])))%alignment\n\treturn slice[offset : offset+size]\n}\n"
  }
]