avatar
staszhukov has added 5bf4d7c639
gcrypt: Add Streabog (GOST R 34.11-2012 and -94) hashing algorithm su...

...pportRequires: rpmlib(FileDigests) - 5.4.10-103
Configure with gcrypt:
cd rpm5 && ./configure ... --with-gcrypt=external && make && ./tools/rpmdigest --help
...
Available digests:
...
--gostr3411_94 GOST R 34.11-94.
--stribog256 GOST R 34.11-2012, 256 bit.
--stribog512 GOST R 34.11-2012, 512 bit.
...
Hash Algorithms in enum pgpHashAlgo_e (rpmio/rpmiotypes.c):
PGPHASHALGO_GOSTR3411_94 = 98 + 0 (GCRY_MD_GOSTR3411_94 = 308 + 0)
PGPHASHALGO_STRIBOG256 = 98 + 1 (GCRY_MD_STRIBOG256 = 308 + 1)
PGPHASHALGO_STRIBOG512 = 98 + 2 (GCRY_MD_STRIBOG512 = 308 + 2)
Setup hash algorithm stribog256:
/etc/rpm/macros: %source_filedigest_algorithm 99
/etc/rpm/macros: %binary_filedigest_algorithm 99

Changes to be committed:
modified: build/files.c
modified: lib/rpmds.c
modified: lib/rpmfi.c
modified: rpmdb/hdrfmt.c
modified: rpmdb/rpmrepo.c
modified: rpmio/digest.c
new file: rpmio/gcry_digest.c
modified: rpmio/poptIO.c
modified: rpmio/rpmgc.c
modified: rpmio/rpmiotypes.h
modified: rpmio/rpmpgp.c
modified: tools/rpmmtree.c

... ... --- a/build/files.c
... ... +++ b/build/files.c
... ... @@ -1310,6 +1310,18 @@ static rpmuint32_t getDigestAlgo(Header h, int isSrc)
1310 1310
    case PGPHASHALGO_CRC64:
1311 1311
	(void) rpmlibNeedsFeature(h, "FileDigestParameterized", "4.4.6-1");
1312 1312
	    /*@switchbreak@*/ break;
1313
#if defined(WITH_GCRYPT)
1314
    case PGPHASHALGO_GOSTR3411_94:
1315
    case PGPHASHALGO_STRIBOG256:
1316
    case PGPHASHALGO_STRIBOG512:
1317
	(void) rpmlibNeedsFeature(h, "FileDigests", "5.4.10-103");
1318
	he->tag = RPMTAG_FILEDIGESTALGO;
1319
	he->t = RPM_UINT32_TYPE;
1320
	he->p.ui32p = &dalgo;
1321
	he->c = 1;
1322
	xx = headerPut(h, he, 0);
1323
	/*@switchbreak@*/ break;
1324
#endif
1313 1325
    case PGPHASHALGO_MD5:
1314 1326
    case PGPHASHALGO_HAVAL_5_160:		/* XXX unimplemented */
1315 1327
    default:
... ... --- a/lib/rpmds.c
... ... +++ b/lib/rpmds.c
... ... @@ -1558,6 +1558,11 @@ static struct rpmlibProvides_s rpmlibProvides[] = {
1558 1558
    { "rpmlib(FileDigests)",    "4.6.0-1",
1559 1559
	(evrFlags)(RPMSENSE_RPMLIB|RPMSENSE_EQUAL),
1560 1560
    N_("file digests can be other than MD5.") },
1561
#if defined(WITH_GCRYPT)
1562
    { "rpmlib(FileDigests)",		"5.4.10-103",
1563
	(evrFlags)(RPMSENSE_RPMLIB|RPMSENSE_EQUAL),
1564
    N_("file digests can be GOSTR3411_94, STRIBOG256, STRIBOG512") },
1565
#endif
1561 1566
#if defined(SUPPORT_AR_PAYLOADS)
1562 1567
    { "rpmlib(PayloadIsAr)",		"5.1-1",
1563 1568
	(evrFlags)(RPMSENSE_RPMLIB|RPMSENSE_EQUAL),
... ... --- a/lib/rpmfi.c
... ... +++ b/lib/rpmfi.c
... ... @@ -1555,6 +1555,11 @@ assert(dalgo == (pgpHashAlgo)fi->fdigestalgos[i]);
1555 1555
    case PGPHASHALGO_SHA384:	fi->digestlen = 384/8;	break;
1556 1556
    case PGPHASHALGO_SHA512:	fi->digestlen = 512/8;	break;
1557 1557
    case PGPHASHALGO_CRC32:	fi->digestlen = 32/8;	break;
1558
#if defined(WITH_GCRYPT)
1559
    case PGPHASHALGO_GOSTR3411_94: fi->digestlen = 256/8; break;
1560
    case PGPHASHALGO_STRIBOG256: fi->digestlen = 256/8; break;
1561
    case PGPHASHALGO_STRIBOG512: fi->digestlen = 512/8; break;
1562
#endif
1558 1563
    }
1559 1564
    fi->digestalgo = dalgo;
1560 1565
view file @ 5bf4d7c639
... ... --- a/rpmdb/hdrfmt.c
... ... +++ b/rpmdb/hdrfmt.c
... ... @@ -4400,6 +4400,11 @@ static KEY keyDigests[] = {
4400 4400
    { "sha384",		PGPHASHALGO_SHA384 },
4401 4401
    { "sha512",		PGPHASHALGO_SHA512 },
4402 4402
    { "tiger192",	PGPHASHALGO_TIGER192 },
4403
#if defined(WITH_GCRYPT)
4404
    { "gostr3411_94",	PGPHASHALGO_GOSTR3411_94 },
4405
    { "stribog256",	PGPHASHALGO_STRIBOG256 },
4406
    { "stribog512",	PGPHASHALGO_STRIBOG512 },
4407
#endif
4403 4408
};
4404 4409
/*@unchecked@*/
4405 4410
static size_t nkeyDigests = sizeof(keyDigests) / sizeof(keyDigests[0]);
view file @ 5bf4d7c639
... ... --- a/rpmdb/rpmrepo.c
... ... +++ b/rpmdb/rpmrepo.c
... ... @@ -1048,6 +1048,11 @@ algo2tagname(uint32_t algo)
1048 1048
    case PGPHASHALGO_RIPEMD320:	tagname = "rmd320";	break;
1049 1049
    case PGPHASHALGO_SALSA10:	tagname = "salsa10";	break;
1050 1050
    case PGPHASHALGO_SALSA20:	tagname = "salsa20";	break;
1051
#if defined(WITH_GCRYPT)
1052
    case PGPHASHALGO_GOSTR3411_94: tagname = "gostr3411_94"; break;
1053
    case PGPHASHALGO_STRIBOG256: tagname = "stribog256"; break;
1054
    case PGPHASHALGO_STRIBOG512: tagname = "stribog512"; break;
1055
#endif
1051 1056
    default:			tagname = NULL;		break;
1052 1057
    }
1053 1058
    return tagname;
view file @ 5bf4d7c639
... ... --- a/rpmio/digest.c
... ... +++ b/rpmio/digest.c
... ... @@ -106,6 +106,10 @@
106 106
107 107
#include "debug.h"
108 108
109
#if defined(WITH_GCRYPT)
110
#include "gcry_digest.c"
111
#endif
112
109 113
/*@unchecked@*/
110 114
int _ctx_debug = 0;
111 115
... ... @@ -889,6 +893,50 @@ tib3:
893 893
	ctx->Update = (int (*)(void *, const byte *, size_t)) _tib3_Update;
894 894
	ctx->Digest = (int (*)(void *, byte *)) tib3_Final;
895 895
	break;
896
#if defined(WITH_GCRYPT)
897
    case PGPHASHALGO_GOSTR3411_94:
898
	ctx->name = gcry_md_algo_name (GCRY_MD_GOSTR3411_94);
899
	ctx->digestsize = gcry_md_get_algo_dlen(GCRY_MD_GOSTR3411_94);
900
/*@-sizeoftype@*/ /* FIX: union, not void pointer */
901
	ctx->paramsize = sizeof(gcry_md_hd_t);
902
/*@=sizeoftype@*/
903
	ctx->param = DRD_xcalloc(1, ctx->paramsize);
904
	(void)gcry_md_open ((gcry_md_hd_t*)(ctx->param), GCRY_MD_GOSTR3411_94, 0);
905
/*@-type@*/
906
	ctx->Reset = (int (*)(void *)) rpmgcDigestReset;
907
	ctx->Update = (int (*)(void *, const byte *, size_t)) rpmgcDigestUpdate;
908
	ctx->Digest = (int (*)(void *, byte *)) rpmgcDigestGOST3411_94;
909
/*@=type@*/
910
	break;
