rpm  5.4.10
rpmpgp.h
Go to the documentation of this file.
1 #ifndef H_RPMPGP
2 #define H_RPMPGP
3 
13 #include <string.h>
14 #include <popt.h>
15 #include <rpmiotypes.h>
16 #include <yarn.h>
17 
18 #if defined(_RPMPGP_INTERNAL)
19 #include <rpmsw.h>
20 
21 /*@unchecked@*/
22 extern int _pgp_error_count;
23 
27 struct pgpDigParams_s {
28 /*@only@*/ /*@null@*/
29  const char * userid;
30 /*@dependent@*/ /*@null@*/
31  const rpmuint8_t * hash;
32  rpmuint8_t tag;
33 
34  rpmuint8_t version;
35  rpmuint8_t time[4];
36  rpmuint8_t pubkey_algo;
38  rpmuint8_t hash_algo;
39  rpmuint8_t sigtype;
40  size_t hashlen;
41  rpmuint8_t signhash16[2];
42  rpmuint8_t signid[8];
43  rpmuint8_t expire[4];
44  rpmuint8_t keyexpire[4];
46  rpmuint8_t saved;
47 #define PGPDIG_SAVED_TIME (1 << 0)
48 #define PGPDIG_SAVED_ID (1 << 1)
49 
50 };
51 
55 struct pgpDig_s {
56  struct rpmioItem_s _item;
57  struct pgpDigParams_s signature;
58  struct pgpDigParams_s pubkey;
59 
60 /*@observer@*/ /*@null@*/
61  const char * pubkey_algoN;
62 /*@observer@*/ /*@null@*/
63  const char * hash_algoN;
64 
65  rpmuint32_t sigtag;
66  rpmuint32_t sigtype;
67 /*@relnull@*/
68  const void * sig;
69  size_t siglen;
70  const void * pub;
71  size_t publen;
74  struct rpmop_s dops;
75  struct rpmop_s sops;
77  int (*findPubkey) (void * _ts, /*@null@*/ void * _dig)
78  /*@modifies *_ts, *_dig @*/;
79 /*@null@*/
80  void * _ts;
82  rpmuint8_t ** ppkts;
83  int npkts;
84  size_t nbytes;
86 /*@only@*/ /*@null@*/
87  DIGEST_CTX sha1ctx;
88 /*@only@*/ /*@null@*/
89  DIGEST_CTX hdrsha1ctx;
90 /*@only@*/ /*@null@*/
91  void * sha1;
92  size_t sha1len;
94 /*@only@*/ /*@null@*/
95  DIGEST_CTX md5ctx;
96 /*@only@*/ /*@null@*/
97  DIGEST_CTX hdrctx;
98 /*@only@*/ /*@null@*/
99  void * md5;
100  size_t md5len;
102 /*@owned@*/ /*@relnull@*/
103  void * impl;
105 #if defined(__LCLINT__)
106 /*@refs@*/
107  int nrefs;
108 #endif
109 };
110 #endif /* _RPMPGP_INTERNAL */
111 
114 typedef const struct pgpValTbl_s {
115  int val;
116 /*@observer@*/
117  const char * str;
118 } * pgpValTbl;
119 
127 typedef enum pgpTag_e {
146  PGPTAG_MDC = 19,
151 } pgpTag;
152 
155 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
156 extern struct pgpValTbl_s pgpTagTbl[];
157 
192 typedef struct pgpPktPubkey_s {
194  rpmuint8_t keyid[8];
196 } pgpPktPubkey;
197 
204 /*@-typeuse@*/
205 typedef enum pgpSigType_e {
225 } pgpSigType;
226 /*@=typeuse@*/
227 
230 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
231 extern struct pgpValTbl_s pgpSigTypeTbl[];
232 
256 /*@-typeuse@*/
257 typedef enum pgpPubkeyAlgo_e {
269 } pgpPubkeyAlgo;
270 /*@=typeuse@*/
271 
274 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
275 extern struct pgpValTbl_s pgpPubkeyTbl[];
276 
302 /*@-typeuse@*/
303 typedef enum pgpSymkeyAlgo_e {
319 } pgpSymkeyAlgo;
320 /*@=typeuse@*/
321 
325 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
326 extern struct pgpValTbl_s pgpSymkeyTbl[];
327 
343 /*@-typeuse@*/
344 typedef enum pgpCompressAlgo_e {
350 /*@=typeuse@*/
351 
355 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
356 extern struct pgpValTbl_s pgpCompressionTbl[];
357 
361 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
362 extern struct pgpValTbl_s pgpHashTbl[];
363 
385 typedef struct pgpPktSigV3_s {
389  rpmuint8_t time[4];
390  rpmuint8_t signid[8];
393  rpmuint8_t signhash16[2];
394 } * pgpPktSigV3;
395 
417 typedef struct pgpPktSigV4_s {
422  rpmuint8_t hashlen[2];
423 } * pgpPktSigV4;
424 
503 /*@-typeuse@*/
504 typedef enum pgpSubType_e {
544 } pgpSubType;
545 /*@=typeuse@*/
546 
550 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
551 extern struct pgpValTbl_s pgpSubTypeTbl[];
552 
573 typedef union pgpPktSig_u {
574  struct pgpPktSigV3_s v3;
575  struct pgpPktSigV4_s v4;
576 } * pgpPktSig;
577 
606 typedef struct pgpPktSymkey_s {
609  rpmuint8_t s2k[1];
610 } pgpPktSymkey;
611 
641 typedef struct pgpPktOnepass_s {
646  rpmuint8_t signid[8];
648 } * pgpPktOnepass;
649 
722 typedef struct pgpPktKeyV3_s {
724  rpmuint8_t time[4];
725  rpmuint8_t valid[2];
727 } * pgpPktKeyV3;
728 
760 typedef struct pgpPktKeyV4_s {
762  rpmuint8_t time[4];
764 } * pgpPktKeyV4;
765 
830 typedef union pgpPktKey_u {
831  struct pgpPktKeyV3_s v3;
832  struct pgpPktKeyV4_s v4;
833 } pgpPktKey;
834 
859 typedef struct pgpPktCdata_s {
861  rpmuint8_t data[1];
862 } pgpPktCdata;
863 
898 typedef struct pgpPktEdata_s {
899  rpmuint8_t data[1];
900 } pgpPktEdata;
901 
918 /*
919  * 5.9. Literal Data Packet (Tag 11)
920  *
921  * A Literal Data packet contains the body of a message; data that is
922  * not to be further interpreted.
923  *
924  * The body of this packet consists of:
925  * - A one-octet field that describes how the data is formatted.
926  *
927  * If it is a 'b' (0x62), then the literal packet contains binary data.
928  * If it is a 't' (0x74), then it contains text data, and thus may need
929  * line ends converted to local form, or other text-mode changes. RFC
930  * 1991 also defined a value of 'l' as a 'local' mode for machine-local
931  * conversions. This use is now deprecated.
932  * - File name as a string (one-octet length, followed by file name),
933  * if the encrypted data should be saved as a file.
934  *
935  * If the special name "_CONSOLE" is used, the message is considered to
936  * be "for your eyes only". This advises that the message data is
937  * unusually sensitive, and the receiving program should process it more
938  * carefully, perhaps avoiding storing the received data to disk, for
939  * example.
940  * - A four-octet number that indicates the modification date of the
941  * file, or the creation time of the packet, or a zero that
942  * indicates the present time.
943  * - The remainder of the packet is literal data.
944  *
945  * Text data is stored with <CR><LF> text endings (i.e. network-normal
946  * line endings). These should be converted to native line endings by
947  * the receiving software.
948  */
949 typedef struct pgpPktLdata_s {
952  rpmuint8_t filename[1];
953 } pgpPktLdata;
954 
968 typedef struct pgpPktTrust_s {
970 } pgpPktTrust;
971 
982 typedef struct pgpPktUid_s {
983  rpmuint8_t userid[1];
984 } pgpPktUid;
985 
988 /*@-typeuse@*/
989 typedef enum pgpArmor_e {
997 #define PGPARMOR_ERROR PGPARMOR_ERR_NO_BEGIN_PGP
1006 } pgpArmor;
1007 /*@=typeuse@*/
1008 
1012 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
1013 extern struct pgpValTbl_s pgpArmorTbl[];
1014 
1017 /*@-typeuse@*/
1018 typedef enum pgpArmorKey_e {
1024 } pgpArmorKey;
1025 /*@=typeuse@*/
1026 
1030 /*@observer@*/ /*@unchecked@*/ /*@unused@*/
1031 extern struct pgpValTbl_s pgpArmorKeyTbl[];
1032 
1033 #if defined(_RPMPGP_INTERNAL)
1034 
1036 union pgpPktPre_u {
1037  pgpPktPubkey pubkey;
1038  pgpPktSig sig;
1039  pgpPktSymkey symkey;
1040  pgpPktOnepass onepass;
1041  pgpPktKey key;
1042  pgpPktCdata cdata;
1043  pgpPktEdata edata;
1045  pgpPktLdata ldata;
1046  pgpPktTrust tdata;
1047  pgpPktUid uid;
1048 };
1049 
1050 struct pgpPkt_s {
1051  pgpTag tag;
1052  unsigned int pktlen;
1053  union {
1054  const rpmuint8_t * h;
1055  const pgpPktKeyV3 j;
1056  const pgpPktKeyV4 k;
1057  const pgpPktSigV3 r;
1058  const pgpPktSigV4 s;
1059  const pgpPktUid * u;
1060  } u;
1061  unsigned int hlen;
1062 };
1063 #endif /* _RPMPGP_INTERNAL */
1064 
1065 /*@-fcnuse@*/
1066 #ifdef __cplusplus
1067 extern "C" {
1068 #endif
1069 
1076 /*@unused@*/ static inline
1077 unsigned int pgpGrab(const rpmuint8_t * s, size_t nbytes)
1078  /*@*/
1079 {
1080  unsigned int i = 0;
1081  size_t nb = (nbytes <= sizeof(i) ? nbytes : sizeof(i));
1082  while (nb--)
1083  i = (i << 8) | *s++;
1084  return i;
1085 }
1086 
1093 /*@unused@*/ static inline
1094 unsigned int pgpLen(const rpmuint8_t * s, /*@out@*/ unsigned int * lenp)
1095  /*@modifies *lenp @*/
1096 {
1097  if (*s < (rpmuint8_t)192) {
1098  *lenp = (unsigned int) *s++;
1099  return 1;
1100  } else if (*s < (rpmuint8_t)255) {
1101  *lenp = (unsigned int) ((((unsigned)s[0]) - 192) << 8) + (unsigned)s[1] + 192;
1102  return 2;
1103  } else {
1104  *lenp = pgpGrab(s+1, 4);
1105  return 5;
1106  }
1107 }
1108 
1114 /*@unused@*/ static inline
1115 unsigned int pgpMpiBits(const rpmuint8_t * p)
1116  /*@requires maxRead(p) >= 1 @*/
1117  /*@*/
1118 {
1119  return (unsigned int) ((p[0] << 8) | p[1]);
1120 }
1121 
1127 /*@unused@*/ static inline
1128 unsigned int pgpMpiLen(const rpmuint8_t * p)
1129  /*@requires maxRead(p) >= 1 @*/
1130  /*@*/
1131 {
1132  return (2 + ((pgpMpiBits(p)+7)>>3));
1133 }
1134 
1142 /*@unused@*/ static inline
1143 char * pgpHexCvt(/*@returned@*/ char * t, const rpmuint8_t * s, size_t nbytes)
1144  /*@modifies *t @*/
1145 {
1146  static char hex[] = "0123456789abcdef";
1147  while (nbytes-- > 0) {
1148  unsigned int i;
1149  i = (unsigned int) *s++;
1150  *t++ = hex[ (i >> 4) & 0xf ];
1151  *t++ = hex[ (i ) & 0xf ];
1152  }
1153  *t = '\0';
1154  return t;
1155 }
1156 
1164 /*@unused@*/ static inline /*@observer@*/
1165 char * pgpHexStr(const rpmuint8_t * p, size_t plen)
1166  /*@*/
1167 {
1168  static char prbuf[8*BUFSIZ]; /* XXX ick */
1169  char *t = prbuf;
1170  t = pgpHexCvt(t, p, plen);
1171  return prbuf;
1172 }
1173 
1180 /*@unused@*/ static inline /*@observer@*/
1181 const char * pgpMpiStr(const rpmuint8_t * p)
1182  /*@requires maxRead(p) >= 3 @*/
1183  /*@*/
1184 {
1185  static char prbuf[8*BUFSIZ]; /* XXX ick */
1186  char *t = prbuf;
1187  sprintf(t, "[%4u]: ", pgpGrab(p, 2));
1188  t += strlen(t);
1189  t = pgpHexCvt(t, p+2, pgpMpiLen(p)-2);
1190  return prbuf;
1191 }
1192 
1199 /*@unused@*/ static inline /*@observer@*/
1200 const char * pgpValStr(pgpValTbl vs, rpmuint8_t val)
1201  /*@*/
1202 {
1203  do {
1204  if (vs->val == (int)val)
1205  break;
1206  } while ((++vs)->val != -1);
1207  return vs->str;
1208 }
1209 
1217 /*@unused@*/ static inline
1218 int pgpValTok(pgpValTbl vs, const char * s, const char * se)
1219  /*@*/
1220 {
1221  do {
1222  size_t vlen = strlen(vs->str);
1223  if (vlen <= (size_t)(se-s) && !strncmp(s, vs->str, vlen))
1224  break;
1225  } while ((++vs)->val != -1);
1226  return vs->val;
1227 }
1228 
1235 /*@-exportlocal@*/
1236 void pgpPrtVal(const char * pre, pgpValTbl vs, rpmuint8_t val)
1237  /*@globals fileSystem @*/
1238  /*@modifies fileSystem @*/;
1239 /*@=exportlocal@*/
1240 
1248 #if defined(_RPMPGP_INTERNAL)
1249 /*@-exportlocal@*/
1250 int pgpPrtSubType(const rpmuint8_t * h, size_t hlen, pgpSigType sigtype)
1251  /*@globals fileSystem @*/
1252  /*@modifies fileSystem @*/;
1253 /*@=exportlocal@*/
1254 #endif
1255 
1261 #if defined(_RPMPGP_INTERNAL)
1262 /*@-exportlocal@*/
1263 int pgpPrtSig(const pgpPkt pp)
1264  /*@globals fileSystem, internalState @*/
1265  /*@modifies fileSystem, internalState @*/;
1266 
1267 int pgpPrtSigParams(pgpDig dig, const pgpPkt pp, pgpPubkeyAlgo pubkey_algo,
1268  pgpSigType sigtype, const rpmuint8_t * p)
1269  /*@globals fileSystem @*/
1270  /*@modifies fileSystem @*/;
1271 
1272 const rpmuint8_t * pgpPrtPubkeyParams(pgpDig dig, const pgpPkt pp,
1273  pgpPubkeyAlgo pubkey_algo, /*@returned@*/ const rpmuint8_t * p)
1274  /*@globals fileSystem, internalState @*/
1275  /*@modifies fileSystem, internalState @*/;
1276 
1277 /*@=exportlocal@*/
1278 #endif
1279 
1285 #if defined(_RPMPGP_INTERNAL)
1286 int pgpPrtKey(const pgpPkt pp)
1287  /*@globals fileSystem, internalState @*/
1288  /*@modifies fileSystem, internalState @*/;
1289 #endif
1290 
1296 #if defined(_RPMPGP_INTERNAL)
1297 /*@-exportlocal@*/
1298 int pgpPrtUserID(const pgpPkt pp)
1299  /*@globals fileSystem, internalState @*/
1300  /*@modifies fileSystem, internalState @*/;
1301 /*@=exportlocal@*/
1302 #endif
1303 
1309 #if defined(_RPMPGP_INTERNAL)
1310 /*@-exportlocal@*/
1311 int pgpPrtComment(const pgpPkt pp)
1312  /*@globals fileSystem @*/
1313  /*@modifies fileSystem @*/;
1314 /*@=exportlocal@*/
1315 #endif
1316 
1325 /*@-exportlocal@*/
1326 int pgpPubkeyFingerprint(const rpmuint8_t * pkt, size_t pktlen,
1327  /*@out@*/ rpmuint8_t * keyid)
1328  /*@modifies *keyid @*/;
1329 /*@=exportlocal@*/
1330 
1338 int pgpExtractPubkeyFingerprint(const char * b64pkt,
1339  /*@out@*/ rpmuint8_t * keyid)
1340  /*@modifies *keyid @*/;
1341 
1349 #if defined(_RPMPGP_INTERNAL)
1350 int pgpPktLen(const rpmuint8_t * pkt, size_t pleft, /*@out@*/ pgpPkt pp)
1351  /*@modifies pp @*/;
1352 #endif
1353 
1360 /*@-exportlocal@*/
1361 int pgpPrtPkt(const rpmuint8_t * pkt, size_t pleft)
1362  /*@globals fileSystem, internalState @*/
1363  /*@modifies fileSystem, internalState @*/;
1364 /*@=exportlocal@*/
1365 
1374 int pgpGrabPkts(const rpmuint8_t * pkts, size_t pktlen,
1375  /*@out@*/ rpmuint8_t *** pppkts, /*@out@*/ int * pnpkts)
1376  /*@modifies *pppkts, *pnpkts @*/;
1377 
1386 int pgpPrtPkts(const rpmuint8_t * pkts, size_t pktlen, pgpDig dig, int printing)
1387  /*@globals fileSystem, internalState @*/
1388  /*@modifies dig, fileSystem, internalState @*/;
1389 
1398  /*@out@*/ rpmuint8_t ** pkt, /*@out@*/ size_t * pktlen)
1399  /*@globals h_errno, fileSystem, internalState @*/
1400  /*@modifies *pkt, *pktlen, fileSystem, internalState @*/;
1401 
1409 pgpArmor pgpReadPkts(const char * fn,
1410  /*@out@*/ rpmuint8_t ** pkt, /*@out@*/ size_t * pktlen)
1411  /*@globals h_errno, fileSystem, internalState @*/
1412  /*@modifies *pkt, *pktlen, fileSystem, internalState @*/;
1413 
1421 char * pgpArmorWrap(rpmuint8_t atype, const unsigned char * s, size_t ns)
1422  /*@*/;
1423 
1430 pgpHashAlgo pgpHashAlgoStringToNumber(const char *name, size_t name_len)
1431  /*@*/;
1432 
1436 /*@unchecked@*/
1437 extern pgpVSFlags pgpDigVSFlags;
1438 
1444 /*@unused@*/ /*@null@*/
1445 pgpDig pgpDigUnlink (/*@killref@*/ /*@only@*/ /*@null@*/ pgpDig dig)
1446  /*@modifies dig @*/;
1447 #define pgpDigUnlink(_dig) \
1448  ((pgpDig)rpmioUnlinkPoolItem((rpmioItem)(_dig), __FUNCTION__, __FILE__, __LINE__))
1449 
1455 /*@unused@*/ /*@newref@*/ /*@null@*/
1456 pgpDig pgpDigLink (/*@null@*/ pgpDig dig)
1457  /*@modifies dig @*/;
1458 #define pgpDigLink(_dig) \
1459  ((pgpDig)rpmioLinkPoolItem((rpmioItem)(_dig), __FUNCTION__, __FILE__, __LINE__))
1460 
1466 /*@unused@*/ /*@null@*/
1467 pgpDig pgpDigFree(/*@killref@*/ /*@only@*/ /*@null@*/ pgpDig dig)
1468  /*@modifies dig @*/;
1469 #define pgpDigFree(_dig) \
1470  ((pgpDig)rpmioFreePoolItem((rpmioItem)(_dig), __FUNCTION__, __FILE__, __LINE__))
1471 
1479 /*@relnull@*/
1481  /*@globals fileSystem @*/
1482  /*@modifies fileSystem @*/;
1483 int rpmbcExportPubkey(pgpDig dig)
1484  /*@*/;
1485 int rpmbcExportSignature(pgpDig dig, /*@only@*/ DIGEST_CTX ctx)
1486  /*@*/;
1487 
1492 void pgpDigClean(/*@null@*/ pgpDig dig)
1493  /*@modifies dig @*/;
1494 
1500 /*@exposed@*/
1501 pgpDigParams pgpGetPubkey(const pgpDig dig)
1502  /*@*/;
1503 
1509 /*@exposed@*/
1511  /*@*/;
1512 
1518 rpmuint32_t pgpGetSigtag(const pgpDig dig)
1519  /*@*/;
1520 
1526 rpmuint32_t pgpGetSigtype(const pgpDig dig)
1527  /*@*/;
1528 
1534 /*@observer@*/ /*@null@*/
1535 extern const void * pgpGetSig(const pgpDig dig)
1536  /*@*/;
1537 
1543 rpmuint32_t pgpGetSiglen(const pgpDig dig)
1544  /*@*/;
1545 
1555 int pgpSetSig(pgpDig dig,
1556  rpmuint32_t sigtag, rpmuint32_t sigtype,
1557  /*@kept@*/ /*@null@*/ const void * sig, rpmuint32_t siglen)
1558  /*@modifies dig @*/;
1559 
1566 /*@null@*/
1567 void * pgpStatsAccumulator(pgpDig dig, int opx)
1568  /*@*/;
1569 
1577 int pgpSetFindPubkey(pgpDig dig,
1578  /*@null@*/ int (*findPubkey) (void *ts, /*@null@*/ void *dig),
1579  /*@exposed@*/ /*@null@*/ void * _ts)
1580  /*@modifies dig @*/;
1581 
1587 int pgpFindPubkey(pgpDig dig)
1588  /*@modifies dig @*/;
1589 
1596 /*@unused@*/ static inline
1597 int pgpIsPkt(const rpmuint8_t * p, /*@null@*/ pgpTag * tagp)
1598  /*@modifies *tagp @*/
1599 {
1600  unsigned int val = (unsigned int) *p++;
1601  pgpTag tag;
1602  int rc;
1603 
1604  /* XXX can't deal with these. */
1605  if (!(val & 0x80))
1606  return 0;
1607 
1608  if (val & 0x40)
1609  tag = (pgpTag)(val & 0x3f);
1610  else
1611  tag = (pgpTag)((val >> 2) & 0xf);
1612 
1613  switch (tag) {
1614  case PGPTAG_MARKER:
1617  case PGPTAG_PUBLIC_KEY:
1618  case PGPTAG_SECRET_KEY:
1620  case PGPTAG_SIGNATURE:
1621  case PGPTAG_COMMENT:
1622  case PGPTAG_COMMENT_OLD:
1623  case PGPTAG_LITERAL_DATA:
1625  case PGPTAG_SYMMETRIC_DATA:
1626  rc = 1;
1627  break;
1628  case PGPTAG_PUBLIC_SUBKEY:
1629  case PGPTAG_SECRET_SUBKEY:
1630  case PGPTAG_USER_ID:
1631  case PGPTAG_RESERVED:
1632  case PGPTAG_TRUST:
1633  case PGPTAG_PHOTOID:
1634  case PGPTAG_ENCRYPTED_MDC:
1635  case PGPTAG_MDC:
1636  case PGPTAG_PRIVATE_60:
1637  case PGPTAG_PRIVATE_62:
1638  case PGPTAG_CONTROL:
1639  default:
1640  rc = 0;
1641  break;
1642  }
1643  if (tagp != NULL)
1644  *tagp = tag;
1645  return rc;
1646 }
1647 
1648 #define CRC24_INIT 0xb704ce
1649 #define CRC24_POLY 0x1864cfb
1650 
1657 /*@unused@*/ static inline
1658 unsigned int pgpCRC(const rpmuint8_t * octets, size_t len)
1659  /*@*/
1660 {
1661  unsigned int crc = CRC24_INIT;
1662  int i;
1663 
1664  while (len--) {
1665  crc ^= (*octets++) << 16;
1666  for (i = 0; i < 8; i++) {
1667  crc <<= 1;
1668  if (crc & 0x1000000)
1669  crc ^= CRC24_POLY;
1670  }
1671  }
1672  return crc & 0xffffff;
1673 }
1674 
1677 typedef int (*pgpImplSet_t) (/*@only@*/ DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
1678  /*@modifies ctx, dig @*/;
1679 
1682 typedef int (*pgpImplErrChk_t) (pgpDig dig, const char * msg, int rc, unsigned expected)
1683  /*@*/;
1684 
1687 typedef int (*pgpImplAvailable_t) (pgpDig dig, int algo)
1688  /*@*/;
1689 
1692 typedef int (*pgpImplGenerate_t) (pgpDig dig)
1693  /*@*/;
1694 
1697 typedef int (*pgpImplSign_t) (pgpDig dig)
1698  /*@*/;
1699 
1702 typedef int (*pgpImplVerify_t) (pgpDig dig)
1703  /*@*/;
1704 
1707 typedef int (*pgpImplMpiItem_t) (const char * pre, pgpDig dig, int itemno,
1708  const rpmuint8_t * p, /*@null@*/ const rpmuint8_t * pend)
1709  /*@globals fileSystem @*/
1710  /*@modifies dig, fileSystem @*/;
1711 
1714 typedef void (*pgpImplClean_t) (void * impl)
1715  /*@modifies impl @*/;
1716 
1719 typedef void * (*pgpImplFree_t) (/*@only@*/ void * impl)
1720  /*@modifies impl @*/;
1721 
1724 typedef void * (*pgpImplInit_t) (void)
1725  /*@*/;
1726 
1727 
1730 typedef struct pgpImplVecs_s {
1735 
1740 
1744 
1749 } pgpImplVecs_t;
1750 
1753 /*@unchecked@*/
1754 extern pgpImplVecs_t * pgpImplVecs;
1755 
1756 /*@-mustmod@*/
1759 /*@unused@*/ static inline
1760 int pgpImplSetRSA(/*@only@*/ DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
1761  /*@modifies ctx, dig @*/
1762 {
1763  return (*pgpImplVecs->_pgpSetRSA) (ctx, dig, sigp);
1764 }
1765 
1768 /*@unused@*/ static inline
1769 int pgpImplSetDSA(/*@only@*/ DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
1770  /*@modifies ctx, dig @*/
1771 {
1772  return (*pgpImplVecs->_pgpSetDSA) (ctx, dig, sigp);
1773 }
1774 
1777 /*@unused@*/ static inline
1778 int pgpImplSetELG(/*@only@*/ DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
1779  /*@modifies ctx, dig @*/
1780 {
1781  return (*pgpImplVecs->_pgpSetELG) (ctx, dig, sigp);
1782 }
1783 
1786 /*@unused@*/ static inline
1787 int pgpImplSetECDSA(/*@only@*/ DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
1788  /*@modifies ctx, dig @*/
1789 {
1790  return (*pgpImplVecs->_pgpSetECDSA) (ctx, dig, sigp);
1791 }
1792 
1795 /*@unused@*/ static inline
1796 int pgpImplErrChk(pgpDig dig, const char * msg, int rc, unsigned expected)
1797  /*@*/
1798 {
1799  return (pgpImplVecs->_pgpErrChk
1800  ? (*pgpImplVecs->_pgpErrChk) (dig, msg, rc, expected)
1801  : rc);
1802 }
1803 
1806 /*@unused@*/ static inline
1807 int pgpImplAvailableCipher(pgpDig dig, int algo)
1808  /*@*/
1809 {
1810  return (pgpImplVecs->_pgpAvailableCipher
1811  ? (*pgpImplVecs->_pgpAvailableCipher) (dig, algo)
1812  : 0);
1813 }
1814 
1817 /*@unused@*/ static inline
1818 int pgpImplAvailableDigest(pgpDig dig, int algo)
1819  /*@*/
1820 {
1821  return (pgpImplVecs->_pgpAvailableDigest
1822  ? (*pgpImplVecs->_pgpAvailableDigest) (dig, algo)
1823  : 0);
1824 }
1825 
1828 /*@unused@*/ static inline
1829 int pgpImplAvailablePubkey(pgpDig dig, int algo)
1830  /*@*/
1831 {
1832  return (pgpImplVecs->_pgpAvailablePubkey
1833  ? (*pgpImplVecs->_pgpAvailablePubkey) (dig, algo)
1834  : 0);
1835 }
1836 
1839 /*@unused@*/ static inline
1841  /*@*/
1842 {
1843  return (pgpImplVecs->_pgpVerify
1844  ? (*pgpImplVecs->_pgpVerify) (dig)
1845  : 0);
1846 }
1847 
1850 /*@unused@*/ static inline
1852  /*@*/
1853 {
1854  return (pgpImplVecs->_pgpSign
1855  ? (*pgpImplVecs->_pgpSign) (dig)
1856  : 0);
1857 }
1858 
1861 /*@unused@*/ static inline
1863  /*@*/
1864 {
1865  return (pgpImplVecs->_pgpGenerate
1866  ? (*pgpImplVecs->_pgpGenerate) (dig)
1867  : 0);
1868 }
1869 
1872 /*@unused@*/ static inline
1873 int pgpImplMpiItem(const char * pre, pgpDig dig, int itemno,
1874  const rpmuint8_t * p, /*@null@*/ const rpmuint8_t * pend)
1875  /*@modifies dig @*/
1876 {
1877  return (*pgpImplVecs->_pgpMpiItem) (pre, dig, itemno, p, pend);
1878 }
1879 
1882 /*@unused@*/ static inline
1883 void pgpImplClean(void * impl)
1884  /*@modifies impl @*/
1885 {
1886 /*@-noeffectuncon@*/
1887  (*pgpImplVecs->_pgpClean) (impl);
1888 /*@=noeffectuncon@*/
1889 }
1890 
1893 /*@unused@*/ static inline
1894 /*@null@*/
1895 void * pgpImplFree(/*@only@*/ void * impl)
1896  /*@modifies impl @*/
1897 {
1898  return (*pgpImplVecs->_pgpFree) (impl);
1899 }
1900 
1903 /*@unused@*/ static inline
1904 void * pgpImplInit(void)
1905  /*@*/
1906 {
1907  return (*pgpImplVecs->_pgpInit) ();
1908 }
1909 /*@=mustmod@*/
1910 
1911 
1912 #ifdef __cplusplus
1913 }
1914 #endif
1915 /*@=fcnuse@*/
1916 
1917 #endif /* H_RPMPGP */
rpmuint8_t pubkey_algo
Definition: rpmpgp.h:763
static int pgpValTok(pgpValTbl vs, const char *s, const char *se)
Return value of an OpenPGP string.
Definition: rpmpgp.h:1218
int(* pgpImplSet_t)(DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
Definition: rpmpgp.h:1677
int pgpSetSig(pgpDig dig, rpmuint32_t sigtag, rpmuint32_t sigtype, const void *sig, rpmuint32_t siglen)
Set signature tag info, i.e.
Definition: rpmpgp.c:1257
rpmuint8_t sigtype
Definition: rpmpgp.h:419
5.5.1.
Definition: rpmpgp.h:722
const rpmuint8_t * pgpPrtPubkeyParams(pgpDig dig, const pgpPkt pp, pgpPubkeyAlgo pubkey_algo, const rpmuint8_t *p)
Definition: rpmpgp.c:682
5.7.
Definition: rpmpgp.h:898
int rpmbcExportSignature(pgpDig dig, DIGEST_CTX ctx)
Definition: rpmbc.c:923
rpmuint8_t hash_algo
Definition: rpmpgp.h:421
int(* pgpImplVerify_t)(pgpDig dig)
Definition: rpmpgp.h:1702
static const char * pgpValStr(pgpValTbl vs, rpmuint8_t val)
Return string representation of am OpenPGP value.
Definition: rpmpgp.h:1200
static unsigned int pgpCRC(const rpmuint8_t *octets, size_t len)
Return CRC of a buffer.
Definition: rpmpgp.h:1658
pgpPubkeyAlgo_e
9.1.
Definition: rpmpgp.h:257
int(* pgpImplMpiItem_t)(const char *pre, pgpDig dig, int itemno, const rpmuint8_t *p, const rpmuint8_t *pend)
Definition: rpmpgp.h:1707
rpmuint8_t compressalgo
Definition: rpmpgp.h:860
void(* pgpImplClean_t)(void *impl)
Definition: rpmpgp.h:1714
rpmuint8_t format
Definition: rpmpgp.h:950
struct pgpPktPubkey_s pgpPktPubkey
5.1.
struct pgpValTbl_s pgpArmorTbl[]
Armor (string, value) pairs.
Definition: rpmpgp.c:232
int pgpPktLen(const rpmuint8_t *pkt, size_t pleft, pgpPkt pp)
Definition: rpmpgp.c:940
static int pgpImplAvailableDigest(pgpDig dig, int algo)
Definition: rpmpgp.h:1818
pgpSymkeyAlgo_e
9.2.
Definition: rpmpgp.h:303
const void * pgpGetSig(const pgpDig dig)
Get signature tag data, i.e.
Definition: rpmpgp.c:1247
enum pgpCompressAlgo_e pgpCompressAlgo
9.3.
pgpCompressAlgo_e
9.3.
Definition: rpmpgp.h:344
pgpImplAvailable_t _pgpAvailableCipher
Definition: rpmpgp.h:1737
enum pgpSubType_e pgpSubType
5.2.3.1.
5.6.
Definition: rpmpgp.h:859
struct pgpDigParams_s * pgpDigParams
Definition: rpmiotypes.h:87
static unsigned int pgpLen(const rpmuint8_t *s, unsigned int *lenp)
Return length of an OpenPGP packet.
Definition: rpmpgp.h:1094
5.11.
Definition: rpmpgp.h:982
static unsigned int pgpGrab(const rpmuint8_t *s, size_t nbytes)
Return (native-endian) integer from big-endian representation.
Definition: rpmpgp.h:1077
enum pgpHashAlgo_e pgpHashAlgo
9.4.
struct pgpValTbl_s pgpCompressionTbl[]
Compression (string, value) pairs.
Definition: rpmpgp.c:136
pgpSigType_e
5.2.1.
Definition: rpmpgp.h:205
pgpImplSet_t _pgpSetECDSA
Definition: rpmpgp.h:1734
static rpmVSFlags vsflags
Definition: rpmcache.c:547
#define CRC24_POLY
Definition: rpmpgp.h:1649
union pgpPktKey_u pgpPktKey
5.5.3.
int pgpGrabPkts(const rpmuint8_t *pkts, size_t pktlen, rpmuint8_t ***pppkts, int *pnpkts)
Return array of packet pointers.
Definition: rpmpgp.c:1307
5.2.3.
Definition: rpmpgp.h:417
enum pgpSigType_e pgpSigType
5.2.1.
#define pgpDigLink(_dig)
Definition: rpmpgp.h:1458
rpmuint8_t pubkey_algo
Definition: rpmpgp.h:420
static int pgpImplGenerate(pgpDig dig)
Definition: rpmpgp.h:1862
int rpmbcExportPubkey(pgpDig dig)
Definition: rpmbc.c:864
pgpDig pgpDigNew(pgpVSFlags vsflags, pgpPubkeyAlgo pubkey_algo)
Create a container for parsed OpenPGP packates.
Definition: rpmpgp.c:1206
char * pgpArmorWrap(rpmuint8_t atype, const unsigned char *s, size_t ns)
Wrap a OpenPGP packets in ascii armor for transport.
Definition: rpmpgp.c:1574
pgpImplMpiItem_t _pgpMpiItem
Definition: rpmpgp.h:1745
#define pgpDigUnlink(_dig)
Definition: rpmpgp.h:1447
pgpImplClean_t _pgpClean
Definition: rpmpgp.h:1746
struct pgpValTbl_s pgpArmorKeyTbl[]
Armor key (string, value) pairs.
Definition: rpmpgp.c:243
static int pgpImplSign(pgpDig dig)
Definition: rpmpgp.h:1851
static int pgpImplAvailableCipher(pgpDig dig, int algo)
Definition: rpmpgp.h:1807
struct pgpValTbl_s pgpSubTypeTbl[]
Subtype (string, value) pairs.
Definition: rpmpgp.c:166
static int pgpImplSetELG(DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
Definition: rpmpgp.h:1778
static int pgpImplSetDSA(DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
Definition: rpmpgp.h:1769
5.2.2.
Definition: rpmpgp.h:385
5.5.3.
Definition: rpmpgp.h:830
struct pgpPktTrust_s pgpPktTrust
5.10.
struct pgpPktEdata_s pgpPktEdata
5.7.
static int pgpIsPkt(const rpmuint8_t *p, pgpTag *tagp)
Is buffer at beginning of an OpenPGP packet?
Definition: rpmpgp.h:1597
rpmuint8_t hashlen
Definition: rpmpgp.h:387
pgpHashAlgo pgpHashAlgoStringToNumber(const char *name, size_t name_len)
Convert a hash algorithm "foo" to the internal PGPHASHALGO_FOO number.
Definition: rpmpgp.c:1623
pgpDigParams pgpGetPubkey(const pgpDig dig)
Return OpenPGP pubkey parameters.
Definition: rpmpgp.c:1232
pgpImplAvailable_t _pgpAvailableDigest
Definition: rpmpgp.h:1738
static void * pgpImplFree(void *impl)
Definition: rpmpgp.h:1895
static void * pgpImplInit(void)
Definition: rpmpgp.h:1904
unsigned int rpmuint32_t
Definition: rpmiotypes.h:25
int(* pgpImplErrChk_t)(pgpDig dig, const char *msg, int rc, unsigned expected)
Definition: rpmpgp.h:1682
rpmuint8_t algo
Definition: rpmpgp.h:195
void *(* pgpImplInit_t)(void)
Definition: rpmpgp.h:1724
int pgpExtractPubkeyFingerprint(const char *b64pkt, rpmuint8_t *keyid)
Extract OpenPGP public key fingerprint from base64 encoded packet.
Definition: rpmpgp.c:1029
static int crc(FD_t fd, uint32_t *cval, uint32_t *clen)
Definition: rpmmtree.c:515
rpmuint8_t symkey_algo
Definition: rpmpgp.h:608
struct pgpPktSigV4_s * pgpPktSigV4
5.2.3.
struct pgpPktLdata_s pgpPktLdata
5.8.
int pgpPrtSigParams(pgpDig dig, const pgpPkt pp, pgpPubkeyAlgo pubkey_algo, pgpSigType sigtype, const rpmuint8_t *p)
Definition: rpmpgp.c:430
pgpSubType_e
5.2.3.1.
Definition: rpmpgp.h:504
struct pgpValTbl_s pgpSigTypeTbl[]
Definition: rpmpgp.c:84
rpmuint8_t version
Definition: rpmpgp.h:761
unsigned char rpmuint8_t
Private int typedefs to avoid C99 portability issues.
Definition: rpmiotypes.h:23
int pgpPrtPkt(const rpmuint8_t *pkt, size_t pleft)
Return lenth of a OpenPGP packet.
Definition: rpmpgp.c:1041
rpmuint8_t filenamelen
Definition: rpmpgp.h:951
rpmuint8_t flag
Definition: rpmpgp.h:969
rpmuint32_t pgpGetSigtype(const pgpDig dig)
Get signature tag type.
Definition: rpmpgp.c:1242
static const char * pgpMpiStr(const rpmuint8_t *p)
Return hex formatted representation of a multiprecision integer.
Definition: rpmpgp.h:1181
void pgpDigClean(pgpDig dig)
Release (malloc&#39;d) data from container.
Definition: rpmpgp.c:1107
struct pgpPktUid_s pgpPktUid
5.11.
struct pgpValTbl_s pgpSymkeyTbl[]
Symmetric key (string, value) pairs.
Definition: rpmpgp.c:117
static unsigned int pgpMpiBits(const rpmuint8_t *p)
Return no.
Definition: rpmpgp.h:1115
static char * pgpHexCvt(char *t, const rpmuint8_t *s, size_t nbytes)
Convert to hex.
Definition: rpmpgp.h:1143
enum pgpVSFlags_e pgpVSFlags
Bit(s) to control digest and signature verification.
struct pgpPkt_s * pgpPkt
Definition: rpmiotypes.h:79
rpmuint8_t pubkey_algo
Definition: rpmpgp.h:645
int _pgp_error_count
Definition: rpmpgp.c:35
pgpArmor pgpReadPkts(const char *fn, rpmuint8_t **pkt, size_t *pktlen)
Parse armored OpenPGP packets from a file.
Definition: rpmpgp.c:1564
int pgpPubkeyFingerprint(const rpmuint8_t *pkt, size_t pktlen, rpmuint8_t *keyid)
Print/parse an OpenPGP subtype packet.
Definition: rpmpgp.c:970
void * pgpStatsAccumulator(pgpDig dig, int opx)
Return pgpDig container accumulator structure.
Definition: rpmpgp.c:1271
Digest private data.
Definition: digest.c:127
enum pgpArmorKey_e pgpArmorKey
struct pgpValTbl_s pgpPubkeyTbl[]
Definition: rpmpgp.c:103
pgpImplSet_t _pgpSetRSA
Definition: rpmpgp.h:1731
rpmuint8_t version
Definition: rpmpgp.h:193
struct pgpPktCdata_s pgpPktCdata
5.6.
struct pgpDig_s * pgpDig
Definition: rpmiotypes.h:83
static int pgpImplSetECDSA(DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
Definition: rpmpgp.h:1787
rpmuint8_t sigtype
Definition: rpmpgp.h:388
rpmuint8_t version
Definition: rpmpgp.h:386
static int pgpImplErrChk(pgpDig dig, const char *msg, int rc, unsigned expected)
Definition: rpmpgp.h:1796
rpmuint8_t nested
Definition: rpmpgp.h:647
pgpImplAvailable_t _pgpAvailablePubkey
Definition: rpmpgp.h:1739
struct pgpPktKeyV4_s * pgpPktKeyV4
The version 4 format is similar to the version 3 format except for the absence of a validity period...
pgpImplSet_t _pgpSetDSA
Definition: rpmpgp.h:1732
rpmuint8_t sigtype
Definition: rpmpgp.h:643
pgpVSFlags pgpDigVSFlags
Disabler bits(s) for signature/digest checking.
Definition: rpmpgp.c:1105
pgpImplErrChk_t _pgpErrChk
Definition: rpmpgp.h:1736
pgpImplInit_t _pgpInit
Definition: rpmpgp.h:1748
pgpImplVerify_t _pgpVerify
Definition: rpmpgp.h:1741
int pgpPrtPkts(const rpmuint8_t *pkts, size_t pktlen, pgpDig dig, int printing)
Print/parse a OpenPGP packet(s).
Definition: rpmpgp.c:1351
pgpImplVecs_t * pgpImplVecs
Definition: rpmpgp.c:38
Cumulative statistics for an operation.
Definition: rpmsw.h:33
int pgpFindPubkey(pgpDig dig)
Call find pubkey vector.
Definition: rpmpgp.c:1299
pgpImplSet_t _pgpSetELG
Definition: rpmpgp.h:1733
union pgpPktSig_u * pgpPktSig
5.2.
static int pgpImplSetRSA(DIGEST_CTX ctx, pgpDig dig, pgpDigParams sigp)
Definition: rpmpgp.h:1760
int(* pgpImplSign_t)(pgpDig dig)
Definition: rpmpgp.h:1697
int(* pgpImplGenerate_t)(pgpDig dig)
Definition: rpmpgp.h:1692
rpmuint32_t pgpGetSiglen(const pgpDig dig)
Get signature tag data length, i.e.
Definition: rpmpgp.c:1252
enum pgpPubkeyAlgo_e pgpPubkeyAlgo
9.1.
rpmuint8_t hash_algo
Definition: rpmpgp.h:644
static unsigned int pgpMpiLen(const rpmuint8_t *p)
Return no.
Definition: rpmpgp.h:1128
pgpImplFree_t _pgpFree
Definition: rpmpgp.h:1747
int pgpPrtSubType(const rpmuint8_t *h, size_t hlen, pgpSigType sigtype)
Definition: rpmpgp.c:300
int pgpPrtComment(const pgpPkt pp)
Definition: rpmpgp.c:911
static void pgpImplClean(void *impl)
Definition: rpmpgp.h:1883
const char * str
Definition: rpmpgp.h:117
struct pgpPktSigV3_s * pgpPktSigV3
5.2.2.
struct rpmiob_s * rpmiob
Definition: rpmiotypes.h:57
5.2.
Definition: rpmpgp.h:573
int pgpPrtUserID(const pgpPkt pp)
Definition: rpmpgp.c:894
static int pgpImplVerify(pgpDig dig)
Definition: rpmpgp.h:1840
enum pgpSymkeyAlgo_e pgpSymkeyAlgo
9.2.
rpmuint8_t version
Definition: rpmpgp.h:607
enum pgpArmor_e pgpArmor
enum pgpTag_e pgpTag
4.3.
const struct pgpValTbl_s * pgpValTbl
rpmuint32_t pgpGetSigtag(const pgpDig dig)
Get signature tag.
Definition: rpmpgp.c:1237
int pgpSetFindPubkey(pgpDig dig, int(*findPubkey)(void *ts, void *dig), void *_ts)
Set find pubkey vector.
Definition: rpmpgp.c:1285
struct pgpPktSymkey_s pgpPktSymkey
5.3.
int val
Definition: rpmpgp.h:115
rpmuint8_t version
Definition: rpmpgp.h:418
rpmuint8_t version
Definition: rpmpgp.h:642
pgpImplSign_t _pgpSign
Definition: rpmpgp.h:1742
pgpArmorKey_e
Definition: rpmpgp.h:1018
void pgpPrtVal(const char *pre, pgpValTbl vs, rpmuint8_t val)
Print an OpenPGP value.
Definition: rpmpgp.c:290
static const char * name
struct pgpValTbl_s pgpTagTbl[]
Definition: rpmpgp.c:206
5.8.
Definition: rpmpgp.h:949
rpmuint8_t version
Definition: rpmpgp.h:723
#define pgpDigFree(_dig)
Definition: rpmpgp.h:1469
rpmuint8_t pubkey_algo
Definition: rpmpgp.h:391
#define CRC24_INIT
Definition: rpmpgp.h:1648
rpmuint8_t hash_algo
Definition: rpmpgp.h:392
static int pgpImplMpiItem(const char *pre, pgpDig dig, int itemno, const rpmuint8_t *p, const rpmuint8_t *pend)
Definition: rpmpgp.h:1873
static int pgpImplAvailablePubkey(pgpDig dig, int algo)
Definition: rpmpgp.h:1829
struct pgpImplVecs_s pgpImplVecs_t
pgpArmor pgpArmorUnwrap(rpmiob iob, rpmuint8_t **pkt, size_t *pktlen)
Parse armored OpenPGP packets from an iob.
Definition: rpmpgp.c:1397
static char * pgpHexStr(const rpmuint8_t *p, size_t plen)
Return hex formatted representation of bytes.
Definition: rpmpgp.h:1165
int(* pgpImplAvailable_t)(pgpDig dig, int algo)
Definition: rpmpgp.h:1687
rpmuint8_t pubkey_algo
Definition: rpmpgp.h:726
struct pgpValTbl_s pgpHashTbl[]
Hash (string, value) pairs.
Definition: rpmpgp.c:144
pgpDigParams pgpGetSignature(const pgpDig dig)
Return OpenPGP signature parameters.
Definition: rpmpgp.c:1227
struct pgpPktKeyV3_s * pgpPktKeyV3
5.5.1.
pgpImplGenerate_t _pgpGenerate
Definition: rpmpgp.h:1743
The version 4 format is similar to the version 3 format except for the absence of a validity period...
Definition: rpmpgp.h:760
5.10.
Definition: rpmpgp.h:968
int pgpPrtSig(const pgpPkt pp)
Definition: rpmpgp.c:506
void *(* pgpImplFree_t)(void *impl)
Definition: rpmpgp.h:1719
struct pgpPktOnepass_s * pgpPktOnepass
5.4.
int pgpPrtKey(const pgpPkt pp)
Definition: rpmpgp.c:833
pgpTag_e
4.3.
Definition: rpmpgp.h:127
pgpArmor_e
Definition: rpmpgp.h:989