[erlang-questions] Use new crypto functions

pablo platt pablo.platt@REDACTED
Tue Nov 19 12:09:42 CET 2013


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20131119/91b3feca/attachment.htm>


More information about the erlang-questions mailing list