Midori128错误的密文

时间:2018-07-06 09:31:17

标签: encryption block-cipher

我有一个项目,在其中必须为Arduino Uno R3实现各种安全协议,例如Present,Misty,Prince等。目前,我正在尝试实现Midori128。我设法使Midiori64正常工作,但对于Midori128,加密不正确,而解密正常。

这是当前的代码,请记住我是从GitHub上获取此代码,然后对其进行更改以使其尽可能高效地在Arduino上运行;但是就像我说的那样,加密是错误的,我也不知道为什么。

#include <stdio.h>
#include <stdint.h>


static uint16_t s_box[16] = { 0x1,0x0,0x5,0x3,0xe,0x2,0xf,0x7,0xd,0xa,0x9,0xb,0xc,0x8,0x4,0x6 };
static uint16_t const_key[19][16] = { { 0,0,0,1,0,1,0,1,1,0,1,1,0,0,1,1 },{ 0,1,1,1,1,0,0,0,1,1,0,0,0,0,0,0 },
                                     { 1,0,1,0,0,1,0,0,0,0,1,1,0,1,0,1 },{ 0,1,1,0,0,0,1,0,0,0,0,1,0,0,1,1 },
                                     { 0,0,0,1,0,0,0,0,0,1,0,0,1,1,1,1 },{ 1,1,0,1,0,0,0,1,0,1,1,1,0,0,0,0 },
                                     { 0,0,0,0,0,0,1,0,0,1,1,0,0,1,1,0 },{ 0,0,0,0,1,0,1,1,1,1,0,0,1,1,0,0 },
                                     { 1,0,0,1,0,1,0,0,1,0,0,0,0,0,0,1 },{ 0,1,0,0,0,0,0,0,1,0,1,1,1,0,0,0 },
                                     { 0,1,1,1,0,0,0,1,1,0,0,1,0,1,1,1 },{ 0,0,1,0,0,0,1,0,1,0,0,0,1,1,1,0 },
                                     { 0,1,0,1,0,0,0,1,0,0,1,1,0,0,0,0 },{ 1,1,1,1,1,0,0,0,1,1,0,0,1,0,1,0 },
                                     { 1,1,0,1,1,1,1,1,1,0,0,1,0,0,0,0 },{ 0,1,1,1,1,1,0,0,1,0,0,0,0,0,0,1 },
                                     { 0,0,0,1,1,1,0,0,0,0,1,0,0,1,0,0 },{ 0,0,1,0,0,0,1,1,1,0,1,1,0,1,0,0 },
                                     {0,1,1,0,0,0,1,0,1,0,0,0,1,0,1,0} };

uint16_t bit_permutation_0(uint16_t x)
{
    uint16_t temp = 0x00;
    temp ^= ((x & 0x08) << 4), temp ^= ((x & 0x40)), temp ^= ((x & 0x02) << 4), temp ^= (x & 0x10),
        temp ^= ((x & 0x80) >> 4), temp ^= ((x & 0x04)), temp ^= ((x & 0x20) >> 4), temp ^= (x & 0x01);
    return temp;
}

uint16_t bit_permutation_1(uint16_t x)
{
    uint16_t temp = 0x00;
    temp ^= ((x & 0x40) << 1), temp ^= ((x & 0x02) << 5), temp ^= ((x & 0x01) << 5), temp ^= ((x & 0x80) >> 3),
        temp ^= ((x & 0x04) << 1), temp ^= ((x & 0x20) >> 3), temp ^= ((x & 0x10) >> 3), temp ^= ((x & 0x08) >> 3);
    return temp;
}

uint16_t inv_bit_permutation_1(uint16_t x)
{
    uint16_t temp = 0x00;
    temp ^= ((x & 0x10) << 3), temp ^= ((x & 0x80) >> 1), temp ^= ((x & 0x04) << 3), temp ^= ((x & 0x02) << 3),
        temp ^= ((x & 0x01) << 3), temp ^= ((x & 0x08) >> 1), temp ^= ((x & 0x40) >> 5), temp ^= ((x & 0x20) >> 5);
    return temp;
}

uint16_t bit_permutation_2(uint16_t x)
{
    uint16_t temp = 0x00;
    temp ^= ((x & 0x20) << 2), temp ^= ((x & 0x10) << 2), temp ^= ((x & 0x08) << 2), temp ^= ((x & 0x40) >> 2),
        temp ^= ((x & 0x02) << 2), temp ^= ((x & 0x01) << 2), temp ^= ((x & 0x80) >> 6), temp ^= ((x & 0x04) >> 2);
    return temp;
}

uint16_t inv_bit_permutation_2(uint16_t x)
{
    uint16_t temp = 0x00;
    temp ^= ((x & 0x02) << 6), temp ^= ((x & 0x10) << 2), temp ^= ((x & 0x80) >> 2), temp ^= ((x & 0x40) >> 2),
        temp ^= ((x & 0x20) >> 2), temp ^= ((x & 0x01) << 2), temp ^= ((x & 0x08) >> 2), temp ^= ((x & 0x04) >> 2);
    return temp;
}

uint16_t bit_permutation_3(uint16_t x)
{
    uint16_t temp = 0x00;
    temp ^= ((x & 0x01) << 7), temp ^= ((x & 0x08) << 3), temp ^= ((x & 0x40) >> 1), temp ^= ((x & 0x20) >> 1),
        temp ^= ((x & 0x10) >> 1), temp ^= ((x & 0x80) >> 5), temp ^= ((x & 0x04) >> 1), temp ^= ((x & 0x02) >> 1);
    return temp;
}

uint16_t inv_bit_permutation_3(uint16_t x)
{
    uint16_t temp = 0x00;
    temp ^= ((x & 0x04) << 5), temp ^= ((x & 0x20) << 1), temp ^= ((x & 0x10) << 1), temp ^= ((x & 0x08) << 1),
        temp ^= ((x & 0x40) >> 3), temp ^= ((x & 0x02) << 1), temp ^= ((x & 0x01) << 1), temp ^= ((x & 0x80) >> 7);
    return temp;
}

uint16_t Midori128_S_Box(int r, uint16_t x)
{
    uint16_t y;
    if (r % 4 == 0)
    {
        y = bit_permutation_0(x);
        y = (s_box[(y & 0xf0) >> 4] << 4) ^ (s_box[(y & 0x0f)]);
        y = bit_permutation_0(y);
    }
    if (r % 4 == 1)
    {
        y = bit_permutation_1(x);
        y = (s_box[(y & 0xf0) >> 4] << 4) ^ s_box[(y & 0x0f)];
        y = inv_bit_permutation_1(y);
    }
    if (r % 4 == 2)
    {
        y = bit_permutation_2(x);
        y = (s_box[(y & 0xf0) >> 4] << 4) ^ s_box[(y & 0x0f)];
        y = inv_bit_permutation_2(y);
    }
    else
    {
        y = bit_permutation_3(x);
        y = (s_box[(y & 0xf0) >> 4] << 4) ^ s_box[(y & 0x0f)];
        y = inv_bit_permutation_3(y);
    }
    return y;
}

void SubCell(int r,uint16_t *state)
{
    int i;
    for (i = 0; i <= 15; i++)
    {
        state[i] = Midori128_S_Box(r%4,state[i]);
    }
}

void ShuffleCell(uint16_t *state)
{
    int i;
    uint16_t temp[16];
    temp[0] = state[0], temp[1] = state[10], temp[2] = state[5], temp[3] = state[15],
        temp[4] = state[14], temp[5] = state[4], temp[6] = state[11], temp[7] = state[1],
        temp[8] = state[9], temp[9] = state[3], temp[10] = state[12], temp[11] = state[6],
        temp[12] = state[7], temp[13] = state[13], temp[14] = state[2], temp[15] = state[8];
    for (i = 0; i <= 15; i++)
    {
        state[i] = temp[i];
    }
}

