NRF_CRYPTO AESCCM and python AES CCM encryption not gives the same output

Hi Nordic Team,

NRF crypto example  AES CCM main.c code follows NIST standards and  Pycryptodome library follows the same. I tried encryption on both platform but the results will be different, So How can I match the outputs. Suggest any methods to sync the same.  

The Outputs are given below

C Code Output

Plain text (hex) (len: 3) ----41 42 43

Encrypted text (hex) (len: 3) ----86 9E 06

MAC (hex) (len: 4) ---- 06 C6 68 5D

Python Code Output

Plain text -- 414243

Ciphertext: --e1 29 d1

MAC:-- bc 3a b0 c8

 I hereby attached the python code. The parameters of AES CCM are same for both python and C code 

Parents
  • Hello,

    Did you modify main.c and sdk_config.h to use an AES 256-bit cipher? Note: cc310 does not support 256-bit keys.

    Best regards,

    Vidar

  • Hi Vedar 

    In nrf5 sdk 17.0.2->examples->crypto->nrf_crypto->aes->aes_ccm this location had on main.c file 

    I worked on this file for aes ccm encryption and decryption. In this file key size is 256bit only. So how can I sync the output of device and python/android app. Is there is any other file to encrypt the data via aes ccm?  

Reply
  • Hi Vedar 

    In nrf5 sdk 17.0.2->examples->crypto->nrf_crypto->aes->aes_ccm this location had on main.c file 

    I worked on this file for aes ccm encryption and decryption. In this file key size is 256bit only. So how can I sync the output of device and python/android app. Is there is any other file to encrypt the data via aes ccm?  

Children
  • You are selecting a 128-bit chipher in your init function here:

    If you want to use a 256-bit chipher, you need to change g_nrf_crypto_aes_ccm_128_info to g_nrf_crypto_aes_ccm_256_info and enable the mbedtls AES backend by setting NRF_CRYPTO_BACKEND_CC310_AES_CCM_ENABLED to '0' and NRF_CRYPTO_BACKEND_MBEDTLS_AES_CCM_ENABLED to '1'

  • I just tried with 128 bit key the output is not same. I tried one example from NIST_800_38C document  example 1. In python library gives the same output but nrf52840 gives different output.  

    Clipped From NIST 800-38c

    My constraints is not to match the 128 0r 256 bit. I need to match the nrf52840 and python script output. 

  • I'm able to match the output from the c code and the python script when using the original input you posted.

  • Thanks Vidar, Now its works good, the outputs are perfectly matched.

    Best Regards 

    Sriyogesh Gopal 

  • I'm glad to hear that. Thank you for the update, Sriyogesh.