Skip to content

Producing different encrypted data on different processors. #4

@BurakYasin

Description

@BurakYasin

Hello, I tried this library on PSOC, arduino and computer(online c compliler).

On Psoc and and my computer, encrypt datas are same, however on arduino, encrypt are different from others. Are there any reason for that ? like a processor speed, gcc version ?

When I create main code, I refer the test code on your project. All codes are same in 3 processors.
(note: I comment #define TARGET_FLASH_MEMORY PROGMEM due to errors) (I am using #define TARGET_FLASH_MEMORY for all)
(UPDATE: to fix errors in compiler when I use #define TARGET_FLASH_MEMORY PROGMEM, I changed s_box, s_box_inverse and rcon arrays with const uint8_t. But now encyped results always give 2,2,2,2.. now :( )
Main code:

#include "project.h"
#include <aes.h>

#define X2D(x) \
  ((x) <= 'F' && (x) >= 'A' ? (x) - 'A' + 10 : \
    ((x) <= 'f' && (x) >= 'a' ? (x) - 'a' + 10 : \
      ((x) <= '9' && (x) >= '0' ? (x) - '0' : 0)))

int key_size = 128, decrypt = 0, i, c;
char hex_key[128], hex_block[16];
uint8_t key[16], block[16];

aes_128_context_t context;
uint8_t current_vector[16];

void aes_128(uint8_t *key, uint8_t *block, int decrypt)
{
  aes_128_context_t ctx;

  aes_128_init(&ctx, key);

  if (decrypt) aes_128_decrypt(&ctx, block);
  else aes_128_encrypt(&ctx, block);
}

int main(void){
    
  for(i=0;i<128;i++){
    hex_key[i] = i+1;
  }
  for(i=0;i<16;i++){
    hex_block[i] = i+2;
  }
  key_size= 128;

  for (i = 0; hex_key[i] && hex_key[i + 1] && i < key_size >> 2; i += 2) {
    key[i >> 1] = (X2D(hex_key[i]) << 4) | X2D(hex_key[i | 1]);
  }
    for (i = 0; hex_block[i] && hex_block[i + 1] && i < 32; i += 2) {
        block[i >> 1] = (X2D(hex_block[i]) << 4) | X2D(hex_block[i | 1]);
      }
    aes_128(key, block, decrypt);

    for(;;)
    {
       
    }
}

`

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions