forked from GoKillers/libsodium-go
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request GoKillers#21 from silkeh/update-1.0.12
Update crypo_stream and version to 1.0.12
- Loading branch information
Showing
7 changed files
with
99 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters