Open-source aspects of GOST Cryptography
 help / color / mirror / Atom feed
From: Vitaly Chikunov <vt@altlinux.org>
To: Open-source aspects of GOST Cryptography
	<oss-gost-crypto@lists.altlinux.org>
Subject: [oss-gost-crypto] Streebog padding bug Ex:  "Об open-source реализациях
Date: Mon, 13 Jan 2020 11:22:04 +0300
Message-ID: <20200113082204.frjobaxuod3lq2iv@altlinux.org> (raw)
In-Reply-To: <CADqLbzKYy0Bf-ojR4n3i0uVVY9a3yMt=WNDBZq6GTws-JZWhvA@mail.gmail.com>

On Mon, Jan 13, 2020 at 09:51:18AM +0300, Dmitry Belyavsky wrote:
> On Mon, Jan 13, 2020 at 8:07 AM Vitaly Chikunov <vt@altlinux.org> wrote:
> 
> > (В копилку ошибочных реализаций.)
> >
> > В одном российском линуксе, хэш для данных с длинной кратной 64
> > считаются иначе чем у всех остальных:
> >
> > ...
> 
> >
> > Интересно что там могло пойти не так.
> >
> 
> Ну как. Финализация включает в себя дополнение непрохешированного остатка
> до полного блока.
> Вот если остаток не оставить, а всё равно дополнить - будет именно это
> скорее всего.

1. По-моему мы так и делаем.

А вот они не делают заполнение _пустого блока_.

В ГОСТ (для полных блоков) они пропускают шаги 3.1, 3.2, 3.3, 3.4.
В примерах сказано "длина сообщения меньше 512, _поэтому_ происходит
заполнение неполного блока". А что же делать когда блок полный?

Кто прав?

Вот патч который дает результаты "как у них":

diff --git a/gost3411-2012-core.c b/gost3411-2012-core.c
index de582c6..55aad37 100644
--- a/gost3411-2012-core.c
+++ b/gost3411-2012-core.c
@@ -163,13 +163,15 @@ stage3(GOST34112012Context *CTX)
     buf.QWORD[0] = BSWAP64(CTX->bufsize << 3);
 #endif
 
-    pad(CTX);
+    if (CTX->bufsize) {
+	pad(CTX);
 
-    g(&(CTX->h), &(CTX->N), (const unsigned char *) &(CTX->buffer));
+	g(&(CTX->h), &(CTX->N), (const unsigned char *) &(CTX->buffer));
 
-    add512(&(CTX->N), &buf, &(CTX->N));
-    add512(&(CTX->Sigma), (const union uint512_u *) &CTX->buffer[0],
-           &(CTX->Sigma));
+	add512(&(CTX->N), &buf, &(CTX->N));
+	add512(&(CTX->Sigma), (const union uint512_u *) &CTX->buffer[0],
+	    &(CTX->Sigma));
+    }
 
     g(&(CTX->h), &buffer0, (const unsigned char *) &(CTX->N));
 

2. Кроме того, в нашем коде есть странность:

| static inline void
| pad(GOST34112012Context *CTX)
| {
|     if (CTX->bufsize > 63)
|         return;
|
|     memset(CTX->buffer + CTX->bufsize,
|         0x00, sizeof(CTX->buffer) - CTX->bufsize);
|
|     CTX->buffer[CTX->bufsize] = 0x01;
| }


`CTX->bufsize` никогда не может быть больше 63.




  parent reply	other threads:[~2020-01-13  8:22 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-02 12:41 [oss-gost-crypto] "Об open-source реализациях хэш-функции ГОСТ Р 34.11-2012" Vitaly Chikunov
2019-05-04 21:33 ` Dmitry Eremin-Solenikov
2019-05-04 21:57     ` Vitaly Chikunov
2019-05-25 20:03       ` Vitaly Chikunov
2019-05-25 21:32         ` Vitaly Chikunov
2020-01-13  5:07           ` Vitaly Chikunov
2020-01-13  5:55             ` Wartan Hachaturow
2020-01-13  8:22               ` Vitaly Chikunov [this message]
2019-05-25 19:53   ` Dmitry Eremin-Solenikov
2019-07-09 15:20     ` Vitaly Chikunov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200113082204.frjobaxuod3lq2iv@altlinux.org \
    --to=vt@altlinux.org \
    --cc=oss-gost-crypto@lists.altlinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Open-source aspects of GOST Cryptography

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/oss-gost-crypto/0 oss-gost-crypto/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 oss-gost-crypto oss-gost-crypto/ http://lore.altlinux.org/oss-gost-crypto \
		oss-gost-crypto@lists.altlinux.org oss-gost-crypto@lists.altlinux.ru oss-gost-crypto@lists.altlinux.com
	public-inbox-index oss-gost-crypto

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.oss-gost-crypto


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git