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: Re: [oss-gost-crypto] Патч для  libgcrypt
Date: Mon, 6 May 2019 16:21:36 +0300
Message-ID: <20190506132135.vbnelupki2z7duwz@altlinux.org> (raw)
In-Reply-To: <b53f0a39-dd27-f634-b06f-b5fb26c557fe@altlinux.org>

FYI,

On Mon, May 06, 2019 at 02:59:47PM +0300, Aleksei Nikiforov wrote:
> Здравствуйте.
> 
> Я узнал о проблеме со stribog в libgcrypt, и посмотрел патчи, в частности
> для openssl и libgcrypt:
> 
> https://github.com/gost-engine/engine/commit/835e0d788bfec1f51545b038cef135b02456b27b#diff-e3af9488a17fea1bdc808c139088e6ff
> 
> https://lists.gnupg.org/pipermail/gcrypt-devel/2019-May/004700.html
> 
> Мне патч для openssl понравился больше, в связи с чем я его переложил на
> libgcrypt. Результат можно посмотреть вот здесь:
> 
> http://git.altlinux.org/people/darktemplar/packages/?p=libgcrypt.git;a=commitdiff;h=a161d7e069ce4e6741cc89f74bdbee71cf1519d6
> 
> Что скажете по поводу данного патча? Можете посмотреть и проревьюить? Или же
> лучше использовать уже отправленный в libgcrypt патч?

Я протестил все реализации (на u8 представлении int32'ов вместо u64
представления 512-bit integers, для того чтоб можно было прогнать все 
релевантные значения) и они не дали ошибок (кроме одной где ошибка
ожидалась).

Код тестов ниже:

---
#include <stdio.h>
#include <stdlib.h>

void add32_kernel(unsigned char *x, unsigned char *y)
{
    int i;
    unsigned char CF = 0;

    for (i = 0; i < sizeof(int); i++) {
	unsigned char left = x[i];
	unsigned char sum;

	sum = left + y[i] + CF;
	if (sum != left)
	    CF = (sum < left);
	x[i] = sum;
    }
}

void add32_streebog(unsigned char *x, unsigned char *y)
{
    int i;
    unsigned char OF = 0, CF = 0;

    for (i = 0; i < sizeof(int); i++) {
	unsigned char tmp = x[i] + y[i];

	if (tmp < x[i])
	    OF = 1;
	else
	    OF = 0;
	tmp += CF;
	if (CF > 0 && tmp == 0)
	    OF = 1;
	CF = OF;
	x[i] = tmp;
    }
}

void add32_darktemplar(unsigned char *Sigma, unsigned char *M)
{
    int i;
    unsigned char of = 0, cf = 0;

    for (i = 0; i < sizeof(int); i++) {
	if ((unsigned char)(M[i] + Sigma[i]) < M[i])
	    of = 1;
	else
	    of = 0;
	Sigma[i] += M[i] + cf;
	if ((cf > 0) && (Sigma[i] == 0))
	    of = 1;
	cf = of;
    }
}

void add32_libgcrypt(unsigned char *Sigma, unsigned char *M)
{
    int i;

    Sigma[0] += M[0];
    for (i = 1; i < sizeof(int); i++)
	if (Sigma[i-1] < M[i-1])
	    Sigma[i] += M[i] + 1;
	else
	    Sigma[i] += M[i];
}

void add32_libgcrypt_new(unsigned char *Sigma, unsigned char *M)
{
    int i;
    unsigned char cf;

    Sigma[0] += M[0];
    cf = 0;
    for (i = 1; i < sizeof(int); i++)
    {
	if (Sigma[i-1] != M[i-1])
	    cf = (Sigma[i-1] < M[i-1]);
	Sigma[i] += M[i] + cf;
    }
}

int main(int argc, char **argv)
{
    unsigned int i, j;

    for (i = 0; i < 65539; i++) {
	printf("%u\r", i);
	for (j = 0; j < 65539; j++) {
	    unsigned int k = i;

	    add32_libgcrypt_new((unsigned char *)&k, (unsigned char *)&j);

	    if (k != i+j) {
		printf("%u+%u=%u != %u\n", i, j, i+j, k);
		exit(1);
	    }

	}
    }
    return 0;
}


  reply	other threads:[~2019-05-06 13:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-06 11:59 Aleksei Nikiforov
2019-05-06 13:21 ` Vitaly Chikunov [this message]
2019-05-06 14:22 ` Aleksei Nikiforov

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=20190506132135.vbnelupki2z7duwz@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