void Inv_ShuffleCell(uint16_t *state)
{
    int i;
    uint16_t temp[16];
    temp[0] = state[0], temp[1] = state[7], temp[2] = state[14], temp[3] = state[9],
        temp[4] = state[5], temp[5] = state[2], temp[6] = state[11], temp[7] = state[12],
        temp[8] = state[15], temp[9] = state[8], temp[10] = state[1], temp[11] = state[6],
        temp[12] = state[10], temp[13] = state[13], temp[14] = state[4], temp[15] = state[3];
    for (i = 0; i <= 15; i++)
    {
        state[i] = temp[i];
    }
}


void MixColumn(uint16_t *state)
{
    int i;
    uint16_t temp[16];
    for (i = 0; i <= 3; i++)
    {
        temp[4 * i + 0] = state[4 * i + 1] ^ state[4 * i + 2] ^ state[4 * i + 3];
        temp[4 * i + 1] = state[4 * i + 0] ^ state[4 * i + 2] ^ state[4 * i + 3];
        temp[4 * i + 2] = state[4 * i + 0] ^ state[4 * i + 1] ^ state[4 * i + 3];
        temp[4 * i + 3] = state[4 * i + 0] ^ state[4 * i + 1] ^ state[4 * i + 2];
    }
    for (i = 0; i <= 15; i++)
    {
        state[i] = temp[i];
    }
}


void rth_Round_Encrypt_KeyAdd(int r, uint16_t *state, uint16_t *K)
{
    int i;  
    for (i = 0; i <= 15; i++)
    {
        state[i] = state[i] ^ K[i] ^ const_key[r][i];
    }

}

void rth_Round_Decrypt_KeyAdd(int r, uint16_t *state, uint16_t *K)
{
    int i;
    uint16_t Kr[16];
    for (i = 0; i <= 15; i++)
    {
        Kr[i] = K[i] ^ const_key[r][i];
    }
    MixColumn(Kr);
    Inv_ShuffleCell(Kr);
    for (i = 0; i <= 15; i++)
    {
        state[i] = state[i] ^ Kr[i];
    }
}

void Encrypt(int r, uint16_t *plaintext, uint16_t *K, uint16_t *ciphertext)
{
    int i;
    for (i = 0; i <= 15; i++)
    {
        ciphertext[i] = plaintext[i];
    }
    for (i = 0; i <= 15; i++)
    {
        ciphertext[i] = ciphertext[i] ^ K[i];
    }
    for (i = 0; i <= (r - 2); i++)
    {
        SubCell(i, ciphertext);
        ShuffleCell(ciphertext);
        MixColumn(ciphertext);
        rth_Round_Encrypt_KeyAdd(i, ciphertext, K);
    }
    SubCell(i, ciphertext);
    for (i = 0; i <= 15; i++)
    {
        ciphertext[i] = ciphertext[i] ^ K[i];
    }
}
void Decrypt(int r, uint16_t *ciphertext, uint16_t *K,uint16_t *plaintext)
{
    int i;
    for (i = 0; i <= 15; i++)
    {
        plaintext[i] = ciphertext[i];
    }
    for (i = 0; i <= 15; i++)
    {
        plaintext[i] = plaintext[i] ^ K[i];
    }
    for (i = (r-2); i >=0;i--)
    {
        SubCell(i + 1, plaintext);
        MixColumn(plaintext);
        Inv_ShuffleCell(plaintext);
        rth_Round_Decrypt_KeyAdd(i, plaintext, K);

    }
    SubCell(i, plaintext);
    for (i = 0; i <= 15; i++)
    {
        plaintext[i] = plaintext[i] ^ K[i];
    }
}
void setup (){
Serial.begin(9600);
printf.begin();
}

