diff --git a/cryptostream/crypto_stream_chacha20.go b/cryptostream/crypto_stream_chacha20.go index 4b75577..06de21e 100644 --- a/cryptostream/crypto_stream_chacha20.go +++ b/cryptostream/crypto_stream_chacha20.go @@ -57,17 +57,14 @@ func CryptoStreamChaCha20XORIC(m []byte, n []byte, ic uint64, k []byte) ([]byte, return c, exit } -// Requires 1.0.12 -//func CryptoStreamChaCha20Keygen() []byte { -// c := make([]byte, CryptoStreamChaCha20KeyBytes()) -// C.crypto_stream_chacha20_keygen((*C.uchar)(&c[0])) -// return c -//} +func CryptoStreamChaCha20Keygen() []byte { + c := make([]byte, CryptoStreamChaCha20KeyBytes()) + C.crypto_stream_chacha20_keygen((*C.uchar)(&c[0])) + return c +} func CryptoStreamChaCha20IETFKeyBytes() int { - // Requires 1.0.12 - // return int(C.crypto_stream_chacha20_ietf_keybytes()) - return CryptoStreamChaCha20KeyBytes() + return int(C.crypto_stream_chacha20_ietf_keybytes()) } func CryptoStreamChaCha20IETFNonceBytes() int { @@ -117,9 +114,8 @@ func CryptoStreamChaCha20IETFXORIC(m []byte, n []byte, ic uint32, k []byte) ([]b return c, exit } -// Requires 1.0.12 -//func CryptoStreamChaCha20IETFKeygen() []byte { -// c := make([]byte, CryptoStreamChaCha20IETFKeyBytes()) -// C.crypto_stream_chacha20_ietf_keygen((*C.uchar)(&c[0])) -// return c -//} +func CryptoStreamChaCha20IETFKeygen() []byte { + c := make([]byte, CryptoStreamChaCha20IETFKeyBytes()) + C.crypto_stream_chacha20_ietf_keygen((*C.uchar)(&c[0])) + return c +} diff --git a/cryptostream/crypto_stream_salsa20.go b/cryptostream/crypto_stream_salsa20.go index b373218..270574f 100644 --- a/cryptostream/crypto_stream_salsa20.go +++ b/cryptostream/crypto_stream_salsa20.go @@ -57,9 +57,8 @@ func CryptoStreamSalsa20XORIC(m []byte, n []byte, ic uint64, k []byte) ([]byte, return c, exit } -// Requires 1.0.12 -//func CryptoStreamSalsa20Keygen() []byte { -// c := make([]byte, CryptoStreamSalsa20KeyBytes()) -// C.crypto_stream_salsa20_keygen((*C.uchar)(&c[0])) -// return c -//} +func CryptoStreamSalsa20Keygen() []byte { + c := make([]byte, CryptoStreamSalsa20KeyBytes()) + C.crypto_stream_salsa20_keygen((*C.uchar)(&c[0])) + return c +} diff --git a/cryptostream/crypto_stream_salsa2012.go b/cryptostream/crypto_stream_salsa2012.go index c69ae41..30a07ac 100644 --- a/cryptostream/crypto_stream_salsa2012.go +++ b/cryptostream/crypto_stream_salsa2012.go @@ -41,9 +41,8 @@ func CryptoStreamSalsa2012XOR(m []byte, n []byte, k []byte) ([]byte, int) { return c, exit } -// Requires 1.0.12 -//func CryptoStreamSalsa2012Keygen() []byte { -// c := make([]byte, CryptoStreamSalsa2012KeyBytes()) -// C.crypto_stream_salsa2012_keygen((*C.uchar)(&c[0])) -// return c -//} +func CryptoStreamSalsa2012Keygen() []byte { + c := make([]byte, CryptoStreamSalsa2012KeyBytes()) + C.crypto_stream_salsa2012_keygen((*C.uchar)(&c[0])) + return c +} diff --git a/cryptostream/crypto_stream_salsa208.go b/cryptostream/crypto_stream_salsa208.go index 69ec827..02ad510 100644 --- a/cryptostream/crypto_stream_salsa208.go +++ b/cryptostream/crypto_stream_salsa208.go @@ -41,9 +41,8 @@ func CryptoStreamSalsa208XOR(m []byte, n []byte, k []byte) ([]byte, int) { return c, exit } -// Requires 1.0.12 -//func CryptoStreamSalsa208Keygen() []byte { -// c := make([]byte, CryptoStreamSalsa208KeyBytes()) -// C.crypto_stream_salsa208_keygen((*C.uchar)(&c[0])) -// return c -//} +func CryptoStreamSalsa208Keygen() []byte { + c := make([]byte, CryptoStreamSalsa208KeyBytes()) + C.crypto_stream_salsa208_keygen((*C.uchar)(&c[0])) + return c +} diff --git a/cryptostream/crypto_stream_xchacha20.go b/cryptostream/crypto_stream_xchacha20.go new file mode 100644 index 0000000..d9b9609 --- /dev/null +++ b/cryptostream/crypto_stream_xchacha20.go @@ -0,0 +1,64 @@ +package cryptostream + +// #cgo pkg-config: libsodium +// #include +// #include +import "C" +import "github.com/GoKillers/libsodium-go/support" + +func CryptoStreamXChaCha20KeyBytes() int { + return int(C.crypto_stream_xchacha20_keybytes()) +} + +func CryptoStreamXChaCha20NonceBytes() int { + return int(C.crypto_stream_xchacha20_noncebytes()) +} + +func CryptoStreamXChaCha20(clen int, n []byte, k []byte) ([]byte, int) { + support.CheckSize(n, CryptoStreamXChaCha20NonceBytes(), "nonce") + support.CheckSize(k, CryptoStreamXChaCha20KeyBytes(), "key") + c := make([]byte, clen) + exit := int(C.crypto_stream_xchacha20( + (*C.uchar)(&c[0]), + (C.ulonglong)(clen), + (*C.uchar)(&n[0]), + (*C.uchar)(&k[0]))) + + return c, exit +} + +func CryptoStreamXChaCha20XOR(m []byte, n []byte, k []byte) ([]byte, int) { + support.CheckSize(n, CryptoStreamXChaCha20NonceBytes(), "nonce") + support.CheckSize(k, CryptoStreamXChaCha20KeyBytes(), "key") + c := make([]byte, len(m)) + exit := int(C.crypto_stream_xchacha20_xor( + (*C.uchar)(&c[0]), + (*C.uchar)(&m[0]), + (C.ulonglong)(len(m)), + (*C.uchar)(&n[0]), + (*C.uchar)(&k[0]))) + + return c, exit +} + +func CryptoStreamXChaCha20XORIC(m []byte, n []byte, ic uint64, k []byte) ([]byte, int) { + support.CheckSize(n, CryptoStreamXChaCha20NonceBytes(), "nonce") + support.CheckSize(k, CryptoStreamXChaCha20KeyBytes(), "key") + + c := make([]byte, len(m)) + exit := int(C.crypto_stream_xchacha20_xor_ic( + (*C.uchar)(&c[0]), + (*C.uchar)(&m[0]), + (C.ulonglong)(len(m)), + (*C.uchar)(&n[0]), + (C.uint64_t)(ic), + (*C.uchar)(&k[0]))) + + return c, exit +} + +func CryptoStreamXChaCha20Keygen() []byte { + c := make([]byte, CryptoStreamXChaCha20KeyBytes()) + C.crypto_stream_xchacha20_keygen((*C.uchar)(&c[0])) + return c +} diff --git a/cryptostream/crypto_stream_xsalsa20.go b/cryptostream/crypto_stream_xsalsa20.go index 4ab01b9..193319d 100644 --- a/cryptostream/crypto_stream_xsalsa20.go +++ b/cryptostream/crypto_stream_xsalsa20.go @@ -57,9 +57,8 @@ func CryptoStreamXSalsa20XORIC(m []byte, n []byte, ic uint64, k []byte) ([]byte, return c, exit } -// Requires 1.0.12 -//func CryptoStreamXSalsa20Keygen() []byte { -// c := make([]byte, CryptoStreamXSalsa20KeyBytes()) -// C.crypto_stream_xsalsa20_keygen((*C.uchar)(&c[0])) -// return c -//} +func CryptoStreamXSalsa20Keygen() []byte { + c := make([]byte, CryptoStreamXSalsa20KeyBytes()) + C.crypto_stream_xsalsa20_keygen((*C.uchar)(&c[0])) + return c +} diff --git a/sodium/version.go b/sodium/version.go index 5360aef..14bc225 100644 --- a/sodium/version.go +++ b/sodium/version.go @@ -16,3 +16,7 @@ func SodiumLibaryVersionMajor() int { func SodiumLibaryVersionMinor() int { return int(C.sodium_library_version_minor()) } + +func SodiumLibaryMinimal() bool { + return int(C.sodium_library_minimal()) != 0 +} \ No newline at end of file