1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis
3 * LibTomCrypt is a library that provides various cryptographic
4 * algorithms in a highly modular and flexible manner.
6 * The library is free for all purposes without any express
14 Initialize a CCM state
15 @param ccm The CCM state to initialize
16 @param cipher The index of the cipher to use
17 @param key The secret key
18 @param keylen The length of the secret key
19 @param ptlen The length of the plain/cipher text that will be processed
20 @param taglen The max length of the MAC tag
21 @param aadlen The length of the AAD
23 @return CRYPT_OK on success
25 int ccm_init(ccm_state *ccm, int cipher,
26 const unsigned char *key, int keylen, int ptlen, int taglen, int aadlen)
30 LTC_ARGCHK(ccm != NULL);
31 LTC_ARGCHK(key != NULL);
32 LTC_ARGCHK(taglen != 0);
34 XMEMSET(ccm, 0, sizeof(ccm_state));
36 /* check cipher input */
37 if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
40 if (cipher_descriptor[cipher].block_length != 16) {
41 return CRYPT_INVALID_CIPHER;
44 /* make sure the taglen is even and <= 16 */
47 if (ccm->taglen > 16) {
52 if (ccm->taglen < 4) {
53 return CRYPT_INVALID_ARG;
57 if ((err = cipher_descriptor[cipher].setup(key, keylen, 0, &ccm->K)) != CRYPT_OK) {
62 /* let's get the L value */
79 /* ref: $Format:%D$ */
80 /* git commit: $Format:%H$ */
81 /* commit time: $Format:%ai$ */