void loop ()
{
    int i,j1,j2,j3;
    uint16_t plaintext[16] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
    uint16_t Key[16] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    uint16_t plaintext_temp[16];
    uint16_t ciphertext_temp[16];
    for (j1 = 0; j1 <= 0xff; j1++)
    { 
        plaintext[0] = j1;
        for (j2 = 0; j2 <= 0xff; j2++)
        {
            plaintext[1] = j2;
            for (j3 = 0; j3 <= 0xff; j3++)
            {
                plaintext[2] = j3;
                /*printf("Before Encryption: ");
                for (i = 0; i < 16; i++)
                {
                    printf("%x ", plaintext[i]);
                }
                printf("\n");*/
                Encrypt(20, plaintext, Key, ciphertext_temp);
                printf("After Encryption: ");
                for (i = 0; i < 16; i++)
                {
                    printf("%x ", ciphertext_temp[i]);
                        }
                        printf("\n");
                        /*Decrypt(20, ciphertext_temp, Key, plaintext_temp);
                        printf("After Decryption: ");
                        for (i = 0; i < 16; i++)
                        {
                            printf("%x ", plaintext_temp[i]);
                        }
                        printf("\n");*/
                        printf("\n");
                    }
                }
            }
        }

我对原始论文进行了无数次审查,并且对方法非常了解,但是我无法查明其未输出正确密文的确切原因,即c055cbb95996d14902b60574d5e728d6。任何帮助或提示将不胜感激。谢谢。

最新修改: 我设法找到了在Midori128中使用的4个sbox,但是,如果有人有任何想法,我仍然很困惑如何将它们准确地合并到我的代码中。

