3

I am looking for the methods in CommonCrypto to generate the shared secret based on ECDH (Elliptic curve Diffie–Hellman). I can find proprietary implementations like this one https://github.com/surespot/surespot-ios/blob/master/surespot/encryption/EncryptionController.mm but this one is not using CommonCrypto. The method to calculate the shared secret is called sometimes Key Exchange and includes the calculation of the shared secret. Can someone send a link to the right documentation or to an example that uses CommonCrypto for generating the shared secret based on Elliptic curve Diffie–Hellman?

Simon
  • 509
  • 7
  • 25

1 Answers1

1

Look at CommonCrypto function from CommonECCryptor.h

CCECCryptorComputeSharedSecret( CCECCryptorRef privateKey, CCECCryptorRef publicKey, void *out, size_t *outLen)

It constructs a Diffie-Hellman shared secret with a private and public ECC key. Most information they provide are in the header file's commence lines. Header of CCECCryptorComputeSharedSecret is here

Vlad
  • 1,977
  • 19
  • 44
  • 1
    That is nice but do you have an include path? `#import ` does not work. Is this in the Security Framework? Is it a public API? – zaph Nov 05 '14 at 13:06
  • #import ? My answer's URL links to C/C++ header. C includes headers with #include. – Vlad Nov 05 '14 at 15:24
  • I'm not so modern as you:) I use old C. The test that in particular invokes this function is [here](http://www.opensource.apple.com/source/CommonCrypto/CommonCrypto-60026/CCRegression/CommonCrypto/CommonEC.c) – Vlad Nov 05 '14 at 17:42
  • The issue is iOS that can only use public APIs. – zaph Nov 05 '14 at 19:42
  • The author of question was looking for the methods in CommonCrypto to generate the shared secret based on ECDH. I pointed to the function. The question does not contain any restrictions (App store, language, etc.). Author should decide if his environment allows such method. – Vlad Nov 05 '14 at 21:20
  • The question is tagged "ios", that would be considered a restriction. – zaph Nov 05 '14 at 21:54
  • Zaph, I have no iOS now to test, author didn't share his results. So if you have no updates I will delete my answer. Please let me know. – Vlad Nov 16 '14 at 03:46
  • I think you should look to `SecKeyCopyKeyExchangeResult` for a modern and secure approach and also Apple reccomendation – Fabiosoft Apr 13 '20 at 17:40
  • Is there an example code of how to use CCECCryptorComputeSharedSecret in swift ? with private and public EC keys ? – Max May 26 '20 at 21:58