Не подтверждена Коммит 14db4cb2 создал по автору nikolvin's avatar nikolvin
Просмотр файлов

Add R 1323565.1.042

- Implement key system from R 1323565.1.042
- Implement (en/de)cryption functions from R 1323565.1.042
- Tweak R 1323565.1.022 to allow more flexibility
- Fix missing externs for some functions
- Bump version to 1.3.0
владелец 5bf31bbd
......@@ -4,6 +4,9 @@
# CLion build directories
cmake-build-*
# Doxygen-generated docs
docs
# Build and clangd files
.build*
.cache
......
cmake_minimum_required(VERSION 3.18)
project(rucrypto VERSION 1.2.1 LANGUAGES C CXX)
project(rucrypto VERSION 1.3.0 LANGUAGES C CXX)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 20)
......
Это отличие свёрнуто
......@@ -7,8 +7,10 @@ This library has not been tested against side channel attacks and other attacks
- Implements GOST 34.12-2018 256-bit block cipher
- Implements GOST 34.13-2018 block cipher encryption algorithms
- Implements R 1323565.1.022 HMAC256, HMAC512, NMAC, kdf and format functions
- Implements R 1323565.1.042 key system and sector encryption/unencryption functions
## Change notes
* 1.3.0 - Implement R 1323565.1.0.42 key system and sector access functions
* 1.2.1 - Fix installation of R 1323565.1.022 (it was missing headers)
* 1.2.0 - Implement R 1323565.1.022 HMAC256, HMAC512, NMAC, format and kdf functions. Use internal types everywhere. Allow building for kernel
* 1.1.0 - Restructure project, add python bindings for GOST 34.13-2018 (with block cipher from GOST 34.12-2018)
......
......@@ -4,4 +4,5 @@ add_subdirectory(gost_34_11)
add_subdirectory(gost_34_12)
add_subdirectory(gost_34_13)
add_subdirectory(r_1323565_1_022)
add_subdirectory(r_1323565_1_042)
/**
* @file rucrypto/common/allocator_provider.h
*/
#ifndef RUCRYPTO_COMMON_ALLOCATOR_PROVIDER_H
#define RUCRYPTO_COMMON_ALLOCATOR_PROVIDER_H
......@@ -23,7 +27,7 @@ typedef struct {
* @details If malloc is available, allocator is already initialized with
* malloc/free. Otherwise the pointers are NULL
*/
void rucrypto_init_allocator(rucrypto_allocator_t allocator);
extern void rucrypto_init_allocator(rucrypto_allocator_t allocator);
/**
* @brief Allocate buffer using previously provided allocator
......@@ -32,7 +36,7 @@ void rucrypto_init_allocator(rucrypto_allocator_t allocator);
* @details Used internally by all functions so they can be used than malloc is
* not available
*/
void* rucrypto_allocate(rucrypto_size_t size);
extern void* rucrypto_allocate(rucrypto_size_t size);
/**
* @brief Allocate zeroed buffer
......@@ -42,7 +46,7 @@ void* rucrypto_allocate(rucrypto_size_t size);
* @details Used internally by all functions so they can be used than malloc is
* not available
*/
void* rucrypto_allocate_zeroed(rucrypto_size_t count, rucrypto_size_t size);
extern void* rucrypto_allocate_zeroed(rucrypto_size_t count, rucrypto_size_t size);
/**
* @brief Deallocate buffer, previously allocated via rucrypto_allocate using
......@@ -51,7 +55,7 @@ void* rucrypto_allocate_zeroed(rucrypto_size_t count, rucrypto_size_t size);
* @details Used internally by all functions so they can be used than malloc is
* not available
*/
void rucrypto_deallocate(void* ptr);
extern void rucrypto_deallocate(void* ptr);
#ifdef __cplusplus
}
......
/**
* @file rucrypto/common/types.h
*/
#ifndef RUCRYPTO_COMMON_TYPES_H
#define RUCRYPTO_COMMON_TYPES_H
......@@ -71,14 +75,22 @@ typedef rucrypto_uint8_t rucrypto_vec256_t[256 / 8];
typedef rucrypto_uint8_t rucrypto_vec512_t[512 / 8];
typedef rucrypto_uint8_t rucrypto_vec1024_t[1024 / 8];
typedef struct {
rucrypto_uint8_t* buffer;
rucrypto_size_t size;
} rucrypto_variable_buffer_t;
typedef enum {
rucrypto_result_ok,
rucrypto_result_accepted,
rucrypto_result_not_accepted,
rucrypto_result_out_of_memory,
rucrypto_result_invalid_parameters
rucrypto_result_ok,
rucrypto_result_accepted,
rucrypto_result_not_accepted,
rucrypto_result_out_of_memory,
rucrypto_result_invalid_parameters,
rucrypto_result_cannot_continue,
} rucrypto_result_t;
#define RUCRYPTO_CHECK_ARGS(expr) if (!(expr)) { return rucrypto_result_invalid_parameters; }
#ifdef __cplusplus
}
#endif // __cplusplus
......
/**
* @file rucrypto/gost_34_10/gost_34_10.h
*/
#ifndef RUCRYPTO_GOST_34_10_GOST_34_10_H
#define RUCRYPTO_GOST_34_10_GOST_34_10_H
......
/**
* @file rucrypto/gost_34_11/gost_13_11.h
*/
#ifndef RUCRYPTO_GOST_34_11_GOST_34_11_H
#define RUCRYPTO_GOST_34_11_GOST_34_11_H
......
/**
* @file rucrypto/gost_34_12/gost_34_12.h
*/
#ifndef RUCRYPTO_GOST_34_12_GOST_34_12_H
#define RUCRYPTO_GOST_34_12_GOST_34_12_H
......
/**
* @file rucrypto/gost_34_13/cbc.h
*/
#ifndef RUCRYPTO_GOST_34_13_CBC_H
#define RUCRYPTO_GOST_34_13_CBC_H
......
/**
* @file rucrypto/gost_34_13/cfb.h
*/
#ifndef RUCRYPTO_GOST_34_13_CFB_H
#define RUCRYPTO_GOST_34_13_CFB_H
......
/**
* @file rucrypto/gost_34_13/common.h
*/
#ifndef RUCRYPTO_GOST_34_13_COMMON_H
#define RUCRYPTO_GOST_34_13_COMMON_H
......
/**
* @file rucrypto/gost_34_13/ctr.h
*/
#ifndef RUCRYPTO_GOST_34_13_CTR_H
#define RUCRYPTO_GOST_34_13_CTR_H
......
/**
* @file rucrypto/gost_34_13/ecb.h
*/
#ifndef RUCRYPTO_GOST_34_13_ECB_H
#define RUCRYPTO_GOST_34_13_ECB_H
......
/**
* @file rucrypto/gost_34_13/gost_34_13.h
*/
#ifndef RUCRYPTO_GOST_34_13_GOST_34_13_H
#define RUCRYPTO_GOST_34_13_GOST_34_13_H
......
/**
* @file rucrypto/gost_34_13/mac.h
*/
#ifndef RUCRYPTO_GOST_34_13_MAC_H
#define RUCRYPTO_GOST_34_13_MAC_H
......
/**
* @file rucrypto/gost_34_13/ofb.h
*/
#ifndef RUCRYPTO_GOST_34_13_OFB_H
#define RUCRYPTO_GOST_34_13_OFB_H
......
#ifndef RUCRYPTO_R_1323565_1_022_KEY_GEN_H
#define RUCRYPTO_R_1323565_1_022_KEY_GEN_H
/**
* @file rucrypto/r_1323565_1_022/key_generator.h
*/
#ifndef RUCRYPTO_R_1323565_1_022_KEY_GENERATOR_H
#define RUCRYPTO_R_1323565_1_022_KEY_GENERATOR_H
#include <rucrypto/common/common.h>
......@@ -26,15 +30,14 @@ typedef struct rucrypto_r_1323565_1_022_format_flags_t {
rucrypto_bool_t _zero2 : 1; // Unused, must be 0
} rucrypto_r_1323565_1_022_format_flags_t;
typedef rucrypto_uint8_t rucrypto_r_1323565_1_022_counter_t[32];
typedef rucrypto_uint8_t rucrypto_r_1323565_1_022_length_t[31];
typedef rucrypto_uint8_t rucrypto_r_1323565_1_022_usage_t[32];
typedef rucrypto_uint8_t rucrypto_r_1323565_1_022_users_t[16];
typedef rucrypto_uint8_t rucrypto_r_1323565_1_022_additional_t[16];
typedef rucrypto_variable_buffer_t rucrypto_r_1323565_1_022_counter_t; // 32
typedef rucrypto_variable_buffer_t rucrypto_r_1323565_1_022_zpart_t; // 64
typedef rucrypto_variable_buffer_t rucrypto_r_1323565_1_022_length_t; // 31
typedef rucrypto_variable_buffer_t rucrypto_r_1323565_1_022_usage_t; // 32
typedef rucrypto_variable_buffer_t rucrypto_r_1323565_1_022_users_t; // 16
typedef rucrypto_variable_buffer_t rucrypto_r_1323565_1_022_additional_t; // 16
// f + C_i + z_(i-1) + L + P + U + A
// 1 + 32 + 64 + 31 + 32 + 16 + 16
typedef rucrypto_uint8_t rucrypto_r_1323565_1_022_format_t[192];
typedef rucrypto_variable_buffer_t rucrypto_r_1323565_1_022_iv_t; // 64
typedef enum rucrypto_r_1323565_1_022_key_data_gen_type_t {
rucrypto_r_1323565_1_022_key_data_gen_type_cmac128,
......@@ -63,55 +66,70 @@ extern rucrypto_result_t rucrypto_r_1323565_1_022_gen_intermediate_key(
rucrypto_size_t saltSize,
rucrypto_r_1323565_1_022_intermediate_key_t key);
typedef void (*rucrypto_r_1323565_1_022_format_func_t)(
rucrypto_r_1323565_1_022_format_flags_t flags,
const rucrypto_r_1323565_1_022_counter_t* counter,
const rucrypto_r_1323565_1_022_zpart_t* zpart,
const rucrypto_r_1323565_1_022_length_t* length,
const rucrypto_r_1323565_1_022_usage_t* usage,
const rucrypto_r_1323565_1_022_users_t* users,
const rucrypto_r_1323565_1_022_additional_t* additional,
rucrypto_uint8_t format[],
rucrypto_size_t* formatSize);
/**
* @brief Format info for key data generation
* @param [in] f Flags
* @param [in] flags Flags
* @param [in] counter Counter variable
* @param [in] zpart Previous part
* @param [in] zpart Previous part size
* @param [in] length Length of requested key data
* @param [in] usage Key data usage mark
* @param [in] users Key data user information
* @param [in] additional Additional information
* @param [out] format Resulting buffer
* @param [in, out] formatSize Buffer size
* @details Formating of usage, users and additional info are not defined in R 1323565.1.022, so are left to the user's discretion
* @details Although part size may vary, the allocated block for size is 512 bits. If it is less, the less is filled with 0
* @details Buffer must be 192 bytes or bigger. If not, formatSize will be set to 192 and function will return rucrypto_result_invalid_parameters
*/
extern rucrypto_result_t rucrypto_r_1323565_1_022_format(
const rucrypto_r_1323565_1_022_format_flags_t flags,
const rucrypto_r_1323565_1_022_counter_t counter,
const rucrypto_uint8_t zpart[],
rucrypto_size_t zpartSize,
const rucrypto_r_1323565_1_022_length_t length,
const rucrypto_r_1323565_1_022_usage_t usage,
const rucrypto_r_1323565_1_022_users_t users,
const rucrypto_r_1323565_1_022_additional_t additional,
rucrypto_r_1323565_1_022_format_t format);
extern void rucrypto_r_1323565_1_022_format(
rucrypto_r_1323565_1_022_format_flags_t flags,
const rucrypto_r_1323565_1_022_counter_t* counter,
const rucrypto_r_1323565_1_022_zpart_t* zpart,
const rucrypto_r_1323565_1_022_length_t* length,
const rucrypto_r_1323565_1_022_usage_t* usage,
const rucrypto_r_1323565_1_022_users_t* users,
const rucrypto_r_1323565_1_022_additional_t* additional,
rucrypto_uint8_t format[],
rucrypto_size_t* formatSize);
/**
* @brief Init key data generator
* @param [out] ctx Pointer to rucrypto_r_1323565_1_022_key_generator_context_t
* @param [in] genType Type of MAC function to use
* @param [in] Intermediate key, generated with rucrypto_r_1323565_1_022_gen_intermediate_key
* @param [in] key Intermediate key, generated with rucrypto_r_1323565_1_022_gen_intermediate_key
* @param [in] formatFunc Formatting function
* @param [in] flags Flags to use for format function rucrypto_r_1323565_1_022_format
* @param [in] counter Buffer for counter, must be initialized with zeroes
* @param [in] iv Initializing value for z0 (as per R 1323565.1.022)
* @param [in] ivSize Size of initializing value
* @param [in] length Length of key data to generate (may be NULL if relevant flag is false)
* @param [in] usage Usage information (may be NULL if relevant flag is false)
* @param [in] users Users inforamtion (may be NULL if relevant flafs is false)
* @param [in] additional Additional information (may be NULL if relevant flag is false)
* @details Buffers for length, usage, users and additional should be valid until generator is de-initialized
*/
extern rucrypto_result_t rucrypto_r_1323565_1_022_init_generator(
extern rucrypto_result_t rucrypto_r_1323565_1_022_generator_init(
rucrypto_r_1323565_1_022_key_generator_context_t** ctx,
const rucrypto_r_1323565_1_022_key_data_gen_type_t genType,
rucrypto_r_1323565_1_022_key_data_gen_type_t genType,
const rucrypto_r_1323565_1_022_intermediate_key_t key,
const rucrypto_r_1323565_1_022_format_flags_t flags,
const rucrypto_uint8_t iv[],
rucrypto_size_t ivSize,
const rucrypto_r_1323565_1_022_length_t length,
const rucrypto_r_1323565_1_022_usage_t usage,
const rucrypto_r_1323565_1_022_users_t users,
const rucrypto_r_1323565_1_022_additional_t additional);
rucrypto_r_1323565_1_022_format_func_t formatFunc,
rucrypto_r_1323565_1_022_format_flags_t flags,
rucrypto_r_1323565_1_022_counter_t* counter,
const rucrypto_r_1323565_1_022_iv_t* iv,
rucrypto_r_1323565_1_022_length_t* length,
rucrypto_r_1323565_1_022_usage_t* usage,
rucrypto_r_1323565_1_022_users_t* users,
rucrypto_r_1323565_1_022_additional_t* additional);
/**
* @brief Generate next part of key data rucrypto_r_1323565_1_022_init_generator
......@@ -130,10 +148,10 @@ extern rucrypto_result_t rucrypto_r_1323565_1_022_gen_next_key_data_part(
* @brief Deallocate memory and securely clear buffers with leftover information
* @param [in, out] ctx Key generator context
*/
extern void rucrypto_r_1323565_1_022_fini_generator(rucrypto_r_1323565_1_022_key_generator_context_t** ctx);
extern void rucrypto_r_1323565_1_022_generator_fini(rucrypto_r_1323565_1_022_key_generator_context_t** ctx);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // RUCRYPTO_R_1323565_1_022_KEY_GEN_H
#endif // RUCRYPTO_R_1323565_1_022_KEY_GENERATOR_H
#ifndef RUCRYPTO_R_1323565_1_022_HASHING_FUNCTIONS_H
#define RUCRYPTO_R_1323565_1_022_HASHING_FUNCTIONS_H
/**
* @file rucrypto/r_1323565_1_022/mac_functions.h
*/
#ifndef RUCRYPTO_R_1323565_1_022_MAC_FUNCTIONS_H
#define RUCRYPTO_R_1323565_1_022_MAC_FUNCTIONS_H
#include <rucrypto/common/common.h>
......@@ -94,4 +98,4 @@ extern rucrypto_result_t rucrypto_r_1323565_1_022_nmac_fini(rucrypto_r_1323565_1
}
#endif // __cplusplus
#endif // RUCRYPTO_R_1323565_1_022_HASHING_FUNCTIONS_H
#endif // RUCRYPTO_R_1323565_1_022_MAC_FUNCTIONS_H
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать