Digital signatures are crpytographic schemes that provide message authentication (the receiver can verify the origin of the message), integrity (the receiver can verify that the message has not been modified since it was signed) and non-repudiation (the sender cannot falsely claim that they have not signed the message).
In this short note, we discuss arithmetic circuit constraints that ensures that a witness, a set of inputs and outputs, correctly computes (or are related to each other through) the Digital Signature Algorithm (DSA) and its more advanced version that uses elliptic curves. Both algorithms are based on groups of known order and the discrete logarithm (DL) security assumptions.
A signature scheme has three parts, the setup algorithm which involves private and public key generation, the signature algorithm itself, and a verification algorithm for checking if a signature is authentic.
The verification algorithm is the only part of the scheme that is public and is typically the only part that is of importance for circuit constraints. For example, the verification algorithm for DSA appears in smart contracts executed in the Ethereum Virtual Machine. The veracity of the inputs and outputs of this verification algorithm can be shown by encoding a set of contraints into a circuit used to prove a larger set of computations with a ZK-SNARK.
We will introduce the two algorithms, DSA and Elliptic-curve DSA in turn and briefly discuss the circuit constraints associated with each.
Setup Algorithm: The setup algorithm generates a private key known only to the sender (or signee) and a corresponding public key. Since the setup algorithm is privately computed and not really relevant to the verification process, it is possible to skip this section, which only provides background information on why DSA works.
The algorithm goes as follows. Security parameters are chosen and publically shared. is a prime of size bits and is a prime of size bits chosen in such a way that for a particular . The reason for this contraint is as follows.
The signatures created by DSA will be utilizing a cyclic subgroup of prime order with a generator . Now the question of interest is how to find such a generator.
is the multiplicative group (with non-prime order ) of the prime field , which will act as the base field. Any subgroups of this multiplicative group have orders that can divide due to Lagrange's theorem and are cyclic (all subgroups of a cyclic group are cyclic).
We need . Since is prime and have no divisors except and itself, a that satisfies this equation would be a generator of a subgroup of order or would be the identity element . We can generate such a by considering a random element in . Then, we can consider the candidate , as for any , due to Fermat's little theorem. Therefore, is either or a generator of the cyclic subgroup and we can find other candidates if we end up with .
are determined through this process. Once these are determined, we can operate within by raising the generator to to obtain the sequence , which is the isomorphism. Note that the group operation within the subgroup is and not .
Based on all this setup, the sender choses a private key to keep hidden and computes a corresponding public key from the subgroup , , which gets published along with the generator . In addition to these, a cryptographic hash function is chosen and published.
Overall, the setup algorithm executed by the sender publishes and keeps hidden .
Signature Algorithm: Similar to the setup algorithm, the signature algorithm itself is not publically computed and therefore is not typically a subject of circuit constraints. The section can be skipped, as it only explains how the signatures are created by the sender.
DSA is a stochastic signature scheme and therefore, each time a signature is generated for a particular fixed message , the signature is different. This requires a source of randomness, .
Then, a one-time random key is created by trying a number of until (few tries are needed) which are related through the following equation. Note that is an element of . The exponentiation in this computation is the most computationally expensive part of the signing operation, but it may be computed before the message is known, which is an advantage of the scheme. We also need to calculate , using the Extended Euclidean algorithm (EEA), which is the second most expensive operation.
In order to generate the signature for a given message , which can be of variable length, we first hash it to a fixed-size digest, . This digest, along with the randomness variables , and the public key , is then used to compute the following,Then, the triplet is published as the signed message. Note that the message-sender pair is now interlocked to the signature pair through this signed message.
Verification Algorithm: The verification algorithm is the only publically computed part of the scheme and is of great interest to proof systems. In this section, we will give a description and then discuss the circuit constraints in the next section.
Given a signed message and the public variables , verification process is centered around checking a relation between these variables that is efficiently computable. As a preliminary, the algorithm first checks , , and then computes (usually using EEA for efficiency).
Based on how is computed in the signature algorithm, we can obtain the following candidate relation that could be useful for verification,However, the verification algorithm does not know the private key to be able to check this relationship. On the other hand, the subgroup encrypted version of this relationship, is much more useful, as it replaces the private key with the public key if the correct set of simplification steps take place (note that can be removed, as the subgroup is known to have an order ):This could further be improved to,Based on the above, are interlocked into this relationship through the generator , the hash function and the pair, which is checked by the verification algorithm to confirm that the signature matches the message-sender pair .
Circuit constraints: Finally, we discuss the circuit constraints that replicate the verification algorithm in proving that the signature in a signed message matches the message-sender pair .
As it is the case in most arithmetic circuits, this is accomplished by breaking down the verification check equation into a set of simpler arithmetic equations with the use of auxiliary advice variables, provided as inputs to the circuit, that need to match intermediate computations.
These advice variables are, the output of the hash function , the inverse of variable (modulo ) , quotients for modulo operations , and various intermediate computations .
Given a witness, inputs + advice variables,
the following set of circuit constraints can be used to verify the authenticity of a signed message, Exponentiations are handled by decomposing the constraint into many smaller constraints that build upon, e.g. and and so on until some is reached, similar to the square multiply algorithm used in efficient group exponentiation. There are logarithmic number (in the exponent) of such constraints needed.
In general, doing all this efficiently requires decomposing single constraints with large integers in them, into multiple constraints with smaller integers, as the integers inputted to these constraints can be huge due to security requirements of DSA. This is a topic we explore in another note focused on efficient large number arithmetic circuits.
Setup Algorithm: Elliptic Curve DSA is identical to DSA, except that it changes the subgroup used. It replaces the prime order subgroup of the multiplicative group of the field with an elliptic curve constructed on . Much of the three algorithms remain the same. Security parameters are again and is the order of the elliptic curve and the generator of the curve is .
In the same manner as DSA, the private key is chosen from and the public key is computed using the curve group operation according to . We will use the multiplicative notation for the elliptic curve to match the earlier discussion of DSA, even though an additive notation is more common for elliptic curves.
Signature Algorithm: The source of randomness, , is the same as DSA. However, is now a curve point calculated as .
In DSA, the one-time random key was a digest of with some bits of information lost through a smaller modulo operation, when was in a larger field of order . Similarly, in ECDSA is calculated as a digest from the curve point by taking its coordinate and then passing it through modulo ,
Again, the group operations (exponentiation) in this computation is the most computationally expensive part of the signing operation, but it may be computed before the message is known. needs to be randomly chosen such that , the identity element of the elliptic curve at infinity.
The inverse and the signature are computed exactly in the same way as DSA,
The signed message is then published.
Verification Algorithm: Once again, as a preliminary, the algorithm checks that , and then computes (usually using EEA for efficiency).
It is still the case that . Again, the verifier does not know the private key to be able to check this. Similarly, since is the generator of with order , the group encrypted version of this relationship is the same as , and is much more useful, as it replaces the private key with the public key if the correct set of simplification steps take place.This could further be improved to,which interlocks to each other. Verifying this relationship is enough to verify that the signature matches the message/sender pair , which can be done efficiently.
As we can see in all of these three algorithm, ECDSA is almost exactly the same as DSA except that the subgroup used is changed from a modulo group to an elliptic curve (digest operation to compute the one-time key also has a slight change).
Circuit constraints: Again, we discuss the circuit constraints that replicate the verification algorithm in proving that the signature in a signed message matches the message-sender pair .
The advice variables are, the output of the hash function , the inverse of variable (modulo ) , quotients for modulo operations , the coordinates and various intermediate computations .
Given a witness, inputs + advice variables,
the following set of circuit constraints can be used to verify the authenticity of a signed message, Now, multiplications in the constraints with and are no longer integer constraints but elliptic curve constraints, which will have to be expanded to the specific integer computations involved in the group operation of the curve.
Aside from that, the only difference between these constraints and those of DSA is the addition of as advice variables that represent the coordinates of the elliptic curve point corresponding to and the removal of the quotients related to modulo .