drand/tlock

Avoid magic numbers

AnomalRoil opened this issue · 3 comments

These values (48, 32, 32) might change if we were to start using another curve than BLS12-381:

kyberPoint, err := readPayloadBytes(rr, 48)
if err != nil {
return tlock.CipherInfo{}, fmt.Errorf("failed to read kyber point: %w", err)
}
cipherV, err := readPayloadBytes(rr, 32)
if err != nil {
return tlock.CipherInfo{}, fmt.Errorf("failed to read cipher v: %w", err)
}
cipherW, err := readPayloadBytes(rr, 32)

Not sure what's the best solution:

  • have them be const in a constant.go file?
  • have a way to determine them from the encrypted file?

WDYT @nikkolasg ? Do we have them somewhere already as part of the current "scheme-name" drand is using? I don't think so.

The length are present in the suite
https://github.com/drand/kyber/blob/master/group.go#L171-L174
So using the suite as in drand will make these generic over the curve's length

I have added constants for everything and included calculating the size of the PEM labels. If you decide to add these constants the code can be easily changed.

There are no more magic numbers. Everything has a constant.