Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Hasher Factory #365

Merged
merged 2 commits into from Feb 8, 2017
Merged

Create Hasher Factory #365

merged 2 commits into from Feb 8, 2017

Conversation

gdbelvin
Copy link
Contributor

@gdbelvin gdbelvin commented Feb 7, 2017

  • Support looking up the hasher based on the log config.
  • Create a separate, test hasher for use in tests.
    This supports future decoupling of tests from hard-coded values.
  • Moves RFC6962 hasher into its own module.

Partial work towards #331

@Martin2112
Copy link
Contributor

Did this get rebased after #364?

@gdbelvin
Copy link
Contributor Author

gdbelvin commented Feb 8, 2017

This is rebased and ready for review

// See the License for the specific language governing permissions and
// limitations under the License.

package rfc6962
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably this should be part of the personality specific code but I don't think we can do this without having a dependency from generic -> personality that we don't want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. There's a lot of places in the code where this is either hard-coded, supposed to be looked up from the log config.

Hopefully this change to putting this hashing algorithm in it's own package will make it easier to isolate the personality specific stuff later.

// TODO(Martin2112): Hasher must be selected based on log config.
hasher, err := merkle.Factory("RFC6962-SHA256")
if err != nil {
panic("Uknown hash strategy")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -160,15 +160,23 @@ func (t *readOnlyLogTX) GetActiveLogIDsWithPendingWork() ([]int64, error) {
return getActiveLogIDsWithPendingWork(t.tx)
}

func (m *mySQLLogStorage) hasher(treeID int64) (merkle.TreeHasher, error) {
// TODO: read hash algorithm from storage.
return merkle.Factory("RFC6962-SHA256")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking we should declare these hasher type strings as constants then IDEs can find usages of them easily.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

)

// Hasher is the default hasher for tests.
// TODO: Make this a custom algorithm to decouple hashing from coded defaults.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do this soon after this PR? It would show up if there's any RFC6962 specific assumptions in the generic code. There shouldn't be but it's possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can do this very soon. Doing this means re-writing the tests such that they don't depend on test vectors that are specific to this hash function. Anyone want to volunteer?

HashEmpty() []byte
HashLeaf(leaf []byte) []byte
HashChildren(l, r []byte) []byte
Size() int
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like Size() for the name of this method but that's what the Go crypto uses so we can leave it like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a future PR we can rename this BitLength() and return the number of bits in the hash to as to remove many of the Size()*8 bits I see in the code.

@@ -27,7 +27,7 @@ import (

// This root was calculated with the C++/Python sparse Merkle tree code in the
// github.com/google/certificate-transparency repo.
const sparseEmptyRootHashB64 = "xmifEIEqCYCXbZUz2Dh1KCFmFZVn7DUVVxbBQTr1PWo="
var sparseEmptyRootHashB64 = testonly.MustDecodeBase64("xmifEIEqCYCXbZUz2Dh1KCFmFZVn7DUVVxbBQTr1PWo=")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to break if you change the testonly hasher? Add a TODO if so.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please clarify?

  • This doesn't change the behavior of the test as is - so it passes.
  • If we changed the test only hasher, yes, this would break. A stronger test would compute this properly based on the hasher, but there's not enough documentation on how the test vector was computed to do so.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just meant to TODO it to switch this to a generic test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added todo

- Support looking up the hasher based on the log config.
- Create a separate, test hasher for use in tests.
  This supports future decoupling of tests from hard-coded values.
- Moves RFC6962 hasher into its own module.
@gdbelvin gdbelvin merged commit f59017a into google:master Feb 8, 2017
@gdbelvin gdbelvin deleted the testhasher branch July 4, 2017 09:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants