# Why the need to hash before signing small data?

I’ve got two questions:

1. I’m doing the following:

Data :  uuid + int + nonce
Signature:  ECDSA(sha256(Data) )


To verify the signature:

decrypt(Signature) == sha256(data)


So if the data, hash function, and public key are known, why is there a need to hash?

2. If the same Data with a different nonce is sent over and over, can someone figure out my private key?

First of all I do not know your implementation, but it seems that you have some basic misunderstandings.

Signature: ECDSA(sha256(Data) )

ECDSA is typically implemented in a way that you do not explicitly hash the data prior to passing it to the signing algorithm (but as this might be your own implementation and signing may still work correctly).

decrypt(Signature) == sha256(data)

In ECDSA signature verification you do not decrypt anything nor compare the hash value of the message with some signature value, but the hash value of the message is used implicitly in the verification relation. So I do not see any chance that your verification will work.

I think you actually read a bad source about RSA signatures which uses the wrong and misleading term "decrypt with public key". This is sometimes used because in RSA the enryption and decryption function is commutative and thus RSA encryption and RSA signature schemes use the same operations in different order. So you sometimes read instead of signing the term "encrypt with private key" and instead of verifying "decrypt with public key", but you should not use this terminology, as this does not apply to other signature schemes such as ECDSA. Furthermore, due to this way of signing in RSA in the verification you compare the value obtained by performing the public key operation on the signature with the hash value, but also this does not hold for other signature schemes such as ECDSA.

So if the data, hash function, and public key are known, why is there a need to hash?

If you do not hash the data before signing you cannot have one consistent signature algorithm, because you could only sign messages up to a certain size and if the size of the message gets too large you would need to hash. But that is not a good practice for signature schemes. More importantly, there are signature schemes which can easily be forged when the data is not hashed, such as RSA, see my answer here. In order to have security independent of the size of the signed message, we typically use this hash-then-sign paradigm, i.e., hash the plain message before performing signing operations on it, and thus the signature algorithm works for any size of the message and we do not really have to care about the message size.