Skip to content

Commit

Permalink
Merge pull request #12 from SpiderOak/fix-cryptobox-seal
Browse files Browse the repository at this point in the history
Fix CryptoBoxSeal
  • Loading branch information
redragonx authored Jul 13, 2016
2 parents ea710a8 + 4aad531 commit 21fce0a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cryptobox/crypto_box_seal.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import "github.com/GoKillers/libsodium-go/support"

func CryptoBoxSeal(m []byte, pk []byte) ([]byte, int) {
support.CheckSize(pk, CryptoBoxPublicKeyBytes(), "public key")
c := make([]byte, len(m)+CryptoBoxMacBytes())
c := make([]byte, len(m)+CryptoBoxSealBytes())
exit := int(C.crypto_box_seal(
(*C.uchar)(&c[0]),
(*C.uchar)(&m[0]),
Expand All @@ -21,7 +21,7 @@ func CryptoBoxSeal(m []byte, pk []byte) ([]byte, int) {
func CryptoBoxSealOpen(c []byte, pk []byte, sk []byte) ([]byte, int) {
support.CheckSize(pk, CryptoBoxPublicKeyBytes(), "public key")
support.CheckSize(sk, CryptoBoxSecretKeyBytes(), "secret key")
m := make([]byte, len(c)-CryptoBoxMacBytes())
m := make([]byte, len(c)-CryptoBoxSealBytes())
exit := int(C.crypto_box_seal_open(
(*C.uchar)(&m[0]),
(*C.uchar)(&c[0]),
Expand Down
22 changes: 22 additions & 0 deletions cryptobox/crypto_box_seal_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package cryptobox

import "testing"

func TestCryptoBoxSeal(t *testing.T) {
sk, pk, exit := CryptoBoxKeyPair()
if exit != 0 {
t.Fatalf("CryptoBoxKeyPair failed: %v", exit)
}
testStr := "test string 12345678901234567890123456789012345678901234567890"
cipherText, exit := CryptoBoxSeal([]byte(testStr), pk)
if exit != 0 {
t.Fatalf("CryptoBoxSeal failed: %v", exit)
}
plaintext, exit := CryptoBoxSealOpen(cipherText, pk, sk)
if exit != 0 {
t.Fatalf("CryptoBoxSealOpen failed: %v", exit)
}
if string(plaintext) != testStr {
t.Fatalf("Bad plaintext: %#v", plaintext)
}
}

0 comments on commit 21fce0a

Please sign in to comment.