[erlang-questions] Use new crypto functions

Ingela Andin <>
Tue Nov 19 15:54:38 CET 2013


Hi!

The new API does not want any mpints (binaries with size tags) so if you
hade mpints as input you will have to remove the size tag. If you used
erlang integers there will not be any need to make any changes.

Regards Ingela Erlang/OTP team - Ericsson AB


2013/11/19 pablo platt <>

> Hi,
>
> I'm trying to replace the deprecated crypto functions dh_generate_key/1
> and dh_compute_key/3 with the new functions generate_key/2 and
> compute_key/3 but my app fails.
>
> The byte_size of the results are different between the old and new API:
> Old:
> PublicKey - 132 Bytes
> PrivateKey - 132 Bytes
> Shared - 128 Bytes
>
> New
> PublicKey - 129 Bytes
> PrivateKey - 129 Bytes
> Shared - 129 Bytes
>
> Shouldn't the functionality and the size of the keys be the same?
> Do I need to change something to make it work?
>
> Code:
>
> Old functions:
> {PublicKey, PrivateKey} = crypto:dh_generate_key([?DH_P, ?DH_G]),
> Shared = crypto:dh_compute_key(ClientKey, PrivateKey, [?DH_P, ?DH_G]),
> <<_:32, PublicKey2/binary>> = PublicKey. % Needed for my app with the old
> API
>
> New functions:
> {PublicKey, PrivateKey} = crypto:generate_key(dh, [?DH_P, ?DH_G]),
> Shared = crypto:compute_key(dh, ClientKey, PrivateKey, [?DH_P, ?DH_G]),
> <<_:32, PublicKey2/binary>> = PublicKey.
>
> % ?DH_P size is 132 Bytes
> % ?DH_G size is 5 Bytes
>
> Thanks
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20131119/b84f1640/attachment.html>


More information about the erlang-questions mailing list