How to compile and use CommonCrypto for iOS 4?

大憨熊 提交于 2019-12-13 20:31:12

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/9958661/how-to-compile-and-use-commoncrypto-for-ios-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!