godot icon indicating copy to clipboard operation
godot copied to clipboard

Update CryptoKey documentation to mention ECC.

Open basicer opened this issue 10 months ago • 3 comments

The documentation makes it seem like CryptoKey can only hold an RSA key. This is compounded by the fact that Cypto only has a function generate an RSA based key. Godot however is perfectly happy loading and using ECC based keys.

basicer avatar Apr 30 '24 06:04 basicer

Example showing signing and verifying with an secp256k1 key.

var key = CryptoKey.new()
key.load_from_string("""-----BEGIN EC PRIVATE KEY-----
MHQCAQEEIGIumMFpusqAcqCkwN15oFS/QXNIf9LsmTCYMNwp9/G8oAcGBSuBBAAK
oUQDQgAEigp/7pvDMxn0mNDDuJuepWgWeXTw71jNk/aSo8LqyTSHXULaUbZh3G57
G3P3LqXcwRgm2Wz7J+9JoGzDokr1Pw==
-----END EC PRIVATE KEY-----""")

print(key.save_to_string())
print(key.save_to_string(true))
var pub = CryptoKey.new()
pub.load_from_string(key.save_to_string(true), true)

var ctx = HashingContext.new()
ctx.start(HashingContext.HASH_SHA256)
ctx.update("Hi!".to_ascii_buffer())
var hash = ctx.finish()


var sig = Crypto.new().sign(HashingContext.HASH_SHA256, hash, key)
print("SIG", sig)
print("Ok?", Crypto.new().verify(HashingContext.HASH_SHA256, hash, sig, pub))

basicer avatar Apr 30 '24 07:04 basicer

As we're just passing this through to mbedtls, I'd expect both RSA and ECC to work, yes. Adding a link to the Crypto class for actually generating keys would also make sense. We should also add ECC key generation there. :) Would be worth opening an issue for.

mhilbrunner avatar Apr 30 '24 08:04 mhilbrunner

We should also add ECC key generation there.

I was looking into this, but held off for now. It needs a bit of API design on how the user specifies which curve they want to use and also how to enumerate the available curves along with their bit size.

basicer avatar May 01 '24 03:05 basicer

Could you amend the commit message to be more explicit, like the PR title?

Edit: Let me know if you're not familiar with how to do this with Git, I can also do this update myself.

akien-mga avatar May 08 '24 11:05 akien-mga

@semensanyok Hi, does this fix work for you? I tried to follow your changes to modify this

case FORMAT_BPTC_RGBA:
	return 4; //btpc bc6h

Does it fix everything for you? Not working well for me, I am trying to figure out which part I get wrong.

there is also diff in drivers/gles3/storage/texture_storage.cpp in my PR (https://github.com/godotengine/godot/pull/91508), did you miss it by any chance? its not like your's

~~answering your question - yes it does, and switching layer in shader works for all profiles, loading all 4 layers for 4 textures correctly.~~

nope looks like its not fixed, cached version, keep looking. forward is broken currently by this draft

P.S. its wrong, 1 is correct value, forget this diff

basicer avatar May 09 '24 03:05 basicer

Thanks!

akien-mga avatar May 10 '24 07:05 akien-mga