Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
52a6aeb
Revert "config: Update README.md"
Mar 8, 2026
b3eb61e
Reapply "config: Update README.md"
ShowhyT Mar 8, 2026
d35fd72
add: Makefile
ShowhyT Mar 8, 2026
a8e9fe4
add: project structure
ShowhyT Mar 8, 2026
a64bd12
add: add GOST docs
ShowhyT Mar 9, 2026
af8af6e
fix: revert README.md
ShowhyT Mar 9, 2026
6270275
add: Makefile configuration
ShowhyT Mar 12, 2026
072ecdb
add: init a table
ShowhyT Mar 20, 2026
36a30c1
add: complete include/ and refactor tests dir
ShowhyT Mar 20, 2026
16bdf32
add: Google style code and configure auto format
ShowhyT Mar 25, 2026
b72620c
fix: change compiler to gcc in windows
ShowhyT Mar 25, 2026
0013695
fix: change compiler to gcc in windows
ShowhyT Mar 25, 2026
517103f
fix: change compiler to gcc in windows
ShowhyT Mar 25, 2026
aa2d822
add: write a StreebogInit function
ShowhyT Mar 25, 2026
ce6f349
fix: привел к единой системы записи битов
ShowhyT Mar 25, 2026
7fcee26
add: added all files into project
ShowhyT Mar 28, 2026
a08530a
add: added all files into projects. Tests we write later
ShowhyT Mar 28, 2026
100a989
фикс: изменил с русской с на английскую
ShowhyT Mar 29, 2026
f633a79
фикс: добавил вывод в качестве заглушки
ShowhyT Mar 30, 2026
0b3cd41
фикс: небольшое улучшение стиля, дальше слияние в 1 ветку
ShowhyT Apr 10, 2026
3a3f672
Update team member name in README
ShowhyT Apr 10, 2026
38a2755
рефакторинг: добавил LPS, подкорректировал имена переменной. Пофиксил…
ShowhyT Apr 15, 2026
5202391
фикс: добавил тесты для инициализации векторов
ShowhyT Apr 15, 2026
a6ac025
фикс: добавил тесты для инициализации векторов
ShowhyT Apr 15, 2026
88936e2
Merge branch 'master' into module
ShowhyT Apr 15, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
BasedOnStyle: Google
IndentWidth: 2
AllowShortFunctionsOnASingleLine: Empty
DerivePointerAlignment: false
ColumnLimit: 0
34 changes: 34 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
---
Checks: 'readability-identifier-naming'
CheckOptions:
# Классы и структуры: PascalCase
- key: readability-identifier-naming.ClassCase
value: PascalCase
- key: readability-identifier-naming.StructCase
value: PascalCase

# Публичные поля (в структурах): snake_case
- key: readability-identifier-naming.PublicMemberCase
value: snake_case

# Приватные поля (в классах): snake_case_ с подчеркиванием в конце
- key: readability-identifier-naming.PrivateMemberCase
value: snake_case
- key: readability-identifier-naming.PrivateMemberSuffix
value: '_'

# Локальные переменные: snake_case
- key: readability-identifier-naming.VariableCase
value: snake_case

# Функции и методы: PascalCase
- key: readability-identifier-naming.FunctionCase
value: PascalCase

# Константы (k + PascalCase)
- key: readability-identifier-naming.GlobalConstantCase
value: CamelCase
- key: readability-identifier-naming.GlobalConstantPrefix
value: 'k'

HeaderFilterRegex: '^(src/|include/|tools/)'
19 changes: 5 additions & 14 deletions .github/workflows/cmake-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,14 @@ jobs:
matrix:
os: [ubuntu-latest, windows-latest]
build_type: [Release]
c_compiler: [gcc, clang, cl]
c_compiler: [gcc]
include:
- os: windows-latest
c_compiler: cl
cpp_compiler: cl
- os: ubuntu-latest
c_compiler: gcc
cpp_compiler: g++
- os: ubuntu-latest
c_compiler: clang
cpp_compiler: clang++
exclude:
- os: windows-latest
c_compiler: gcc
- os: windows-latest
c_compiler: clang
- os: ubuntu-latest
c_compiler: cl
cpp_compiler: g++

