hyperledger / aries-askar

Secure storage designed for Hyperledger Aries agents.
Apache License 2.0
58 stars 42 forks source link

Bls12381G2 key created with Askar vs Mattr based on same seed give different key #219

Open TimoGlastra opened 5 months ago

TimoGlastra commented 5 months ago

Is it expected that the same seed as input for Bls12381G2 key in the Mattr key generator from seed, results in the same private key being generated in Askar?

The seed testseed000000000000000000000001, gives me the following results (base64 encoded)

{
  mattrKey: 'tkKNXrPdZPclfBOlfJVp96+RQLH28zqC809wHsPBtH4S3rpQ1GezEaXaswI6sVrFBcFYuUB+efEgYwu8X2nk7II4VswwTfup9J3l+YODt9Tv6TKdu9t3uPlUepRY0Yur',
  askarKey: 'pcXFzjM1/CR9Jq/1fN0C3CZhk1IUNntgXiqPqy8Zf/dco63UbXbHnVpl0YZ0O9SABuSzuQEQ71T66SWMNwC92A0kHTfB6gz0IAbOF2nP4X4JNAfP41W+sV+BpCl2plsh'
}
TimoGlastra commented 5 months ago

Using https://github.com/mattrglobal/bbs-signatures

andrewwhitehead commented 1 month ago

The method the bbs crate uses to generate keys from a seed is here: https://github.com/hyperledger/aries-bbssignatures-rs/blob/main/src/keys.rs#L331

This method is similar to the BLS keygen algorithm, but with Blake2 as the hash algorithm, and a different salt value. Askar currently offers the BLS keygen algorithm as an option when using Key.from_seed("bls12381g2", seed, method="bls_keygen") (in the Python wrapper) so a compatible version could be added based on this method: https://github.com/hyperledger/aries-askar/blob/e2b6f97fd65a691dd5bfd4446478af5a81c793f2/askar-crypto/src/alg/bls.rs#L257