1 #ifndef _RPMDIGEST_H
2 #define _RPMDIGEST_H
3 
4 #include <rpm/rpmpgp.h>
5 
6 typedef struct pgpDigAlg_s * pgpDigAlg;
7 
8 typedef int (*setmpifunc)(pgpDigAlg digp, int num, const uint8_t *p);
9 typedef int (*verifyfunc)(pgpDigAlg pgpkey, pgpDigAlg pgpsig,
10                           uint8_t *hash, size_t hashlen, int hash_algo);
11 typedef void (*freefunc)(pgpDigAlg digp);
12 
13 struct pgpDigAlg_s {
14     setmpifunc setmpi;
15     verifyfunc verify;
16     freefunc free;
17     int curve;
18     int mpis;
19     void *data;			/*!< algorithm specific private data */
20 };
21 
22 /** \ingroup rpmio
23  * Values parsed from OpenPGP signature/pubkey packet(s).
24  */
25 struct pgpDigParams_s {
26     char * userid;
27     uint8_t * hash;
28     uint8_t tag;
29 
30     uint8_t version;		/*!< version number. */
31     uint32_t time;		/*!< key/signature creation time. */
32     uint8_t pubkey_algo;		/*!< public key algorithm. */
33 
34     uint8_t hash_algo;
35     uint8_t sigtype;
36     uint8_t hashlen;
37     uint8_t signhash16[2];
38     pgpKeyID_t signid;
39     uint8_t saved;
40 #define	PGPDIG_SAVED_TIME	(1 << 0)
41 #define	PGPDIG_SAVED_ID		(1 << 1)
42 
43     pgpDigAlg alg;
44 };
45 
46 pgpDigAlg pgpPubkeyNew(int algo, int curve);
47 
48 pgpDigAlg pgpSignatureNew(int algo);
49 
50 pgpDigAlg pgpDigAlgFree(pgpDigAlg da);
51 
52 /** \ingroup rpmpgp
53  * Return no. of bits in a multiprecision integer.
54  * @param p		pointer to multiprecision integer
55  * @return		no. of bits
56  */
57 static inline
pgpMpiBits(const uint8_t * p)58 unsigned int pgpMpiBits(const uint8_t *p)
59 {
60     return ((p[0] << 8) | p[1]);
61 }
62 
63 /** \ingroup rpmpgp
64  * Return no. of bytes in a multiprecision integer.
65  * @param p		pointer to multiprecision integer
66  * @return		no. of bytes
67  */
68 static inline
pgpMpiLen(const uint8_t * p)69 size_t pgpMpiLen(const uint8_t *p)
70 {
71     return (2 + ((pgpMpiBits(p)+7)>>3));
72 }
73 
74 #endif /* _RPMDIGEST_H */
75