Fine vs Coarse grained crypto API
Is there any good reason for picki开发者_运维百科ng a coarse api over a fine grained one especially for crypto processing?
Coarse:
AESDecrypt(pad_type,
mode_type,
mode_data, /* CTR or IV */
ciphertext,
plaintext)
Fine:
AES128_ECB_Decrypt(ciphertext, plaintext)
AES128_CBC_PKCS5_Decrypt(iv, ciphertext, plaintext)
AES128_CBC_NOPAD_Decrypt(iv, ciphertext, plaintext)
AES256_CTR_Decrypt(ctr, ciphertext, plaintext)
There is not really any difference in functionality (or security).
With the only one function for all version, you can change the algorithm and mode without recompiling (if your application takes these values from somewhere else), and the library can support new algorithms without API changes.
In the lots of different functions version your application either is locked to a particular algorithm or you need a lot of if/case statements to support multiple ones.
精彩评论