Nikos Mavrogiannopoulos nmav@gnutls.org writes:
The attached patch adds the GOST R 34.11-94 hash algorithm. I based this code on Alexei Kravchenko's code from librhash.
Some comments:
- Implementation written by Alexei Kravchenko.
- Ported to nettle by Nikos Mavrogiannopoulos.
- Copyleft:
- I hereby release this code into the public domain. This applies worldwide.
- I grant any entity the right to use this work for ANY PURPOSE,
- without any conditions, unless such conditions are required by law.
- */
The public domain notice, that is Alexei's, right? Do you intend your modified version to also be in the public domain? (If we end up doing any major changes to the file, I'd prefer to license the Nettle version as LGPL, but if changes are minor, keeping it public domain is fine with me).
The rhash license appear to be somewhat different (see http://rhash.anz.ru/license.php), and the sourceforge page says it's using the MIT license (see http://sourceforge.net/projects/rhash/).
+/**
- Calculate a lookup table from S-Boxes.
- A substitution table is used to speed up hash calculation.
- @param out pointer to the lookup table to fill
- @param src pointer to eight S-Boxes to fill the table from
- */
+static void +fill_gost94_sbox (uint32_t out[4][256], const uint8_t src[8][16])
Maybe this should be moved to a separate file gost-data, to generate the tables during the build process?
+void +gost94_init2 (gost94_ctx * ctx, unsigned int flag) +{
- memset (ctx, 0, sizeof (gost94_ctx));
- ctx->flag = flag;
- if (ctx->flag & GOST_FLAG_CRYPTOPRO)
ctx->sbox = (uint32_t*)gost94_sbox_cryptpro;
- else
ctx->sbox = (uint32_t*)gost94_sbox;
+}
Can you explain briefly what this gost94_sbox and gost94_sbox_cryptpro is about? I don't quite like having to put an sbox pointer into the context struct, but maybe there's a good reason? Or maybe it's better to treat them as two distinct hash functions (one could still share internal functions like gost_block_compress, and pass appropriate sboxes as an argument).
--- /dev/null +++ b/gost94.h @@ -0,0 +1,55 @@ +/* md5.h
That shouldn't say "md5" ;-)
+#undef GENERATE_GOST_LOOKUP_TABLE
I don't think GENERATE_GOST_LOOKUP_TABLE belongs in the header file.
+#define GOST94_DATA_SIZE 32 +#define GOST94_DIGEST_SIZE 32
+/* if set it enables the CryptoPro parameter set */ +#define GOST_FLAG_CRYPTOPRO 1
And neither does this, I think. If "CryptoPro" should be supported, that should be unconditional (but with any large tables in a separate file).
+/* algorithm context */ +typedef struct gost94_ctx +{
- uint32_t hash[8]; /* algorithm 256-bit state */
- uint32_t sum[8]; /* sum of processed message blocks */
- uint8_t message[GOST94_DATA_SIZE]; /* 256-bit buffer for leftovers */
- uint64_t length; /* number of processed bytes */
- uint32_t *sbox;
- unsigned flag; /* flag, type of sbox to use */
The flag is set but unused, as far as I see.
Regards, /Niels