911
    case PGPHASHALGO_STRIBOG256:
912
	ctx->name = gcry_md_algo_name (GCRY_MD_STRIBOG256);
913
	ctx->digestsize = gcry_md_get_algo_dlen(GCRY_MD_STRIBOG256);
914
/*@-sizeoftype@*/ /* FIX: union, not void pointer */
915
	ctx->paramsize = sizeof(gcry_md_hd_t);
916
/*@=sizeoftype@*/
917
	ctx->param = DRD_xcalloc(1, ctx->paramsize);
918
	(void)gcry_md_open ((gcry_md_hd_t*)(ctx->param), GCRY_MD_STRIBOG256, 0);
919
/*@-type@*/
920
	ctx->Reset = (int (*)(void *)) rpmgcDigestReset;
921
	ctx->Update = (int (*)(void *, const byte *, size_t)) rpmgcDigestUpdate;
922
	ctx->Digest = (int (*)(void *, byte *)) rpmgcDigestSTRIBOG256;
923
/*@=type@*/
924
	break;
925
    case PGPHASHALGO_STRIBOG512:
926
	ctx->name = gcry_md_algo_name (GCRY_MD_STRIBOG512);
927
	ctx->digestsize = gcry_md_get_algo_dlen(GCRY_MD_STRIBOG512);
928
/*@-sizeoftype@*/ /* FIX: union, not void pointer */
929
	ctx->paramsize = sizeof(gcry_md_hd_t);
930
/*@=sizeoftype@*/
931
	ctx->param = DRD_xcalloc(1, ctx->paramsize);
932
	(void)gcry_md_open ((gcry_md_hd_t*)(ctx->param), GCRY_MD_STRIBOG512, 0);
933
/*@-type@*/
934
	ctx->Reset = (int (*)(void *)) rpmgcDigestReset;
935
	ctx->Update = (int (*)(void *, const byte *, size_t)) rpmgcDigestUpdate;
936
	ctx->Digest = (int (*)(void *, byte *)) rpmgcDigestSTRIBOG512;
937
/*@=type@*/
938
	break;
939
#endif
896 940
    case PGPHASHALGO_HAVAL_5_160:
897 941
    default:
898 942
	(void)rpmioFreePoolItem((rpmioItem)ctx, __FUNCTION__, __FILE__, __LINE__);
view file @ 5bf4d7c639
... ... --- /dev/null
... ... +++ b/rpmio/gcry_digest.c
... ... @@ -0,0 +1,49 @@
1
/** \ingroup signature
2
 * \file rpmio/gcry_digest.c
3
 */
4
5
#if defined(WITH_GCRYPT)
6
7
#include <gcrypt.h>
8
9
static int
10
rpmgcDigestReset (void * param)
11
{
12
  gcry_md_reset (*(gcry_md_hd_t*)param);
13
  return 0;
14
}
15
static int
16
rpmgcDigestUpdate (void * param, const byte * _data, size_t _len)
17
{
18
  gcry_md_write (*(gcry_md_hd_t*)param, (const void *)_data, _len);
19
  return 0;
20
}
21
22
static int rpmgcDigestGOST3411_94 (void * param, byte * digest)
23
{
24
  unsigned char * h = gcry_md_read (*(gcry_md_hd_t*)param, GCRY_MD_GOSTR3411_94);
25
  unsigned int diglen = gcry_md_get_algo_dlen(GCRY_MD_GOSTR3411_94);
26
  memcpy(digest, h, diglen);
27
  gcry_md_close(*(gcry_md_hd_t*)param);
28
  return 0;
29
}
30
static int
31
rpmgcDigestSTRIBOG256 (void * param, byte * digest)
32
{
33
  unsigned char * h = gcry_md_read (*(gcry_md_hd_t*)param, GCRY_MD_STRIBOG256);
34
  unsigned int diglen = gcry_md_get_algo_dlen(GCRY_MD_STRIBOG256);
35
  memcpy(digest, h, diglen);
36
  gcry_md_close(*(gcry_md_hd_t*)param);
37
  return 0;
38
}
39
static int
40
rpmgcDigestSTRIBOG512 (void * param, byte * digest)
41
{
42
  unsigned char * h = gcry_md_read (*(gcry_md_hd_t*)param, GCRY_MD_STRIBOG512);
43
  unsigned int diglen = gcry_md_get_algo_dlen(GCRY_MD_STRIBOG512);
44
  memcpy(digest, h, diglen);
45
  gcry_md_close(*(gcry_md_hd_t*)param);
46
  return 0;
47
}
48
49
#endif
view file @ 5bf4d7c639
... ... --- a/rpmio/poptIO.c
... ... +++ b/rpmio/poptIO.c
... ... @@ -349,6 +349,14 @@ struct poptOption rpmioDigestPoptTable[] = {
349 349
	N_("ADLER-32 checksum"), NULL },