steps:
- uses: actions/checkout@v4
Expand All @@ -59,15 +49,16 @@ jobs:
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
cmake -G "Ninja"
-B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S ${{ github.workspace }}

- name: Build
# Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator).
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }}
run: cmake --build ${{ steps.strings.outputs.build-output-dir }}

- name: Test
working-directory: ${{ steps.strings.outputs.build-output-dir }}
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,8 @@ dkms.conf

# debug information files
*.dwo

# Build files
build/
.cache
.vscode
56 changes: 56 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
cmake_minimum_required(VERSION 3.10)

project(Streebog LANGUAGES C)

# Настройки стандарта
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
set(CMAKE_C_EXTENSIONS OFF)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

set(CMAKE_C_COMPILER gcc)

enable_testing()

# --- Инструменты качества кода ---

# Clang-Tidy
find_program(CLANG_TIDY_EXE NAMES "clang-tidy")
if(CLANG_TIDY_EXE)
set(CMAKE_C_CLANG_TIDY ${CLANG_TIDY_EXE})
endif()

# Clang-Format
find_program(CLANG_FORMAT_EXE NAMES "clang-format")
if(CLANG_FORMAT_EXE)
file(GLOB_RECURSE ALL_SOURCE_FILES src/*.c src/*.h tests/*.c tests/*.h)
add_custom_target(format
COMMAND ${CLANG_FORMAT_EXE} -i ${ALL_SOURCE_FILES}
COMMENT "Formatting code with clang-format..."
)
endif()

add_compile_options(-Wall -Wextra -Wpedantic)

# Библиотека самого алгоритма
add_library(streebog_lib
src/streebog.c
src/streebog_tables.c
)

target_include_directories(streebog_lib PUBLIC src)

# Библиотека Unity (фреймворк для тестов)
add_library(unity_lib
tests/unity/unity.c
)
target_include_directories(unity_lib PUBLIC tests/unity)

set(TEST_TARGETS test_streebog)

foreach(target ${TEST_TARGETS})
add_executable(${target} tests/tests.c)
target_link_libraries(${target} PRIVATE streebog_lib unity_lib)
endforeach()

add_test(NAME StreebogInit COMMAND test_streebog)
41 changes: 35 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,42 @@
Работаем по проекту ГОСТ-34-11.2012

# Роли в проекте:
- **Имя** - математик-программист, обеспечивает и проверяет корректность программирования математических объектов
- **Имя** - программист арифметики в конечных полях.
- **Имя** - программист всего алгоритма, включая процедуры ввода-вывода
- **Имя** - программист оболочки под DOS и Windows, сборщик программных модулей
- **Имя** - тестировщик корректности работы программы и её оптимальности.
- **skellekroon-svg** - математик-программист, обеспечивает и проверяет корректность программирования математических объектов
- **Jaba** - программист арифметики в конечных полях.
- **ShowhyT** - программист всего алгоритма, включая процедуры ввода-вывода
- **Armigodf** - программист оболочки под DOS и Windows, сборщик программных модулей
- **Pomidor/ShowhyT** - тестировщик корректности работы программы и её оптимальности.

# Строение проекта:
```

projectwork/
├── Makefile # Сборка
├── README.md # Описание проекта
├── include/
│ ├── streebog.h # Публичный API хэш-функции
│ ├── streebog_tables.h # Таблицы констант (S-box, tau, A, C)
│ └── streebog_internal.h # Внутренние типы и макросы
├── src/
│ ├── streebog.c # Основная логика: Init / Update / Final
│ ├── streebog_compress.c # Функция сжатия g_N
│ ├── streebog_tables.c # Определения таблиц (Lookup Tables)
│ ├── streebog_transform.c # Преобразования: S, P, L, X, E (шифр)
│ └── streebog_utils.c # Вспомогательные функции (XOR, ADDC и т.д.)
├── tests/
│ ├── test_main.c # Точка входа тестов
│ ├── test_vectors_256.c # Тест-векторы для Стрибог-256
│ ├── test_vectors_512.c # Тест-векторы для Стрибог-512
│ └── test_vectors.h # Данные тест-векторов из ГОСТ
├── tools/
│ ├── main.c # CLI-утилита: вычисление хэша файла/строки
│ └── bench.c # Бенчмарк производительности
└── docs/
├── GOST_R_3411-2012.pdf # Текст стандарта
└── gost-r-34.pdf # Текст стандарта
```
Binary file added docs/GOST_R_3411-2012.pdf
Binary file not shown.
Binary file added docs/gost-r-34.pdf
Binary file not shown.
24 changes: 24 additions & 0 deletions include/streebog.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef STREEBOG_H
#define STREEBOG_H

#include <stddef.h>
#include <stdint.h>

#define STREEBOG_256_DIGEST_SIZE 32 /* половина размера от основной функции */
#define STREEBOG_512_DIGEST_SIZE 64 /* байт */
#define STREEBOG_BLOCK_SIZE 64 /* размер блока (байт — 512 бит) */

typedef struct {
uint8_t h[64]; /*Текущее значение хэша для 512 бит */
uint8_t N[64]; /* Счётчик отработки битов */
uint8_t sigma[64]; /* контрольная сумма всех блоков */
uint8_t buffer[64]; /*хранилище для неполных блоков */
size_t len_buffer;
int t_size; /*256 или 512 в init */
} streebog_ctx_t;

void StreebogInit(streebog_ctx_t* ctx, int bits);
void StreebogUpdate(streebog_ctx_t* ctx, const uint8_t* data, size_t len);
void StreebogFinal(streebog_ctx_t* ctx, uint8_t* digest);

#endif
33 changes: 33 additions & 0 deletions include/streebog_internal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef STREEBOG_INTERNAL_H
#define STREEBOG_INTERNAL_H

#include <stdint.h>

// * Сложение двух 512-битных чисел по модулю 2^512
void Add512(uint8_t* a, const uint8_t* b);

// * XOR двух 512-битных блоков
void Xor512(uint8_t* a, const uint8_t* b);

// * Функция сжатия
void gN(uint8_t* h, const uint8_t* N, const uint8_t* m);

// * XOR с ключом
void X(uint8_t* block, const uint8_t* key);

// * Байтовая подстановка
void S(uint8_t* block);

// * Перестановка байт
void P(uint8_t* block);

// * Линейное преобразование
void L(uint8_t* block);

// * 12 раундов X→S→P→L
void E(uint8_t* block, const uint8_t* key);

// * L+P+S в одном
void LPS(uint8_t* block);

#endif
11 changes: 11 additions & 0 deletions include/streebog_tables.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#ifndef STREEBOG_TABLES_H
#define STREEBOG_TABLES_H

#include <stdint.h>

extern const uint8_t kPiPrime[256];
extern const uint8_t kTau[64];
extern const uint64_t kMatrixAGF2[64];
extern const uint64_t kC[12][8];

#endif
21 changes: 21 additions & 0 deletions src/streebog.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "../include/streebog.h"
// ! После проверки не забыть удалить
#include <stdio.h>
#include <string.h>
// !
void StreebogInit(streebog_ctx_t* ctx, int bits) {
memset(ctx, 0x00, sizeof(streebog_ctx_t));
ctx->t_size = bits;
if (bits == 256)
memset(ctx->h, 0x01, 64);
else
memset(ctx->h, 0x00, 64);
}

void StreebogUpdate(streebog_ctx_t* ctx, const uint8_t* data, size_t len) {
printf("%p %p %llu", ctx, data, len);
}

void StreebogFinal(streebog_ctx_t* ctx, uint8_t* digest) {
printf("%p %p", ctx, digest);
}
26 changes: 26 additions & 0 deletions src/streebog_compress.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include "../include/streebog_internal.h"

// ! После проверки не забыть удалить
#include <stddef.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
// !

// * Функция сжатия
void gN(uint8_t* h, const uint8_t* N, const uint8_t* m) {
uint8_t* block = (uint8_t*)malloc(64 * sizeof(uint8_t)); // uint8_t = 8 бит, нам надо 512 бит
// Проверка на выделение памяти:
if (block == NULL) {
return; // Ошибка выделения памяти
}
memcpy(block, h, 64); // Копируем данные из h в block
// Математические преобразования:
Xor512(block, N);
LPS(block);
E(block, m);
Xor512(block, h);
Xor512(block, m);
memcpy(h, block, 64); // Копируем данные из block в h
free(block);
}
Loading
Loading