This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

There's a problem encrypting the sensor values.

Hello

I am using SDK v17.0.2 and nrf52DK.  I am trying to encrypt and  output the saadc value of the sensor.

I used the AES CTR example almost exactly the same.  

And I encrypted the value of the sensor using sprintf as shown below.

    for (;;)
    {
        idle_state_handle();

          if(adc_value > 0)
          {
            //sensor data -> string
            sprintf(m_plain_text, "%d", adc_value); //error : The length of the one or more output arguments was too small (longer than 16 char?)
            crypt_ctr();

            adc_value = 0;
          }
    }

And when encryption is performed, the following error is printed.

-Plain text-
410 //sensor value

Error = 0x8514
The length of the one or more output arguments was too small

If I write a long string for encryption, it will be output properly.  I have modified the two values below to change the length of the encryption string, but if I modify it, an error will be output from peer_manager_init.

#define SEC_PARAM_MIN_KEY_SIZE       7  /**< Minimum encryption key size. */
#define SEC_PARAM_MAX_KEY_SIZE       16 /**< Maximum encryption key size. */

.
.
.

/**@brief Function for the Peer Manager initialization.
 */
static void peer_manager_init(void)
{
    ble_gap_sec_params_t sec_param;
    ret_code_t           err_code;

    err_code = pm_init();
    APP_ERROR_CHECK(err_code);

    memset(&sec_param, 0, sizeof(ble_gap_sec_params_t));

    // Security parameters to be used for all security procedures.
    sec_param.bond           = SEC_PARAM_BOND;
    sec_param.mitm           = SEC_PARAM_MITM;
    sec_param.lesc           = SEC_PARAM_LESC;
    sec_param.keypress       = SEC_PARAM_KEYPRESS;
    sec_param.io_caps        = SEC_PARAM_IO_CAPABILITIES;
    sec_param.oob            = SEC_PARAM_OOB;
    sec_param.min_key_size   = SEC_PARAM_MIN_KEY_SIZE;
    sec_param.max_key_size   = SEC_PARAM_MAX_KEY_SIZE;
    sec_param.kdist_own.enc  = 1;
    sec_param.kdist_own.id   = 1;
    sec_param.kdist_peer.enc = 1;
    sec_param.kdist_peer.id  = 1;

    err_code = pm_sec_params_set(&sec_param); //error
    APP_ERROR_CHECK(err_code);

    err_code = pm_register(pm_evt_handler);
    APP_ERROR_CHECK(err_code);
}

How do I change the length of the data string to be used for encryption?

Thank you.

Parents
  • Hello,

    If I recall correctly, the plaintext has to be the same number of bytes or more as the size of the block chiper (16 bytes if you use 128 bit AES  key, or 32if you use 256-bit). Can you try to append '0' padding to your sensor data and see if it works then?

    e.g.,

    uint8_t sensor_data_w_padding[32];

    memset(sensor_data_w_padding, 0, sizeof(sensor_data_w_padding));

    memcpy(sensor_data_w_padding, sensor data, <len of sensor data in bytes));

Reply
  • Hello,

    If I recall correctly, the plaintext has to be the same number of bytes or more as the size of the block chiper (16 bytes if you use 128 bit AES  key, or 32if you use 256-bit). Can you try to append '0' padding to your sensor data and see if it works then?

    e.g.,

    uint8_t sensor_data_w_padding[32];

    memset(sensor_data_w_padding, 0, sizeof(sensor_data_w_padding));

    memcpy(sensor_data_w_padding, sensor data, <len of sensor data in bytes));

Children
No Data
Related