Equal checks equality of two secret sharing polynomials p and q. If p and q are trivially unequal (e.g., due to mismatching cryptographic groups or polynomial size), this routine returns in variable time. Otherwise it runs in constant time regardless of whether it eventually returns true or false.
(q *PriPoly)
| 115 | // returns in variable time. Otherwise it runs in constant time regardless of whether it |
| 116 | // eventually returns true or false. |
| 117 | func (p *PriPoly) Equal(q *PriPoly) bool { |
| 118 | if p.g.String() != q.g.String() { |
| 119 | return false |
| 120 | } |
| 121 | if len(p.coeffs) != len(q.coeffs) { |
| 122 | return false |
| 123 | } |
| 124 | b := 1 |
| 125 | for i := 0; i < p.Threshold(); i++ { |
| 126 | pb, _ := p.coeffs[i].MarshalBinary() |
| 127 | qb, _ := q.coeffs[i].MarshalBinary() |
| 128 | b &= subtle.ConstantTimeCompare(pb, qb) |
| 129 | } |
| 130 | return b == 1 |
| 131 | } |
| 132 | |
| 133 | // Commit creates a public commitment polynomial for the given base point b or |
| 134 | // the standard base if b == nil. |