// Sign signs a message using the given EdDSA private key, returning the signature. func (priv EdDSAPrivate) Sign(message []byte) []byte { signature := make([]byte, EdDSASignatureLength) rv := C.crypto_sign_detached( (*C.uchar)(&signature[0]), nil, (*C.uchar)(&message[0]), C.ulonglong(len(message)), (*C.uchar)(&priv[0])) if rv != 0 { panic("crypto_sign_detached returned non-zero") } return signature }
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 (s *Ed25519Signer) SignHash(h []byte) (sig []byte, err error) { var ch [32]C.uchar for i, b := range h { ch[i] = C.uchar(b) } var csig [32]C.uchar var smlen_p C.ulonglong res := C.crypto_sign_detached(&csig[0], &smlen_p, &ch[0], C.ulonglong(32), &s.k[0]) if res == 0 { // success signing sig = make([]byte, 32) for i, b := range csig { sig[i] = byte(b) } } else { // failed signing err = errors.New(fmt.Sprintf("failed to sign: crypto_sign_detached exit code %d", int(res))) } return }
// sign data detached with secret key sk func CryptoSignDetached(msg, sk []byte) []byte { msgbuff := NewBuffer(msg) defer msgbuff.Free() skbuff := NewBuffer(sk) defer skbuff.Free() if skbuff.size != C.crypto_sign_bytes() { return nil } // allocate the signature buffer sig := malloc(C.crypto_sign_bytes()) defer sig.Free() // compute signature siglen := C.ulonglong(0) res := C.crypto_sign_detached(sig.uchar(), &siglen, msgbuff.uchar(), C.ulonglong(msgbuff.size), skbuff.uchar()) if res == 0 && siglen == C.ulonglong(C.crypto_sign_bytes()) { // return copy of signature buffer return sig.Bytes() } // failure to sign return nil }