示例#1
0
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])))
}
示例#2
0
// Verify verifies a signature and a message using a public key. If there is
// a problem, then a non-nil value would be returned. A nil value means
// everything is fine.
func (publ EdDSAPublic) Verify(message []byte, signature []byte) error {
	if len(signature) != EdDSASignatureLength {
		panic(fmt.Sprintf("Signature passed has the wrong length (%v != %v)",
			len(signature), EdDSASignatureLength))
	}
	rv := C.crypto_sign_verify_detached(
		(*C.uchar)(&signature[0]),
		(*C.uchar)(&message[0]),
		C.ulonglong(len(message)),
		(*C.uchar)(&publ[0]))
	if rv != 0 {
		return errors.New("EdDSA signature is forged!")
	}
	return nil
}
示例#3
0
文件: verfiy.go 项目: ZiRo-/srndv2
// verfiy a detached signature
// return true on valid otherwise false
func CryptoVerifyDetached(msg, sig, pk []byte) bool {
	msg_buff := NewBuffer(msg)
	defer msg_buff.Free()
	sig_buff := NewBuffer(sig)
	defer sig_buff.Free()
	pk_buff := NewBuffer(pk)
	defer pk_buff.Free()

	if pk_buff.size != C.crypto_sign_publickeybytes() {
		return false
	}

	// invalid sig size
	if sig_buff.size != C.crypto_sign_bytes() {
		return false
	}
	return C.crypto_sign_verify_detached(sig_buff.uchar(), msg_buff.uchar(), C.ulonglong(len(msg)), pk_buff.uchar()) == 0
}
示例#4
0
func (v *Ed25519Verifier) VerifyHash(h, sig []byte) (err error) {
	if len(sig) == C.crypto_sign_BYTES {
		// valid size of sig
		// copy signature and hash
		var csig, ch [32]C.uchar
		for i, b := range h {
			ch[i] = C.uchar(b)
		}
		for i, b := range sig {
			csig[i] = C.uchar(b)
		}
		// verify
		if C.crypto_sign_verify_detached(&csig[0], &ch[0], C.ulonglong(32), &v.k[0]) == 0 {
			// valid signature
		} else {
			// bad signature
			err = ErrInvalidSignature
		}
	} else {
		// bad size of sig
		err = ErrBadSignatureSize
	}
	return
}