Skip to content

Commit

Permalink
Merge pull request GoKillers#21 from silkeh/update-1.0.12
Browse files Browse the repository at this point in the history
Update crypo_stream and version to 1.0.12
  • Loading branch information
redragonx authored Mar 20, 2017
2 parents 9c4aee2 + c5c027d commit ca026aa
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 39 deletions.
26 changes: 11 additions & 15 deletions cryptostream/crypto_stream_chacha20.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
11 changes: 5 additions & 6 deletions cryptostream/crypto_stream_salsa20.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 5 additions & 6 deletions cryptostream/crypto_stream_salsa2012.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 5 additions & 6 deletions cryptostream/crypto_stream_salsa208.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
64 changes: 64 additions & 0 deletions cryptostream/crypto_stream_xchacha20.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package cryptostream

// #cgo pkg-config: libsodium
// #include <stdlib.h>
// #include <sodium.h>
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
}
11 changes: 5 additions & 6 deletions cryptostream/crypto_stream_xsalsa20.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions sodium/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit ca026aa

Please sign in to comment.