以下是框:

    static uint16_t ssb0[16][16] = {
  {0x11, 0x10, 0x51, 0x50, 0xb4, 0x30, 0xf4, 0x70, 0x59, 0x58, 0x19, 0x18, 0xfc, 0x78, 0xbc, 0x38},
  {0x01, 0x00, 0x13, 0x12, 0xa4, 0x20, 0xb6, 0x32, 0x0b, 0x0a, 0x1b, 0x1a, 0xae, 0x2a, 0xbe, 0x3a},
  {0x15, 0x31, 0x55, 0x71, 0xb5, 0x35, 0xf5, 0x75, 0x5d, 0x79, 0x1d, 0x39, 0xfd, 0x7d, 0xbd, 0x3d},
  {0x05, 0x21, 0x17, 0x33, 0xa5, 0x25, 0xb7, 0x37, 0x0f, 0x2b, 0x1f, 0x3b, 0xaf, 0x2f, 0xbf, 0x3f},
  {0x4b, 0x4a, 0x5b, 0x5a, 0xee, 0x6a, 0xfe, 0x7a, 0x49, 0x48, 0x41, 0x40, 0xec, 0x68, 0xe4, 0x60},
  {0x03, 0x02, 0x53, 0x52, 0xa6, 0x22, 0xf6, 0x72, 0x09, 0x08, 0x43, 0x42, 0xac, 0x28, 0xe6, 0x62},
  {0x4f, 0x6b, 0x5f, 0x7b, 0xef, 0x6f, 0xff, 0x7f, 0x4d, 0x69, 0x45, 0x61, 0xed, 0x6d, 0xe5, 0x65},
  {0x07, 0x23, 0x57, 0x73, 0xa7, 0x27, 0xf7, 0x77, 0x0d, 0x29, 0x47,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90, 0x92, 0x53, 0xd3, 0x84, 0x86, 0x47, 0xc7},
  {0xbc, 0xbe, 0x7f, 0xff, 0xa0, 0xa2, 0x63, 0xe3, 0xb8, 0xba, 0x7b, 0xfb, 0xb0, 0xb2, 0x73, 0xf3},
  {0xca, 0xc8, 0x4a, 0x0a, 0xee, 0xec, 0x6e, 0x2e, 0xc2, 0xc0, 0x42, 0x02, 0xd6, 0xd4, 0x56, 0x16},
  {0xea, 0xe8, 0x6a, 0x2a, 0xce, 0xcc, 0x4e, 0x0e, 0xda, 0xd8, 0x5a, 0x1a, 0xde, 0xdc, 0x5e, 0x1e},
  {0xf6, 0xf4, 0x76, 0x36, 0xe6, 0xe4, 0x66, 0x26, 0xd2, 0xd0, 0x52, 0x12, 0xc6, 0xc4, 0x46, 0x06},
  {0xfe, 0xfc, 0x7e, 0x3e, 0xe2, 0xe0, 0x62, 0x22, 0xfa, 0xf8, 0x7a, 0x3a, 0xf2, 0xf0, 0x72, 0x32},
  {0x08, 0x89, 0x09, 0x8b, 0x2c, 0xad, 0x2d, 0xaf, 0x00, 0x81, 0x01, 0x83, 0x14, 0x95, 0x15, 0x97},
  {0x28, 0xa9, 0x29, 0xab, 0x0c, 0x8d, 0x0d, 0x8f, 0x18, 0x99, 0x19, 0x9b, 0x1c, 0x9d, 0x1d, 0x9f},
  {0x34, 0xb5, 0x35, 0xb7, 0x24, 0xa5, 0x25, 0xa7, 0x10, 0x91, 0x11, 0x93, 0x04, 0x85, 0x05, 0x87},
  {0x3c, 0xbd, 0x3d, 0xbf, 0x20, 0xa1, 0x21, 0xa3, 0x38, 0xb9, 0x39, 0xbb, 0x30, 0xb1, 0x31, 0xb3},
  {0x49, 0xc9, 0x48, 0x0b, 0x6d, 0xed, 0x6c, 0x2f, 0x41, 0xc1, 0x40, 0x03, 0x55, 0xd5, 0x54, 0x17},
  {0x69, 0xe9, 0x68, 0x2b, 0x4d, 0xcd, 0x4c, 0x0f, 0x59, 0xd9, 0x58, 0x1b, 0x5d, 0xdd, 0x5c, 0x1f},
  {0x75, 0xf5, 0x74, 0x37, 0x65, 0xe5, 0x64, 0x27, 0x51, 0xd1, 0x50, 0x13, 0x45, 0xc5, 0x44, 0x07},
  {0x7d, 0xfd, 0x7c, 0x3f, 0x61, 0xe1, 0x60, 0x23, 0x79, 0xf9, 0x78, 0x3b, 0x71, 0xf1, 0x70, 0x33}
};

