README.txt 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. To realize the AES-CCM functionality using the aes.c interface herewith, pull the files aes-ccm.c and aes.h from the repo: https://github.com/wi-fi-analyzer/crackle, and make the following updates -
  2. ** Update the 'xor_aes_block()' function implementation as below and use.
  3. static void xor_aes_block(u8 *dst, const u8 *src)
  4. {
  5. #ifdef HAVE_ALIGNED_MEM_OPERATION
  6. u32 *d = (u32 *) dst;
  7. u32 *s = (u32 *) src;
  8. *d++ ^= *s++;
  9. *d++ ^= *s++;
  10. *d++ ^= *s++;
  11. *d++ ^= *s++;
  12. #else /* HAVE_ALIGNED_MEM_OPERATION */
  13. u32 i;
  14. for (i = 0; i < 16; i++)
  15. {
  16. *dst++ ^= *src++;
  17. }
  18. #endif /* HAVE_ALIGNED_MEM_OPERATION */
  19. }
  20. ** Update the 'aes_ccm_encr()' function implementation as below and use.
  21. static void aes_ccm_encr(void *aes, size_t L, const u8 *in, size_t len, u8 *out,
  22. u8 *a)
  23. {
  24. size_t last = len % AES_BLOCK_SIZE;
  25. size_t i;
  26. /* crypt = msg XOR (S_1 | S_2 | ... | S_n) */
  27. for (i = 1; i <= len / AES_BLOCK_SIZE; i++) {
  28. PUT_BE16(&a[AES_BLOCK_SIZE - 2], i);
  29. /* S_i = E(K, A_i) */
  30. aes_encrypt(aes, a, out);
  31. xor_aes_block(out, in);
  32. out += AES_BLOCK_SIZE;
  33. in += AES_BLOCK_SIZE;
  34. }
  35. #if 0
  36. if (last) {
  37. PUT_BE16(&a[AES_BLOCK_SIZE - 2], i);
  38. aes_encrypt(aes, a, out);
  39. /* XOR zero-padded last block */
  40. for (i = 0; i < last; i++)
  41. *out++ ^= *in++;
  42. }
  43. #else /* 0 */
  44. if (last) {
  45. u8 tout[AES_BLOCK_SIZE];
  46. PUT_BE16(&a[AES_BLOCK_SIZE - 2], i);
  47. aes_encrypt(aes, a, tout);
  48. /* XOR zero-padded last block */
  49. for (i = 0; i < last; i++)
  50. *out++ = tout[i] ^ *in++;
  51. }
  52. #endif /* 0 */
  53. }