Question

Since CCKeyDerivationPBKDF is not available until after iOS 5.0, people have suggested using the open source code for CommonCrypto available here:

http://www.opensource.apple.com/source/CommonCrypto/CommonCrypto-55010/

My question is - how does one use this open source code in an existing project? Should we create dylib and somehow include it in the project or take the source code files and add them to the existing project? How do you do it in Xcode? How do you make sure that at run-time on iOS 4 device/simulator, it finds the function?

Thanks.

Était-ce utile?

La solution

I had to include CommonKeyDerivation.c, CommonKeyDerivation.h, CommonKeyDerivationPriv.h in my Xcode project, but that was enough – because it seems other supporting/underlying functions needed by CCKeyDerivationPBKDF are already included in iOS4 CommonCrypto.

Autres conseils

To summarize, since @Raj Lalwani's answer is not fully complete - some details were left out!!!

Three files:

  • CommonKeyDerivation.c
  • CommonKeyDerivation.h
  • CommonKeyDerivationPriv.h

In the source for CommonKeyDerivation.c, at the below of the standard Apple license comment, insert this:

#define KERNEL

This will shut off the compiler error.

In the source for CommonKeyDerivation.h, there's two prototypes as shown:

int 
CCKeyDerivationPBKDF( CCPBKDFAlgorithm algorithm, const char *password, size_t passwordLen,
                      const uint8_t *salt, size_t saltLen,
                      CCPseudoRandomAlgorithm prf, uint rounds, 
                      uint8_t *derivedKey, size_t derivedKeyLen)
                      __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);

And

uint
CCCalibratePBKDF(CCPBKDFAlgorithm algorithm, size_t passwordLen, size_t saltLen,
                 CCPseudoRandomAlgorithm prf, size_t derivedKeyLen, uint32_t msec)
                 __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA);

Change the __OSX_AVAILABLE_STARTING(__MAC_10_7, __IPHONE_NA) to this __OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_4_2) if on Snow Leopard targetting iOS 4.2.

You may have to specify a include path in the build options.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top