static uint16_t ssb2[16][16] = {
  {0x44, 0xc3, 0x47, 0x43, 0x40, 0xc0, 0xc2, 0x42, 0x54, 0xd3, 0x57, 0x53, 0x50, 0xd0, 0xd2, 0x52},
  {0x3c, 0xbb, 0x3f, 0x3b, 0x38, 0xb8, 0xba, 0x3a, 0x7c, 0xfb, 0x7f, 0x7b, 0x78, 0xf8, 0xfa, 0x7a},
  {0x74, 0xf3, 0x77, 0x73, 0x70, 0xf0, 0xf2, 0x72, 0x64, 0xe3, 0x67, 0x63, 0x60, 0xe0, 0xe2, 0x62},
  {0x34, 0xb3, 0x37, 0x33, 0x30, 0xb0, 0xb2, 0x32, 0x14, 0x93, 0x17, 0x13, 0x10, 0x90, 0x92, 0x12},
  {0x04, 0x83, 0x07, 0x03, 0x00, 0x80, 0x82, 0x02, 0x4c, 0xcb, 0x4f, 0x4b, 0x48, 0xc8, 0xca, 0x4a},
  {0x0c, 0x8b, 0x0f, 0x0b, 0x08, 0x88, 0x8a, 0x0a, 0x5c, 0xdb, 0x5f, 0x5b, 0x58, 0xd8, 0xda, 0x5a},
  {0x2c, 0xab, 0x2f, 0x2b, 0x28, 0xa8, 0xaa, 0x2a, 0x6c, 0xeb, 0x6f, 0x6b, 0x68, 0xe8, 0xea, 0x6a},
  {0x24, 0xa3, 0x27, 0x23, 0x20, 0xa0, 0xa2, 0x22, 0x1c, 0x9b, 0x1f, 0x1b, 0x18, 0x98, 0x9a, 0x1a},
  {0x45, 0xc7, 0x46, 0x41, 0xc4, 0xc5, 0xc6, 0xc1, 0x55, 0xd7, 0x56, 0x51, 0xd4, 0xd5, 0xd6, 0xd1},
  {0x3d, 0xbf, 0x3e, 0x39, 0xbc, 0xbd, 0xbe, 0xb9, 0x7d, 0xff, 0x7e, 0x79, 0xfc, 0xfd, 0xfe, 0xf9},
  {0x75, 0xf7, 0x76, 0x71, 0xf4, 0xf5, 0xf6, 0xf1, 0x65, 0xe7, 0x66, 0x61, 0xe4, 0xe5, 0xe6, 0xe1},
  {0x35, 0xb7, 0x36, 0x31, 0xb4, 0xb5, 0xb6, 0xb1, 0x15, 0x97, 0x16, 0x11, 0x94, 0x95, 0x96, 0x91},
  {0x05, 0x87, 0x06, 0x01, 0x84, 0x85, 0x86, 0x81, 0x4d, 0xcf, 0x4e, 0x49, 0xcc, 0xcd, 0xce, 0xc9},
  {0x0d, 0x8f, 0x0e, 0x09, 0x8c, 0x8d, 0x8e, 0x89, 0x5d, 0xdf, 0x5e, 0x59, 0xdc, 0xdd, 0xde, 0xd9},
  {0x2d, 0xaf, 0x2e, 0x29, 0xac, 0xad, 0xae, 0xa9, 0x6d, 0xef, 0x6e, 0x69, 0xec, 0xed, 0xee, 0xe9},
  {0x25, 0xa7, 0x26, 0x21, 0xa4, 0xa5, 0xa6, 0xa1, 0x1d, 0x9f, 0x1e, 0x19, 0x9c, 0x9d, 0x9e, 0x99}
};

static uint16_t ssb3[16][16] = {
  {0x22, 0x2b, 0x20, 0x29, 0xa2, 0xab, 0x26, 0x2f, 0x4b, 0x0b, 0x49, 0x09, 0xcb, 0x8b, 0x4f, 0x0f},
  {0xb2, 0xbb, 0x34, 0x3d, 0x32, 0x3b, 0x36, 0x3f, 0xdb, 0x9b, 0x5d, 0x1d, 0x5b, 0x1b, 0x5f, 0x1f},
  {0x02, 0x43, 0x00, 0x41, 0x82, 0xc3, 0x06, 0x47, 0x42, 0x03, 0x40, 0x01, 0xc2, 0x83, 0x46, 0x07},
  {0x92, 0xd3, 0x14, 0x55, 0x12, 0x53, 0x16, 0x57, 0xd2, 0x93, 0x54, 0x15, 0x52, 0x13, 0x56, 0x17},
  {0x2a,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xe0, 0xe1, 0xe4, 0xe5, 0xf8, 0xd8, 0x78, 0x58, 0xe8, 0xc8, 0xec, 0xcc}
};

1 个答案:

答案 0 :(得分:1)

您的代码包含Sb1,Sb0在哪里?根据{{​​3}},有2个较小的4位盒子构成8位sbox。

  • void Encrypt(int r,uint16_t *明文,uint16_t * K,uint16_t *密文)中,您只需要对明文进行xor键即可得到密文而不复制,然后进行xoring,为循环使用一个

将此链接用作开发original paper的基准