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