Created
April 9, 2019 18:05
-
-
Save lrascao/22a8f9643edfdde26b4632b7617e36d7 to your computer and use it in GitHub Desktop.
Validating Elliptic curve signatures in Erlang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% check against sigs generated at https://8gwifi.org/ecsignverify.jsp | |
% ideas from https://github.com/0x6e6562/otp_ecc/blob/master/src/otp_ecc.erl | |
Erlang/OTP 19 [erts-8.3] [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false] | |
Eshell V8.3 (abort with ^G) | |
1> PublicBin = <<"-----BEGIN PUBLIC KEY----- | |
1> MFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAElMlYUyrmL2UJV7hlug5/p1eeoOmXptgM | |
1> 3K4h8opBX3rGSFHhOIA2Yw1DBKCXKC8cGnNEUsmCunslB1OaYcFinw== | |
1> -----END PUBLIC KEY----- | |
1> ">>. | |
<<"-----BEGIN PUBLIC KEY-----\nMFYwEAYHKoZIzj0CAQYFK4EEAAoDQgAElMlYUyrmL2UJV7hlug5/p1eeoOmXptgM\n3K4h8opBX3rGSFHhOIA2Yw1D"...>> | |
2> [PublicPemEntry] = public_key:pem_decode(PublicBin), PublicKey = public_key:pem_entry_decode(PublicPemEntry). | |
{{'ECPoint',<<4,148,201,88,83,42,230,47,101,9,87,184,101, | |
186,14,127,167,87,158,160,233,151,166,216, | |
12,220,...>>}, | |
{namedCurve,{1,3,132,0,10}}} | |
3> Sig = <<"MEQCIARxV3Lmms1vLhdlShi6qyfA+wu7fWrttekksOk/o/FbAiA0Y5/yYI4yAuXKqO/zrQjkju+hMfGw8Jus8V5b/hVTLQ==">>. | |
<<"MEQCIARxV3Lmms1vLhdlShi6qyfA+wu7fWrttekksOk/o/FbAiA0Y5/yYI4yAuXKqO/zrQjkju+hMfGw8Jus8V5b/hVTLQ==">> | |
4> public_key:verify(<<"a">>, sha256, base64:decode(Sig), PublicKey). | |
true | |
5> public_key:verify(<<"aa">>, sha256, base64:decode(Sig), PublicKey). | |
false | |
6> f(Sig). | |
ok | |
7> Sig = <<"MEUCIQCFjP4VGwDmCcGLbPWUtJdY67TuaohaNipgbBiGriw1GQIgERxAwDiVQs3c6hy4beMaz5BDVk12fr3mf3gScKFDQYA=">>. | |
<<"MEUCIQCFjP4VGwDmCcGLbPWUtJdY67TuaohaNipgbBiGriw1GQIgERxAwDiVQs3c6hy4beMaz5BDVk12fr3mf3gScKFDQYA=">> | |
8> public_key:verify(<<"aa">>, sha256, base64:decode(Sig), PublicKey). | |
true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment