diff --git a/dap-sdk/crypto/src/GOST/28147_14.c b/dap-sdk/crypto/src/GOST/28147_14.c index 69133fa7771e4083c7b526f2b06627af4723660d..7b49540a848f09aeacb7d0cbe04236c429b9fd2c 100644 --- a/dap-sdk/crypto/src/GOST/28147_14.c +++ b/dap-sdk/crypto/src/GOST/28147_14.c @@ -403,7 +403,7 @@ int DLL_IMPORT ExpandKey(unsigned char* masterKey, unsigned char* keys, printou return 0; } -int DLL_IMPORT Encrypt_14(unsigned char* plainText, unsigned char* chipherText, unsigned char* keys, printout_byte_array print, printout_uint_array print_uint) +int DLL_IMPORT Encrypt_14(const unsigned char* plainText, unsigned char* chipherText, unsigned char* keys, printout_byte_array print, printout_uint_array print_uint) { unsigned char xTemp[16]; unsigned char yTemp[16]; @@ -442,7 +442,7 @@ int DLL_IMPORT Encrypt_14(unsigned char* plainText, unsigned char* chipherText, return 0; } -int DLL_IMPORT Decrypt_14(unsigned char* chipherText, unsigned char* plainText, unsigned char* keys, printout_byte_array print, printout_uint_array print_uint) +int DLL_IMPORT Decrypt_14(const unsigned char* chipherText, unsigned char* plainText, unsigned char* keys, printout_byte_array print, printout_uint_array print_uint) { unsigned char xTemp[16]; unsigned char yTemp[16]; @@ -478,4 +478,4 @@ int DLL_IMPORT Decrypt_14(unsigned char* chipherText, unsigned char* plainText, } return 0; -} \ No newline at end of file +} diff --git a/dap-sdk/crypto/src/GOST/28147_14.h b/dap-sdk/crypto/src/GOST/28147_14.h index 80ac954416dea6970a459373d8d61e691f94512d..2bc201a9d42e8da24a29076197b3da02d10d402d 100644 --- a/dap-sdk/crypto/src/GOST/28147_14.h +++ b/dap-sdk/crypto/src/GOST/28147_14.h @@ -151,7 +151,7 @@ int DLL_IMPORT ExpandKey(unsigned char* masterKey, unsigned char* keys, printout * @return 0 еÑли вÑе преобразование прошло уÑпешно * @return -1 еÑли произошла ошибка */ -int DLL_IMPORT Encrypt_14(unsigned char* plainText, unsigned char* chipherText, unsigned char* keys, printout_byte_array print, printout_uint_array print_uint); +int DLL_IMPORT Encrypt_14(const unsigned char* plainText, unsigned char* chipherText, unsigned char* keys, printout_byte_array print, printout_uint_array print_uint); /** @brief Выполение раÑÑˆÐ¸Ñ„Ñ€Ð¾Ð²Ð°Ð½Ð¸Ñ Ð±Ð»Ð¾ÐºÐ° * @@ -163,7 +163,7 @@ int DLL_IMPORT Encrypt_14(unsigned char* plainText, unsigned char* chipherText, * @return 0 еÑли вÑе преобразование прошло уÑпешно * @return -1 еÑли произошла ошибка */ -int DLL_IMPORT Decrypt_14(unsigned char* chipherText, unsigned char* plainText, unsigned char* keys, printout_byte_array print, printout_uint_array print_uint); +int DLL_IMPORT Decrypt_14(const unsigned char* chipherText, unsigned char* plainText, unsigned char* keys, printout_byte_array print, printout_uint_array print_uint); #ifdef __cplusplus } diff --git a/dap-sdk/crypto/src/GOST/28147_89.c b/dap-sdk/crypto/src/GOST/28147_89.c index 0f45378cac7b356a8b8247a52407aec8705ea979..60eda929366dc55ebc41eea0d290883e7685c40b 100644 --- a/dap-sdk/crypto/src/GOST/28147_89.c +++ b/dap-sdk/crypto/src/GOST/28147_89.c @@ -11,7 +11,7 @@ * @param[in] input маÑÑив из 4 байт * @return int32 чиÑло */ -static unsigned int uint8ToUint32(unsigned char* input) +static unsigned int uint8ToUint32(const unsigned char* input) { unsigned int r = ( (input[3]) | (input[2]<<8) | (input[1]<<16) | (input[0]<<24)); return r; @@ -143,7 +143,7 @@ void DLL_IMPORT RoundShtrih(unsigned int* a1, unsigned int* a0, unsigned int k, } } -int DLL_IMPORT CryptBlock(unsigned char* input, unsigned char* output, unsigned char* key, unsigned char* keyIndex, printout_uint_array print) +int DLL_IMPORT CryptBlock(const unsigned char* input, unsigned char* output, unsigned char* key, unsigned char* keyIndex, printout_uint_array print) { unsigned int a1 = uint8ToUint32(input); unsigned int a0 = uint8ToUint32(input + 4); @@ -175,17 +175,17 @@ int DLL_IMPORT CryptBlock(unsigned char* input, unsigned char* output, unsigned return 0; } -int DLL_IMPORT EncryptBlock(unsigned char* input, unsigned char* output, unsigned char* key, printout_uint_array print) +int DLL_IMPORT EncryptBlock(const unsigned char* input, unsigned char* output, unsigned char* key, printout_uint_array print) { return CryptBlock(input, output, key, kEncRoundKey, print); } -int DLL_IMPORT DecryptBlock(unsigned char* input, unsigned char* output, unsigned char* key, printout_uint_array print) +int DLL_IMPORT DecryptBlock(const unsigned char* input, unsigned char* output, unsigned char* key, printout_uint_array print) { return CryptBlock(input, output, key, kDecRoundKey, print); } -int DLL_IMPORT Encrypt_89(unsigned char* input, unsigned char* output, unsigned char* key, printout_byte_array print, printout_uint_array print_uint) +int DLL_IMPORT Encrypt_89(const unsigned char* input, unsigned char* output, unsigned char* key, printout_byte_array print, printout_uint_array print_uint) { if( !input || !output || !key ) { @@ -206,7 +206,7 @@ int DLL_IMPORT Encrypt_89(unsigned char* input, unsigned char* output, unsigned return 0; } -int DLL_IMPORT Decrypt_89(unsigned char* input, unsigned char* output, unsigned char* key, printout_byte_array print, printout_uint_array print_uint) +int DLL_IMPORT Decrypt_89(const unsigned char* input, unsigned char* output, unsigned char* key, printout_byte_array print, printout_uint_array print_uint) { if( !input || !output || !key ) { diff --git a/dap-sdk/crypto/src/GOST/28147_89.h b/dap-sdk/crypto/src/GOST/28147_89.h index a0f78eb8a7ae1be046866357be601aafddd1c2e0..5a80f03a45c4f0553dfa2f5fb6f8a61443f90b41 100644 --- a/dap-sdk/crypto/src/GOST/28147_89.h +++ b/dap-sdk/crypto/src/GOST/28147_89.h @@ -59,7 +59,7 @@ void DLL_IMPORT RoundShtrih(unsigned int *a1, unsigned int *a0, unsigned int k, * @return 0 еÑли вÑе преобразование прошло уÑпешно * @return -1 еÑли произошла ошибка */ -int DLL_IMPORT CryptBlock(unsigned char* input, unsigned char* output, unsigned char* key, unsigned char* keySequence, printout_uint_array print); +int DLL_IMPORT CryptBlock(const unsigned char* input, unsigned char* output, unsigned char* key, unsigned char* keySequence, printout_uint_array print); /** @brief Шифруем блок данных * @@ -70,7 +70,7 @@ int DLL_IMPORT CryptBlock(unsigned char* input, unsigned char* output, unsigned * @return 0 еÑли вÑе преобразование прошло уÑпешно * @return -1 еÑли произошла ошибка */ -int DLL_IMPORT EncryptBlock(unsigned char* input, unsigned char* output, unsigned char* key, printout_uint_array print); +int DLL_IMPORT EncryptBlock(const unsigned char* input, unsigned char* output, unsigned char* key, printout_uint_array print); /** @brief РаÑшифровываем блок данных * @@ -81,7 +81,7 @@ int DLL_IMPORT EncryptBlock(unsigned char* input, unsigned char* output, unsigne * @return 0 еÑли вÑе преобразование прошло уÑпешно * @return -1 еÑли произошла ошибка */ -int DLL_IMPORT DecryptBlock(unsigned char* input, unsigned char* output, unsigned char* key, printout_uint_array print); +int DLL_IMPORT DecryptBlock(const unsigned char* input, unsigned char* output, unsigned char* key, printout_uint_array print); /** @brief Шифруем блок данных * @@ -93,7 +93,7 @@ int DLL_IMPORT DecryptBlock(unsigned char* input, unsigned char* output, unsigne * @return 0 еÑли вÑе преобразование прошло уÑпешно * @return -1 еÑли произошла ошибка */ -int DLL_IMPORT Encrypt_89(unsigned char* input, unsigned char* output, unsigned char* key, printout_byte_array print, printout_uint_array print_uint); +int DLL_IMPORT Encrypt_89(const unsigned char* input, unsigned char* output, unsigned char* key, printout_byte_array print, printout_uint_array print_uint); /** @brief РаÑшифровываем блок данных * @@ -105,7 +105,7 @@ int DLL_IMPORT Encrypt_89(unsigned char* input, unsigned char* output, unsigned * @return 0 еÑли вÑе преобразование прошло уÑпешно * @return -1 еÑли произошла ошибка */ -int DLL_IMPORT Decrypt_89(unsigned char* input, unsigned char* output, unsigned char* key, printout_byte_array print, printout_uint_array print_uint); +int DLL_IMPORT Decrypt_89(const unsigned char* input, unsigned char* output, unsigned char* key, printout_byte_array print, printout_uint_array print_uint); #ifdef __cplusplus } diff --git a/dap-sdk/crypto/src/GOST/GOST.pri b/dap-sdk/crypto/src/GOST/GOST.pri index 176c5281c593784d1dbd5853b8aef35a2d1ba64c..2f44dc32c02c18288edaffcd53567d5c4205326d 100644 --- a/dap-sdk/crypto/src/GOST/GOST.pri +++ b/dap-sdk/crypto/src/GOST/GOST.pri @@ -6,11 +6,9 @@ HEADERS += $$PWD/28147_14.h \ $$PWD/dll_import.h \ $$PWD/print_data.h \ $$PWD/table.h \ - $$PWD/test_data.inc \ $$PWD/block_cipher.h SOURCES += $$PWD/28147_14.c \ $$PWD/28147_89.c \ $$PWD/block_cipher.c \ $$PWD/print_data.c \ - $$PWD/testgost.c diff --git a/dap-sdk/crypto/src/GOST/block_cipher.c b/dap-sdk/crypto/src/GOST/block_cipher.c index 80ad6231dc1223690e19b9c84ceac0eea9dafe12..e1f9685be24889e15c1213cf9be4ab6bc8734076 100644 --- a/dap-sdk/crypto/src/GOST/block_cipher.c +++ b/dap-sdk/crypto/src/GOST/block_cipher.c @@ -28,10 +28,10 @@ const unsigned char kAlg14 = 1; const unsigned char kAlg89 = 2; /** @brief указатель на функцию ÑˆÐ¸Ñ„Ñ€Ð¾Ð²Ð°Ð½Ð¸Ñ */ -typedef int (DLL_IMPORT *pEncrypt)(unsigned char* plainText, unsigned char* chipherText, unsigned char* keys, printout_byte_array print, printout_uint_array print_uint); +typedef int (DLL_IMPORT *pEncrypt)(const unsigned char* plainText, unsigned char* chipherText, unsigned char* keys, printout_byte_array print, printout_uint_array print_uint); /** @brief указатель на функцию раÑÑˆÐ¸Ñ„Ñ€Ð¾Ð²Ð°Ð½Ð¸Ñ */ -typedef int (DLL_IMPORT *pDecrypt)(unsigned char* chipherText, unsigned char* plainText, unsigned char* keys, printout_byte_array print, printout_uint_array print_uint); +typedef int (DLL_IMPORT *pDecrypt)(const unsigned char* chipherText, unsigned char* plainText, unsigned char* keys, printout_byte_array print, printout_uint_array print_uint); /** @brief Ð¤ÑƒÐ½ÐºÑ†Ð¸Ñ ÑамотеÑÑ‚Ð¸Ñ€Ð¾Ð²Ð°Ð½Ð¸Ñ Ñ€ÐµÐ¶Ð¸Ð¼Ð° ECB */ static int SelfTestGost14Ecb(); @@ -256,7 +256,7 @@ void DLL_IMPORT free_ecb(void* ctx) } } -static int init_cbc_14_impl(unsigned char *key, void* ctx, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint) +static int init_cbc_14_impl(unsigned char *key, void* ctx, const unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint) { Context_cbc* context; INFOTECS_ASSERT(sizeof(Context_cbc)<=kCbc14ContextLen); @@ -293,14 +293,14 @@ static int init_cbc_14_impl(unsigned char *key, void* ctx, unsigned char *iv, si return 0; } -int DLL_IMPORT init_cbc_14(unsigned char *key, void* ctx, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint) +int DLL_IMPORT init_cbc_14(unsigned char *key, void* ctx, const unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint) { if(SelfTestGost14Cbc()) return -1; return init_cbc_14_impl(key, ctx, iv, ivLength, print, print_uint); } -static int init_cbc_89_impl(unsigned char *key, void* ctx, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint) +static int init_cbc_89_impl(unsigned char *key, void* ctx, const unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint) { Context_cbc* context; INFOTECS_ASSERT(sizeof(Context_cbc)<=kCbc89ContextLen); @@ -337,7 +337,7 @@ static int init_cbc_89_impl(unsigned char *key, void* ctx, unsigned char *iv, si return 0; } -int DLL_IMPORT init_cbc_89(unsigned char *key, void* ctx, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint) +int DLL_IMPORT init_cbc_89(unsigned char *key, void* ctx, const unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint) { if(SelfTestGost89Cbc()) return -1; @@ -382,7 +382,7 @@ void DLL_IMPORT free_cbc(void* ctx) } } -static int init_ctr_14_impl(unsigned char* key, unsigned char *iv, size_t s, void *ctx, printout_byte_array print, printout_uint_array print_uint) +static int init_ctr_14_impl(unsigned char* key, const unsigned char *iv, size_t s, void *ctx, printout_byte_array print, printout_uint_array print_uint) { Context_ctr* context; INFOTECS_ASSERT(sizeof(Context_ctr)<=kCtr14ContextLen); @@ -418,14 +418,14 @@ static int init_ctr_14_impl(unsigned char* key, unsigned char *iv, size_t s, voi return 0; } -int DLL_IMPORT init_ctr_14(unsigned char* key, unsigned char *iv, size_t s, void *ctx, printout_byte_array print, printout_uint_array print_uint) +int DLL_IMPORT init_ctr_14(unsigned char* key, const unsigned char *iv, size_t s, void *ctx, printout_byte_array print, printout_uint_array print_uint) { if(SelfTestGost14Ctr()) return -1; return init_ctr_14_impl(key, iv, s, ctx, print, print_uint); } -static int init_ctr_89_impl(unsigned char* key, unsigned char *iv, size_t s, void *ctx, printout_byte_array print, printout_uint_array print_uint) +static int init_ctr_89_impl(unsigned char* key, const unsigned char *iv, size_t s, void *ctx, printout_byte_array print, printout_uint_array print_uint) { Context_ctr* context; INFOTECS_ASSERT(sizeof(Context_ctr)<=kCtr89ContextLen); @@ -460,7 +460,7 @@ static int init_ctr_89_impl(unsigned char* key, unsigned char *iv, size_t s, voi return 0; } -int DLL_IMPORT init_ctr_89(unsigned char* key, unsigned char *iv, size_t s, void *ctx, printout_byte_array print, printout_uint_array print_uint) +int DLL_IMPORT init_ctr_89(unsigned char* key, const unsigned char *iv, size_t s, void *ctx, printout_byte_array print, printout_uint_array print_uint) { if(SelfTestGost89Ctr()) return -1; @@ -495,7 +495,7 @@ void DLL_IMPORT free_ctr(void* ctx) } } -static int init_ofb_14_impl(unsigned char *key, void *ctx, size_t s, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint) +static int init_ofb_14_impl(unsigned char *key, void *ctx, size_t s, const unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint) { Context_ofb* context; INFOTECS_ASSERT(sizeof(Context_ofb)<=kOfb14ContextLen); @@ -542,7 +542,7 @@ int DLL_IMPORT init_ofb_14(unsigned char *key, void *ctx, size_t s, const unsign return init_ofb_14_impl(key, ctx, s, iv, ivLength, print, print_uint); } -static int init_ofb_89_impl(unsigned char *key, void *ctx, size_t s, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint) +static int init_ofb_89_impl(unsigned char *key, void *ctx, size_t s, const unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint) { Context_ofb* context; INFOTECS_ASSERT(sizeof(Context_ofb)<=kOfb89ContextLen); @@ -580,7 +580,7 @@ static int init_ofb_89_impl(unsigned char *key, void *ctx, size_t s, unsigned ch return 0; } -int DLL_IMPORT init_ofb_89(unsigned char *key, void *ctx, size_t s, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint) +int DLL_IMPORT init_ofb_89(unsigned char *key, void *ctx, size_t s, const unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint) { if(SelfTestGost89Ofb()) return -1; @@ -622,7 +622,7 @@ void DLL_IMPORT free_ofb(void* ctx) } -static int init_cfb_14_impl(unsigned char *key, void *ctx, size_t s, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint) +static int init_cfb_14_impl(unsigned char *key, void *ctx, size_t s, const unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint) { Context_cfb* context; INFOTECS_ASSERT(sizeof(Context_cfb)<=kCfb14ContextLen); @@ -661,14 +661,14 @@ static int init_cfb_14_impl(unsigned char *key, void *ctx, size_t s, unsigned ch return 0; } -int DLL_IMPORT init_cfb_14(unsigned char *key, void *ctx, size_t s, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint) +int DLL_IMPORT init_cfb_14(unsigned char *key, void *ctx, size_t s, const unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint) { if(SelfTestGost14Cfb()) return -1; return init_cfb_14_impl(key, ctx, s, iv, ivLength, print, print_uint); } -static int init_cfb_89_impl(unsigned char *key, void *ctx, size_t s, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint) +static int init_cfb_89_impl(unsigned char *key, void *ctx, size_t s, const unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint) { Context_cfb* context; INFOTECS_ASSERT(sizeof(Context_cfb)<=kCfb89ContextLen); @@ -706,7 +706,7 @@ static int init_cfb_89_impl(unsigned char *key, void *ctx, size_t s, unsigned ch return 0; } -int DLL_IMPORT init_cfb_89(unsigned char *key, void *ctx, size_t s, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint) +int DLL_IMPORT init_cfb_89(unsigned char *key, void *ctx, size_t s, const unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint) { if(SelfTestGost89Cfb()) return -1; @@ -1043,7 +1043,7 @@ int DLL_IMPORT decrypt_ecb(void *ctx, const unsigned char *indata, unsigned char return 0; } -static void PackBlock(unsigned char* a, size_t aLen, unsigned char* b, unsigned char* r, size_t rLen) +static void PackBlock(unsigned char* a, size_t aLen, const unsigned char* b, unsigned char* r, size_t rLen) { memcpy(r, a, aLen); memcpy(r + aLen, b, rLen - aLen); diff --git a/dap-sdk/crypto/src/GOST/block_cipher.h b/dap-sdk/crypto/src/GOST/block_cipher.h index 4a6315ee1540c59ea0fc4fa651836721161e9212..00f60cc5643dbdbc8b6db944c1d11b407ef1ae55 100644 --- a/dap-sdk/crypto/src/GOST/block_cipher.h +++ b/dap-sdk/crypto/src/GOST/block_cipher.h @@ -105,7 +105,7 @@ void DLL_IMPORT free_ecb(void* ctx); * @return 0 еÑли вÑе преобразование прошло уÑпешно * @return -1 еÑли произошла ошибка */ -int DLL_IMPORT init_cbc_14(unsigned char *key, void* ctx, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint); +int DLL_IMPORT init_cbc_14(unsigned char *key, void* ctx, const unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint); /** @brief Ð˜Ð½Ð¸Ñ†Ð¸Ð°Ð»Ð¸Ð·Ð°Ñ†Ð¸Ñ ÐºÐ¾Ð½Ñ‚ÐµÐºÑта ÑˆÐ¸Ñ„Ñ€Ð¾Ð²Ð°Ð½Ð¸Ñ Ð² режиме CBC Ð´Ð»Ñ Ð°Ð»Ð³Ð¾Ñ€Ð¸Ñ‚Ð¼Ð° 28147-89 * @@ -118,7 +118,7 @@ int DLL_IMPORT init_cbc_14(unsigned char *key, void* ctx, unsigned char *iv, si * @return 0 еÑли вÑе преобразование прошло уÑпешно * @return -1 еÑли произошла ошибка */ -int DLL_IMPORT init_cbc_89(unsigned char *key, void* ctx, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint); +int DLL_IMPORT init_cbc_89(unsigned char *key, void* ctx, const unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint); /** @brief Удаление контекÑта cbc * @@ -139,7 +139,7 @@ void DLL_IMPORT free_cbc(void* ctx); * @return 0 еÑли вÑе преобразование прошло уÑпешно * @return -1 еÑли произошла ошибка */ -int DLL_IMPORT init_ctr_14(unsigned char* key, unsigned char *iv, size_t length, void *ctx, printout_byte_array print, printout_uint_array print_uint); +int DLL_IMPORT init_ctr_14(unsigned char* key, const unsigned char *iv, size_t length, void *ctx, printout_byte_array print, printout_uint_array print_uint); /** @brief Ð˜Ð½Ð¸Ñ†Ð¸Ð°Ð»Ð¸Ð·Ð°Ñ†Ð¸Ñ ÐºÐ¾Ð½Ñ‚ÐµÐºÑта ÑˆÐ¸Ñ„Ñ€Ð¾Ð²Ð°Ð½Ð¸Ñ Ð² режиме CTR Ð´Ð»Ñ Ð°Ð»Ð³Ð¾Ñ€Ð¸Ñ‚Ð¼Ð° 28147-89 * @@ -152,7 +152,7 @@ int DLL_IMPORT init_ctr_14(unsigned char* key, unsigned char *iv, size_t length, * @return 0 еÑли вÑе преобразование прошло уÑпешно * @return -1 еÑли произошла ошибка */ -int DLL_IMPORT init_ctr_89(unsigned char* key, unsigned char *iv, size_t length, void *ctx, printout_byte_array print, printout_uint_array print_uint); +int DLL_IMPORT init_ctr_89(unsigned char* key, const unsigned char *iv, size_t length, void *ctx, printout_byte_array print, printout_uint_array print_uint); /** @brief Удаление контекÑта ctr * @@ -188,7 +188,7 @@ int DLL_IMPORT init_ofb_14(unsigned char *key, void *ctx, size_t s, const unsign * @return 0 еÑли вÑе преобразование прошло уÑпешно * @return -1 еÑли произошла ошибка */ -int DLL_IMPORT init_ofb_89(unsigned char *key, void *ctx, size_t s, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint); +int DLL_IMPORT init_ofb_89(unsigned char *key, void *ctx, size_t s, const unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint); /** @brief Удаление контекÑта ofb * @@ -210,7 +210,7 @@ void DLL_IMPORT free_ofb(void* ctx); * @return 0 еÑли вÑе преобразование прошло уÑпешно * @return -1 еÑли произошла ошибка */ -int DLL_IMPORT init_cfb_14(unsigned char *key, void *ctx, size_t s, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint); +int DLL_IMPORT init_cfb_14(unsigned char *key, void *ctx, size_t s, const unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint); /** @brief Ð˜Ð½Ð¸Ñ†Ð¸Ð°Ð»Ð¸Ð·Ð°Ñ†Ð¸Ñ ÐºÐ¾Ð½Ñ‚ÐµÐºÑта ÑˆÐ¸Ñ„Ñ€Ð¾Ð²Ð°Ð½Ð¸Ñ Ð² режиме CFB Ð´Ð»Ñ Ð°Ð»Ð³Ð¾Ñ€Ð¸Ñ‚Ð¼Ð° 28147-89 * @@ -224,7 +224,7 @@ int DLL_IMPORT init_cfb_14(unsigned char *key, void *ctx, size_t s, unsigned cha * @return 0 еÑли вÑе преобразование прошло уÑпешно * @return -1 еÑли произошла ошибка */ -int DLL_IMPORT init_cfb_89(unsigned char *key, void *ctx, size_t s, unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint); +int DLL_IMPORT init_cfb_89(unsigned char *key, void *ctx, size_t s, const unsigned char *iv, size_t ivLength, printout_byte_array print, printout_uint_array print_uint); /** @brief Удаление контекÑта cfb * diff --git a/dap-sdk/crypto/src/GOST/callback_print.h b/dap-sdk/crypto/src/GOST/callback_print.h index 01e387f0db946f85d4eec859e0f26229362aa236..5d76323e3e3e74587ac7187190786d900bbaa22d 100644 --- a/dap-sdk/crypto/src/GOST/callback_print.h +++ b/dap-sdk/crypto/src/GOST/callback_print.h @@ -10,9 +10,9 @@ #include "dll_import.h" /** @brief callback Ð´Ð»Ñ Ð²Ñ‹Ð²Ð¾Ð´Ð° маÑÑива byte */ -typedef void (DLL_IMPORT *printout_byte_array)(const char* text, unsigned char* value, unsigned int valueSize); +typedef void (DLL_IMPORT *printout_byte_array)(const char* text, const unsigned char* value, unsigned int valueSize); /** @brief callback Ð´Ð»Ñ Ð²Ñ‹Ð²Ð¾Ð´Ð° маÑÑива unsigned int32 */ -typedef void (DLL_IMPORT *printout_uint_array)(const char* text, unsigned int* value, unsigned int valueSize); +typedef void (DLL_IMPORT *printout_uint_array)(const char* text, const unsigned int* value, unsigned int valueSize); #endif diff --git a/dap-sdk/crypto/src/GOST/test_data.inc b/dap-sdk/crypto/src/GOST/test_data.inc deleted file mode 100644 index 94d893eb745e313b9bc06c72d25edfdf75b2b76d..0000000000000000000000000000000000000000 --- a/dap-sdk/crypto/src/GOST/test_data.inc +++ /dev/null @@ -1,313 +0,0 @@ -/*---------------------------------------------------------------------- - * теÑтовые Ð·Ð½Ð°Ñ‡ÐµÐ½Ð¸Ñ Ð´Ð»Ñ Ð°Ð»Ð³Ð¾Ñ€Ð¸Ñ‚Ð¼Ð° кузнечик из Ñтандарта - */ - -/* теÑтовые Ð·Ð½Ð°Ñ‡ÐµÐ½Ð¸Ñ Ð¿Ñ€ÐµÐ¾Ð±Ñ€Ð°Ð·Ð¾Ð²Ð°Ð½Ð¸Ñ S */ -unsigned char kSData[5][kBlockLen14] = -{ - {0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x00}, - {0xb6, 0x6c, 0xd8, 0x88, 0x7d, 0x38, 0xe8, 0xd7, 0x77, 0x65, 0xae, 0xea, 0x0c, 0x9a, 0x7e, 0xfc}, - {0x55, 0x9d, 0x8d, 0xd7, 0xbd, 0x06, 0xcb, 0xfe, 0x7e, 0x7b, 0x26, 0x25, 0x23, 0x28, 0x0d, 0x39}, - {0x0c, 0x33, 0x22, 0xfe, 0xd5, 0x31, 0xe4, 0x63, 0x0d, 0x80, 0xef, 0x5c, 0x5a, 0x81, 0xc5, 0x0b}, - {0x23, 0xae, 0x65, 0x63, 0x3f, 0x84, 0x2d, 0x29, 0xc5, 0xdf, 0x52, 0x9c, 0x13, 0xf5, 0xac, 0xda} -}; - -/* теÑтовые Ð·Ð½Ð°Ñ‡ÐµÐ½Ð¸Ñ Ð¿Ñ€ÐµÐ¾Ð±Ñ€Ð°Ð·Ð¾Ð²Ð°Ð½Ð¸Ñ R */ -unsigned char kRData[5][kBlockLen14] = -{ - {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00}, - {0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01}, - {0xa5, 0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x64, 0xa5, 0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0x0d, 0x64, 0xa5, 0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} -}; - -/* теÑтовые Ð·Ð½Ð°Ñ‡ÐµÐ½Ð¸Ñ Ð¿Ñ€ÐµÐ¾Ð±Ñ€Ð°Ð·Ð¾Ð²Ð°Ð½Ð¸Ñ L */ -unsigned char kLData[5][kBlockLen14] = -{ - {0x64, 0xa5, 0x94, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, - {0xd4, 0x56, 0x58, 0x4d, 0xd0, 0xe3, 0xe8, 0x4c, 0xc3, 0x16, 0x6e, 0x4b, 0x7f, 0xa2, 0x89, 0x0d}, - {0x79, 0xd2, 0x62, 0x21, 0xb8, 0x7b, 0x58, 0x4c, 0xd4, 0x2f, 0xbc, 0x4f, 0xfe, 0xa5, 0xde, 0x9a}, - {0x0e, 0x93, 0x69, 0x1a, 0x0c, 0xfc, 0x60, 0x40, 0x8b, 0x7b, 0x68, 0xf6, 0x6b, 0x51, 0x3c, 0x13}, - {0xe6, 0xa8, 0x09, 0x4f, 0xee, 0x0a, 0xa2, 0x04, 0xfd, 0x97, 0xbc, 0xb0, 0xb4, 0x4b, 0x85, 0x80} -}; - -/* теÑтовые Ð·Ð½Ð°Ñ‡ÐµÐ½Ð¸Ñ Ñ€Ð°Ð·Ð²ÐµÑ€Ð½ÑƒÑ‚Ñ‹Ñ… ключей */ -static const unsigned char kKData[10][kBlockLen14] = -{ - {0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77}, - {0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef}, - {0xdb, 0x31, 0x48, 0x53, 0x15, 0x69, 0x43, 0x43, 0x22, 0x8d, 0x6a, 0xef, 0x8c, 0xc7, 0x8c, 0x44}, - {0x3d, 0x45, 0x53, 0xd8, 0xe9, 0xcf, 0xec, 0x68, 0x15, 0xeb, 0xad, 0xc4, 0x0a, 0x9f, 0xfd, 0x04}, - {0x57, 0x64, 0x64, 0x68, 0xc4, 0x4a, 0x5e, 0x28, 0xd3, 0xe5, 0x92, 0x46, 0xf4, 0x29, 0xf1, 0xac}, - {0xbd, 0x07, 0x94, 0x35, 0x16, 0x5c, 0x64, 0x32, 0xb5, 0x32, 0xe8, 0x28, 0x34, 0xda, 0x58, 0x1b}, - {0x51, 0xe6, 0x40, 0x75, 0x7e, 0x87, 0x45, 0xde, 0x70, 0x57, 0x27, 0x26, 0x5a, 0x00, 0x98, 0xb1}, - {0x5a, 0x79, 0x25, 0x01, 0x7b, 0x9f, 0xdd, 0x3e, 0xd7, 0x2a, 0x91, 0xa2, 0x22, 0x86, 0xf9, 0x84}, - {0xbb, 0x44, 0xe2, 0x53, 0x78, 0xc7, 0x31, 0x23, 0xa5, 0xf3, 0x2f, 0x73, 0xcd, 0xb6, 0xe5, 0x17}, - {0x72, 0xe9, 0xdd, 0x74, 0x16, 0xbc, 0xf4, 0x5b, 0x75, 0x5d, 0xba, 0xa8, 0x8e, 0x4a, 0x40, 0x43}, -}; - -/* теÑтовые Ð·Ð½Ð°Ñ‡ÐµÐ½Ð¸Ñ Ð¼Ð°Ñтер-ключа */ -unsigned char kMasterKeyData[32] = -{ - 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66,0x77, - 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef -}; - -/* значение открытого текÑта */ -unsigned char kPlainTextData[] = -{ - 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x00, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88 -}; - - -/* значение шифротекÑта */ -unsigned char kChipherTextData[] = -{ - 0x7f, 0x67, 0x9d, 0x90, 0xbe, 0xbc, 0x24, 0x30, 0x5a, 0x46, 0x8d, 0x42, 0xb9, 0xd4, 0xed, 0xcd -}; - -/* теÑтовые Ð·Ð½Ð°Ñ‡ÐµÐ½Ð¸Ñ Ð¾Ð±Ñ€Ð°Ñ‚Ð½Ð¾Ð³Ð¾ Ð¿Ñ€ÐµÐ¾Ð±Ñ€Ð°Ð·Ð¾Ð²Ð°Ð½Ð¸Ñ L */ -unsigned char kReverseLData[2][kBlockLen14] = -{ - {0x0d, 0x8e, 0x40, 0xe4, 0xa8, 0x00, 0xd0, 0x6b, 0x2f, 0x1b, 0x37, 0xea, 0x37, 0x9e, 0xad, 0x8e}, - {0x8a, 0x6b, 0x93, 0x0a, 0x52, 0x21, 0x1b, 0x45, 0xc5, 0xba, 0xa4, 0x3f, 0xf8, 0xb9, 0x13, 0x19}, -}; - -/* теÑтовые Ð·Ð½Ð°Ñ‡ÐµÐ½Ð¸Ñ Ð¾Ð±Ñ€Ð°Ñ‚Ð½Ð¾Ð³Ð¾ Ð¿Ñ€ÐµÐ¾Ð±Ñ€Ð°Ð·Ð¾Ð²Ð°Ð½Ð¸Ñ LSX */ -unsigned char kReverseLSXData[10][kBlockLen14] = -{ - {0x8a, 0x6b, 0x93, 0x0a, 0x52, 0x21, 0x1b, 0x45, 0xc5, 0xba, 0xa4, 0x3f, 0xf8, 0xb9, 0x13, 0x19}, - {0x76, 0xca, 0x14, 0x9e, 0xef, 0x27, 0xdl, 0xbl, 0x0d, 0x17, 0xe3, 0xd5, 0xd6, 0x8e, 0x5a, 0x72}, - {0x5d, 0x9b, 0x06, 0xd4, 0x1b, 0x9d, 0x1d, 0x2d, 0x04, 0xdf, 0x77, 0x55, 0x36, 0x3e, 0x94, 0xa9}, - {0x79, 0x48, 0x71, 0x92, 0xaa, 0x45, 0x70, 0x9c, 0x11, 0x55, 0x59, 0xd6, 0xe9, 0x28, 0x0f, 0x6e}, - {0xae, 0x50, 0x69, 0x24, 0xc8, 0xce, 0x33, 0x1b, 0xb9, 0x18, 0xfc, 0x5b, 0xdf, 0xbl, 0x95, 0xfa}, - {0xbb, 0xff, 0xbf, 0xc8, 0x93, 0x9e, 0xaa, 0xff, 0xaf, 0xb8, 0xe2, 0x27, 0x69, 0xe3, 0x23, 0xaa}, - {0x3c, 0xc2, 0xf0, 0x7c, 0xc0, 0x7a, 0x8b, 0xec, 0x0f, 0x3e, 0xa0, 0xed, 0x2a, 0xe3, 0x3e, 0x4a}, - {0xf3, 0x6f, 0x01, 0x29, 0x1d, 0x0b, 0x96, 0xd5, 0x91, 0xe2, 0x28, 0xb7, 0x2d, 0x01, 0x1c, 0x36}, - {0x1c, 0x4b, 0x0c, 0x1e, 0x95, 0x01, 0x82, 0xbl, 0xce, 0x69, 0x6a, 0xf5, 0xc0, 0xbf, 0xc5, 0xdf}, - {0x99, 0xbb, 0x99, 0xff, 0x99, 0xbb, 0x99, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff} -}; - -unsigned char kGost14SV[8] = -{ - 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef -}; - -unsigned char kGost14PlainText[64] = -{ - 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x00, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, - 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xee, 0xff, 0x0a, - 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xee, 0xff, 0x0a, 0x00, - 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xee, 0xff, 0x0a, 0x00, 0x11 -}; - -unsigned char kGost14EcbEncText[64] = -{ - 0x7f, 0x67, 0x9d, 0x90, 0xbe, 0xbc, 0x24, 0x30, 0x5a, 0x46, 0x8d, 0x42, 0xb9, 0xd4, 0xed, 0xcd, - 0xb4, 0x29, 0x91, 0x2c, 0x6e, 0x00, 0x32, 0xf9, 0x28, 0x54, 0x52, 0xd7, 0x67, 0x18, 0xd0, 0x8b, - 0xf0, 0xca, 0x33, 0x54, 0x9d, 0x24, 0x7c, 0xee, 0xf3, 0xf5, 0xa5, 0x31, 0x3b, 0xd4, 0xb1, 0x57, - 0xd0, 0xb0, 0x9c, 0xcd, 0xe8, 0x30, 0xb9, 0xeb, 0x3a, 0x02, 0xc4, 0xc5, 0xaa, 0x8a, 0xda, 0x98 -}; - - -unsigned char kGost14CtrSV[16] = -{ - 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xce, 0xf0, 0xa1, 0xb2, 0xc3, 0xd4, 0xe5, 0xf0, 0x01, 0x12 -}; - -unsigned char kGost14CtrC[64] = -{ - 0xf1, 0x95, 0xd8, 0xbe, 0xc1, 0x0e, 0xd1, 0xdb, 0xd5, 0x7b, 0x5f, 0xa2, 0x40, 0xbd, 0xa1, 0xb8, - 0x85, 0xee, 0xe7, 0x33, 0xf6, 0xa1, 0x3e, 0x5d, 0xf3, 0x3c, 0xe4, 0xb3, 0x3c, 0x45, 0xde, 0xe4, - 0xa5, 0xea, 0xe8, 0x8b, 0xe6, 0x35, 0x6e, 0xd3, 0xd5, 0xe8, 0x77, 0xf1, 0x35, 0x64, 0xa3, 0xa5, - 0xcb, 0x91, 0xfa, 0xb1, 0xf2, 0x0c, 0xba, 0xb6, 0xd1, 0xc6, 0xd1, 0x58, 0x20, 0xbd, 0xba, 0x73 -}; - -unsigned char kGost14OfbSV[32] = -{ - 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xce, 0xf0, 0xa1, 0xb2, 0xc3, 0xd4, 0xe5, 0xf0, 0x01, 0x12, - 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89, 0x90, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19 -}; - -unsigned char kGost14OfbC[64] = -{ - 0x81, 0x80, 0x0a, 0x59, 0xb1, 0x84, 0x2b, 0x24, 0xff, 0x1f, 0x79, 0x5e, 0x89, 0x7a, 0xbd, 0x95, - 0xed, 0x5b, 0x47, 0xa7, 0x04, 0x8c, 0xfa, 0xb4, 0x8f, 0xb5, 0x21, 0x36, 0x9d, 0x93, 0x26, 0xbf, - 0x66, 0xa2, 0x57, 0xac, 0x3c, 0xa0, 0xb8, 0xb1, 0xc8, 0x0f, 0xe7, 0xfc, 0x10, 0x28, 0x8a, 0x13, - 0x20, 0x3e, 0xbb, 0xc0, 0x66, 0x13, 0x86, 0x60, 0xa0, 0x29, 0x22, 0x43, 0xf6, 0x90, 0x31, 0x50 -}; - -unsigned char kGost14CbcSV[32] = -{ - 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xce, 0xf0, 0xa1, 0xb2, 0xc3, 0xd4, 0xe5, 0xf0, 0x01, 0x12, - 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89, 0x90, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19 -}; - -unsigned char kGost14CbcC[64] = -{ - 0x68, 0x99, 0x72, 0xd4, 0xa0, 0x85, 0xfa, 0x4d, 0x90, 0xe5, 0x2e, 0x3d, 0x6d, 0x7d, 0xcc, 0x27, - 0x28, 0x26, 0xe6, 0x61, 0xb4, 0x78, 0xec, 0xa6, 0xaf, 0x1e, 0x8e, 0x44, 0x8d, 0x5e, 0xa5, 0xac, - 0xfe, 0x7b, 0xab, 0xf1, 0xe9, 0x19, 0x99, 0xe8, 0x56, 0x40, 0xe8, 0xb0, 0xf4, 0x9d, 0x90, 0xd0, - 0x16, 0x76, 0x88, 0x06, 0x5a, 0x89, 0x5c, 0x63, 0x1a, 0x2d, 0x9a, 0x15, 0x60, 0xb6, 0x39, 0x70 -}; - -unsigned char kGost14CfbSV[32] = -{ - 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xce, 0xf0, 0xa1, 0xb2, 0xc3, 0xd4, 0xe5, 0xf0, 0x01, 0x12, - 0x23, 0x34, 0x45, 0x56, 0x67, 0x78, 0x89, 0x90, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19 -}; - -unsigned char kGost14CfbC[64] = -{ - 0x81, 0x80, 0x0a, 0x59, 0xb1, 0x84, 0x2b, 0x24, 0xff, 0x1f, 0x79, 0x5e, 0x89, 0x7a, 0xbd, 0x95, - 0xed, 0x5b, 0x47, 0xa7, 0x04, 0x8c, 0xfa, 0xb4, 0x8f, 0xb5, 0x21, 0x36, 0x9d, 0x93, 0x26, 0xbf, - 0x79, 0xf2, 0xa8, 0xeb, 0x5c, 0xc6, 0x8d, 0x38, 0x84, 0x2d, 0x26, 0x4e, 0x97, 0xa2, 0x38, 0xb5, - 0x4f, 0xfe, 0xbe, 0xcd, 0x4e, 0x92, 0x2d, 0xe6, 0xc7, 0x5b, 0xd9, 0xdd, 0x44, 0xfb, 0xf4, 0xd1 -}; - -unsigned char kGost14ImitS[8] = -{ - 0x33, 0x6f, 0x4d, 0x29, 0x60, 0x59, 0xfb, 0xe3 -}; - - - - -/* -------------------------------------------------------- */ - -unsigned char kMasterKeyGost89[] = -{ - 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x88, - 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00, - 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, - 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff -}; - -/* теÑтовые Ð·Ð½Ð°Ñ‡ÐµÐ½Ð¸Ñ Ð¸Ð· Ñтандарты Ð´Ð»Ñ Ð°Ð»Ð³Ð¾Ñ€Ð¸Ñ‚Ð¼Ð° 89го года */ -unsigned char kGost89StandartPlainText[] = -{ - 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10 -}; - -unsigned char kGost89StandartEncrText[] = -{ - 0x4e, 0xe9, 0x01, 0xe5, 0xc2, 0xd8, 0xca, 0x3d -}; - -/* теÑтовые Ð·Ð½Ð°Ñ‡ÐµÐ½Ð¸Ñ Ð´Ð»Ñ Ð¿Ñ€ÐµÐ¾Ð±Ñ€Ð°Ð·Ð¾Ð²Ð°Ð½Ð¸Ñ t, опиÑанного в Ñтандарте */ -unsigned int kTData[5] = -{ - 0xfdb97531, 0x2a196f34, 0xebd9f03a, 0xb039bb3d, 0x68695433 -}; - -/* теÑтовые Ð·Ð½Ð°Ñ‡ÐµÐ½Ð¸Ñ Ð´Ð»Ñ Ð¿Ñ€ÐµÐ¾Ð±Ñ€Ð°Ð·Ð¾Ð²Ð°Ð½Ð¸Ñ g, опиÑанного в Ñтандарте */ -unsigned int kgData[4][3] = -{ - {0x87654321, 0xfedcba98, 0xfdcbc20c}, - {0xfdcbc20c, 0x87654321, 0x7e791a4b}, - {0x7e791a4b, 0xfdcbc20c, 0xc76549ec}, - {0xc76549ec, 0x7e791a4b, 0x9791c849} -}; - -unsigned char kGost89PlaintText[32] = -{ - 0x92, 0xde, 0xf0, 0x6b, 0x3c, 0x13, 0x0a, 0x59, - 0xdb, 0x54, 0xc7, 0x04, 0xf8, 0x18, 0x9d, 0x20, - 0x4a, 0x98, 0xfb, 0x2e, 0x67, 0xa8, 0x02, 0x4c, - 0x89, 0x12, 0x40, 0x9b, 0x17, 0xb5, 0x7e, 0x41, -}; - -unsigned char kGost89EcbC[32] = -{ - 0x2b, 0x07, 0x3f, 0x04, 0x94, 0xf3, 0x72, 0xa0, - 0xde, 0x70, 0xe7, 0x15, 0xd3, 0x55, 0x6e, 0x48, - 0x11, 0xd8, 0xd9, 0xe9, 0xea, 0xcf, 0xbc, 0x1e, - 0x7c, 0x68, 0x26, 0x09, 0x96, 0xc6, 0x7e, 0xfb -}; - -unsigned char kGost89CtrSV[4] = -{ - 0x12, 0x34, 0x56, 0x78 -}; - -unsigned char kGost89CtrC[32] = -{ - 0x4e, 0x98, 0x11, 0x0c, 0x97, 0xb7, 0xb9, 0x3c, - 0x3e, 0x25, 0x0d, 0x93, 0xd6, 0xe8, 0x5d, 0x69, - 0x13, 0x6d, 0x86, 0x88, 0x07, 0xb2, 0xdb, 0xef, - 0x56, 0x8e, 0xb6, 0x80, 0xab, 0x52, 0xa1, 0x2d -}; - -unsigned char kGost89OfbSV[16] = -{ - 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, - 0x23, 0x45, 0x67, 0x89, 0x0a, 0xbc, 0xde, 0xf1 -}; - -unsigned char kGost89OfbC[32] = -{ - 0xdb, 0x37, 0xe0, 0xe2, 0x66, 0x90, 0x3c, 0x83, - 0x0d, 0x46, 0x64, 0x4c, 0x1f, 0x9a, 0x08, 0x9c, - 0xa0, 0xf8, 0x30, 0x62, 0x43, 0x0e, 0x32, 0x7e, - 0xc8, 0x24, 0xef, 0xb8, 0xbd, 0x4f, 0xdb, 0x05 -}; - - -unsigned char kGost89CbcSV[24] = -{ - 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, - 0x23, 0x45, 0x67, 0x89, 0x0a, 0xbc, 0xde, 0xf1, - 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, -}; - -unsigned char kGost89CbcC[32] = -{ - 0x96, 0xd1, 0xb0, 0x5e, 0xea, 0x68, 0x39, 0x19, - 0xaf, 0xf7, 0x61, 0x29, 0xab, 0xb9, 0x37, 0xb9, - 0x50, 0x58, 0xb4, 0xa1, 0xc4, 0xbc, 0x00, 0x19, - 0x20, 0xb7, 0x8b, 0x1a, 0x7c, 0xd7, 0xe6, 0x67, -}; - -unsigned char kGost89CfbSV[16] = -{ - 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, - 0x23, 0x45, 0x67, 0x89, 0x0a, 0xbc, 0xde, 0xf1 -}; - -unsigned char kGost89CfbC[32] = -{ - 0xdb, 0x37, 0xe0, 0xe2, 0x66, 0x90, 0x3c, 0x83, - 0x0d, 0x46, 0x64, 0x4c, 0x1f, 0x9a, 0x08, 0x9c, - 0x24, 0xbd, 0xd2, 0x03, 0x53, 0x15, 0xd3, 0x8b, - 0xbc, 0xc0, 0x32, 0x14, 0x21, 0x07, 0x55, 0x05 -}; - -unsigned char kGost89ImitS[8] = -{ - 0x15, 0x4e, 0x72, 0x10, 0x20, 0x30, 0xc5, 0xbb -}; - -/* ----------------------------------------------------- */ - -unsigned char kPaddingText[16] = -{ - 2, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -unsigned char kPaddingText2[32] = -{ - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -unsigned char paddingBufferText[16] = -{ - 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -unsigned char paddingBufferText2[32] = -{ - 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; diff --git a/dap-sdk/crypto/src/GOST/testgost.c b/dap-sdk/crypto/src/GOST/testgost.c deleted file mode 100644 index 289b71abc9ec45ea62796e553ee17293f2c0a9da..0000000000000000000000000000000000000000 --- a/dap-sdk/crypto/src/GOST/testgost.c +++ /dev/null @@ -1,906 +0,0 @@ -/** @file - * @brief Ð ÐµÐ°Ð»Ð¸Ð·Ð°Ñ†Ð¸Ñ Ñ„ÑƒÐ½ÐºÑ†Ð¸Ð¹ теÑÑ‚Ð¸Ñ€Ð¾Ð²Ð°Ð½Ð¸Ñ Ð°Ð»Ð³Ð¾Ñ€Ð¸Ñ‚Ð¼Ð¾Ð² "кузнечик" и 28147-89. Ртакже режимов работы блочных шифров - * - * @copyright InfoTeCS. All rights reserved. - */ - -#include <memory.h> - -#include "28147_14.h" -#include "block_cipher.h" -#include "28147_89.h" -#include "test_data.inc" -#include "print_data.h" - -/** @brief размер теÑтовых данных Ð´Ð»Ñ Ð°Ð»Ð³Ð¾Ñ€Ð¸Ñ‚Ð¼Ð° "кузнечик" */ -#define textLen14 sizeof(kGost14PlainText) - -/** @brief размер теÑтовых данных Ð´Ð»Ñ Ð°Ð»Ð³Ð¾Ñ€Ð¸Ñ‚Ð¼Ð° "28147-89" */ -#define textLen89 sizeof(kGost89PlaintText) - -/** @brief теÑтирование Ð¿Ñ€ÐµÐ¾Ð±Ñ€Ð°Ð·Ð¾Ð²Ð°Ð½Ð¸Ñ S из алгоритма "кузнечик" */ -int testS() -{ - unsigned char tmp[kBlockLen14]; - unsigned int i; - - PrintLabel("Test S function start."); - - for(i = 0; i < 4; ++i) - { - funcS(kSData[i], tmp, 0); - - PrintBlockLeft("Test ", i+1); - PrintBlock("Input Value: ", kSData[i], kBlockLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Output Value: ", tmp, kBlockLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Control Value: ", kSData[i+1], kBlockLen14, kBlockLen14); - PrintEmptyLine(); - - if(memcmp(tmp, kSData[i+1], kBlockLen14)) - return -1; - } - - return 0; -} - -/** @brief теÑтирование Ð¿Ñ€ÐµÐ¾Ð±Ñ€Ð°Ð·Ð¾Ð²Ð°Ð½Ð¸Ñ R из алгоритма "кузнечик" */ -int testR() -{ - unsigned char tmp[kBlockLen14]; - int i; - - PrintLabel("Test R function start."); - - for(i =0; i < 4; ++i) - { - if(funcR(kRData[i], tmp, 0)) - return -1; - - PrintBlockLeft("Test ", i+1); - PrintBlock("Input Value: ", kRData[i], kBlockLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Output Value: ", tmp, kBlockLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Control Value: ", kRData[i+1], kBlockLen14, kBlockLen14); - PrintEmptyLine(); - - if(memcmp(tmp, kRData[i+1], kBlockLen14)) - return -1; - } - - return 0; -} - -/** @brief теÑтирование Ð¿Ñ€ÐµÐ¾Ð±Ñ€Ð°Ð·Ð¾Ð²Ð°Ð½Ð¸Ñ L из алгоритма "кузнечик" */ -int testL() -{ - unsigned char tmp[kBlockLen14]; - int i; - - PrintLabel("Test L function start."); - - for(i =0; i < 4; ++i) - { - if(funcL(kLData[i], tmp, 0)) - return -1; - - PrintBlockLeft("Test ", i+1); - PrintBlock("Input Value: ", kLData[i], kBlockLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Output Value: ", tmp, kBlockLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Control Value: ", kLData[i+1], kBlockLen14, kBlockLen14); - PrintEmptyLine(); - - if( memcmp(tmp, kLData[i+1], kBlockLen14)) - return -1; - } - return 0; -} - -/** @brief теÑтирование Ñ€Ð°Ð·Ð²Ð¾Ñ€Ð°Ñ‡Ð¸Ð²Ð°Ð½Ð¸Ñ ÐºÐ»ÑŽÑ‡Ð° из алгоритма "кузнечик" */ -int testExpandKey() -{ - const size_t keyLen = sizeof(kMasterKeyData)/sizeof(kMasterKeyData[0]); - unsigned char keys[160]; - int i; - - PrintLabel("Test Expand Key function start."); - - if(ExpandKey(kMasterKeyData, keys, 0)) - return -1; - - PrintBlock("Master Key: ", kMasterKeyData, keyLen, kBlockLen14); - PrintEmptyLine(); - - for(i = 0; i < 10; ++i) - { - PrintBlock("Output Key: ", keys+i*kBlockLen14, kBlockLen14, kBlockLen14); - PrintBlock("Control Key: ", (unsigned char*)kKData[i], kBlockLen14, kBlockLen14); - PrintEmptyLine(); - - if( memcmp(keys+i*kBlockLen14, kKData[i], kBlockLen14)) - return -1; - } - - return 0; -} - -/** @brief теÑтирование ÑˆÐ¸Ñ„Ñ€Ð¾Ð²Ð°Ð½Ð¸Ñ Ð¿Ð¾ алгоритму "кузнечик" */ -int testEncrypt() -{ - const size_t keyLen = sizeof(kMasterKeyData)/sizeof(kMasterKeyData[0]); - - unsigned char ctx[kEcb14ContextLen]; - unsigned char output[kBlockLen14]; - - PrintLabel("Test Encrypt start."); - - if(init_ecb_14(kMasterKeyData, ctx, 0, 0)) - return -1; - - if(encrypt_ecb(ctx, kPlainTextData, output, kBlockLen14)) - return -1; - - PrintBlock("Master Key: ", kMasterKeyData, keyLen, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Input Value: ", kPlainTextData, kBlockLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Output Value: ", output, kBlockLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Control value: ", kChipherTextData, kBlockLen14, kBlockLen14); - PrintEmptyLine(); - - if( memcmp(output, kChipherTextData, kBlockLen14)) - return -1; - - return 0; -} - -/** @brief теÑтирование раÑÑˆÐ¸Ñ„Ñ€Ð¾Ð²Ð°Ð½Ð¸Ñ Ð¿Ð¾ алгоритму "кузнечик" */ -int testDecrypt() -{ - const size_t keyLen = sizeof(kMasterKeyData)/sizeof(kMasterKeyData[0]); - - unsigned char ctx[kEcb14ContextLen]; - unsigned char output[kBlockLen14]; - - PrintLabel("Test Decrypt start."); - - if(init_ecb_14(kMasterKeyData, ctx, 0, 0)) - return -1; - - if(decrypt_ecb(ctx, kChipherTextData, output, kBlockLen14)) - return -1; - - PrintBlock("Master Key: ", kMasterKeyData, keyLen, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Input Value: ", kChipherTextData, kBlockLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Output Value: ", output, kBlockLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Control value: ", kPlainTextData, kBlockLen14, kBlockLen14); - PrintEmptyLine(); - - if( memcmp(output, kPlainTextData, kBlockLen14) ) - return -1; - - free_ecb(ctx); - - return 0; -} - -/** @brief теÑтирование шифроавание в режиме ecb по алгоритму "кузнечик" */ -int gost14_ECB_test() -{ - unsigned char ctx[kEcb14ContextLen]; - unsigned char output[textLen14]; - unsigned char outputE[textLen14]; - - PrintLabel("Ecb mode 28147-14 test start."); - - if(init_ecb_14(kMasterKeyData, ctx, print_array, print_uint_array)) - return -1; - - if(encrypt_ecb(ctx, kGost14PlainText, output, textLen14)) - return -1; - - PrintBlock("Master Key: ", kMasterKeyData, 32, kBlockLen14); - PrintEmptyLine(); - PrintLineLeft("Test Encrypt."); - PrintEmptyLine(); - PrintBlock("Input Value: ", kGost14PlainText, kBlockLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Output Value: ", output, kBlockLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Control value: ", kGost14EcbEncText, kBlockLen14, kBlockLen14); - PrintEmptyLine(); - - if( memcmp(output, kGost14EcbEncText, textLen14)) - return -1; - - if(init_ecb_14(kMasterKeyData, ctx, print_array, print_uint_array)) - return -1; - - if(decrypt_ecb(ctx, output, outputE, textLen14)) - return -1; - - PrintLineLeft("Test Decrypt."); - PrintEmptyLine(); - PrintBlock("Input Value: ", output, kBlockLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Output Value: ", outputE, kBlockLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Control value: ", kGost14PlainText, kBlockLen14, kBlockLen14); - PrintEmptyLine(); - - if( memcmp(outputE, kGost14PlainText, textLen14)) - return -1; - - free_ecb(ctx); - - return 0; -} - -/** @brief теÑтирование режима ctr алгоритма "кузнечик" */ -int gost14_CTR_test() -{ - const size_t svLen = sizeof(kGost14CtrSV); - - unsigned char outText[textLen14]; - unsigned char ctx[kCtr14ContextLen]; - - PrintLabel("CTR mode 28147-14 test start."); - - if(init_ctr_14(kMasterKeyData, kGost14CtrSV, svLen, ctx, print_array, print_uint_array)) - return -1; - - if(crypt_ctr(ctx, kGost14PlainText, outText, textLen14)) - return -1; - - free_ctr(ctx); - - PrintBlock("Master Key: ", kMasterKeyData, 32, kBlockLen14); - PrintEmptyLine(); - PrintBlock("SV: ", kGost14CtrSV, kBlockLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Input Value: ", kGost14PlainText, textLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Output Value: ", outText, textLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Control value: ", kGost14CtrC, textLen14, kBlockLen14); - PrintEmptyLine(); - - return memcmp(outText, kGost14CtrC, textLen14); -} - -/** @brief теÑтирование режима ofb алгоритма "кузнечик" */ -int gost14_OFB_test() -{ - const size_t svLen = sizeof(kGost14OfbSV); - - unsigned char outText[textLen14]; - unsigned char ctx[kOfb14ContextLen]; - - PrintLabel("OFB mode 28147-14 test start."); - - if(init_ofb_14(kMasterKeyData, ctx, kBlockLen14, kGost14OfbSV, svLen, print_array, print_uint_array)) - return -1; - - if(crypt_ofb(ctx, kGost14PlainText, outText, textLen14)) - return -1; - - free_ofb(ctx); - - PrintBlock("Master Key: ", kMasterKeyData, 32, kBlockLen14); - PrintEmptyLine(); - PrintBlock("SV: ", kGost14OfbSV, kBlockLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Input Value: ", kGost14PlainText, textLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Output Value: ", outText, textLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Control value: ", kGost14OfbC, textLen14, kBlockLen14); - PrintEmptyLine(); - - return memcmp(outText, kGost14OfbC, textLen14); -} - -/** @brief теÑтирование режима cbc алгоритма "кузнечик" */ -int gost14_CBC_test() -{ - const size_t svLen = sizeof(kGost14CbcSV); - - unsigned char outText[textLen14]; - unsigned char outTextDec[textLen14]; - unsigned char ctx[kCbc14ContextLen]; - - PrintLabel("CBC mode 28147-14 test start."); - - if(init_cbc_14(kMasterKeyData, ctx, kGost14CbcSV, svLen, print_array, print_uint_array)) - return -1; - - if(encrypt_cbc(ctx, kGost14PlainText, outText, textLen14)) - return -1; - - free_cbc(ctx); - - PrintBlock("Master Key: ", kMasterKeyData, 32, kBlockLen14); - PrintEmptyLine(); - PrintLineLeft("Test Encrypt."); - PrintEmptyLine(); - PrintBlock("SV: ", kGost14CbcSV, svLen, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Input Value: ", kGost14PlainText, textLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Output Value: ", outText, textLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Control value: ", kGost14CbcC, textLen14, kBlockLen14); - PrintEmptyLine(); - - if(init_cbc_14(kMasterKeyData, ctx, kGost14CbcSV, svLen, print_array, print_uint_array)) - return -1; - - if(decrypt_cbc(ctx, outText, outTextDec, textLen14)) - return -1; - - free_cbc(ctx); - - PrintLineLeft("Test Decrypt."); - PrintEmptyLine(); - PrintBlock("Input Value: ", outText, textLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Output Value: ", outTextDec, textLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Control value: ", kGost14PlainText, textLen14, kBlockLen14); - PrintEmptyLine(); - - if(memcmp(outTextDec, kGost14PlainText, textLen14)) - return -1; - - return memcmp(outText, kGost14CbcC, textLen14); -} - -/** @brief теÑтирование режима cfb алгоритма "кузнечик" */ -int gost14_CFB_test() -{ - const size_t svLen = sizeof(kGost14CfbSV); - - unsigned char outText[textLen14]; - unsigned char outTextDec[textLen14]; - unsigned char ctx[kCfb14ContextLen]; - - PrintLabel("CFB mode 28147-14 test start."); - - if(init_cfb_14(kMasterKeyData, ctx, kBlockLen14, kGost14CfbSV, svLen, print_array, print_uint_array)) - return -1; - - if(encrypt_cfb(ctx, kGost14PlainText, outText, textLen89)) - return -1; - - if(memcmp(outText, kGost14CfbC, textLen89)) - return -1; - - PrintBlock("Master Key: ", kMasterKeyData, 32, kBlockLen14); - PrintEmptyLine(); - PrintBlock("SV: ", kGost14CfbSV, svLen, kBlockLen14); - PrintEmptyLine(); - PrintLineLeft("Test Encrypt."); - PrintEmptyLine(); - PrintBlock("Input Value: ", kGost14PlainText, textLen89, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Output Value: ", outText, textLen89, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Control value: ", kGost14CfbC, textLen89, kBlockLen14); - PrintEmptyLine(); - - free_cfb(ctx); - - if(init_cfb_14(kMasterKeyData, ctx, 16, kGost14CfbSV, svLen, print_array, print_uint_array)) - return -1; - - if(decrypt_cfb(ctx, outText, outTextDec, textLen89)) - return -1; - - PrintLineLeft("Test Decrypt."); - PrintEmptyLine(); - PrintBlock("Input Value: ", outText, textLen89, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Output Value: ", outTextDec, textLen89, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Control value: ", kGost14PlainText, textLen89, kBlockLen14); - PrintEmptyLine(); - - if(memcmp(outTextDec, kGost14PlainText, textLen89)) - return -1; - - free_cfb(ctx); - - return 0; -} - -/** @brief теÑтирование режима имитовÑтавки алгоритма "кузнечик" */ -int gost14_imita_test() -{ - const size_t imitLen = sizeof(kGost14ImitS); - unsigned char outText[16]; - unsigned char ctx[kImit14ContextLen]; - - PrintLabel("Imita mode 28147-14 test start."); - - if(init_imit_14(kMasterKeyData, kBlockLen14, ctx, print_array, print_uint_array)) - return -1; - - if(imit(ctx, kGost14PlainText, textLen14)) - return 0; - - done_imit(ctx, outText); - - PrintBlock("Input Value: ", kGost14PlainText, textLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Output Value: ", outText, imitLen, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Control value: ", kGost14ImitS, imitLen, kBlockLen14); - PrintEmptyLine(); - - free_imit(ctx); - - return memcmp(outText, kGost14ImitS, imitLen); -} - -/** @brief теÑтирование режима ecb алгоритма 28147-89 */ -int gost89_ECB_test() -{ - unsigned char ctx[kEcb89ContextLen]; - unsigned char output[textLen89]; - unsigned char outputDec[textLen89]; - - PrintLabel("Ecb mode 28147-89 test start."); - - if(init_ecb_89(kMasterKeyGost89, ctx, print_array, print_uint_array)) - return -1; - - if(encrypt_ecb(ctx, kGost89PlaintText, output, textLen89)) - return -1; - - PrintBlock("Master Key: ", kMasterKeyGost89, 32, kBlockLen89); - PrintEmptyLine(); - PrintBlock("Input Value: ", kGost89PlaintText, textLen89, kBlockLen89); - PrintEmptyLine(); - PrintBlock("Output Value: ", output, textLen89, kBlockLen89); - PrintEmptyLine(); - PrintBlock("Control value: ", kGost89EcbC, textLen89, kBlockLen89); - PrintEmptyLine(); - - if(memcmp(output, kGost89EcbC, textLen89)) - return -1; - - free_ecb(ctx); - - if(init_ecb_89(kMasterKeyGost89, ctx, print_array, print_uint_array)) - return -1; - - if(decrypt_ecb(ctx, output, outputDec, textLen89)) - return -1; - - if(memcmp(outputDec, kGost89PlaintText, textLen89)) - return -1; - - free_ecb(ctx); - - return 0; -} - -/** @brief теÑтирование режима ctr алгоритма 28147-89 */ -int gost89_CTR_test() -{ - const size_t SvLen = sizeof(kGost89CtrSV); - - unsigned char outText[textLen89]; - unsigned char ctx[kCtr89ContextLen]; - - PrintLabel("Ctr mode 28147-89 test start."); - - if(init_ctr_89(kMasterKeyGost89, kGost89CtrSV, kBlockLen89, ctx, print_array, print_uint_array)) - return -1; - - if(crypt_ctr(ctx, kGost89PlaintText, outText, textLen89)) - return -1; - - free_ctr(ctx); - - PrintBlock("Master Key: ", kMasterKeyGost89, 32, kBlockLen89); - PrintEmptyLine(); - PrintBlock("SV: ", kGost89CtrSV, SvLen, kBlockLen89); - PrintEmptyLine(); - PrintBlock("Input Value: ", kGost89PlaintText, textLen89, kBlockLen89); - PrintEmptyLine(); - PrintBlock("Output Value: ", outText, textLen89, kBlockLen89); - PrintEmptyLine(); - PrintBlock("Control value: ", kGost89CtrC, textLen89, kBlockLen89); - PrintEmptyLine(); - - return memcmp(outText, kGost89CtrC, textLen89); -} - -/** @brief теÑтирование режима ofb алгоритма 28147-89 */ -int gost89_OFB_test() -{ - const size_t SvLen = sizeof(kGost89OfbSV); - - unsigned char outText[textLen89]; - unsigned char ctx[kOfb89ContextLen]; - - PrintLabel("Ofb mode 28147-89 test start."); - - if(init_ofb_89(kMasterKeyGost89, ctx, kBlockLen89, kGost89OfbSV, SvLen, print_array, print_uint_array)) - return -1; - - if(crypt_ofb(ctx, kGost89PlaintText, outText, textLen89)) - return -1; - - PrintBlock("Master Key: ", kMasterKeyGost89, 32, kBlockLen89); - PrintEmptyLine(); - PrintBlock("SV: ", kGost89OfbSV, SvLen, kBlockLen89); - PrintEmptyLine(); - PrintBlock("Input Value: ", kGost89PlaintText, textLen89, kBlockLen89); - PrintEmptyLine(); - PrintBlock("Output Value: ", outText, textLen89, kBlockLen89); - PrintEmptyLine(); - PrintBlock("Control value: ", kGost89OfbC, textLen89, kBlockLen89); - PrintEmptyLine(); - - free_ofb(ctx); - - return memcmp(outText, kGost89OfbC, textLen89); -} - -/** @brief теÑтирование режима cbc алгоритма 28147-89 */ -int gost89_CBC_test() -{ - const size_t SvLen = sizeof(kGost89CbcSV); - - unsigned char outText[textLen89]; - unsigned char outTextDec[textLen89]; - unsigned char ctx[kCbc89ContextLen]; - - PrintLabel("Cbc mode 28147-89 test start."); - - if(init_cbc_89(kMasterKeyGost89, ctx, kGost89CbcSV, SvLen, print_array, print_uint_array)) - return -1; - - if(encrypt_cbc(ctx, kGost89PlaintText, outText, textLen89)) - return 0; - - free_cbc(ctx); - - PrintBlock("Master Key: ", kMasterKeyGost89, 32, kBlockLen89); - PrintEmptyLine(); - PrintBlock("SV: ", kGost89CbcSV, SvLen, kBlockLen89); - PrintEmptyLine(); - PrintBlock("Input Value: ", kGost89PlaintText, textLen89, kBlockLen89); - PrintEmptyLine(); - PrintBlock("Output Value: ", outText, textLen89, kBlockLen89); - PrintEmptyLine(); - PrintBlock("Control value: ", kGost89CbcC, textLen89, kBlockLen89); - PrintEmptyLine(); - - if(init_cbc_89(kMasterKeyGost89, ctx, kGost89CbcSV, SvLen, print_array, print_uint_array)) - return -1; - - if(decrypt_cbc(ctx, outText, outTextDec, textLen89)) - return -1; - - free_cbc(ctx); - - if(memcmp(outTextDec, kGost89PlaintText, textLen89)) - return -1; - - return memcmp(outText, kGost89CbcC, textLen89); -} - -/** @brief ТеÑтирование криптографичеÑкого Ð¿Ñ€ÐµÐ¾Ð±Ñ€Ð°Ð·Ð¾Ð²Ð°Ð½Ð¸Ñ Ð°Ð»Ð³Ð¾Ñ€Ð¸Ñ‚Ð¼Ð° 28147-89 */ -int standart_89_encr_test() -{ - const size_t textLen = sizeof(kGost89StandartPlainText); - - unsigned char ctx[kEcb89ContextLen]; - unsigned char output[sizeof(kGost89StandartPlainText)]; - unsigned char outputE[sizeof(kGost89StandartPlainText)]; - - PrintLabel("Standart 28147-89 encryption test start."); - - if(init_ecb_89(kMasterKeyGost89, ctx, print_array, print_uint_array)) - return -1; - - if(encrypt_ecb(ctx, kGost89StandartPlainText, output, textLen)) - return -1; - - PrintBlock("Master Key: ", kMasterKeyGost89, 32, kBlockLen89); - PrintEmptyLine(); - - PrintBlock("Input Value: ", kGost89StandartPlainText, textLen, kBlockLen89); - PrintEmptyLine(); - PrintBlock("Output Value: ", output, textLen, kBlockLen89); - PrintEmptyLine(); - PrintBlock("Control value: ", kGost89StandartEncrText, textLen, kBlockLen89); - PrintEmptyLine(); - - if(memcmp(output, kGost89StandartEncrText, textLen)) - return -1; - - free_ecb(ctx); - - if(init_ecb_89(kMasterKeyGost89, ctx, print_array, print_uint_array)) - return -1; - - if(decrypt_ecb(ctx, output, outputE, textLen)) - return -1; - - if(memcmp(outputE, kGost89StandartPlainText, textLen)) - return -1; - - free_ecb(ctx); - - return 0; -} - -/** @brief теÑтирование режима cfb алгоритма 28147-89 */ -int gost89_CFB_test() -{ - const size_t SvLen = sizeof(kGost89CfbSV); - - unsigned char outText[textLen89]; - unsigned char outTextDec[textLen89]; - unsigned char ctx[kCfb89ContextLen]; - - PrintLabel("Cfb mode 28147-89 test start."); - - if(init_cfb_89(kMasterKeyGost89, ctx, kBlockLen89, kGost89CfbSV, SvLen, print_array, print_uint_array)) - return -1; - - if(encrypt_cfb(ctx, kGost89PlaintText, outText, textLen89)) - return -1; - - PrintBlock("Master Key: ", kMasterKeyGost89, 32, kBlockLen89); - PrintEmptyLine(); - PrintBlock("SV: ", kGost89CfbSV, SvLen, kBlockLen89); - PrintEmptyLine(); - PrintBlock("Input Value: ", kGost89PlaintText, textLen89, kBlockLen89); - PrintEmptyLine(); - PrintBlock("Output Value: ", outText, textLen89, kBlockLen89); - PrintEmptyLine(); - PrintBlock("Control value: ", kGost89CfbC, textLen89, kBlockLen89); - PrintEmptyLine(); - - if(memcmp(outText, kGost89CfbC, textLen89)) - return -1; - - free_cfb(ctx); - - if(init_cfb_89(kMasterKeyGost89, ctx, kBlockLen89, kGost89CfbSV, SvLen, print_array, print_uint_array)) - return -1; - - if(decrypt_cfb(ctx, outText, outTextDec, textLen89)) - return -1; - - if(memcmp(outTextDec, kGost89PlaintText, textLen89)) - return -1; - - free_cfb(ctx); - - return 0; -} -#include<stdio.h> -/** @brief теÑтирование режима имтовÑтавки алгоритма 28147-89 */ -int gost89_imita_test() -{ - const size_t imitLen = sizeof(kGost89ImitS); - - unsigned char outText[sizeof(kGost89ImitS)]; - unsigned char ctx[kImit89ContextLen]; - - PrintLabel("Imita mode 28147-89 test start."); - - if(init_imit_89(kMasterKeyGost89, kBlockLen89, ctx, print_array, print_uint_array)) - return -1; - - if(imit(ctx, kGost89PlaintText, textLen89)) - return -1; - - done_imit(ctx, outText); - - free_imit(ctx); - - PrintBlock("Master Key: ", kMasterKeyGost89, 32, kBlockLen89); - PrintEmptyLine(); - PrintBlock("Input Value: ", kGost89PlaintText, textLen89, kBlockLen89); - PrintEmptyLine(); - PrintBlock("Output Value: ", outText, imitLen, kBlockLen89); - PrintEmptyLine(); - PrintBlock("Control value: ", kGost89ImitS, imitLen, kBlockLen89); - PrintEmptyLine(); - - return memcmp(outText, kGost89ImitS, imitLen); -} - -/** @brief теÑтирование Ð´Ð¾Ð¿Ð¾Ð»Ð½ÐµÐ½Ð¸Ñ ÑÐ¾Ð¾Ð±Ñ‰ÐµÐ½Ð¸Ñ */ -int testPadding() -{ - const size_t len = sizeof(kPaddingText)/sizeof(kPaddingText[0]); - const size_t len2 = sizeof(kPaddingText2)/sizeof(kPaddingText2[0]); - - padd(paddingBufferText, 1, kBlockLen14); - padd(paddingBufferText2, kBlockLen14, 2*kBlockLen14); - - PrintLineLeft("Test 1"); - PrintBlock("Input Value: ", paddingBufferText, 1, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Output Value: ", paddingBufferText, kBlockLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Control value: ", kPaddingText, len, kBlockLen14); - PrintEmptyLine(); - -// if(memcmp(paddingBufferText, kPaddingText, len)) -// return -1; - - PrintLineLeft("Test 2"); - PrintBlock("Input Value: ", paddingBufferText2, kBlockLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Output Value: ", paddingBufferText2, 2*kBlockLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Control value: ", kPaddingText2, len2, kBlockLen14); - PrintEmptyLine(); - fflush(stdout); - -// if(memcmp(paddingBufferText2, kPaddingText2, len2)) -// return -1; - - return 0; -} - -/** @brief теÑтирование ÑнÑÑ‚Ð¸Ñ Ð´Ð¾Ð¿Ð¾Ð»Ð½ÐµÐ½Ð¸Ñ ÑÐ¾Ð¾Ð±Ñ‰ÐµÐ½Ð¸Ñ */ -int testCut() -{ - size_t rLen, rLen2; - padd(paddingBufferText, 1, kBlockLen14); - padd(paddingBufferText2, kBlockLen14, 2*kBlockLen14); - - rLen = unpadd(paddingBufferText, kBlockLen14); - rLen2 = unpadd(paddingBufferText2, 2*kBlockLen14); - - PrintLabel("Cut padding test start."); - - PrintLineLeft("Test 1"); - PrintBlock("Input Value: ", paddingBufferText, kBlockLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Output Value: ", paddingBufferText, rLen, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Control value: ", kPaddingText, 1, kBlockLen14); - PrintEmptyLine(); - - PrintLineLeft("Test 2"); - PrintBlock("Input Value: ", paddingBufferText2, 2*kBlockLen14, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Output Value: ", paddingBufferText2, rLen2, kBlockLen14); - PrintEmptyLine(); - PrintBlock("Control value: ", kPaddingText2, kBlockLen14, kBlockLen14); - PrintEmptyLine(); - - if(rLen !=1 ) - return -1; - - if(rLen2 != kBlockLen14) - return -1; - - return 0; -} - -/** @brief ТеÑтирование Ð¿Ñ€ÐµÐ¾Ð±Ñ€Ð°Ð·Ð¾Ð²Ð°Ð½Ð¸Ñ t алгоритма 28147-89 */ -int testFuncT() -{ - int i; - PrintLabel("Test 28147-89 function T start."); - - for(i = 0; i < 4; ++i) - { - unsigned int ans; - ans = funcT(kTData[i], 0); - - PrintBlockLeft("Test ", i+1); - PrintBlockInt("Input value", kTData[i]); - PrintBlockInt("Ouput value", ans); - PrintBlockInt("Control value", kTData[i+1]); - PrintEmptyLine(); - - if(ans != kTData[i+1]) - return -1; - } - - return 0; -} - -/** @brief ТеÑтирование Ð¿Ñ€ÐµÐ¾Ð±Ñ€Ð°Ð·Ð¾Ð²Ð°Ð½Ð¸Ñ g алгоритма 28147-89 */ -int testG() -{ - int i; - PrintLabel("Test 28147-89 function G start."); - - for(i = 0; i < 4; ++i) - { - unsigned int ans; - ans = funcG(kgData[i][0], kgData[i][1], 0); - - PrintBlockLeft("Test ", i+1); - PrintBlockInt("Input value", kgData[i][0]); - PrintBlockInt("Key value", kgData[i][1]); - PrintBlockInt("Ouput value", ans); - PrintBlockInt("Control value", kgData[i][2]); - PrintEmptyLine(); - - if( ans!= kgData[i][2]) - return -1; - } - - return 0; -} - -/** @brief точка входа */ -int main_gost_test() -{ - int testRes = 0; - PrintLine("TEST start."); - PrintEmptyLine(); - - PrintLine("TEST 28147-14 standart start."); - testRes |= PrintTest("S function test end", testS()); - testRes |= PrintTest("R function test.", testR()); - testRes |= PrintTest("L function test.", testL()); - testRes |= PrintTest("Expand Key 28147-14 test.", testExpandKey()); - testRes |= PrintTest("Encrypt test.", testEncrypt()); - testRes |= PrintTest("Decrypt test.", testDecrypt()); - PrintEmptyLine(); - - PrintLine("TEST 28147-89 standart test."); - testRes |= PrintTest("28147-89 T function test.", testFuncT()); - testRes |= PrintTest("28147-89 G function test.", testG()); - testRes |= PrintTest("Encrypt test.", standart_89_encr_test()); - PrintEmptyLine(); - - PrintLine("TEST 28147-14 mode test."); - testRes |= PrintTest("Ecb mode 28147-14 test.", gost14_ECB_test()); - testRes |= PrintTest("CTR mode 28147-14 test.", gost14_CTR_test()); - testRes |= PrintTest("OFB mode 28147-14 test.", gost14_OFB_test()); - testRes |= PrintTest("CBC mode 28147-14 test.", gost14_CBC_test()); - testRes |= PrintTest("CFB mode 28147-14 test.", gost14_CFB_test()); - testRes |= PrintTest("Imita mode 28147-14 test.", gost14_imita_test()); - PrintEmptyLine(); - - PrintLine("TEST 28147-89 mode test."); - testRes |= PrintTest("Ecb mode 28147-89 test.", gost89_ECB_test()); - testRes |= PrintTest("CTR mode 28147-89 test.", gost89_CTR_test()); - testRes |= PrintTest("OFB mode 28147-89 test.", gost89_OFB_test()); - testRes |= PrintTest("CBC mode 28147-89 test.", gost89_CBC_test()); - testRes |= PrintTest("CFB mode 28147-89 test.", gost89_CFB_test()); - testRes |= PrintTest("Imita mode 28147-89 test.", gost89_imita_test()); - PrintEmptyLine(); - - PrintLine("TEST padding test."); - - testRes |= PrintTest("Add padding test.", testPadding()); - testRes |= PrintTest("Cut padding test.", testCut()); - PrintEmptyLine(); - - if ( testRes ) - { - PrintLine("FAILED TESTS EXIST!!!!!."); - } - else - { - PrintLine("ALL TEST OK."); - } - - return testRes; -} diff --git a/dap-sdk/crypto/src/rand/dap_rand.c b/dap-sdk/crypto/src/rand/dap_rand.c index 7a2c48e3a6c787e858c3fbde3d87f406c387f974..4e102fd6621a6f20d858866b89e504ceb746ae8d 100755 --- a/dap-sdk/crypto/src/rand/dap_rand.c +++ b/dap-sdk/crypto/src/rand/dap_rand.c @@ -29,7 +29,7 @@ uint32_t random_uint32_t(const uint32_t MAX_NUMBER) int randombase64(void*random_array, unsigned int size) { int off = size - (size/4)*3; - int odd_signs = size - ((size/4)*4); + unsigned int odd_signs = size - ((size/4)*4); if(odd_signs < size) { randombytes(random_array + off, (size/4)*3); @@ -39,8 +39,8 @@ int randombase64(void*random_array, unsigned int size) { uint8_t tmpv[7]; randombytes(tmpv+4,3); - dap_enc_base64_encode(tmpv + 4, 3,tmpv,DAP_ENC_DATA_TYPE_B64); - for(int i = 0; i < odd_signs; ++i) + dap_enc_base64_encode(tmpv + 4, 3,(char*)tmpv,DAP_ENC_DATA_TYPE_B64); + for(unsigned int i = 0; i < odd_signs; ++i) { ((uint8_t*)random_array)[size - odd_signs + i] = tmpv[i]; } diff --git a/dap-sdk/crypto/src/ringct20/poly.c b/dap-sdk/crypto/src/ringct20/poly.c index ed350c619ddbff01cbcc30892d2bdb58ec3aa6ec..f00896fa7674fafe494c2ca1cc05e617ec3f66e3 100644 --- a/dap-sdk/crypto/src/ringct20/poly.c +++ b/dap-sdk/crypto/src/ringct20/poly.c @@ -427,7 +427,7 @@ void poly_serial(poly_ringct20 *r) r->coeffs[i] = coeff_freeze(r->coeffs[i]); } } -void poly_cofcopy(poly_ringct20 *des, poly_ringct20 *sour) +void poly_cofcopy(poly_ringct20 *des, const poly_ringct20 *sour) { size_t i; for ( i = 0; i < NEWHOPE_RINGCT20_N; i++) @@ -436,18 +436,16 @@ void poly_cofcopy(poly_ringct20 *des, poly_ringct20 *sour) } } -void poly_copy(poly_ringct20 *des, poly_ringct20 *sou, size_t mLen) +void poly_copy(poly_ringct20 *des, const poly_ringct20 *sou, const int mLen) { - size_t i; - for ( i = 0; i < mLen; i++) + for (int i = 0; i < mLen; i++) { poly_cofcopy(des + i, sou + i); } } int poly_equal(const poly_ringct20 *a, const poly_ringct20 *b) { - size_t i; - for ( i = 0; i < NEWHOPE_RINGCT20_N; i++) + for (int i = 0; i < NEWHOPE_RINGCT20_N; i++) { if (a->coeffs[i] != b->coeffs[i]) { @@ -459,9 +457,8 @@ int poly_equal(const poly_ringct20 *a, const poly_ringct20 *b) void poly_constmul(poly_ringct20 *r, const poly_ringct20 *a, uint16_t cof) { - size_t i; uint32_t tmp = 0; - for (i = 0; i < NEWHOPE_RINGCT20_N; i++) + for (int i = 0; i < NEWHOPE_RINGCT20_N; i++) { tmp = cof * a->coeffs[i]; r->coeffs[i] = tmp%NEWHOPE_RINGCT20_2Q; diff --git a/dap-sdk/crypto/src/ringct20/poly.h b/dap-sdk/crypto/src/ringct20/poly.h index 78894205666f6bf34f20ef088bb7444ee302ab91..c05658f14f508352453036aa109e10e2e5dd02ac 100644 --- a/dap-sdk/crypto/src/ringct20/poly.h +++ b/dap-sdk/crypto/src/ringct20/poly.h @@ -45,7 +45,7 @@ int poly_equal(const poly_ringct20 *a, const poly_ringct20 *b); // void poly_constmul(poly_ringct20 *r, const poly_ringct20 *a, uint16_t cof); void poly_serial(poly_ringct20 *r); -void poly_cofcopy(poly_ringct20 *des, poly_ringct20 *sour); -void poly_copy(poly_ringct20 *des, poly_ringct20 *sour, size_t mLen); +void poly_cofcopy(poly_ringct20 *des, const poly_ringct20 *sour); +void poly_copy(poly_ringct20 *des, const poly_ringct20 *sour, const int mLen); void poly_shift(poly_ringct20 *des, const poly_ringct20 *r, int iNumber); #endif diff --git a/dap-sdk/crypto/src/ringct20/ring.c b/dap-sdk/crypto/src/ringct20/ring.c index ca36f6dfdb059169ced2222e99fa6b462a33ddeb..e85b12ebecfad7d9770ee71d415a988a1035cef9 100644 --- a/dap-sdk/crypto/src/ringct20/ring.c +++ b/dap-sdk/crypto/src/ringct20/ring.c @@ -5,10 +5,10 @@ #define Keccak_HashInitialize_SHA3_KDF(hashInstance, out_bytes) Keccak_HashInitialize(hashInstance, 1088, 512, out_bytes*8, 0x06) -void LRCT_SampleKey(poly_ringct20 *r, size_t mLen) +void LRCT_SampleKey(poly_ringct20 *r, int mLen) { uint8_t seed[NEWHOPE_RINGCT20_SYMBYTES] = { 0 }; - size_t i; + int i; for ( i = 0; i < mLen; i++) { #ifndef NEW_SAMPLE_KEY @@ -57,11 +57,11 @@ void LRCT_SampleKey(poly_ringct20 *r, size_t mLen) } } -void LRCT_Setup(poly_ringct20 *A, poly_ringct20 *H, size_t mLen) +void LRCT_Setup(poly_ringct20 *A, poly_ringct20 *H, int mLen) { uint8_t seed[NEWHOPE_RINGCT20_SYMBYTES] = { 0 }; - size_t i = 0; + int i = 0; for ( i = 0; i < mLen; i++) { @@ -74,16 +74,18 @@ void LRCT_Setup(poly_ringct20 *A, poly_ringct20 *H, size_t mLen) } } -void LRCT_KeyGen(poly_ringct20 *a, poly_ringct20 *A, poly_ringct20 *S, size_t mLen) +void LRCT_KeyGen(poly_ringct20 *a, poly_ringct20 *A, poly_ringct20 *S, int mLen) { LRCT_MatrixMulPoly(a, A, S, mLen); poly_serial(a); } -void LRCT_SigGen(poly_ringct20 *c1, poly_ringct20 **t, poly_ringct20 *h, poly_ringct20 *A, poly_ringct20 *H, poly_ringct20 *S, poly_ringct20 *u, size_t mLen, poly_ringct20 *L, uint8_t w, uint8_t pai, const unsigned char *msg, int msgLen) +void LRCT_SigGen(poly_ringct20 *c1, poly_ringct20 **t, poly_ringct20 *h, + poly_ringct20 *A, poly_ringct20 *H, poly_ringct20 *S, poly_ringct20 *u, + int mLen, poly_ringct20 *L, int w, int pai, const unsigned char *msg, int msgLen) { //H2q - size_t i, j, k; + int i, j, k; poly_ringct20 *H2q = (poly_ringct20 *)malloc((mLen + 1) * sizeof(poly_ringct20)); poly_ringct20 *S2q = (poly_ringct20 *)malloc((mLen + 1) * sizeof(poly_ringct20)); poly_ringct20 *A2qp = (poly_ringct20 *)malloc((mLen + 1) * sizeof(poly_ringct20)); @@ -93,7 +95,7 @@ void LRCT_SigGen(poly_ringct20 *c1, poly_ringct20 **t, poly_ringct20 *h, poly_ri //SHA256_CTX ctx; Keccak_HashInstance ctx; - unsigned char bHash[32] = { 0 }; +// unsigned char bHash[32] = { 0 }; unsigned char bpoly[NEWHOPE_RINGCT20_POLYBYTES] = { 0 }; unsigned char bt[NEWHOPE_RINGCT20_POLYBYTES] = { 0 }; uint8_t coin = 0; @@ -232,16 +234,16 @@ void LRCT_SigGen(poly_ringct20 *c1, poly_ringct20 **t, poly_ringct20 *h, poly_ri free(A2qp); free(tmp2q); } -int LRCT_SigVer(const poly_ringct20 *c1, poly_ringct20 **t, poly_ringct20 *A, poly_ringct20 *H, size_t mLen, poly_ringct20 *h, poly_ringct20 *L, - uint8_t w, const unsigned char *msg, int msgLen) +int LRCT_SigVer(const poly_ringct20 *c1, poly_ringct20 **t, poly_ringct20 *A, poly_ringct20 *H, int mLen, poly_ringct20 *h, poly_ringct20 *L, + int w, const unsigned char *msg, int msgLen) { - size_t i,k; + int i,k; poly_ringct20 *H2q = (poly_ringct20 *)malloc((mLen + 1) * sizeof(poly_ringct20)); poly_ringct20 *A2qp = (poly_ringct20 *)malloc((mLen + 1) * sizeof(poly_ringct20)); poly_ringct20 c, tmp, tmp1; //SHA256_CTX ctx; Keccak_HashInstance ctx; - unsigned char bHash[32] = { 0 }; +// unsigned char bHash[32] = { 0 }; unsigned char bpoly[NEWHOPE_RINGCT20_POLYBYTES] = { 0 }; for (i = 0; i < (mLen + 1); i++) { @@ -307,14 +309,14 @@ int LRCT_SigVer(const poly_ringct20 *c1, poly_ringct20 **t, poly_ringct20 *A, po return 0; } -void LRCT_Mint(IW *iw, poly_ringct20 *ck, poly_ringct20 *a, poly_ringct20 *A, size_t mLen, unsigned char* bMessage, size_t msglen) +void LRCT_Mint(IW *iw, poly_ringct20 *ck, poly_ringct20 *a, poly_ringct20 *A, int mLen, unsigned char* bMessage, size_t msglen) { LRCT_SampleKey(ck, mLen); LRCT_nttCom(&(iw->cn), A, ck, mLen, bMessage, msglen); poly_cofcopy(&(iw->a), a); } void LRCT_Spend(IW *iwOA, poly_ringct20 *ckOA, poly_ringct20 *c1, poly_ringct20 **t, poly_ringct20 *h, poly_ringct20 *L, unsigned char* bSignMess, size_t sigMsgLen, IW *iws, size_t iwsLen, - int PaiInd, poly_ringct20 *skPai, poly_ringct20 *ckPai, unsigned char* bVal, size_t bvalLen, poly_ringct20 *OA, poly_ringct20 *A, poly_ringct20 *H, size_t mLen) + int PaiInd, poly_ringct20 *skPai, poly_ringct20 *ckPai, unsigned char* bVal, size_t bvalLen, poly_ringct20 *OA, poly_ringct20 *A, poly_ringct20 *H, int mLen) { poly_ringct20 *u = (poly_ringct20 *)malloc((mLen+1)*sizeof(poly_ringct20)); @@ -336,18 +338,18 @@ void LRCT_Spend(IW *iwOA, poly_ringct20 *ckOA, poly_ringct20 *c1, poly_ringct20 free(u); free(S); } -int LRCT_Verify(poly_ringct20 *c1, poly_ringct20 **t, poly_ringct20 *h, poly_ringct20* A, poly_ringct20 *H, size_t mLen, - unsigned char* bSignMess, size_t sigMsgLen, poly_ringct20 *L, size_t iwsLen) +int LRCT_Verify(poly_ringct20 *c1, poly_ringct20 **t, poly_ringct20 *h, poly_ringct20* A, poly_ringct20 *H, int mLen, + unsigned char* bSignMess, size_t sigMsgLen, poly_ringct20 *L, int iwsLen) { int result = 0; result = LRCT_SigVer(c1, t, A, H, mLen, h, L, iwsLen, bSignMess, sigMsgLen); return result; } /////multiple -void MIMO_LRCT_Setup(poly_ringct20 *A, poly_ringct20 *H, size_t mLen) +void MIMO_LRCT_Setup(poly_ringct20 *A, poly_ringct20 *H, int mLen) { uint8_t seed[NEWHOPE_RINGCT20_SYMBYTES] = { 0 }; - size_t i = 0; + int i = 0; for (i = 0; i < mLen; i++) { @@ -359,23 +361,23 @@ void MIMO_LRCT_Setup(poly_ringct20 *A, poly_ringct20 *H, size_t mLen) poly_serial(H + i); } } -void MIMO_LRCT_KeyGen(poly_ringct20 *a, poly_ringct20 *A, poly_ringct20 *S, size_t mLen) +void MIMO_LRCT_KeyGen(poly_ringct20 *a, poly_ringct20 *A, poly_ringct20 *S, int mLen) { LRCT_MatrixMulPoly(a, A, S, mLen); poly_serial(a); } -void MIMO_LRCT_Mint(IW *iw, poly_ringct20 *ck, poly_ringct20 *a, poly_ringct20 *A, size_t mLen, unsigned char* bMessage, size_t msglen) +void MIMO_LRCT_Mint(IW *iw, poly_ringct20 *ck, poly_ringct20 *a, poly_ringct20 *A, int mLen, unsigned char* bMessage, size_t msglen) { LRCT_SampleKey(ck, mLen); LRCT_nttCom(&(iw->cn), A, ck, mLen, bMessage, msglen); poly_cofcopy(&(iw->a), a); } -void MIMO_LRCT_Hash(int *pTable, poly_ringct20 *cn, poly_ringct20 *a, poly_ringct20 *ia, int beta) +void MIMO_LRCT_Hash(/*int *pTable, */poly_ringct20 *cn, poly_ringct20 *a, poly_ringct20 *ia, int beta) { //SHA256_CTX ctx; Keccak_HashInstance ctx; - unsigned char bHash[32] = { 0 }; +// unsigned char bHash[32] = { 0 }; unsigned char bpoly[NEWHOPE_RINGCT20_POLYBYTES] = { 0 }; unsigned char bt[NEWHOPE_RINGCT20_POLYCOMPRESSEDBYTES] = { 0 }; int i; @@ -402,8 +404,8 @@ void MIMO_LRCT_Hash(int *pTable, poly_ringct20 *cn, poly_ringct20 *a, poly_ringc } //// -void ZKP_OR(poly_ringct20 *ck, int bit, int betaLen) -{} +//void ZKP_OR(poly_ringct20 *ck, int bit, int betaLen) +//{} ////// void MIMO_LRCT_SigGen(poly_ringct20 *c1, poly_ringct20 *tList, poly_ringct20 *hList, poly_ringct20 *SList, int NLen, poly_ringct20 *A, poly_ringct20 *H, int mLen, poly_ringct20 *LList, int wLen, uint8_t pai, unsigned char *msg, int msgLen) @@ -419,7 +421,7 @@ void MIMO_LRCT_SigGen(poly_ringct20 *c1, poly_ringct20 *tList, poly_ringct20 *hL poly_ringct20 tmp, tmp1, ctmp; poly_ringct20 c, cpai; - unsigned char bHash[32] = { 0 }; +// unsigned char bHash[32] = { 0 }; unsigned char bpoly[NEWHOPE_RINGCT20_POLYBYTES] = { 0 }; unsigned char bt[NEWHOPE_RINGCT20_POLYBYTES] = { 0 }; uint8_t coin = 0; @@ -571,17 +573,17 @@ void MIMO_LRCT_SigGen(poly_ringct20 *c1, poly_ringct20 *tList, poly_ringct20 *hL } -int MIMO_LRCT_SigVer(poly_ringct20 *c1, poly_ringct20 *tList, poly_ringct20 *hList, int NLen, poly_ringct20 *A, poly_ringct20 *H, - size_t mLen, poly_ringct20 *LList, int wLen, unsigned char *msg, int msgLen) +int MIMO_LRCT_SigVer(poly_ringct20 *c1, poly_ringct20 *tList, poly_ringct20 *hList, int NLen, poly_ringct20 *A,/* poly_ringct20 *H,*/ + int mLen, poly_ringct20 *LList, int wLen, unsigned char *msg, int msgLen) { - size_t i,j, k; + int i,j, k; poly_ringct20 *H2q = (poly_ringct20 *)malloc(NLen*(mLen + 1) * sizeof(poly_ringct20)); poly_ringct20 *A2qp = (poly_ringct20 *)malloc((mLen + 1) * sizeof(poly_ringct20)); poly_ringct20 ctmp,tmp, tmp1; //SHA256_CTX ctx; Keccak_HashInstance ctx; - unsigned char bHash[32] = { 0 }; +// unsigned char bHash[32] = { 0 }; unsigned char bpoly[NEWHOPE_RINGCT20_POLYBYTES] = { 0 }; ///////// poly_cofcopy(&ctmp, c1); @@ -639,11 +641,10 @@ int MIMO_LRCT_SigVer(poly_ringct20 *c1, poly_ringct20 *tList, poly_ringct20 *hLi -void LRCT_Lift(poly_ringct20 *LA, poly_ringct20 *A, poly_ringct20 *a, size_t mLen) +void LRCT_Lift(poly_ringct20 *LA, poly_ringct20 *A, poly_ringct20 *a, int mLen) { - size_t i = 0; - size_t j = 0; - int16_t tmp = 0; + int i = 0; + int j = 0; for ( i = 0; i < mLen; i++) { for ( j = 0; j < NEWHOPE_RINGCT20_N; j++) @@ -657,10 +658,10 @@ void LRCT_Lift(poly_ringct20 *LA, poly_ringct20 *A, poly_ringct20 *a, size_t mLe } } -void LRCT_Com(poly_ringct20 *r, poly_ringct20 *A, poly_ringct20 *sk, size_t mLen, unsigned char *bMessage, size_t msglen) +void LRCT_Com(poly_ringct20 *r, poly_ringct20 *A, poly_ringct20 *sk, int mLen, unsigned char *bMessage, size_t msglen) { poly_ringct20 tmp; - size_t j; + size_t j; LRCT_MatrixMulPoly(&tmp, A, sk, mLen); poly_cofcopy(r, &tmp); @@ -678,7 +679,7 @@ void LRCT_Com(poly_ringct20 *r, poly_ringct20 *A, poly_ringct20 *sk, size_t mLen } } -void LRCT_nttCom(poly_ringct20 *r, poly_ringct20 *A, poly_ringct20 *sk, size_t mLen, unsigned char *bMessage, size_t msglen) +void LRCT_nttCom(poly_ringct20 *r, poly_ringct20 *A, poly_ringct20 *sk, int mLen, unsigned char *bMessage, size_t msglen) { poly_ringct20 tmp, pMess; size_t j; @@ -704,9 +705,9 @@ void LRCT_nttCom(poly_ringct20 *r, poly_ringct20 *A, poly_ringct20 *sk, size_t m //N*M mul M*1 -void LRCT_MatrixMulPoly(poly_ringct20 *r, poly_ringct20 *A, poly_ringct20 *s, size_t mLen) +void LRCT_MatrixMulPoly(poly_ringct20 *r, poly_ringct20 *A, poly_ringct20 *s, int mLen) { - size_t i; + int i; poly_ringct20 tmp, tmpA, tmps; poly_init(r); for ( i = 0; i < mLen; i++) @@ -721,35 +722,32 @@ void LRCT_MatrixMulPoly(poly_ringct20 *r, poly_ringct20 *A, poly_ringct20 *s, si //poly_invntt(r); } //M*N mul N*1 -void LRCT_PolyMultMatrix(poly_ringct20 *r, poly_ringct20 *p, poly_ringct20 *A, size_t mLen) +void LRCT_PolyMultMatrix(poly_ringct20 *r, poly_ringct20 *p, poly_ringct20 *A, int mLen) { - size_t i; - for ( i = 0; i < mLen; i++) + for (int i = 0; i < mLen; i++) { poly_mul_pointwise(r+i, A+i, p); } } -void LRCT_MatrixAddMatrix(poly_ringct20 *R, poly_ringct20 *A, poly_ringct20 *B, size_t mLen) +void LRCT_MatrixAddMatrix(poly_ringct20 *R, poly_ringct20 *A, poly_ringct20 *B, int mLen) { - size_t i; - for ( i = 0; i < mLen; i++) + for (int i = 0; i < mLen; i++) { poly_add_ringct20(R + i, A + i, B + i); } } -void LRCT_MatrixSubMatrix(poly_ringct20 *R, poly_ringct20 *A, poly_ringct20 *B, size_t mLen) +void LRCT_MatrixSubMatrix(poly_ringct20 *R, poly_ringct20 *A, poly_ringct20 *B, int mLen) { - size_t i; - for (i = 0; i < mLen; i++) + for (int i = 0; i < mLen; i++) { poly_sub_ringct20(R + i, A + i, B + i); } } -void LRCT_ConstMulMatrix(poly_ringct20 *r, const poly_ringct20 *A, uint16_t cof, size_t mLen) +void LRCT_ConstMulMatrix(poly_ringct20 *r, const poly_ringct20 *A, uint16_t cof, int mLen) { - size_t i, j; + int i, j; for (i = 0; i < mLen; i++) { for ( j = 0; j < NEWHOPE_RINGCT20_N; j++) @@ -760,18 +758,17 @@ void LRCT_ConstMulMatrix(poly_ringct20 *r, const poly_ringct20 *A, uint16_t cof, } } /// -void LRCT_MatrixShift(poly_ringct20 *desCK, poly_ringct20* rCK, size_t mLen, int iNumber) +void LRCT_MatrixShift(poly_ringct20 *desCK, poly_ringct20* rCK, int mLen, int iNumber) { - size_t i; - for ( i = 0; i < mLen; i++) + for (int i = 0; i < mLen; i++) { poly_shift(desCK + i, rCK + i, iNumber); } } -void LRCT_GetCK0(poly_ringct20 *CK0, poly_ringct20 * CK, size_t mLen, poly_ringct20* CKi, int messBitLen) +void LRCT_GetCK0(poly_ringct20 *CK0, poly_ringct20 * CK, int mLen, poly_ringct20* CKi, int messBitLen) { - size_t i; + int i; poly_ringct20 *tmp = (poly_ringct20 *)malloc((mLen) * sizeof(poly_ringct20)); poly_ringct20 *desCK = (poly_ringct20 *)malloc((mLen) * sizeof(poly_ringct20)); for (i = 0; i < (mLen); i++) diff --git a/dap-sdk/crypto/src/ringct20/ring.h b/dap-sdk/crypto/src/ringct20/ring.h index 63c94d7dce4b112ad4bfcb4eaa2dbf87ac7429ef..1d23baec753fd7f84dd0b13bb9a8d87d9d15d536 100644 --- a/dap-sdk/crypto/src/ringct20/ring.h +++ b/dap-sdk/crypto/src/ringct20/ring.h @@ -15,22 +15,22 @@ typedef struct { poly_ringct20 cn; } IW; -void LRCT_Setup(poly_ringct20 *A, poly_ringct20 *H, size_t mLen); -void LRCT_KeyGen(poly_ringct20 *a, poly_ringct20 *A, poly_ringct20 *S, size_t mLen); +void LRCT_Setup(poly_ringct20 *A, poly_ringct20 *H, int mLen); +void LRCT_KeyGen(poly_ringct20 *a, poly_ringct20 *A, poly_ringct20 *S, int mLen); void LRCT_SigGen(poly_ringct20 *c1, poly_ringct20 **t, poly_ringct20 *h, poly_ringct20 *A, poly_ringct20 *H, - poly_ringct20 *S, poly_ringct20 *u, size_t mLen, poly_ringct20 *L, uint8_t w, - uint8_t pai, const unsigned char *msg, int msgLen); -int LRCT_SigVer(const poly_ringct20 *c1, poly_ringct20 **t, poly_ringct20 *A, poly_ringct20 *H, size_t mLen, poly_ringct20 *h, poly_ringct20 *L, - uint8_t w, const unsigned char *msg, int msgLen); + poly_ringct20 *S, poly_ringct20 *u, int mLen, poly_ringct20 *L, int w, + int pai, const unsigned char *msg, int msgLen); +int LRCT_SigVer(const poly_ringct20 *c1, poly_ringct20 **t, poly_ringct20 *A, poly_ringct20 *H, int mLen, poly_ringct20 *h, poly_ringct20 *L, + int w, const unsigned char *msg, int msgLen); /////Single output trading scheme /* plan description: */ -void LRCT_Mint(IW *iw, poly_ringct20 *ck, poly_ringct20 *a, poly_ringct20 *A, size_t mLen, unsigned char* bMessage, size_t msglen); +void LRCT_Mint(IW *iw, poly_ringct20 *ck, poly_ringct20 *a, poly_ringct20 *A, int mLen, unsigned char* bMessage, size_t msglen); void LRCT_Spend(IW *iwOA, poly_ringct20 *ckOA, poly_ringct20 *c1, poly_ringct20 **t, poly_ringct20 *h, poly_ringct20 *L, unsigned char* bSignMess, size_t sigMsgLen, IW *iws, size_t iwsLen, - int PaiInd, poly_ringct20 *skPai, poly_ringct20 *ckPai, unsigned char* bVal, size_t bvalLen, poly_ringct20 *OA, poly_ringct20 *A, poly_ringct20 *H, size_t mLen); -int LRCT_Verify(poly_ringct20 *c1, poly_ringct20 **t, poly_ringct20 *h, poly_ringct20* A, poly_ringct20 *H, size_t mLen, - unsigned char* bSignMess, size_t sigMsgLen, poly_ringct20 *L, size_t iwsLen); + int PaiInd, poly_ringct20 *skPai, poly_ringct20 *ckPai, unsigned char* bVal, size_t bvalLen, poly_ringct20 *OA, poly_ringct20 *A, poly_ringct20 *H, int mLen); +int LRCT_Verify(poly_ringct20 *c1, poly_ringct20 **t, poly_ringct20 *h, poly_ringct20* A, poly_ringct20 *H, int mLen, + unsigned char* bSignMess, size_t sigMsgLen, poly_ringct20 *L, int iwsLen); // /* @@ -41,13 +41,13 @@ MIMO SCheme Function declaration: system initialization, generating public parameters Output: public matrix A, H, row number mLen */ -void MIMO_LRCT_Setup(poly_ringct20 *A, poly_ringct20 *H, size_t mLen); +void MIMO_LRCT_Setup(poly_ringct20 *A, poly_ringct20 *H, int mLen); /* Function declaration: key generation. Input: matrix A, private key S, matrix row number mLen Output: user public key */ -void MIMO_LRCT_KeyGen(poly_ringct20 *a, poly_ringct20 *A, poly_ringct20 *S, size_t mLen); +void MIMO_LRCT_KeyGen(poly_ringct20 *a, poly_ringct20 *A, poly_ringct20 *S, int mLen); /* Function declaration: signature generation Input: private key list SList, length NLen, public parameters A, H, matrix width mLen, public key list LList, length wLen, trader position pai, signature message msg, message length msgLen @@ -59,58 +59,58 @@ void MIMO_LRCT_SigGen(poly_ringct20 *c1, poly_ringct20 *tList, poly_ringct20 *hL Function declaration: signature verification Input: signature (c1, t-list tList, h-list: hList, number of transactions, public parameters A, H, matrix width mLen, public key list LList, list length wLen, signature message, message length) */ -int MIMO_LRCT_SigVer(poly_ringct20 *c1, poly_ringct20 *tList, poly_ringct20 *hList, int NLen, poly_ringct20 *A, poly_ringct20 *H, - size_t mLen, poly_ringct20 *LList, int wLen, unsigned char *msg, int msgLen); +int MIMO_LRCT_SigVer(poly_ringct20 *c1, poly_ringct20 *tList, poly_ringct20 *hList, int NLen, poly_ringct20 *A, /*poly_ringct20 *H,*/ + int mLen, poly_ringct20 *LList, int wLen, unsigned char *msg, int msgLen); /* */ -void MIMO_LRCT_Mint(IW *iw, poly_ringct20 *ck, poly_ringct20 *a, poly_ringct20 *A, size_t mLen, unsigned char* bMessage, size_t msglen); +void MIMO_LRCT_Mint(IW *iw, poly_ringct20 *ck, poly_ringct20 *a, poly_ringct20 *A, int mLen, unsigned char* bMessage, size_t msglen); /// -void MIMO_LRCT_Hash(int *pTable, poly_ringct20 *cn, poly_ringct20 *a, poly_ringct20 *ia, int beta); +void MIMO_LRCT_Hash(/*int *pTable, */poly_ringct20 *cn, poly_ringct20 *a, poly_ringct20 *ia, int beta); ////// void ZKP_OR(poly_ringct20 *ck , int bit, int betaLen); //////////// -void LRCT_Lift(poly_ringct20 *LA, poly_ringct20 *A, poly_ringct20 *a, size_t mLen); +void LRCT_Lift(poly_ringct20 *LA, poly_ringct20 *A, poly_ringct20 *a, int mLen); /* Function declaration: promise message m, r = A * sk + m Input: public matrix A, private key sk, matrix row number mLen, acknowledge message m, message length bMessage Output: Commitment r (polynomial N * 1) */ -void LRCT_Com(poly_ringct20 *r, poly_ringct20 *A, poly_ringct20 *sk, size_t mLen, unsigned char *bMessage, size_t msglen); -void LRCT_nttCom(poly_ringct20 *r, poly_ringct20 *A, poly_ringct20 *sk, size_t mLen, unsigned char *bMessage, size_t msglen); +void LRCT_Com(poly_ringct20 *r, poly_ringct20 *A, poly_ringct20 *sk, int mLen, unsigned char *bMessage, size_t msglen); +void LRCT_nttCom(poly_ringct20 *r, poly_ringct20 *A, poly_ringct20 *sk, int mLen, unsigned char *bMessage, size_t msglen); /* Function declaration: matrix A (N * M) * matrix s (M * 1) Input: matrix A, matrix s, matrix rows mLen Output: matrix r = A * s (N * 1) */ -void LRCT_MatrixMulPoly(poly_ringct20 *r, poly_ringct20 *A, poly_ringct20 *s, size_t mLen); +void LRCT_MatrixMulPoly(poly_ringct20 *r, poly_ringct20 *A, poly_ringct20 *s, int mLen); /* Function declaration: constant * matrix Input: constant cof, matrix A, number of matrix rows (mLen) Output: matrix r */ -void LRCT_ConstMulMatrix(poly_ringct20 *r, const poly_ringct20 *A, uint16_t cof, size_t mLen); +void LRCT_ConstMulMatrix(poly_ringct20 *r, const poly_ringct20 *A, uint16_t cof, int mLen); /* Function declaration: matrix A (M rows and N columns) * polynomial p (N rows and 1 column) Input: polynomial p, matrix A, matrix rows mLen Output: polynomial r (M rows and 1 column) */ -void LRCT_PolyMultMatrix(poly_ringct20 *r, poly_ringct20 *p, poly_ringct20 *A, size_t mLen); +void LRCT_PolyMultMatrix(poly_ringct20 *r, poly_ringct20 *p, poly_ringct20 *A, int mLen); /* Function declaration: matrix addition (A + B) Input: matrix A, matrix B, matrix size mLen Output: Matrix R = (A + B) */ -void LRCT_MatrixAddMatrix(poly_ringct20 *R, poly_ringct20 *A, poly_ringct20 *B, size_t mLen); +void LRCT_MatrixAddMatrix(poly_ringct20 *R, poly_ringct20 *A, poly_ringct20 *B, int mLen); /* Function declaration: Matrix subtraction (A-B) Input: matrix A, matrix B, matrix size mLen Output: Matrix R = (A-B) */ -void LRCT_MatrixSubMatrix(poly_ringct20 *R, poly_ringct20 *A, poly_ringct20 *B, size_t mLen); +void LRCT_MatrixSubMatrix(poly_ringct20 *R, poly_ringct20 *A, poly_ringct20 *B, int mLen); ///////////////////* /* @@ -119,10 +119,10 @@ Input: Key length mLen Output: polynomial matrix r (n * mLen) */ ///////////////// -void LRCT_SampleKey(poly_ringct20 *r, size_t mLen); +void LRCT_SampleKey(poly_ringct20 *r, int mLen); -void LRCT_MatrixShift(poly_ringct20 *desCK, poly_ringct20* rCK, size_t mLen, int iNumber); +void LRCT_MatrixShift(poly_ringct20 *desCK, poly_ringct20* rCK, int mLen, int iNumber); -void LRCT_GetCK0(poly_ringct20 *CK0, poly_ringct20 * CK, size_t mLen, poly_ringct20* CKi, int messBitLen); +void LRCT_GetCK0(poly_ringct20 *CK0, poly_ringct20 * CK, int mLen, poly_ringct20* CKi, int messBitLen); #endif