crypto:dss_sign() fails with bad argument
Kaiduan Xie
kaiduanx@REDACTED
Sat May 8 04:12:26 CEST 2010
After looking the file pubkey_crypto.erl in Erlang/OTP source, I found
the right way as below,
crypto:dss_sign(sized_binary(Bin), [P, Q, G, X]).
sized_binary(Bin) when is_binary(Bin) ->
<<(size(Bin)):32/integer, Bin/binary>>;
sized_binary(List) when is_list(List) ->
sized_binary(list_to_binary(List)).
Another question comes naturally, given a public DSA key in PEM format
to verify, how to get the [P, Q, G, Y] from the public key?
1> public_key:pem_to_der("./pub.pem").
{ok,[]}
2> public_key:pem_to_der("./dsaparam.pem").
{ok,[]}
Thanks,
Kaiduan
On Fri, May 7, 2010 at 7:18 PM, Kaiduan Xie <kaiduanx@REDACTED> wrote:
> Hi,
>
> I am playing with erlang's crypto module for DSS sign/verification,
> and encountered the following failure,
>
> kaiduanx@REDACTED:~/test$ erl
> Erlang (BEAM) emulator version 5.6.5 [source] [async-threads:0] [hipe]
> [kernel-poll:false]
>
> Eshell V5.6.5 (abort with ^G)
> 1> {ok, [Key1]} = public_key:pem_to_der("./privkey.pem").
> {ok,[{dsa_private_key,<<48,130,3,61,2,1,0,2,130,1,1,0,130,
> 155,217,13,154,35,30,61,35,193,
> 177,89,...>>,
> not_encrypted}]}
> 2> {ok, DSAPrivKey} = public_key:decode_private_key(Key1).
> {ok,{'DSAPrivateKey',0,
>
> 16487831091520780258476244829269954905068453299919937468122754367555025389255228167104813916584427117132491697333745898571447582288126735030379964082170022817274086858448078061001221776403199146387597678984540700662102497749323871708629057309007645527617512892347216241068519054813731565592382595863130859729188869666097096597640296820469239977991443749290028015703576616678053020176398097226185345390078018458880065671569994747328759201284973167049924181380228215122295761433727402740292339377060448621018652887515687347119246401586369278290721630262294672892581614282203303348001277520129700110248972612083036183823,
> 1069445346270440656593824092073657983328499138457,
>
> 7214566675159847510543550105259613160453301579561623377843203423614163319395145087833198636004278609701319277802567885081948001327800441061451495445964179176778711411229815801134094069049261847343045298683209010702015484647378262734006939008757875094544682692811028223303902447231625138361611541322285116859770078463180719920891946211261933346941519603064902060705607105259990741513856339667300139111109012511141655066131159463312192937454414940901992301247028509228326669147276129260865537192028595304014436739105124361395299086087865530512935899515885409929656072537826761802885019421821204505764703508239164324041,
>
> 7633100674515027235650509950891694304003982881440195652180376335259908594946224965667327027587338158513959931360517774019595393102978917235479651037021972646784210191530035858681332371458695842841098509902898010434270664893194727388258476377361344595538044057461379480170807524999310663741254536687833627343418977980237734999549443057990979136155378902597245536582084684912096597468826612905623557372778470587564770314993903695513057146844763692020381754294541184291650680501093631643506634398260717309523197216269415879496293970907691201898118313013181084633883085546050181063797462116224600567526013743839898981226,
> 495667775549172824486294937719319801999514557700}}
> 3> {_, 0, P, Q, G, Y, X} = DSAPrivKey.
> {'DSAPrivateKey',0,
>
> 16487831091520780258476244829269954905068453299919937468122754367555025389255228167104813916584427117132491697333745898571447582288126735030379964082170022817274086858448078061001221776403199146387597678984540700662102497749323871708629057309007645527617512892347216241068519054813731565592382595863130859729188869666097096597640296820469239977991443749290028015703576616678053020176398097226185345390078018458880065671569994747328759201284973167049924181380228215122295761433727402740292339377060448621018652887515687347119246401586369278290721630262294672892581614282203303348001277520129700110248972612083036183823,
> 1069445346270440656593824092073657983328499138457,
>
> 7214566675159847510543550105259613160453301579561623377843203423614163319395145087833198636004278609701319277802567885081948001327800441061451495445964179176778711411229815801134094069049261847343045298683209010702015484647378262734006939008757875094544682692811028223303902447231625138361611541322285116859770078463180719920891946211261933346941519603064902060705607105259990741513856339667300139111109012511141655066131159463312192937454414940901992301247028509228326669147276129260865537192028595304014436739105124361395299086087865530512935899515885409929656072537826761802885019421821204505764703508239164324041,
>
> 7633100674515027235650509950891694304003982881440195652180376335259908594946224965667327027587338158513959931360517774019595393102978917235479651037021972646784210191530035858681332371458695842841098509902898010434270664893194727388258476377361344595538044057461379480170807524999310663741254536687833627343418977980237734999549443057990979136155378902597245536582084684912096597468826612905623557372778470587564770314993903695513057146844763692020381754294541184291650680501093631643506634398260717309523197216269415879496293970907691201898118313013181084633883085546050181063797462116224600567526013743839898981226,
> 495667775549172824486294937719319801999514557700}
> 4>
> 4> crypto:start().
> ok
> 5> crypto:dss_sign(list_to_binary("Welcome to erlang land"),
> [crypto:mpint(P), crypto:mpint(Q), crypto:mpint(G), crypto:mpint(X)]).
> ** exception error: bad argument
> in function port_control/3
> called as port_control(crypto_drv02,38,
> [<<"Welcome to erlang land">>,
> [<<0,0,1,1,0,130,155,217,13,154,35,30,61,35,
> 193,177,89,67,155,111,87,191,198,...>>,
> <<0,0,0,21,0,187,83,150,127,162,157,203,222,
> 11,119,150,240,120,83,23,248,64,...>>,
> <<0,0,1,0,57,38,127,21,93,84,216,239,141,178,
> 131,95,23,15,1,197,166,...>>,
> <<0,0,0,20,86,210,131,3,27,84,85,4,140,24,
> 92,36,218,245,126,21,...>>]])
> in call from crypto:control/2
> in call from crypto:dss_sign/2
> 6> crypto:dss_sign(list_to_binary("Welcome to erlang land"), [P, Q, G,
> X]). ** exception error: bad argument
> in function port_control/3
> called as port_control(crypto_drv02,38,
> [<<"Welcome to erlang land">>,
>
> [16487831091520780258476244829269954905068453299919937468122754367555025389255228167104813916584427117132491697333745898571447582288126735030379964082170022817274086858448078061001221776403199146387597678984540700662102497749323871708629057309007645527617512892347216241068519054813731565592382595863130859729188869666097096597640296820469239977991443749290028015703576616678053020176398097226185345390078018458880065671569994747328759201284973167049924181380228215122295761433727402740292339377060448621018652887515687347119246401586369278290721630262294672892581614282203303348001277520129700110248972612083036183823,
>
> 1069445346270440656593824092073657983328499138457,
>
> 7214566675159847510543550105259613160453301579561623377843203423614163319395145087833198636004278609701319277802567885081948001327800441061451495445964179176778711411229815801134094069049261847343045298683209010702015484647378262734006939008757875094544682692811028223303902447231625138361611541322285116859770078463180719920891946211261933346941519603064902060705607105259990741513856339667300139111109012511141655066131159463312192937454414940901992301247028509228326669147276129260865537192028595304014436739105124361395299086087865530512935899515885409929656072537826761802885019421821204505764703508239164324041,
>
> 495667775549172824486294937719319801999514557700]])
> in call from crypto:control/2
> in call from crypto:dss_sign/2
> 7>
>
> 9> crypto:info_lib().
> [{<<"OpenSSL">>,9470079,<<"OpenSSL 0.9.8g 19 Oct 2007">>}]
>
> The privkey.pem is generated by openssl as below,
> openssl dsaparam -out dsaparam.pem 2048
> openssl gendsa -out privkey.pem dsaparam.pem
>
> Can someone point out what is going wrong? Thanks for help,
>
> Kaiduan
>
More information about the erlang-questions
mailing list