rpm  5.4.10
digest.c
Go to the documentation of this file.
1 
5 #include "system.h"
6 
7 #include "rpmio_internal.h"
8 
9 #include <rpmbc.h>
10 
11 #include "crc.h"
12 
13 #include "arirang.h"
14 
15 #include "blake.h"
16 
17 #include "bmw.h"
18 
19 #include "chi.h"
20 
21 #include "cubehash.h"
22 
23 #include "echo.h"
24 #undef BitSequence
25 #undef DataLength
26 #undef HashReturn
27 #undef hashState
28 #undef Init
29 #undef Update
30 #undef Final
31 #undef Hash
32 
33 #include "edon-r.h"
34 
35 #include "fugue.h"
36 
37 #include "groestl.h"
38 #undef BitSequence
39 #undef DataLength
40 #undef HashReturn
41 #undef hashState
42 #undef Init
43 #undef Update
44 #undef Final
45 #undef Hash
46 
47 #include "hamsi.h"
48 
49 #include "jh.h"
50 
51 #include "keccak.h"
52 #undef BitSequence
53 #undef DataLength
54 #undef HashReturn
55 #undef hashState
56 #undef Init
57 #undef Update
58 #undef Final
59 #undef Hash
60 
61 #include "lane.h"
62 
63 #include "luffa.h"
64 
65 #include "md2.h"
66 #include "md6.h"
67 
68 #include "shabal.h"
69 
70 #include "shavite3.h"
71 #undef BitSequence
72 #undef DataLength
73 #undef HashReturn
74 #undef hashState
75 #undef Init
76 #undef Update
77 #undef Final
78 #undef Hash
79 
80 #include "simd.h"
81 #undef BitSequence
82 #undef DataLength
83 #undef HashReturn
84 #undef hashState
85 #undef Init
86 #undef Update
87 #undef Final
88 #undef Hash
89 
90 #include "salsa10.h"
91 #include "salsa20.h"
92 
93 #include "skein.h"
94 
95 #include "tib3.h"
96 #undef BitSequence
97 #undef DataLength
98 #undef HashReturn
99 #undef hashState
100 #undef Init
101 #undef Update
102 #undef Final
103 #undef Hash
104 
105 #include "tiger.h"
106 
107 #include "debug.h"
108 
109 /*@unchecked@*/
110 int _ctx_debug = 0;
111 
112 #ifdef _DIGEST_DEBUG
113 #define DPRINTF(_a) if (_ctx_debug < 0) fprintf _a
114 #else
115 #define DPRINTF(_a)
116 #endif
117 
118 /* Include Bob Jenkins lookup3 hash */
119 #define _JLU3_jlu32l
120 #include "lookup3.c"
121 
122 /*@access DIGEST_CTX@*/
123 
127 struct DIGEST_CTX_s {
129 /*@observer@*/
130  const char * name;
131  size_t paramsize;
132  size_t blocksize;
133  size_t digestsize;
134  int (*Reset) (void * param)
135  /*@modifies param @*/;
136  int (*Update) (void * param, const byte * data, size_t size)
137  /*@modifies param @*/;
138  int (*Digest) (void * param, /*@out@*/ byte * digest)
139  /*@modifies param, digest @*/;
142 /*@observer@*/ /*@null@*/
143  const char * asn1;
144  void * param;
145  void * salt;
146 };
147 
148 static void ctxFini(void * _ctx)
149  /*@modifies _ctx @*/
150 {
151  DIGEST_CTX ctx = (DIGEST_CTX) _ctx;
152  if (ctx->param != NULL && ctx->paramsize > 0)
153  memset(ctx->param, 0, ctx->paramsize); /* In case it's sensitive */
154  ctx->param = _free(ctx->param);
155  if (ctx->salt != NULL && ctx->blocksize > 0)
156  memset(ctx->salt, 0, 2*ctx->paramsize); /* In case it's sensitive */
157  ctx->salt = _free(ctx->salt);
158  ctx->name = NULL;
159  ctx->paramsize = 0;
160  ctx->blocksize = 0;
161  ctx->digestsize = 0;
162  ctx->Reset = NULL;
163  ctx->Update = NULL;
164  ctx->Digest = NULL;
165  ctx->hashalgo = (pgpHashAlgo)0;
166  ctx->flags = (rpmDigestFlags)0;
167  ctx->asn1 = NULL;
168 }
169 
170 /*@unchecked@*/ /*@only@*/ /*@null@*/
172 
174 {
175  DIGEST_CTX ctx;
176 
177  if (_ctxPool == NULL) {
178 ANNOTATE_BENIGN_RACE(&_ctxPool, "");
179  _ctxPool = rpmioNewPool("ctx", sizeof(*ctx), -1, _ctx_debug,
180  NULL, NULL, ctxFini);
181  pool = _ctxPool;
182  }
183  ctx = (DIGEST_CTX) rpmioGetPool(pool, sizeof(*ctx));
184  memset(((char *)ctx)+sizeof(ctx->_item), 0, sizeof(*ctx)-sizeof(ctx->_item));
185  return ctx;
186 }
187 
189 {
190  return (ctx != NULL ? ctx->hashalgo : PGPHASHALGO_NONE);
191 }
192 
194 {
195  return (ctx != NULL ? ctx->flags : RPMDIGEST_NONE);
196 }
197 
198 const char * rpmDigestName(DIGEST_CTX ctx)
199 {
200  return (ctx != NULL ? ctx->name : "UNKNOWN");
201 }
202 
203 const char * rpmDigestASN1(DIGEST_CTX ctx)
204 {
205  return (ctx != NULL ? ctx->asn1 : NULL);
206 }
207 
210 {
211  DIGEST_CTX nctx = ctxGetPool(_ctxPool);
212 
213  nctx->name = octx->name;
214  nctx->digestsize = octx->digestsize;
215  nctx->blocksize = octx->blocksize;
216  nctx->paramsize = octx->paramsize;
217  nctx->Reset = octx->Reset;
218  nctx->Update = octx->Update;
219  nctx->Digest = octx->Digest;
220  nctx->hashalgo = octx->hashalgo;
221  nctx->flags = octx->flags;
222  nctx->asn1 = octx->asn1;
223  nctx->param = (octx->param != NULL && octx->paramsize > 0)
224  ? memcpy(DRD_xmalloc(nctx->paramsize), octx->param, nctx->paramsize)
225  : NULL;
226  nctx->salt = (octx->salt != NULL && octx->blocksize > 0)
227  ? memcpy(DRD_xmalloc(nctx->blocksize), octx->salt, nctx->blocksize)
228  : NULL;
229  return (DIGEST_CTX)rpmioLinkPoolItem((rpmioItem)nctx, __FUNCTION__, __FILE__, __LINE__);
230 }
231 
232 static int noopReset(void * param)
233 {
234  return 0;
235 }
236 
237 /* XXX impedance match bytes -> bits length. */
238 static int md6_Update(void * param, const byte * _data, size_t _len)
239 {
240  return md6_update((md6_state *)param, (unsigned char *) _data, (rpmuint64_t)(8 * _len));
241 }
242 
245 {
246  DIGEST_CTX ctx = ctxGetPool(_ctxPool);
247  int xx;
248 
249  ctx->name = "";
250  ctx->paramsize = 0;
251  ctx->blocksize = 64;
252  ctx->digestsize = 0;
253  ctx->Reset = NULL;
254  ctx->Update = NULL;
255  ctx->Digest = NULL;
256  ctx->hashalgo = hashalgo;
257  ctx->flags = flags;
258  ctx->asn1 = NULL;
259  ctx->param = NULL;
260  ctx->salt = NULL;
261 
262  switch (hashalgo) {
263  case PGPHASHALGO_MD5:
264  ctx->name = "MD5";
265  ctx->digestsize = 128/8;
266 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
267  ctx->paramsize = sizeof(md5Param);
268 /*@=sizeoftype@*/
269  ctx->param = DRD_xcalloc(1, ctx->paramsize);
270 /*@-type@*/
271  ctx->Reset = (int (*)(void *)) md5Reset;
272  ctx->Update = (int (*)(void *, const byte *, size_t)) md5Update;
273  ctx->Digest = (int (*)(void *, byte *)) md5Digest;
274 /*@=type@*/
275  ctx->asn1 = "3020300c06082a864886f70d020505000410";
276  break;
277  case PGPHASHALGO_SHA1:
278  ctx->name = "SHA1";
279  ctx->digestsize = 160/8;
280 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
281  ctx->paramsize = sizeof(sha1Param);
282 /*@=sizeoftype@*/
283  ctx->param = DRD_xcalloc(1, ctx->paramsize);
284 /*@-type@*/
285  ctx->Reset = (int (*)(void *)) sha1Reset;
286  ctx->Update = (int (*)(void *, const byte *, size_t)) sha1Update;
287  ctx->Digest = (int (*)(void *, byte *)) sha1Digest;
288 /*@=type@*/
289  ctx->asn1 = "3021300906052b0e03021a05000414";
290  break;
292  ctx->name = "RIPEMD128";
293  ctx->digestsize = 128/8;
294 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
295  ctx->paramsize = sizeof(ripemd128Param);
296 /*@=sizeoftype@*/
297  ctx->param = DRD_xcalloc(1, ctx->paramsize);
298 /*@-type@*/
299  ctx->Reset = (int (*)(void *)) ripemd128Reset;
300  ctx->Update = (int (*)(void *, const byte *, size_t)) ripemd128Update;
301  ctx->Digest = (int (*)(void *, byte *)) ripemd128Digest;
302 /*@=type@*/
303  break;
305  ctx->name = "RIPEMD160";
306  ctx->digestsize = 160/8;
307 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
308  ctx->paramsize = sizeof(ripemd160Param);
309 /*@=sizeoftype@*/
310  ctx->param = DRD_xcalloc(1, ctx->paramsize);
311 /*@-type@*/
312  ctx->Reset = (int (*)(void *)) ripemd160Reset;
313  ctx->Update = (int (*)(void *, const byte *, size_t)) ripemd160Update;
314  ctx->Digest = (int (*)(void *, byte *)) ripemd160Digest;
315 /*@=type@*/
316  ctx->asn1 = "3021300906052b2403020105000414";
317  break;
319  ctx->name = "RIPEMD256";
320  ctx->digestsize = 256/8;
321 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
322  ctx->paramsize = sizeof(ripemd256Param);
323 /*@=sizeoftype@*/
324  ctx->param = DRD_xcalloc(1, ctx->paramsize);
325 /*@-type@*/
326  ctx->Reset = (int (*)(void *)) ripemd256Reset;
327  ctx->Update = (int (*)(void *, const byte *, size_t)) ripemd256Update;
328  ctx->Digest = (int (*)(void *, byte *)) ripemd256Digest;
329 /*@=type@*/
330  break;
332  ctx->name = "RIPEMD320";
333  ctx->digestsize = 320/8;
334 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
335  ctx->paramsize = sizeof(ripemd320Param);
336 /*@=sizeoftype@*/
337  ctx->param = DRD_xcalloc(1, ctx->paramsize);
338 /*@-type@*/
339  ctx->Reset = (int (*)(void *)) ripemd320Reset;
340  ctx->Update = (int (*)(void *, const byte *, size_t)) ripemd320Update;
341  ctx->Digest = (int (*)(void *, byte *)) ripemd320Digest;
342 /*@=type@*/
343  break;
344  case PGPHASHALGO_SALSA10:
345  ctx->name = "SALSA10";
346  ctx->digestsize = 512/8;
347 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
348  ctx->paramsize = sizeof(salsa10Param);
349 /*@=sizeoftype@*/
350  ctx->param = DRD_xcalloc(1, ctx->paramsize);
351 /*@-type@*/
352  ctx->Reset = (int (*)(void *)) salsa10Reset;
353  ctx->Update = (int (*)(void *, const byte *, size_t)) salsa10Update;
354  ctx->Digest = (int (*)(void *, byte *)) salsa10Digest;
355 /*@=type@*/
356  break;
357  case PGPHASHALGO_SALSA20:
358  ctx->name = "SALSA20";
359  ctx->digestsize = 512/8;
360 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
361  ctx->paramsize = sizeof(salsa20Param);
362 /*@=sizeoftype@*/
363  ctx->param = DRD_xcalloc(1, ctx->paramsize);
364 /*@-type@*/
365  ctx->Reset = (int (*)(void *)) salsa20Reset;
366  ctx->Update = (int (*)(void *, const byte *, size_t)) salsa20Update;
367  ctx->Digest = (int (*)(void *, byte *)) salsa20Digest;
368 /*@=type@*/
369  break;
371  ctx->name = "TIGER192";
372  ctx->digestsize = 192/8;
373 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
374  ctx->paramsize = sizeof(tigerParam);
375 /*@=sizeoftype@*/
376  ctx->param = DRD_xcalloc(1, ctx->paramsize);
377 /*@-type@*/
378  ctx->Reset = (int (*)(void *)) tigerReset;
379  ctx->Update = (int (*)(void *, const byte *, size_t)) tigerUpdate;
380  ctx->Digest = (int (*)(void *, byte *)) tigerDigest;
381 /*@=type@*/
382  ctx->asn1 = "3029300d06092b06010401da470c0205000418";
383  break;
384  case PGPHASHALGO_MD2:
385  ctx->name = "MD2";
386  ctx->digestsize = 128/8;
387  ctx->blocksize = 16;
388 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
389  ctx->paramsize = sizeof(md2Param);
390 /*@=sizeoftype@*/
391  ctx->param = DRD_xcalloc(1, ctx->paramsize);
392 /*@-type@*/
393  ctx->Reset = (int (*)(void *)) md2Reset;
394  ctx->Update = (int (*)(void *, const byte *, size_t)) md2Update;
395  ctx->Digest = (int (*)(void *, byte *)) md2Digest;
396 /*@=type@*/
397  ctx->asn1 = "3020300c06082a864886f70d020205000410";
398  break;
399  case PGPHASHALGO_MD4:
400  ctx->name = "MD4";
401  ctx->digestsize = 128/8;
402 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
403  ctx->paramsize = sizeof(md4Param);
404 /*@=sizeoftype@*/
405  ctx->param = DRD_xcalloc(1, ctx->paramsize);
406 /*@-type@*/
407  ctx->Reset = (int (*)(void *)) md4Reset;
408  ctx->Update = (int (*)(void *, const byte *, size_t)) md4Update;
409  ctx->Digest = (int (*)(void *, byte *)) md4Digest;
410 /*@=type@*/
411  break;
412  case PGPHASHALGO_CRC32:
413  ctx->name = "CRC32";
414  ctx->digestsize = 32/8;
415  ctx->blocksize = 8;
416  { sum32Param * mp = (sum32Param *) DRD_xcalloc(1, sizeof(*mp));
417 /*@-type @*/
418  mp->update = (rpmuint32_t (*)(rpmuint32_t, const byte *, size_t)) __crc32;
420 /*@=type @*/
421  ctx->paramsize = sizeof(*mp);
422  ctx->param = mp;
423  }
424 /*@-type@*/
425  ctx->Reset = (int (*)(void *)) sum32Reset;
426  ctx->Update = (int (*)(void *, const byte *, size_t)) sum32Update;
427  ctx->Digest = (int (*)(void *, byte *)) sum32Digest;
428 /*@=type@*/
429  break;
430  case PGPHASHALGO_ADLER32:
431  ctx->name = "ADLER32";
432  ctx->digestsize = 32/8;
433  ctx->blocksize = 8;
434  { sum32Param * mp = (sum32Param *) DRD_xcalloc(1, sizeof(*mp));
435 /*@-type @*/
436  mp->update = (rpmuint32_t (*)(rpmuint32_t, const byte *, size_t)) __adler32;
438 /*@=type @*/
439  ctx->paramsize = sizeof(*mp);
440  ctx->param = mp;
441  }
442 /*@-type@*/
443  ctx->Reset = (int (*)(void *)) sum32Reset;
444  ctx->Update = (int (*)(void *, const byte *, size_t)) sum32Update;
445  ctx->Digest = (int (*)(void *, byte *)) sum32Digest;
446 /*@=type@*/
447  break;
448  case PGPHASHALGO_JLU32:
449  ctx->name = "JLU32";
450  ctx->digestsize = 32/8;
451  ctx->blocksize = 8;
452  { sum32Param * mp = (sum32Param *) DRD_xcalloc(1, sizeof(*mp));
453 /*@-type @*/
454  mp->update = (rpmuint32_t (*)(rpmuint32_t, const byte *, size_t)) jlu32l;
455 /*@=type @*/
456  ctx->paramsize = sizeof(*mp);
457  ctx->param = mp;
458  }
459 /*@-type@*/
460  ctx->Reset = (int (*)(void *)) sum32Reset;
461  ctx->Update = (int (*)(void *, const byte *, size_t)) sum32Update;
462  ctx->Digest = (int (*)(void *, byte *)) sum32Digest;
463 /*@=type@*/
464  break;
465  case PGPHASHALGO_CRC64:
466  ctx->name = "CRC64";
467  ctx->digestsize = 64/8;
468  ctx->blocksize = 8;
469  { sum64Param * mp = (sum64Param *) DRD_xcalloc(1, sizeof(*mp));
470 /*@-type@*/
471  mp->update = (rpmuint64_t (*)(rpmuint64_t, const byte *, size_t)) __crc64;
473 /*@=type@*/
474  ctx->paramsize = sizeof(*mp);
475  ctx->param = mp;
476  }
477 /*@-type@*/
478  ctx->Reset = (int (*)(void *)) sum64Reset;
479  ctx->Update = (int (*)(void *, const byte *, size_t)) sum64Update;
480  ctx->Digest = (int (*)(void *, byte *)) sum64Digest;
481 /*@=type@*/
482  break;
483  case PGPHASHALGO_SHA224:
484  ctx->name = "SHA224";
485  ctx->digestsize = 224/8;
486 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
487  ctx->paramsize = sizeof(sha224Param);
488 /*@=sizeoftype@*/
489  ctx->param = DRD_xcalloc(1, ctx->paramsize);
490 /*@-type@*/
491  ctx->Reset = (int (*)(void *)) sha224Reset;
492  ctx->Update = (int (*)(void *, const byte *, size_t)) sha224Update;
493  ctx->Digest = (int (*)(void *, byte *)) sha224Digest;
494 /*@=type@*/
495  ctx->asn1 = "302d300d06096086480165030402040500041C";
496  break;
497  case PGPHASHALGO_SHA256:
498  ctx->name = "SHA256";
499  ctx->digestsize = 256/8;
500 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
501  ctx->paramsize = sizeof(sha256Param);
502 /*@=sizeoftype@*/
503  ctx->param = DRD_xcalloc(1, ctx->paramsize);
504 /*@-type@*/
505  ctx->Reset = (int (*)(void *)) sha256Reset;
506  ctx->Update = (int (*)(void *, const byte *, size_t)) sha256Update;
507  ctx->Digest = (int (*)(void *, byte *)) sha256Digest;
508 /*@=type@*/
509  ctx->asn1 = "3031300d060960864801650304020105000420";
510  break;
511  case PGPHASHALGO_SHA384:
512  ctx->name = "SHA384";
513  ctx->digestsize = 384/8;
514  ctx->blocksize = 128;
515 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
516  ctx->paramsize = sizeof(sha384Param);
517 /*@=sizeoftype@*/
518  ctx->param = DRD_xcalloc(1, ctx->paramsize);
519 /*@-type@*/
520  ctx->Reset = (int (*)(void *)) sha384Reset;
521  ctx->Update = (int (*)(void *, const byte *, size_t)) sha384Update;
522  ctx->Digest = (int (*)(void *, byte *)) sha384Digest;
523 /*@=type@*/
524  ctx->asn1 = "3041300d060960864801650304020205000430";
525  break;
526  case PGPHASHALGO_SHA512:
527  ctx->name = "SHA512";
528  ctx->digestsize = 512/8;
529  ctx->blocksize = 128;
530 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
531  ctx->paramsize = sizeof(sha512Param);
532 /*@=sizeoftype@*/
533  ctx->param = DRD_xcalloc(1, ctx->paramsize);
534 /*@-type@*/
535  ctx->Reset = (int (*)(void *)) sha512Reset;
536  ctx->Update = (int (*)(void *, const byte *, size_t)) sha512Update;
537  ctx->Digest = (int (*)(void *, byte *)) sha512Digest;
538 /*@=type@*/
539  ctx->asn1 = "3051300d060960864801650304020305000440";
540  break;
541  case PGPHASHALGO_SKEIN_224: ctx->digestsize = 224/8; goto skein256;
542  case PGPHASHALGO_SKEIN_256: ctx->digestsize = 256/8; goto skein256;
543 skein256:
544  ctx->name = "SKEIN256";
545 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
546  ctx->paramsize = sizeof(Skein_256_Ctxt_t);
547 /*@=sizeoftype@*/
548  ctx->param = DRD_xcalloc(1, ctx->paramsize);
549  (void) Skein_256_Init((Skein_256_Ctxt_t *)ctx->param,
550  (int)(8 * ctx->digestsize));
551  ctx->Reset = (int (*)(void *)) noopReset;
552  ctx->Update = (int (*)(void *, const byte *, size_t)) Skein_256_Update;
553  ctx->Digest = (int (*)(void *, byte *)) Skein_256_Final;
554  break;
555  case PGPHASHALGO_SKEIN_384: ctx->digestsize = 384/8; goto skein512;
556  case PGPHASHALGO_SKEIN_512: ctx->digestsize = 512/8; goto skein512;
557 skein512:
558  ctx->name = "SKEIN512";
559 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
560  ctx->paramsize = sizeof(Skein_512_Ctxt_t);
561 /*@=sizeoftype@*/
562  ctx->param = DRD_xcalloc(1, ctx->paramsize);
563  (void) Skein_512_Init((Skein_512_Ctxt_t *)ctx->param,
564  (int)(8 * ctx->digestsize));
565  ctx->Reset = (int (*)(void *)) noopReset;
566  ctx->Update = (int (*)(void *, const byte *, size_t)) Skein_512_Update;
567  ctx->Digest = (int (*)(void *, byte *)) Skein_512_Final;
568  break;
570  ctx->name = "SKEIN1024";
571  ctx->digestsize = 1024/8;
572 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
573  ctx->paramsize = sizeof(Skein1024_Ctxt_t);
574 /*@=sizeoftype@*/
575  ctx->param = DRD_xcalloc(1, ctx->paramsize);
576  (void) Skein1024_Init((Skein1024_Ctxt_t *)ctx->param,
577  (int)(8 * ctx->digestsize));
578  ctx->Reset = (int (*)(void *)) noopReset;
579  ctx->Update = (int (*)(void *, const byte *, size_t)) Skein1024_Update;
580  ctx->Digest = (int (*)(void *, byte *)) Skein1024_Final;
581  break;
582  case PGPHASHALGO_ARIRANG_224: ctx->digestsize = 224/8; goto arirang;
583  case PGPHASHALGO_ARIRANG_256: ctx->digestsize = 256/8; goto arirang;
584  case PGPHASHALGO_ARIRANG_384: ctx->digestsize = 384/8; goto arirang;
585  case PGPHASHALGO_ARIRANG_512: ctx->digestsize = 512/8; goto arirang;
586 arirang:
587  ctx->name = "ARIRANG";
588 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
589  ctx->paramsize = sizeof(arirangParam);
590 /*@=sizeoftype@*/
591  ctx->param = DRD_xcalloc(1, ctx->paramsize);
592  (void) arirangInit((arirangParam *)ctx->param, (int)(8 * ctx->digestsize));
593  ctx->Reset = (int (*)(void *)) arirangReset;
594  ctx->Update = (int (*)(void *, const byte *, size_t)) arirangUpdate;
595  ctx->Digest = (int (*)(void *, byte *)) arirangDigest;
596  break;
597  case PGPHASHALGO_BLAKE_224: ctx->digestsize = 224/8; goto blake;
598  case PGPHASHALGO_BLAKE_256: ctx->digestsize = 256/8; goto blake;
599  case PGPHASHALGO_BLAKE_384: ctx->digestsize = 384/8; goto blake;
600  case PGPHASHALGO_BLAKE_512: ctx->digestsize = 512/8; goto blake;
601 blake:
602  ctx->name = "BLAKE";
603 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
604  ctx->paramsize = sizeof(blakeParam);
605 /*@=sizeoftype@*/
606  ctx->param = DRD_xcalloc(1, ctx->paramsize);
607  (void) blakeInit((blakeParam *)ctx->param, (int)(8 * ctx->digestsize));
608  ctx->Reset = (int (*)(void *)) blakeReset;
609  ctx->Update = (int (*)(void *, const byte *, size_t)) blakeUpdate;
610  ctx->Digest = (int (*)(void *, byte *)) blakeDigest;
611  break;
612  case PGPHASHALGO_BMW_224: ctx->digestsize = 224/8; goto bmw;
613  case PGPHASHALGO_BMW_256: ctx->digestsize = 256/8; goto bmw;
614  case PGPHASHALGO_BMW_384: ctx->digestsize = 384/8; goto bmw;
615  case PGPHASHALGO_BMW_512: ctx->digestsize = 512/8; goto bmw;
616 bmw:
617  ctx->name = "BMW";
618 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
619  ctx->paramsize = sizeof(bmwParam);
620 /*@=sizeoftype@*/
621  ctx->param = DRD_xcalloc(1, ctx->paramsize);
622  (void) bmwInit((bmwParam *)ctx->param, (int)(8 * ctx->digestsize));
623  ctx->Reset = (int (*)(void *)) bmwReset;
624  ctx->Update = (int (*)(void *, const byte *, size_t)) bmwUpdate;
625  ctx->Digest = (int (*)(void *, byte *)) bmwDigest;
626  break;
627  case PGPHASHALGO_CHI_224: ctx->digestsize = 224/8; goto chi;
628  case PGPHASHALGO_CHI_256: ctx->digestsize = 256/8; goto chi;
629  case PGPHASHALGO_CHI_384: ctx->digestsize = 384/8; goto chi;
630  case PGPHASHALGO_CHI_512: ctx->digestsize = 512/8; goto chi;
631 chi:
632  ctx->name = "CHI";
633 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
634  ctx->paramsize = sizeof(chiParam);
635 /*@=sizeoftype@*/
636  ctx->param = DRD_xcalloc(1, ctx->paramsize);
637  (void) chiInit((chiParam *)ctx->param, (int)(8 * ctx->digestsize));
638  ctx->Reset = (int (*)(void *)) chiReset;
639  ctx->Update = (int (*)(void *, const byte *, size_t)) chiUpdate;
640  ctx->Digest = (int (*)(void *, byte *)) chiDigest;
641  break;
642  case PGPHASHALGO_CUBEHASH_224: ctx->digestsize = 224/8; goto cubehash;
643  case PGPHASHALGO_CUBEHASH_256: ctx->digestsize = 256/8; goto cubehash;
644  case PGPHASHALGO_CUBEHASH_384: ctx->digestsize = 384/8; goto cubehash;
645  case PGPHASHALGO_CUBEHASH_512: ctx->digestsize = 512/8; goto cubehash;
646 cubehash:
647  ctx->name = "CUBEHASH";
648 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
649  ctx->paramsize = sizeof(cubehashParam);
650 /*@=sizeoftype@*/
651  ctx->param = DRD_xcalloc(1, ctx->paramsize);
652  (void) cubehashInit((cubehashParam *)ctx->param, (int)(8 * ctx->digestsize),
653  (int)((ctx->flags >> 8) & 0xff),
654  (int)((ctx->flags ) & 0xff));
655  ctx->Reset = (int (*)(void *)) cubehashReset;
656  ctx->Update = (int (*)(void *, const byte *, size_t)) cubehashUpdate;
657  ctx->Digest = (int (*)(void *, byte *)) cubehashDigest;
658  break;
659  case PGPHASHALGO_ECHO_224: ctx->digestsize = 224/8; goto echo;
660  case PGPHASHALGO_ECHO_256: ctx->digestsize = 256/8; goto echo;
661  case PGPHASHALGO_ECHO_384: ctx->digestsize = 384/8; goto echo;
662  case PGPHASHALGO_ECHO_512: ctx->digestsize = 512/8; goto echo;
663 echo:
664  ctx->name = "ECHO";
665 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
666  ctx->paramsize = sizeof(echo_hashState);
667 /*@=sizeoftype@*/
668  ctx->param = DRD_xcalloc(1, ctx->paramsize);
669  (void) echo_Init((echo_hashState *)ctx->param,
670  (int)(8 * ctx->digestsize));
671  ctx->Reset = (int (*)(void *)) noopReset;
672  ctx->Update = (int (*)(void *, const byte *, size_t)) _echo_Update;
673  ctx->Digest = (int (*)(void *, byte *)) echo_Final;
674  break;
675  case PGPHASHALGO_EDONR_224: ctx->digestsize = 224/8; goto edonr;
676  case PGPHASHALGO_EDONR_256: ctx->digestsize = 256/8; goto edonr;
677  case PGPHASHALGO_EDONR_384: ctx->digestsize = 384/8; goto edonr;
678  case PGPHASHALGO_EDONR_512: ctx->digestsize = 512/8; goto edonr;
679 edonr:
680  ctx->name = "EDON-R";
681 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
682  ctx->paramsize = sizeof(edonr_hashState);
683 /*@=sizeoftype@*/
684  ctx->param = DRD_xcalloc(1, ctx->paramsize);
685  (void) edonr_Init((edonr_hashState *)ctx->param,
686  (int)(8 * ctx->digestsize));
687  ctx->Reset = (int (*)(void *)) noopReset;
688  ctx->Update = (int (*)(void *, const byte *, size_t)) edonr_Update;
689  ctx->Digest = (int (*)(void *, byte *)) edonr_Final;
690  break;
691  case PGPHASHALGO_FUGUE_224: ctx->digestsize = 224/8; goto fugue;
692  case PGPHASHALGO_FUGUE_256: ctx->digestsize = 256/8; goto fugue;
693  case PGPHASHALGO_FUGUE_384: ctx->digestsize = 384/8; goto fugue;
694  case PGPHASHALGO_FUGUE_512: ctx->digestsize = 512/8; goto fugue;
695 fugue:
696  ctx->name = "FUGUE";
697 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
698  ctx->paramsize = sizeof(fugueParam);
699 /*@=sizeoftype@*/
700  ctx->param = DRD_xcalloc(1, ctx->paramsize);
701  (void) fugueInit((fugueParam *)ctx->param, (int)(8 * ctx->digestsize));
702  ctx->Reset = (int (*)(void *)) fugueReset;
703  ctx->Update = (int (*)(void *, const byte *, size_t)) fugueUpdate;
704  ctx->Digest = (int (*)(void *, byte *)) fugueDigest;
705  break;
706  case PGPHASHALGO_GROESTL_224: ctx->digestsize = 224/8; goto groestl;
707  case PGPHASHALGO_GROESTL_256: ctx->digestsize = 256/8; goto groestl;
708  case PGPHASHALGO_GROESTL_384: ctx->digestsize = 384/8; goto groestl;
709  case PGPHASHALGO_GROESTL_512: ctx->digestsize = 512/8; goto groestl;
710 groestl:
711  ctx->name = "GROESTL";
712 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
713  ctx->paramsize = sizeof(groestl_hashState);
714 /*@=sizeoftype@*/
715  ctx->param = DRD_xcalloc(1, ctx->paramsize);
716  (void) groestl_Init((groestl_hashState *)ctx->param,
717  (int)(8 * ctx->digestsize));
718  ctx->Reset = (int (*)(void *)) noopReset;
719  ctx->Update = (int (*)(void *, const byte *, size_t)) _groestl_Update;
720  ctx->Digest = (int (*)(void *, byte *)) groestl_Final;
721  break;
722  case PGPHASHALGO_HAMSI_224: ctx->digestsize = 224/8; goto hamsi;
723  case PGPHASHALGO_HAMSI_256: ctx->digestsize = 256/8; goto hamsi;
724  case PGPHASHALGO_HAMSI_384: ctx->digestsize = 384/8; goto hamsi;
725  case PGPHASHALGO_HAMSI_512: ctx->digestsize = 512/8; goto hamsi;
726 hamsi:
727  ctx->name = "HAMSI";
728 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
729  ctx->paramsize = sizeof(hamsiParam);
730 /*@=sizeoftype@*/
731  ctx->param = DRD_xcalloc(1, ctx->paramsize);
732  (void) hamsiInit((hamsiParam *)ctx->param, (int)(8 * ctx->digestsize));
733  ctx->Reset = (int (*)(void *)) hamsiReset;
734  ctx->Update = (int (*)(void *, const byte *, size_t)) hamsiUpdate;
735  ctx->Digest = (int (*)(void *, byte *)) hamsiDigest;
736  break;
737  case PGPHASHALGO_JH_224: ctx->digestsize = 224/8; goto jh;
738  case PGPHASHALGO_JH_256: ctx->digestsize = 256/8; goto jh;
739  case PGPHASHALGO_JH_384: ctx->digestsize = 384/8; goto jh;
740  case PGPHASHALGO_JH_512: ctx->digestsize = 512/8; goto jh;
741 jh:
742  ctx->name = "JH";
743 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
744  ctx->paramsize = sizeof(jhParam);
745 /*@=sizeoftype@*/
746  ctx->param = DRD_xcalloc(1, ctx->paramsize);
747  (void) jhInit((jhParam *)ctx->param, (int)(8 * ctx->digestsize));
748  ctx->Reset = (int (*)(void *)) jhReset;
749  ctx->Update = (int (*)(void *, const byte *, size_t)) jhUpdate;
750  ctx->Digest = (int (*)(void *, byte *)) jhDigest;
751  break;
752  case PGPHASHALGO_KECCAK_224: ctx->digestsize = 224/8; goto keccak;
753  case PGPHASHALGO_KECCAK_256: ctx->digestsize = 256/8; goto keccak;
754  case PGPHASHALGO_KECCAK_384: ctx->digestsize = 384/8; goto keccak;
755  case PGPHASHALGO_KECCAK_512: ctx->digestsize = 512/8; goto keccak;
756 keccak:
757  ctx->name = "KECCAK";
758 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
759  ctx->paramsize = sizeof(keccak_hashState);
760 /*@=sizeoftype@*/
761  ctx->param = DRD_xcalloc(1, ctx->paramsize);
762  (void) keccak_Init((keccak_hashState *)ctx->param,
763  (int)(8 * ctx->digestsize));
764  ctx->Reset = (int (*)(void *)) noopReset;
765  ctx->Update = (int (*)(void *, const byte *, size_t)) _keccak_Update;
766  ctx->Digest = (int (*)(void *, byte *)) keccak_Final;
767  break;
768  case PGPHASHALGO_LANE_224: ctx->digestsize = 224/8; goto lane;
769  case PGPHASHALGO_LANE_256: ctx->digestsize = 256/8; goto lane;
770  case PGPHASHALGO_LANE_384: ctx->digestsize = 384/8; goto lane;
771  case PGPHASHALGO_LANE_512: ctx->digestsize = 512/8; goto lane;
772 lane:
773  ctx->name = "LANE";
774 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
775  ctx->paramsize = sizeof(laneParam);
776 /*@=sizeoftype@*/
777  ctx->param = DRD_xcalloc(1, ctx->paramsize);
778  (void) laneInit((laneParam *)ctx->param, (int)(8 * ctx->digestsize));
779  ctx->Reset = (int (*)(void *)) laneReset;
780  ctx->Update = (int (*)(void *, const byte *, size_t)) laneUpdate;
781  ctx->Digest = (int (*)(void *, byte *)) laneDigest;
782  break;
783  case PGPHASHALGO_LUFFA_224: ctx->digestsize = 224/8; goto luffa;
784  case PGPHASHALGO_LUFFA_256: ctx->digestsize = 256/8; goto luffa;
785  case PGPHASHALGO_LUFFA_384: ctx->digestsize = 384/8; goto luffa;
786  case PGPHASHALGO_LUFFA_512: ctx->digestsize = 512/8; goto luffa;
787 luffa:
788  ctx->name = "LUFFA";
789 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
790  ctx->paramsize = sizeof(luffaParam);
791 /*@=sizeoftype@*/
792  ctx->param = DRD_xcalloc(1, ctx->paramsize);
793  (void) luffaInit((luffaParam *)ctx->param, (int)(8 * ctx->digestsize));
794  ctx->Reset = (int (*)(void *)) luffaReset;
795  ctx->Update = (int (*)(void *, const byte *, size_t)) luffaUpdate;
796  ctx->Digest = (int (*)(void *, byte *)) luffaDigest;
797  break;
798  case PGPHASHALGO_MD6_224: ctx->digestsize = 224/8; goto md6;
799  case PGPHASHALGO_MD6_256: ctx->digestsize = 256/8; goto md6;
800  case PGPHASHALGO_MD6_384: ctx->digestsize = 384/8; goto md6;
801  case PGPHASHALGO_MD6_512: ctx->digestsize = 512/8; goto md6;
802 md6:
803  ctx->name = "MD6";
804 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
805  ctx->paramsize = sizeof(md6_state);
806 /*@=sizeoftype@*/
807  ctx->param = DRD_xcalloc(1, ctx->paramsize);
808  { int d = (8 * ctx->digestsize); /* no. of bits in digest */
809  int L = md6_default_L; /* no. of parallel passes */
810  unsigned char *K = NULL; /* key */
811  int keylen = 0; /* key length (bytes) */
812  int r = md6_default_r(d, keylen); /* no. of rounds */
813 
814  if (ctx->flags != 0) {
815  r = ((ctx->flags >> 8) & 0xffff);
816  L = ((ctx->flags ) & 0xff);
817  if (r <= 0 || r > 255) r = md6_default_r(d, keylen);
818  }
819  (void) md6_full_init((md6_state *)ctx->param,
820  d, K, keylen, L, r);
821  }
822  ctx->Reset = (int (*)(void *)) noopReset;
823  ctx->Update = (int (*)(void *, const byte *, size_t)) md6_Update;
824  ctx->Digest = (int (*)(void *, byte *)) md6_final;
825  break;
826 #ifdef NOTYET
827  case PGPHASHALGO_SHABAL_192: ctx->digestsize = 192/8; goto shabal;
828 #endif
829  case PGPHASHALGO_SHABAL_224: ctx->digestsize = 224/8; goto shabal;
830  case PGPHASHALGO_SHABAL_256: ctx->digestsize = 256/8; goto shabal;
831  case PGPHASHALGO_SHABAL_384: ctx->digestsize = 384/8; goto shabal;
832  case PGPHASHALGO_SHABAL_512: ctx->digestsize = 512/8; goto shabal;
833 shabal:
834  ctx->name = "SHABAL";
835 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
836  ctx->paramsize = sizeof(shabalParam);
837 /*@=sizeoftype@*/
838  ctx->param = DRD_xcalloc(1, ctx->paramsize);
839  (void) shabalInit((shabalParam *)ctx->param, (int)(8 * ctx->digestsize));
840  ctx->Reset = (int (*)(void *)) shabalReset;
841  ctx->Update = (int (*)(void *, const byte *, size_t)) shabalUpdate;
842  ctx->Digest = (int (*)(void *, byte *)) shabalDigest;
843  break;
844  case PGPHASHALGO_SHAVITE3_224: ctx->digestsize = 224/8; goto shavite3;
845  case PGPHASHALGO_SHAVITE3_256: ctx->digestsize = 256/8; goto shavite3;
846  case PGPHASHALGO_SHAVITE3_384: ctx->digestsize = 384/8; goto shavite3;
847  case PGPHASHALGO_SHAVITE3_512: ctx->digestsize = 512/8; goto shavite3;
848 shavite3:
849  ctx->name = "SHAVITE3";
850 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
851  ctx->paramsize = sizeof(shavite3_hashState);
852 /*@=sizeoftype@*/
853  ctx->param = DRD_xcalloc(1, ctx->paramsize);
854  (void) shavite3_Init((shavite3_hashState *)ctx->param,
855  (int)(8 * ctx->digestsize));
856  ctx->Reset = (int (*)(void *)) noopReset;
857  ctx->Update = (int (*)(void *, const byte *, size_t)) _shavite3_Update;
858  ctx->Digest = (int (*)(void *, byte *)) shavite3_Final;
859  break;
860  case PGPHASHALGO_SIMD_224: ctx->digestsize = 224/8; goto simd;
861  case PGPHASHALGO_SIMD_256: ctx->digestsize = 256/8; goto simd;
862  case PGPHASHALGO_SIMD_384: ctx->digestsize = 384/8; goto simd;
863  case PGPHASHALGO_SIMD_512: ctx->digestsize = 512/8; goto simd;
864 simd:
865  ctx->name = "SIMD";
866 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
867  ctx->paramsize = sizeof(simd_hashState);
868 /*@=sizeoftype@*/
869  ctx->param = DRD_xcalloc(1, ctx->paramsize);
870  (void) simd_Init((simd_hashState *)ctx->param,
871  (int)(8 * ctx->digestsize));
872  ctx->Reset = (int (*)(void *)) noopReset;
873  ctx->Update = (int (*)(void *, const byte *, size_t)) _simd_Update;
874  ctx->Digest = (int (*)(void *, byte *)) simd_Final;
875  break;
876  case PGPHASHALGO_TIB3_224: ctx->digestsize = 224/8; goto tib3;
877  case PGPHASHALGO_TIB3_256: ctx->digestsize = 256/8; goto tib3;
878  case PGPHASHALGO_TIB3_384: ctx->digestsize = 384/8; goto tib3;
879  case PGPHASHALGO_TIB3_512: ctx->digestsize = 512/8; goto tib3;
880 tib3:
881  ctx->name = "TIB3";
882 /*@-sizeoftype@*/ /* FIX: union, not void pointer */
883  ctx->paramsize = sizeof(tib3_hashState);
884 /*@=sizeoftype@*/
885  ctx->param = DRD_xcalloc(1, ctx->paramsize);
886  (void) tib3_Init((tib3_hashState *)ctx->param,
887  (int)(8 * ctx->digestsize));
888  ctx->Reset = (int (*)(void *)) noopReset;
889  ctx->Update = (int (*)(void *, const byte *, size_t)) _tib3_Update;
890  ctx->Digest = (int (*)(void *, byte *)) tib3_Final;
891  break;
893  default:
894  (void)rpmioFreePoolItem((rpmioItem)ctx, __FUNCTION__, __FILE__, __LINE__);
895  return NULL;
896  /*@notreached@*/ break;
897  }
898 
899  xx = (*ctx->Reset) (ctx->param);
900 
901 DPRINTF((stderr, "==> ctx %p ==== Init(%s, %x) param %p\n", ctx, ctx->name, flags, ctx->param));
902  return (DIGEST_CTX)rpmioLinkPoolItem((rpmioItem)ctx, __FUNCTION__, __FILE__, __LINE__);
903 }
904 
905 /*@-mustmod@*/ /* LCL: ctx->param may be modified, but ctx is abstract @*/
906 int
907 rpmDigestUpdate(DIGEST_CTX ctx, const void * data, size_t len)
908 {
909  if (ctx == NULL)
910  return -1;
911 
912 DPRINTF((stderr, "==> ctx %p ==== Update(%s,%p[%u]) param %p\n", ctx, ctx->name, data, (unsigned)len, ctx->param));
913  return (*ctx->Update) (ctx->param, (byte *)data, len);
914 }
915 /*@=mustmod@*/
916 
917 #define HMAC_IPAD 0x36
918 #define HMAC_OPAD 0x5c
919 
920 int
921 rpmDigestFinal(DIGEST_CTX ctx, void * datap, size_t *lenp, int asAscii)
922 {
923  byte * digest;
924  char * t;
925 
926  if (ctx == NULL)
927  return -1;
928  digest = (byte *) DRD_xmalloc(ctx->digestsize);
929 
930 DPRINTF((stderr, "==> ctx %p ==== Final(%s,%p,%p,%d) param %p digest %p[%u]\n", ctx, ctx->name, datap, lenp, asAscii, ctx->param, digest, (unsigned)ctx->digestsize));
931 /*@-noeffectuncon@*/ /* FIX: check rc */
932  (void) (*ctx->Digest) (ctx->param, digest);
933 /*@=noeffectuncon@*/
934 
935  /* If keyed HMAC, re-hash with key material. */
936  if (ctx->salt != NULL) {
938  byte * salt = (byte *) ctx->salt;
939  byte * kdigest = NULL;
940  size_t kdigestlen = 0;
941  unsigned i;
942  for (i = 0; i < ctx->blocksize; i++)
943  salt[i] ^= HMAC_OPAD;
944  rpmDigestUpdate(kctx, ctx->salt, ctx->blocksize);
945  ctx->salt = _free(ctx->salt);
946  rpmDigestUpdate(kctx, digest, ctx->digestsize);
947  (void) rpmDigestFinal(kctx, &kdigest, &kdigestlen, 0);
948  memcpy(digest, kdigest, kdigestlen);
949  kdigest = _free(kdigest);
950  }
951 
952  /* Return final digest. */
953  if (!asAscii) {
954  if (lenp) *lenp = ctx->digestsize;
955  if (datap) {
956  *(byte **)datap = digest;
957  digest = NULL;
958  }
959  } else {
960  if (lenp) *lenp = (2*ctx->digestsize);
961  if (datap) {
962  const byte * s = (const byte *) digest;
963  static const char hex[] = "0123456789abcdef";
964  size_t i;
965 
966  *(char **)datap = t = (char *) DRD_xmalloc((2*ctx->digestsize) + 1);
967  for (i = 0 ; i < ctx->digestsize; i++) {
968  *t++ = hex[ (unsigned)((*s >> 4) & 0x0f) ];
969  *t++ = hex[ (unsigned)((*s++ ) & 0x0f) ];
970  }
971  *t = '\0';
972  }
973  }
974  if (digest) {
975  memset(digest, 0, ctx->digestsize); /* In case it's sensitive */
976  free(digest);
977  }
978  (void)rpmioFreePoolItem((rpmioItem)ctx, __FUNCTION__, __FILE__, __LINE__);
979  return 0;
980 }
981 
982 int
983 rpmHmacInit(DIGEST_CTX ctx, const void * key, size_t keylen)
984 {
985  int rc = 0;
986 
987  if (ctx == NULL)
988  return -1;
989  if (key != NULL) {
990  byte * salt = (byte *) DRD_xcalloc(1, ctx->blocksize);
991  unsigned i;
992  if (keylen == 0) keylen = strlen((char *)key);
993  ctx->salt = salt;
994 DPRINTF((stderr, "==> ctx %p ==== HMAC(%s,%p[%u])\n", ctx, ctx->name, key, (unsigned)keylen));
995  if (keylen > ctx->blocksize) {
996  /* If key is larger than digestlen, then hash the material. */
998  byte * kdigest = NULL;
999  size_t kdigestlen = 0;
1000  rpmDigestUpdate(kctx, key, keylen);
1001  (void) rpmDigestFinal(kctx, &kdigest, &kdigestlen, 0);
1002  memcpy(ctx->salt, kdigest, kdigestlen);
1003  kdigest = _free(kdigest);
1004  } else
1005  memcpy(ctx->salt, key, keylen);
1006 
1007  salt = (byte *)ctx->salt;
1008  for (i = 0; i < ctx->blocksize; i++)
1009  salt[i] ^= HMAC_IPAD;
1010  rpmDigestUpdate(ctx, ctx->salt, ctx->blocksize);
1011  for (i = 0; i < ctx->blocksize; i++)
1012  salt[i] ^= HMAC_IPAD;
1013  }
1014  return rc;
1015 }
#define HMAC_OPAD
Definition: digest.c:918
#define ANNOTATE_BENIGN_RACE(_a, _b)
Definition: debug.h:159
static DIGEST_CTX ctxGetPool(rpmioPool pool)
Definition: digest.c:173
int sum64Digest(sum64Param *mp, rpmuint8_t *data)
Definition: crc.c:447
const char * name
Definition: digest.c:130
size_t paramsize
Definition: digest.c:131
int sum32Reset(register sum32Param *mp)
Definition: crc.c:405
DIGEST_CTX rpmDigestInit(pgpHashAlgo hashalgo, rpmDigestFlags flags)
Initialize digest.
Definition: digest.c:244
rpmioItem rpmioLinkPoolItem(rpmioItem item, const char *msg, const char *fn, unsigned ln)
Increment a pool item refcount.
Definition: rpmmalloc.c:166
enum pgpHashAlgo_e pgpHashAlgo
9.4.
#define DRD_xcalloc(_nmemb, _size)
Definition: debug.h:174
size_t digestsize
Definition: digest.c:133
rpmuint64_t(* update)(rpmuint64_t crc, const rpmuint8_t *data, size_t size)
Definition: crc.h:23
void * rpmioFreePoolItem(rpmioItem item, const char *msg, const char *fn, unsigned ln)
Free a pool item.
Definition: rpmmalloc.c:187
#define DRD_xmalloc(_nb)
Definition: debug.h:173
int(* Update)(void *param, const byte *data, size_t size)
Definition: digest.c:136
void * pool
Definition: rpmiotypes.h:43
enum rpmDigestFlags_e rpmDigestFlags
Bit(s) to control digest operation.
CRC32, CRC64 and ADLER32 checksums.
rpmuint32_t(* update)(rpmuint32_t crc, const rpmuint8_t *data, size_t size)
Definition: crc.h:15
static int md6_Update(void *param, const byte *_data, size_t _len)
Definition: digest.c:238
rpmuint64_t(* combine)(rpmuint64_t crc1, rpmuint64_t crc2, size_t len2)
Definition: crc.h:24
int(* Digest)(void *param, byte *digest)
Definition: digest.c:138
int rpmHmacInit(DIGEST_CTX ctx, const void *key, size_t keylen)
Compute key material and add to digest context.
Definition: digest.c:983
rpmuint32_t __adler32(rpmuint32_t adler, const rpmuint8_t *buf, rpmuint32_t len)
Definition: crc.c:317
rpmuint32_t __adler32_combine(rpmuint32_t adler1, rpmuint32_t adler2, size_t len2)
Definition: crc.c:384
unsigned int rpmuint32_t
Definition: rpmiotypes.h:25
int sum64Update(sum64Param *mp, const rpmuint8_t *data, size_t size)
Definition: crc.c:440
int rpmDigestUpdate(DIGEST_CTX ctx, const void *data, size_t len)
Update context with next plain text buffer.
Definition: digest.c:907
rpmioItem rpmioGetPool(rpmioPool pool, size_t size)
Get unused item from pool, or alloc a new item.
Definition: rpmmalloc.c:221
Definition: crc.h:21
int(* Reset)(void *param)
Definition: digest.c:134
unsigned long long rpmuint64_t
Definition: rpmiotypes.h:26
pgpHashAlgo rpmDigestAlgo(DIGEST_CTX ctx)
Return digest algorithm identifier.
Definition: digest.c:188
void * salt
Definition: digest.c:145
Digest private data.
Definition: digest.c:127
pgpHashAlgo hashalgo
Definition: digest.c:140
Definition: crc.h:13
rpmuint64_t __crc64_combine(rpmuint64_t crc1, rpmuint64_t crc2, size_t len2)
Definition: crc.c:213
int sum32Digest(sum32Param *mp, rpmuint8_t *data)
Definition: crc.c:419
rpmioPool _ctxPool
Definition: digest.c:171
rpmuint32_t __crc32_combine(rpmuint32_t crc1, rpmuint32_t crc2, size_t len2)
Definition: crc.c:82
void * param
Definition: digest.c:144
#define L(CS)
Definition: fnmatch.c:155
rpmioPool rpmioNewPool(const char *name, size_t size, int limit, int flags, char *(*dbg)(void *item), void(*init)(void *item), void(*fini)(void *item))
Create a memory pool.
Definition: rpmmalloc.c:110
#define DPRINTF(_a)
Definition: digest.c:115
rpmDigestFlags rpmDigestF(DIGEST_CTX ctx)
Return digest flags.
Definition: digest.c:193
struct rpmioItem_s _item
Definition: digest.c:128
int sum32Update(sum32Param *mp, const rpmuint8_t *data, size_t size)
Definition: crc.c:412
rpmuint32_t(* combine)(rpmuint32_t crc1, rpmuint32_t crc2, size_t len2)
Definition: crc.h:16
struct DIGEST_CTX_s * DIGEST_CTX
Definition: rpmiotypes.h:75
static void * _free(const void *p)
Wrapper to free(3), hides const compilation noise, permit NULL, return NULL.
Definition: rpmiotypes.h:647
const char * rpmDigestName(DIGEST_CTX ctx)
Return digest name.
Definition: digest.c:198
static int noopReset(void *param)
Definition: digest.c:232
int _ctx_debug
Definition: digest.c:110
static void ctxFini(void *_ctx)
Definition: digest.c:148
int sum64Reset(register sum64Param *mp)
Definition: crc.c:433
#define HMAC_IPAD
Definition: digest.c:917
const char * rpmDigestASN1(DIGEST_CTX ctx)
Return digest ASN1 oid string.
Definition: digest.c:203
int rpmDigestFinal(DIGEST_CTX ctx, void *datap, size_t *lenp, int asAscii)
Return digest and destroy context.
Definition: digest.c:921
rpmuint64_t __crc64(rpmuint64_t crc, const rpmuint8_t *data, size_t size)
Definition: crc.c:140
size_t blocksize
Definition: digest.c:132
rpmDigestFlags flags
Definition: digest.c:141
DIGEST_CTX rpmDigestDup(DIGEST_CTX octx)
Duplicate a digest context.
Definition: digest.c:209
rpmuint32_t __crc32(rpmuint32_t crc, const rpmuint8_t *data, size_t size)
Definition: crc.c:10
const char * asn1
Definition: digest.c:143