Add AES-CCM and CAMELLIA-CCM to the cipher layer
diff --git a/library/cipher.c b/library/cipher.c
index d8b416a..4f76b48 100644
--- a/library/cipher.c
+++ b/library/cipher.c
@@ -42,6 +42,10 @@
#include "polarssl/gcm.h"
#endif
+#if defined(POLARSSL_CCM_C)
+#include "polarssl/ccm.h"
+#endif
+
#include <stdlib.h>
#if defined(POLARSSL_ARC4_C) || defined(POLARSSL_CIPHER_NULL_CIPHER)
@@ -818,7 +822,16 @@
iv, iv_len, ad, ad_len, input, output,
tag_len, tag ) );
}
-#endif
+#endif /* POLARSSL_GCM_C */
+#if defined(POLARSSL_CCM_C)
+ if( POLARSSL_MODE_CCM == ctx->cipher_info->mode )
+ {
+ *olen = ilen;
+ return( ccm_encrypt_and_tag( ctx->cipher_ctx, ilen,
+ iv, iv_len, ad, ad_len, input, output,
+ tag, tag_len ) );
+ }
+#endif /* POLARSSL_CCM_C */
return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
}
@@ -848,7 +861,23 @@
return( ret );
}
-#endif
+#endif /* POLARSSL_GCM_C */
+#if defined(POLARSSL_CCM_C)
+ if( POLARSSL_MODE_CCM == ctx->cipher_info->mode )
+ {
+ int ret;
+
+ *olen = ilen;
+ ret = ccm_auth_decrypt( ctx->cipher_ctx, ilen,
+ iv, iv_len, ad, ad_len,
+ input, output, tag, tag_len );
+
+ if( ret == POLARSSL_ERR_CCM_AUTH_FAILED )
+ ret = POLARSSL_ERR_CIPHER_AUTH_FAILED;
+
+ return( ret );
+ }
+#endif /* POLARSSL_CCM_C */
return( POLARSSL_ERR_CIPHER_FEATURE_UNAVAILABLE );
}