350 350
 { "jlu32",'\0', POPT_ARG_VAL,	&rpmioDigestHashAlgo, PGPHASHALGO_JLU32,
351 351
	N_("Lookup3 hash"), NULL },
352
#if defined(WITH_GCRYPT)
353
 { "gostr3411_94",'\0', POPT_ARG_VAL,&rpmioDigestHashAlgo, PGPHASHALGO_GOSTR3411_94,
354
	N_("GOST R 34.11-94."), NULL },
355
 { "stribog256",'\0', POPT_ARG_VAL,&rpmioDigestHashAlgo, PGPHASHALGO_STRIBOG256,
356
	N_("GOST R 34.11-2012, 256 bit."), NULL },
357
 { "stribog512",'\0', POPT_ARG_VAL,&rpmioDigestHashAlgo, PGPHASHALGO_STRIBOG512,
358
	N_("GOST R 34.11-2012, 512 bit."), NULL },
359
#endif
352 360
 { "nodigest",'\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &rpmioDigestHashAlgo, PGPHASHALGO_NONE,
353 361
	N_("No hash algorithm"), NULL },
354 362
 { "alldigests",'\0', POPT_ARG_VAL|POPT_ARGFLAG_DOC_HIDDEN, &rpmioDigestHashAlgo, 256,
... ... --- a/rpmio/rpmgc.c
... ... +++ b/rpmio/rpmgc.c
... ... @@ -124,6 +124,15 @@ dig->hash_algoN = rpmgcHashAlgo2Name(sigp->hash_algo);
124 124
    case PGPHASHALGO_SHA512:
125 125
	hash_algo_name = "sha512";
126 126
	break;
127
    case PGPHASHALGO_GOSTR3411_94:
128
	hash_algo_name = "gostr3411_94"; // "gost94";
129
	break;
130
    case PGPHASHALGO_STRIBOG256:
131
	hash_algo_name = "stribog256"; // "gost12-256";
132
	break;
133
    case PGPHASHALGO_STRIBOG512:
134
	hash_algo_name = "stribog512"; // "gost12-512";
135
	break;
127 136
    case PGPHASHALGO_SHA224:
128 137
#ifdef	NOTYET
129 138
	hash_algo_name = "sha224";
view file @ 5bf4d7c639
... ... --- a/rpmio/rpmiotypes.h
... ... +++ b/rpmio/rpmiotypes.h
... ... @@ -182,6 +182,13 @@ typedef enum pgpHashAlgo_e {
182 182
    PGPHASHALGO_SHA512		= 10,	/*!< SHA-512 */
183 183
    PGPHASHALGO_SHA224		= 11,	/*!< SHA-224 */
184 184
185
#if defined(WITH_GCRYPT)
186
    PGPHASHALGO_GOSTR3411_94	= 98+0,/*!< (private) GOST R 34.11-94. */
187
    PGPHASHALGO_STRIBOG256	= 98+1,/*!< (private) GOST R 34.11-2012, 256 bit. */
188
    PGPHASHALGO_STRIBOG512	= 98+2,/*!< (private) GOST R 34.11-2012, 512 bit. */
189
#endif
190
191
185 192
    PGPHASHALGO_MD4		= 104,	/*!< (private) MD4 */
186 193
    PGPHASHALGO_RIPEMD128	= 105,	/*!< (private) RIPEMD-128 */
187 194
    PGPHASHALGO_CRC32		= 106,	/*!< (private) CRC-32 */
view file @ 5bf4d7c639
... ... --- a/rpmio/rpmpgp.c
... ... +++ b/rpmio/rpmpgp.c
... ... @@ -15,6 +15,9 @@
15 15
#if defined(WITH_NSS)
16 16
#include <rpmnss.h>
17 17
#endif
18
#if defined(WITH_GCRYPT)
19
#include <rpmgc.h>
20
#endif
18 21
#include "debug.h"
19 22
20 23
/*@access pgpDig @*/
... ... @@ -152,6 +155,9 @@ struct pgpValTbl_s pgpHashTbl[] = {
155 155
    { PGPHASHALGO_SHA256,	"SHA256" },
156 156
    { PGPHASHALGO_SHA384,	"SHA384" },
157 157
    { PGPHASHALGO_SHA512,	"SHA512" },
158
    { PGPHASHALGO_GOSTR3411_94,	"GOSTR3411_94" },
159
    { PGPHASHALGO_STRIBOG256,	"STRIBOG256" },
160
    { PGPHASHALGO_STRIBOG512,	"STRIBOG512" },
158 161
    { -1,			"MD_UNKNOWN" },
159 162
};
160 163
view file @ 5bf4d7c639
... ... --- a/tools/rpmmtree.c
... ... +++ b/tools/rpmmtree.c
... ... @@ -341,6 +341,9 @@ static KEY keylist[] = {
341 341
    { "flags",		MTREE_KEYS_FLAGS,	NEEDVALUE },
342 342
    { "gid",		MTREE_KEYS_GID,		NEEDVALUE },
343 343
    { "gname",		MTREE_KEYS_GNAME,	NEEDVALUE },
344
#if defined(WITH_GCRYPT)
345
    { "gostr3411_94digest",MTREE_KEYS_DIGEST,	PGPHASHALGO_GOSTR3411_94 },
346
#endif
344 347
    { "haval160digest",	MTREE_KEYS_DIGEST,	PGPHASHALGO_HAVAL_5_160 },
345 348
    { "ignore",		MTREE_KEYS_IGN,		0 },
346 349
    { "jlu32",		MTREE_KEYS_DIGEST,	PGPHASHALGO_JLU32 },
... ... @@ -364,6 +367,10 @@ static KEY keylist[] = {
367 367
    { "sha384digest",	MTREE_KEYS_DIGEST,	PGPHASHALGO_SHA384 },
368 368
    { "sha512digest",	MTREE_KEYS_DIGEST,	PGPHASHALGO_SHA512 },
369 369
    { "size",		MTREE_KEYS_SIZE,	NEEDVALUE },
370
#if defined(WITH_GCRYPT)
371
    { "stribog256digest",MTREE_KEYS_DIGEST,	PGPHASHALGO_STRIBOG256 },
372
    { "stribog512digest",MTREE_KEYS_DIGEST,	PGPHASHALGO_STRIBOG512 },
373
#endif
370 374
    { "tiger192digest",	MTREE_KEYS_DIGEST,	PGPHASHALGO_TIGER192 },
371 375
    { "time",		MTREE_KEYS_TIME,	NEEDVALUE },
372 376
    { "type",		MTREE_KEYS_TYPE,	NEEDVALUE },
... ... @@ -428,6 +435,11 @@ algo2tagname(uint32_t algo)
435 435
    case PGPHASHALGO_RIPEMD320:	tagname = "rmd320digest";	break;
436 436
    case PGPHASHALGO_SALSA10:	tagname = "salsa10";		break;
437 437
    case PGPHASHALGO_SALSA20:	tagname = "salsa20";		break;
438
#if defined(WITH_GCRYPT)
439
    case PGPHASHALGO_GOSTR3411_94: tagname = "gostr3411_94digest"; break;
440
    case PGPHASHALGO_STRIBOG256: tagname = "stribog256digest"; break;
441
    case PGPHASHALGO_STRIBOG512: tagname = "stribog512digest"; break;
442
#endif
438 443
    default:			tagname = NULL;			break;
439 444
    }
440 445
    return tagname;
... ... @@ -2052,6 +2064,12 @@ static const char * algo2name(uint32_t algo)
2064 2064
    case PGPHASHALGO_SHA384:       return "SHA384";
2065 2065
    case PGPHASHALGO_SHA512:       return "SHA512";
2066 2066
2067
#if defined(WITH_GCRYPT)
2068
    case PGPHASHALGO_GOSTR3411_94: return "GOSTR3411_94";
2069
    case PGPHASHALGO_STRIBOG256:   return "STRIBOG256";
2070
    case PGPHASHALGO_STRIBOG512:   return "STRIBOG512";
2071
#endif
2072
2067 2073
    case PGPHASHALGO_MD4:	   return "MD4";
2068 2074
    case PGPHASHALGO_RIPEMD128:	   return "RIPEMD128";
2069 2075
    case PGPHASHALGO_CRC32:	   return "CRC32";

Comments