AES Encryption and Decryption using CCM mode

I am trying to write and code of aes encryption and decryption using ccm mode for my application on nrf52832 controller. I have went through some example on Github for the same and took the function from there the git link is "https://github.com/NordicPlayground/nrf52-esb-ccm-example.git" form this in the common folder took files og ccm_crypt.c and ccm_crypt.h and integrated with my project my project code is.
int main(void)
{
  /* Initialise the system clock */
  InitSysClock();
  /* Initialise the Gpios */
  InitSysGpios();

  // Initialize the CCM
  ccm_crypt_init();

  // Prepare the pair request
  ccm_pair_request_packet_t request_out;
  ccm_passkey_t passkey = {0}; // Replace with your passkey
  uint32_t result = ccm_crypt_pair_request_prepare(passkey, &request_out);

  if (result != CCM_CRYPT_SUCCESS)
  {
    printf("Error preparing pair request\n");
    while(1);
  }

  // Accept the pair request
  result = ccm_crypt_pair_request_accept(passkey, &request_out);

  if (result != CCM_CRYPT_SUCCESS)
  {
    printf("Error accepting pair request\n");
    while(1);
  }

  uint8_t plaintext[16] = "This is a test!"; // Your 16-byte plaintext
  uint8_t encrypted_text[20]; // Encrypted text (16-byte ciphertext + 4-byte MAC)
  uint8_t decrypted_text[16]; // Decrypted text (16-byte plaintext)

  // Encrypt a packet
  result = ccm_crypt_packet_encrypt(plaintext, sizeof(plaintext), encrypted_text);

  if (result != CCM_CRYPT_SUCCESS)
  {
    printf("Error encrypting packet\n");
    while(1);
  }

  // Print the plaintext and the encrypted text
  print_data("Plaintext", plaintext, sizeof(plaintext));
  print_data("Encrypted text", encrypted_text, sizeof(encrypted_text));

  // Now let's decrypt the encrypted text
  result = ccm_crypt_packet_decrypt(encrypted_text, sizeof(encrypted_text) - 1, decrypted_text);

  if (result == CCM_CRYPT_SUCCESS)
  {
    // Print the decrypted text
    print_data("Decrypted text", decrypted_text, sizeof(decrypted_text));
  }
  else
  {
    while(1);
  }

  return 0;
}
Now when I amtrying to execute the code it is getting stuck ccm_crypt_pair_request_prepare(passkey, &request_out); my preduction it is not able to generate the key. Can you Help me with this?

Related