Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gost28147 #2

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open

Gost28147 #2

wants to merge 3 commits into from

Conversation

vladimir7485
Copy link
Collaborator

No description provided.

@vladimir7485 vladimir7485 requested a review from mars2860 April 10, 2017 20:45
return EXIT_FAILURE;
}

uint32_t* Key = (uint32_t*)malloc(8 * sizeof(uint32_t));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Уже хорошо, что не в цикле. Но зачем ты вообще делаешь динамическое выделение памяти? Почему нельзя просто объявить массив key[] = {0x0123,...}, тоже самое для subTable

n1 = *((uint32_t *)&blockin[0]);
n2 = *((uint32_t *)&blockin[4]);

// 32 ����� ������� ������
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

поправь кодировку файлы, чтобы комментарии были читабельными


void Gost28147_encode(uint8_t* blockin, uint8_t* blockout, uint32_t* Key, uint8_t** SubTable)
{
uint8_t first_uint8_t, second_uint8_t, zam_symbol, n;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Очень плохие имена переменных! Почитай вот это https://learn.javascript.ru/variable-names

n1 = SUM232;
}

if (k<24)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Может быть будет проще c = k % 8 ??? Одна строчка и никаких if. Чем меньше в коде условий, тем лучше


// ���������� ���������
uint8_t ind = 0;
for (q = 0; q <= 3; q++)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Есть такая замечательная функция как memcpy, но даже лучше обойтись без неё, потому что не будет инструкций на вызов подпрограммы (функции memcpy)

*((uint32_t*)(blockout)) = n1; *((uint32_t*)(blockout+4)) = n2;

blockout[ind++] = *((uint8_t *)&n2 + q);
}

void Gost28147_decode(uint8_t* blockin, uint8_t* blockout, uint32_t* Key, uint8_t** SubTable)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У тебя до этого была хорошая идея, что кодирование и декодирование делалось одним методом, но оформил ты её плохо. На чистом языке Си это можно сделать так

где-нибудь сразу после #include в этом файле обяъвляешь прототип функции (обрати внимание на названия переменных и метода)
static void simpleReplace(uint8_t* in, uint8_t* out, uint32_t* key, uint8_t** subTable, uint8_t mode)
ключевое слово static в данном случае говорит, что метод simpleReplace используется только внутри этого файла и нигде больше в программе. Далее где-нибудь в этом файле пишешь тело функции. А твои методы decode, encode будут выглядеть так

void gost28147_encode(uint8_t* in, uint8_t* out, uint32_t* key, uint8_t** subTable)
{
    simpleReplace(in,out,key,subTable,0);
}

void gost28147_decode(uint8_t* in, uint8_t* out, uint32_t* key, uint8_t** subTable)
{
    simpleReplace(in,out,key,subTable,1);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants