From 141044a9320968c198e6e945702d8aecfce346b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B5=D0=B9=20=D0=AE=D1=80?= =?UTF-8?q?=D1=8C=D0=B5=D0=B2=D0=B8=D1=87=20=D0=9D=D0=B5=D1=81=D1=82=D0=B5?= =?UTF-8?q?=D1=80=D0=B5=D0=BD=D0=BA=D0=BE?= <anesterenko@hse.ru> Date: Fri, 15 Nov 2024 01:12:34 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D1=8B=20=D0=BE=D1=88=D0=B8=D0=B1=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=20=D0=BA=D0=BE=D0=BC=D0=BF=D0=B8=D0=BB=D1=8F?= =?UTF-8?q?=D1=86=D0=B8=D0=B8=20=D1=81=20=D1=84=D0=BB=D0=B0=D0=B3=D0=B0?= =?UTF-8?q?=D0=BC=D0=B8=20-Werror=20-Wextra=20-Wpedantic=20=D0=BD=D0=B0=20?= =?UTF-8?q?32-=D1=85=20=D0=B1=D0=B8=D1=82=D0=BD=D0=BE=D0=B9=20=D0=B0=D1=80?= =?UTF-8?q?=D1=85=D0=B8=D1=82=D0=B5=D0=BA=D1=82=D1=83=D1=80=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- aktool/aktool_key.c | 4 +++- examples/tests/test-asn1-keys.c | 22 ++++++++++++---------- source/ak_asn1_keys.c | 6 +++++- source/ak_file.c | 4 ++-- source/ak_mgm.c | 13 +++++++++---- 5 files changed, 31 insertions(+), 18 deletions(-) diff --git a/aktool/aktool_key.c b/aktool/aktool_key.c index 23d72b5a..37e3dc4d 100644 --- a/aktool/aktool_key.c +++ b/aktool/aktool_key.c @@ -870,6 +870,7 @@ /* ----------------------------------------------------------------------------------------------- */ int aktool_key_new_blom_pairwise( void ) { + ssize_t len = 0; struct blomkey abonent; int exitcode = EXIT_FAILURE; @@ -943,7 +944,8 @@ aktool_error(_("incorrect key file creation")); goto labex1; } - if( ak_file_write( &fs, key, abonent.count ) != abonent.count ) { + len = ak_file_write( &fs, key, abonent.count ); + if(( len < 0 ) || ( (size_t)len != abonent.count )) { aktool_error(_("incorrect write to %s%s%s file"), ak_error_get_start_string(), ki.os_file, ak_error_get_end_string( )); } diff --git a/examples/tests/test-asn1-keys.c b/examples/tests/test-asn1-keys.c index 0a146309..6860f101 100644 --- a/examples/tests/test-asn1-keys.c +++ b/examples/tests/test-asn1-keys.c @@ -191,20 +191,22 @@ /* --------------------------------------------------------------------------------------------- */ int signkey_test( ak_oid curvoid ) { - int result = EXIT_SUCCESS; - ak_oid oid = NULL; - ak_uint8 testkey[64] = { + int result = EXIT_SUCCESS; + ak_oid oid = NULL; + ak_uint8 testkey[64] = { 0xef, 0xcd, 0xab, 0x89, 0x67, 0x45, 0x27, 0x01, 0x10, 0x32, 0x54, 0x76, 0x98, 0xba, 0xdc, 0xfe, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00, 0xff, 0xee, 0xdd, 0xcc, 0xbb, 0xaa, 0x99, 0x38, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0xf1, 0xe2, 0xd3, 0xc4, 0xb5, 0xa6, 0x97, 0x88, 0x79, 0x6a, 0x5b, 0x4c, 0x3d, 0x2e, 0x1f, 0x00 }; - ak_uint8 sign[128]; - char filename[128], tname[256]; - struct signkey skey, lkey; - struct verifykey vkey; - struct random generator; - - ak_random_create_lcg( &generator ); + ak_uint8 sign[128]; + char filename[128], tname[256]; + struct signkey skey, lkey; + struct verifykey vkey; + struct random generator; + + ak_random_create_lcg( &generator ); + /* добавляем случайность в вырабатываемую ключевую информацию */ + ak_random_ptr( &generator, testkey, 64 ); if(( curvoid->engine == identifier ) && ( curvoid->mode == wcurve_params )) { ak_signkey_create( &skey, (ak_wcurve)curvoid->data ); diff --git a/source/ak_asn1_keys.c b/source/ak_asn1_keys.c index cc0bd84a..3c42479d 100644 --- a/source/ak_asn1_keys.c +++ b/source/ak_asn1_keys.c @@ -1329,7 +1329,11 @@ return ak_error_message( ak_error_wrong_oid, __func__, "incorrect value of content identifier" ); /* определяем тип контента ( нас интересует только хранение секретных ключей ) */ - switch(( content_type = ((ak_uint64) oid->data )&0xFF )) { + #ifdef AK_SIZEOF_VOID_P_IS_8 + switch(( content_type = ((ak_uint64)oid->data)&0xFF )) { + #else + switch(( content_type = ((ak_uint32)oid->data)&0xFF )) { + #endif case symmetric_key_content: case secret_key_content: break; diff --git a/source/ak_file.c b/source/ak_file.c index 90334a10..0711a69d 100644 --- a/source/ak_file.c +++ b/source/ak_file.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------------------------- */ -/* Copyright (c) 2004 - 2020, 2022 - 2023 by Axel Kenzo, axelkenzo@mail.ru */ +/* Copyright (c) 2004 - 2020, 2022 - 2024 by Axel Kenzo, axelkenzo@mail.ru */ /* */ /* Файл ak_file.с */ /* ----------------------------------------------------------------------------------------------- */ @@ -242,7 +242,7 @@ } else localbuffer[off++] = ch; /* выходим из цикла если процедура проверки нарушена */ if( error != ak_error_ok ) return error; - } while( ch != EOF ); + } while( 1 ); /* удалено: ch != EOF */ close( fd ); return error; diff --git a/source/ak_mgm.c b/source/ak_mgm.c index 7154b662..9c1f1da7 100644 --- a/source/ak_mgm.c +++ b/source/ak_mgm.c @@ -1,5 +1,5 @@ /* ----------------------------------------------------------------------------------------------- */ -/* Copyright (c) 2017 - 2021 by Axel Kenzo, axelkenzo@mail.ru */ +/* Copyright (c) 2017 - 2021, 2024 by Axel Kenzo, axelkenzo@mail.ru */ /* */ /* Файл ak_mgm.c */ /* - содержит функции, реализующие аутентифицированное шифрование @@ -251,10 +251,12 @@ astep128( temp.b ); } else { /* теперь тоже самое, но для 64-битного шифра */ + /* для 32х битной архитектуры нижеследующее сравнение бессмысленно */ + #ifdef AK_SIZEOF_VOID_P_IS_8 if(( ctx->abitlen > 0xFFFFFFFF ) || ( ctx->pbitlen > 0xFFFFFFFF )) return ak_error_message( ak_error_overflow, __func__, "using an algorithm with very long data" ); - + #endif #ifdef AK_LITTLE_ENDIAN temp.w[0] = (ak_uint32) ctx->pbitlen; temp.w[1] = (ak_uint32) ctx->abitlen; @@ -681,7 +683,8 @@ длины корректны для Магмы и для Кузнечика на 64-х битной архитектуре много может быть только для Магмы => проверяем */ - if(( sizeof ( ak_pointer ) > 4 ) && ( bsize != 16 )) { + #ifdef AK_SIZEOF_VOID_P_IS_8 + if( bsize != 16 ) { if( aval > 0x0000000100000000LL ) return ak_error_message( ak_error_wrong_length, __func__, "length of assosiated data is very large"); if( pval > 0x0000000100000000LL ) return ak_error_message( ak_error_wrong_length, __func__, @@ -689,7 +692,9 @@ if( temp > 0x0000000100000000LL ) return ak_error_message( ak_error_wrong_length, __func__, "total length of assosiated and plain data is very large"); } - + #else + (void) bsize; + #endif return ak_error_ok; } -- GitLab