The Common Crypto library, also known as CCCrypt and 3CC, provide access to a number of types and flavors of encryption algorithms. The Common Crypto library of functions supports AES, DES, 3DES, and other encryption standards. Depending on the encryption algorithm used, block and/or stream ciphers are available.
在OS X v10.5 and later and iOS 5.0 and later 的系统中,Common Crypto成为用于加解密的被推荐的API。而之前的CDSA/CSSM则不被推荐使用。Apple的官方文档对Common Crypto介绍不多,只有manpage。现在我要从结构的角度介绍一下Common Crypto。
简单说Common Crypto就是一组API提供symmetric加解密相关的APIs。更具体而言,Common Crypto提供的API按照功能类别被声明在5个header file中,分别是:
- CommonCryptor.h: 由CCCryptoRef对象提供使用AES128,DES,3DES,CAST,RC4,RC2算法的block cipher或者stream cipher;
- CommonDigest.h:支持MD2、MD4、MD5、SHA1、SHA224、SHA256、SHA384和SHA512等hash算法;
- CommonHMAC.h:HMAC是Hash-based message authentication code,
- CommonKeyDerivation.h:提供derive key的API;
- CommonSymmetricKeywrap.h: 提供wrap/unwrap a symmetric key with a Key Encription Key(KEK is key used to protect other keys);
应该来说,Common Crypto提供的功能还是很丰富的,类似于一个CSP提供的功能。