func CryptoSignVerifyDetached(sig []byte, m []byte, pk []byte) int { support.CheckSize(sig, CryptoSignBytes(), "signature") support.CheckSize(pk, CryptoSignPublicKeyBytes(), "public key") return int(C.crypto_sign_verify_detached( (*C.uchar)(&sig[0]), (*C.uchar)(&m[0]), (C.ulonglong)(len(m)), (*C.uchar)(&pk[0]))) }
func CryptoBoxBeforeNm(pk []byte, sk []byte) ([]byte, int) { support.CheckSize(pk, CryptoBoxPublicKeyBytes(), "public key") support.CheckSize(sk, CryptoBoxSecretKeyBytes(), "sender's secret key") k := make([]byte, CryptoBoxBeforeNmBytes()) exit := int(C.crypto_box_beforenm( (*C.uchar)(&k[0]), (*C.uchar)(&pk[0]), (*C.uchar)(&sk[0]))) return k, exit }
func CryptoBoxEasyAfterNm(m []byte, n []byte, k []byte) ([]byte, int) { support.CheckSize(n, CryptoBoxNonceBytes(), "nonce") support.CheckSize(k, CryptoBoxBeforeNmBytes(), "shared secret key") c := make([]byte, len(m)+CryptoBoxMacBytes()) exit := int(C.crypto_box_easy_afternm( (*C.uchar)(&c[0]), (*C.uchar)(&m[0]), (C.ulonglong)(len(m)), (*C.uchar)(&n[0]), (*C.uchar)(&k[0]))) return c, exit }
func CryptoBoxOpenAfteNm(c []byte, n []byte, k []byte) ([]byte, int) { support.CheckSize(n, CryptoBoxNonceBytes(), "nonce") support.CheckSize(k, CryptoBoxBeforeNmBytes(), "shared secret key") m := make([]byte, len(c)) exit := int(C.crypto_box_afternm( (*C.uchar)(&m[0]), (*C.uchar)(&c[0]), (C.ulonglong)(len(c)), (*C.uchar)(&n[0]), (*C.uchar)(&k[0]))) return m, exit }
func CryptoScalarMult(n []byte, p []byte) ([]byte, int) { support.CheckSize(n, CryptoScalarmultScalarBytes(), "secret key") support.CheckSize(p, CryptoScalarmultScalarBytes(), "public key") q := make([]byte, CryptoScalarmultBytes()) var exit C.int exit = C.crypto_scalarmult( (*C.uchar)(&q[0]), (*C.uchar)(&n[0]), (*C.uchar)(&p[0])) return q, int(exit) }
func CryptoSecretBoxOpen(c []byte, n []byte, k []byte) ([]byte, int) { support.CheckSize(n, CryptoSecretBoxNonceBytes(), "nonce") support.CheckSize(k, CryptoSecretBoxKeyBytes(), "key") m := make([]byte, len(c)-CryptoSecretBoxMacBytes()) exit := int(C.crypto_secretbox_open( (*C.uchar)(&m[0]), (*C.uchar)(&c[0]), (C.ulonglong)(len(c)), (*C.uchar)(&n[0]), (*C.uchar)(&k[0]))) return m, exit }
func CryptoSecretBoxEasy(m []byte, n []byte, k []byte) ([]byte, int) { support.CheckSize(n, CryptoSecretBoxNonceBytes(), "nonce") support.CheckSize(k, CryptoSecretBoxKeyBytes(), "key") c := make([]byte, len(m)+CryptoSecretBoxMacBytes()) exit := int(C.crypto_secretbox_easy( (*C.uchar)(&c[0]), (*C.uchar)(&m[0]), (C.ulonglong)(len(m)), (*C.uchar)(&n[0]), (*C.uchar)(&k[0]))) return c, exit }
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()) exit := int(C.crypto_box_seal_open( (*C.uchar)(&m[0]), (*C.uchar)(&c[0]), (C.ulonglong)(len(c)), (*C.uchar)(&pk[0]), (*C.uchar)(&sk[0]))) return m, exit }
func CryptoBoxEasy(m []byte, n []byte, pk []byte, sk []byte) ([]byte, int) { support.CheckSize(n, CryptoBoxNonceBytes(), "nonce") support.CheckSize(pk, CryptoBoxPublicKeyBytes(), "public key") support.CheckSize(sk, CryptoBoxSecretKeyBytes(), "secret key") c := make([]byte, len(m)+CryptoBoxMacBytes()) exit := int(C.crypto_box_easy( (*C.uchar)(&c[0]), (*C.uchar)(&m[0]), (C.ulonglong)(len(m)), (*C.uchar)(&n[0]), (*C.uchar)(&pk[0]), (*C.uchar)(&sk[0]))) return c, exit }
func CryptoBoxOpen(c []byte, n []byte, pk []byte, sk []byte) ([]byte, int) { support.CheckSize(n, CryptoBoxNonceBytes(), "nonce") support.CheckSize(pk, CryptoBoxPublicKeyBytes(), "public key") support.CheckSize(sk, CryptoBoxPublicKeyBytes(), "secret key") m := make([]byte, len(c)) exit := int(C.crypto_box_open( (*C.uchar)(&m[0]), (*C.uchar)(&c[0]), (C.ulonglong)(len(c)), (*C.uchar)(&n[0]), (*C.uchar)(&pk[0]), (*C.uchar)(&sk[0]))) return m, exit }
func CryptoBoxSeedKeyPair(seed []byte) ([]byte, []byte, int) { support.CheckSize(seed, CryptoBoxSeedBytes(), "seed") sk := make([]byte, CryptoBoxSecretKeyBytes()) pk := make([]byte, CryptoBoxPublicKeyBytes()) exit := int(C.crypto_box_seed_keypair( (*C.uchar)(&pk[0]), (*C.uchar)(&sk[0]), (*C.uchar)(&seed[0]))) return sk, pk, exit }
func CryptoBoxSeal(m []byte, pk []byte) ([]byte, int) { support.CheckSize(pk, CryptoBoxPublicKeyBytes(), "public key") c := make([]byte, len(m)+CryptoBoxMacBytes()) exit := int(C.crypto_box_seal( (*C.uchar)(&c[0]), (*C.uchar)(&m[0]), (C.ulonglong)(len(m)), (*C.uchar)(&pk[0]))) return c, exit }
func CryptoAuthVerify(hmac []byte, in []byte, key []byte) int { support.CheckSize(key, CryptoAuthKeyBytes(), "key") inlen := len(in) exit := int(C.crypto_auth_verify( (*C.uchar)(&hmac[0]), (*C.uchar)(&in[0]), (C.ulonglong)(inlen), (*C.uchar)(&key[0]))) return exit }
func CryptoAuth(in []byte, key []byte) ([]byte, int) { support.CheckSize(key, CryptoAuthKeyBytes(), "key") inlen := len(in) out := make([]byte, inlen+CryptoAuthBytes()) exit := int(C.crypto_auth( (*C.uchar)(&out[0]), (*C.uchar)(&in[0]), (C.ulonglong)(inlen), (*C.uchar)(&key[0]))) return out, exit }
func CryptoSignDetached(m []byte, sk []byte) ([]byte, int) { support.CheckSize(sk, CryptoSignSecretKeyBytes(), "secret key") sig := make([]byte, CryptoSignBytes()) var actualSigSize C.ulonglong exit := int(C.crypto_sign_detached( (*C.uchar)(&sig[0]), (&actualSigSize), (*C.uchar)(&m[0]), (C.ulonglong)(len(m)), (*C.uchar)(&sk[0]))) return sig[:actualSigSize], exit }
func CryptoSignOpen(sm []byte, pk []byte) ([]byte, int) { support.CheckSize(pk, CryptoSignPublicKeyBytes(), "public key") m := make([]byte, len(sm)-CryptoSignBytes()) var actualMSize C.ulonglong exit := int(C.crypto_sign_open( (*C.uchar)(&m[0]), (&actualMSize), (*C.uchar)(&sm[0]), (C.ulonglong)(len(sm)), (*C.uchar)(&pk[0]))) return m[:actualMSize], exit }