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

How to use AES128 ECB for decryption

Hi,

I am using nRF51822, and try to use the ECB block AES128 to do some data decryption. From the SDK I found 2 API functions:

  1. uint32_t sd_ecb_block_encrypt ( nrf_ecb_hal_data_t * p_ecb_data ) Seems this one is only usable for encrypt, can you provide or have a similar one for decrypt?

  2. bool nrf_ecb_crypt ( uint8_t * dst, const uint8_t * src ) This one seems can be used for both encrypt and decrypt, but I am not sure how to specify whether I need to decrypt or encrypt and also how to specify the key correctly, if you have any code snippets or examples that will be really helpful.

Another question is about the data block size, seems it is fixed at 16 bytes now, can I specify a different size or need to cut into 16 byte block in my applicaiton code?

Thanks,

Jun

Parents
  • I am only able to post once so... I edit this one.

    Now I get no errors and warnings building my code but once I try to use AES in order to upload the app code to the nRF51822 BLUETOOTH SMART BEACON KIT, it stop working... The code I used is the following:

    nrf_ecb_hal_data_t *aestructura;

    	*(*aestructura).key=0x12;
    	*(*aestructura).cleartext=16;
    //Aplicacion de AES
    sd_ecb_block_encrypt(aestructura);
    	encriptado=*(*aestructura).ciphertext;
    	printf("Encrypted TEXT: %d",encriptado);
    

    Regards,

    Iván

    I am trying to encypt some data too. I think the first one is the right way in order to encrypt because you have the struct nrf_ecb_hal_data_t which defines the 3 parameters needed for the encryptation. Anyway I don't know what to put in those parameters:

    nrf_ecb_hal_data_t aestructura; aestructura.key=12345678; aestructura.cleartext="what should I put here"; aestructura.ciphertext="what should I put here";

    After that I suppose we only should use the function: sd_ecb_block_encrypt(aestructura));

    And it should give back the encrypted data? Don't know yet.

    I hope some of this can help you a bit, I have many questions though.

    Regards

    Iván

Reply
  • I am only able to post once so... I edit this one.

    Now I get no errors and warnings building my code but once I try to use AES in order to upload the app code to the nRF51822 BLUETOOTH SMART BEACON KIT, it stop working... The code I used is the following:

    nrf_ecb_hal_data_t *aestructura;

    	*(*aestructura).key=0x12;
    	*(*aestructura).cleartext=16;
    //Aplicacion de AES
    sd_ecb_block_encrypt(aestructura);
    	encriptado=*(*aestructura).ciphertext;
    	printf("Encrypted TEXT: %d",encriptado);
    

    Regards,

    Iván

    I am trying to encypt some data too. I think the first one is the right way in order to encrypt because you have the struct nrf_ecb_hal_data_t which defines the 3 parameters needed for the encryptation. Anyway I don't know what to put in those parameters:

    nrf_ecb_hal_data_t aestructura; aestructura.key=12345678; aestructura.cleartext="what should I put here"; aestructura.ciphertext="what should I put here";

    After that I suppose we only should use the function: sd_ecb_block_encrypt(aestructura));

    And it should give back the encrypted data? Don't know yet.

    I hope some of this can help you a bit, I have many questions though.

    Regards

    Iván

Children
Related