Quantcast
Channel: Forum - Recent Threads
Viewing all articles
Browse latest Browse all 5781

Encryption - From Synergy S5D9 to PC

$
0
0

Hi,

I have encrypt / decrypt working ok for BOTH S5 and PC (C#)   however they are NOT compatible with each other.

Here is the encrypt function for both sides, they do not produce the same encrypted output.

Format is:

128 bytes of data

ECB 

128 bytes of key and Initial vector

I have tried both LITTLE and BIG endian in the configurator, is there another byte  swap issue ? (I am using SSP1.3)

Many thanks

Alan..

 

*** S5 code ***

 

uint32_t aes_key[4]     = { 0x768EDCB3, 0x3D2E98E6, 0xBC60F138, 0x3AE70142 };
uint32_t aes_iv[4]        = { 0x81A50AE3, 0x94EDBD12, 0x3BCBD20D, 0x892F7BF8 };
UCHAR aes_buf[128]    = { 0x00, 0x01, 0x02};                                                                // input buffer
UCHAR aes_ebuf[128];                                                                                                    // output encrypted buffer

 

// Encrypt Data buffer
void aes_encrypt (UCHAR* p_aes_buf, UCHAR* p_aes_ebuf, INT len)
{
      ssp_err_t err;

      // Open the AES driver
      g_sce_aes_0.p_api->open(g_sce_aes_0.p_ctrl, g_sce_aes_0.p_cfg);
     

      // Encrypt the data 
      err = g_sce_aes_0.p_api->encrypt(g_sce_aes_0.p_ctrl,
      aes_key,
      aes_iv,
      len,
      (uint32_t *) p_aes_buf,
      p_aes_ebuf);

      // Close AES driver
      g_sce_aes_0.p_api->close(g_sce_aes_0.p_ctrl);     
}

 

*** PC C# code ***

public static byte[] aes_encrypt(byte[] plain)
{
      byte[] key = { 0x76, 0x8E, 0xDC, 0xB3, 0x3D, 0x2E, 0x98, 0xE6, 0xBC, 0x60, 0xF1, 0x38, 0x3A, 0xE7, 0x01, 0x42 };
      byte[] iv   = { 0x81, 0xA5, 0x0A, 0xE3, 0x94, 0xED, 0xBD, 0x12, 0x3B, 0xCB, 0xD2, 0x0D, 0x89, 0x2F, 0x7B, 0xF8 };

      byte[] encrypted;


      using (MemoryStream mstream = new MemoryStream())
      {
            using (AesCryptoServiceProvider aesProvider = new AesCryptoServiceProvider())
            {
                  aesProvider.KeySize = 128;
                  aesProvider.Mode = CipherMode.ECB;
                  aesProvider.Padding = PaddingMode.None;

                  using (CryptoStream cryptoStream = new CryptoStream(mstream, aesProvider.CreateEncryptor(key, iv), CryptoStreamMode.Write))
                  {
                         cryptoStream.Write(plain, 0, plain.Length);
                  }
                  encrypted = mstream.ToArray();
            }
      }
      return encrypted;
}


Viewing all articles
Browse latest Browse all 5781

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>