Bouncycastle GOST 34.311 hash differ from test examples differ

682 Views Asked by At

could you, please, help with bouncycastle for hash function GOST 34.311. Somehow results are diffferent from test vector. Wiki says: "GOST("The quick brown fox jumps over the lazy dog") = 77b7fa410c9ac58a25f49bca7d0468c9296529315eaca76bd1a10f376d1f4294"

when using Digest Gost 34.11:

var testString = "The quick brown fox jumps over the lazy dog";
var result = (new GOST3411.Digest()).digest(testString.getBytes());
var resHex2 = new BigInteger(1, result).toString(16);
assertEquals("77b7fa410c9ac58a25f49bca7d0468c9296529315eaca76bd1a10f376d1f4294", resHex2.toUpperCase());

got:

org.opentest4j.AssertionFailedError: 
Expected :77b7fa410c9ac58a25f49bca7d0468c9296529315eaca76bd1a10f376d1f4294
Actual   :9004294A361A508C586FE53D1F1B02746765E71B765472786E4770D565830A76

with 2012 version:

var testString = "The quick brown fox jumps over the lazy dog";
var result = (new GOST3411.Digest2012_256()).digest(testString.getBytes());
var resHex2 = new BigInteger(1, result).toString(16);
assertEquals("77b7fa410c9ac58a25f49bca7d0468c9296529315eaca76bd1a10f376d1f4294", resHex2.toUpperCase());

got :

AssertionFailedError: 
Expected :77b7fa410c9ac58a25f49bca7d0468c9296529315eaca76bd1a10f376d1f4294
Actual   :3E7DEA7F2384B6C5A3D0E24AAA29C05E89DDD762145030EC22C71A6DB8B2C1F4

Does BouncyCastle support origin GOST 34.311 - 95? What is correct way to calculate it?

1

There are 1 best solutions below

2
On

BC is using the GOST R 34.11-2012 (streebog) version of the standard

$ rhash -G -m "The quick brown fox jumps over the lazy dog"
3e7dea7f2384b6c5a3d0e24aaa29c05e89ddd762145030ec22c71a6db8b2c1f4  (message)

The wikipedia samples are for the deprecated GOST R 34.11-94 version

$ rhash --gost94 -m "The quick brown fox jumps over the lazy dog"
77b7fa410c9ac58a25f49bca7d0468c9296529315eaca76bd1a10f376d1f4294  (message)

If you actually want the old one, you should probably ask for plain GOST3411Digest instead of GOST3411.Digest2012_256 which is the new one.