{"action":"created","issue":{"url":"https://api.github.com/repos/DCIT/perl-CryptX/issues/4","repository_url":"https://api.github.com/repos/DCIT/perl-CryptX","labels_url":"https://api.github.com/repos/DCIT/perl-CryptX/issues/4/labels{/name}","comments_url":"https://api.github.com/repos/DCIT/perl-CryptX/issues/4/comments","events_url":"https://api.github.com/repos/DCIT/perl-CryptX/issues/4/events","html_url":"https://github.com/DCIT/perl-CryptX/issues/4","id":144068975,"number":4,"title":"Crypt::PK::DH Improvements","user":{"login":"lkinley","id":2348464,"avatar_url":"https://avatars.githubusercontent.com/u/2348464?v=3","gravatar_id":"","url":"https://api.github.com/users/lkinley","html_url":"https://github.com/lkinley","followers_url":"https://api.github.com/users/lkinley/followers","following_url":"https://api.github.com/users/lkinley/following{/other_user}","gists_url":"https://api.github.com/users/lkinley/gists{/gist_id}","starred_url":"https://api.github.com/users/lkinley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lkinley/subscriptions","organizations_url":"https://api.github.com/users/lkinley/orgs","repos_url":"https://api.github.com/users/lkinley/repos","events_url":"https://api.github.com/users/lkinley/events{/privacy}","received_events_url":"https://api.github.com/users/lkinley/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":6,"created_at":"2016-03-28T20:01:33Z","updated_at":"2016-03-29T22:28:26Z","closed_at":null,"body":"Moving discussion from email.\r\nYou said:\r\n\r\n---QUOTE---\r\nin my opinion the right way is to enhance https://metacpan.org/pod/Crypt::PK::DH#generate_key\r\n\r\nNow it supports only:\r\nmy $pk = Crypt::PK::DH->new();\r\n$pk->generate_key($keysize);\r\n\r\nlike:\r\n$pk->generate_key(256);\r\n\r\nit should be extended to - let's say:\r\n$pk->generate_key({ p=> '62D031C83F4294F64....', g=> '02' });\r\n\r\nIt would be also nice to patch https://metacpan.org/pod/Crypt::PK::DH#key2hash so that key dump contains also p + g (and maybe import/export routines will need some attention as well).\r\n\r\nI did similar kind of extension for EC crypto in https://metacpan.org/pod/Crypt::PK::ECC#generate_key some time ago.\r\n\r\nBut keep in mind that it will need some nontrivial changes to `cryptx/src/ltc/pk/dh/dh.c` especially `dh_make_key`.\r\n\r\nBasically I am not against major redesign of src/ltc/pk/dh/dh.c (I am member of libtomcrypt project so can try to push the changes upstream) but it is definitely a bunch of work.\r\n---END QUOTE---\r\n\r\nOther than supplying p and g to generate the key, I also need the following functionality, which is largely already written:\r\n-Verify that a supplied public key is valid for my private key -- essentially a range check, y > 1 && y < (p - 1) and if g == 2 make sure more than one bit is set in y.\r\n-Return public key in binary format.  Not entirely necessary because we could unpack this from key2hash but nice nonetheless.\r\n\r\nTo modify Crypt::PK:DH, the path forward I see is:\r\n-Add p,g to dh_key\r\n-Remove index field from dh_key\r\n-Redo import/export to include p,g in the packet and not index\r\n-Change dh_get_size to return the used portion of the mp_int instead of looking up in table\r\n-Free p,g parts of key in dh_free\r\n-Change dh_encrypt_key, dh_decrypt_key to use p,g in key \r\n\r\nI am not sure what to do with:\r\n-dh_sizes function (probably leave alone).\r\n\r\nLet me know your thoughts.\r\n"},"comment":{"url":"https://api.github.com/repos/DCIT/perl-CryptX/issues/comments/203138642","html_url":"https://github.com/DCIT/perl-CryptX/issues/4#issuecomment-203138642","issue_url":"https://api.github.com/repos/DCIT/perl-CryptX/issues/4","id":203138642,"user":{"login":"lkinley","id":2348464,"avatar_url":"https://avatars.githubusercontent.com/u/2348464?v=3","gravatar_id":"","url":"https://api.github.com/users/lkinley","html_url":"https://github.com/lkinley","followers_url":"https://api.github.com/users/lkinley/followers","following_url":"https://api.github.com/users/lkinley/following{/other_user}","gists_url":"https://api.github.com/users/lkinley/gists{/gist_id}","starred_url":"https://api.github.com/users/lkinley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lkinley/subscriptions","organizations_url":"https://api.github.com/users/lkinley/orgs","repos_url":"https://api.github.com/users/lkinley/repos","events_url":"https://api.github.com/users/lkinley/events{/privacy}","received_events_url":"https://api.github.com/users/lkinley/received_events","type":"User","site_admin":false},"created_at":"2016-03-29T22:28:26Z","updated_at":"2016-03-29T22:28:26Z","body":"The primes in dh_static.c are not the length they are supposed to be... I think this was alluded to here: [https://github.com/libtom/libtomcrypt/pull/111](url)\r\n\r\nFor example, the DH-768 entry is 786 bits (131 base64 chars, 131 * 6 == 786)\r\nThe DH-4096 entry is 686 chars for 686 * 6 == 4116 bits\r\n\r\nI wonder if there was a reason for this?\r\n"}}