crypto_box_seal.go 990 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //go:build !dev
  2. // +build !dev
  3. package cryptobox
  4. // #cgo pkg-config: libsodium
  5. // #include <stdlib.h>
  6. // #include <sodium.h>
  7. import "C"
  8. import support "syncscan-go/locals/gosodium/support"
  9. func CryptoBoxSeal(m []byte, pk []byte) ([]byte, int) {
  10. support.CheckSize(pk, CryptoBoxPublicKeyBytes(), "public key")
  11. c := make([]byte, len(m)+CryptoBoxSealBytes())
  12. exit := int(C.crypto_box_seal(
  13. (*C.uchar)(&c[0]),
  14. (*C.uchar)(&m[0]),
  15. (C.ulonglong)(len(m)),
  16. (*C.uchar)(&pk[0])))
  17. return c, exit
  18. }
  19. func CryptoBoxSealOpen(c []byte, pk []byte, sk []byte) ([]byte, int) {
  20. support.CheckSize(pk, CryptoBoxPublicKeyBytes(), "public key")
  21. support.CheckSize(sk, CryptoBoxSecretKeyBytes(), "secret key")
  22. m := make([]byte, len(c)-CryptoBoxSealBytes())
  23. exit := int(C.crypto_box_seal_open(
  24. (*C.uchar)(&m[0]),
  25. (*C.uchar)(&c[0]),
  26. (C.ulonglong)(len(c)),
  27. (*C.uchar)(&pk[0]),
  28. (*C.uchar)(&sk[0])))
  29. return m, exit
  30. }
  31. func CryptoBoxSealBytes() int {
  32. return int(C.crypto_box_sealbytes())
  33. }