Make filter structure the same across the projects
[TortoiseGit.git] / src / TortoiseProc / UpdateCrypto.h
blob89c644435fd6125a7591550c68f956f1020e341f
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2013-2014 Sven Strickroth <email@cs-ware.de>
4 // Copyright (C) VLC project (http://videolan.org)
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include <stdint.h>
22 #include <WinCrypt.h>
23 #include "UpdateDownloader.h"
25 enum /* Public key algorithms */
27 PUBLIC_KEY_ALGO_RSA = 0x01,
28 PUBLIC_KEY_ALGO_DSA = 0x11
31 enum /* Digest algorithms */
33 DIGEST_ALGO_SHA1 = 0x02,
34 DIGEST_ALGO_SHA256 = 0x08,
35 DIGEST_ALGO_SHA384 = 0x09,
36 DIGEST_ALGO_SHA512 = 0x0A,
39 enum /* Packet types */
41 SIGNATURE_PACKET = 0x02,
42 PUBLIC_KEY_PACKET = 0x06,
43 USER_ID_PACKET = 0x0d
46 enum /* Signature types */
48 BINARY_SIGNATURE = 0x00,
49 TEXT_SIGNATURE = 0x01,
51 /* Public keys signatures */
52 GENERIC_KEY_SIGNATURE = 0x10, /* No assumption of verification */
53 PERSONA_KEY_SIGNATURE = 0x11, /* No verification has been made */
54 CASUAL_KEY_SIGNATURE = 0x12, /* Some casual verification */
55 POSITIVE_KEY_SIGNATURE = 0x13 /* Substantial verification */
58 enum /* Signature subpacket types */
60 ISSUER_SUBPACKET = 0x10
63 struct public_key_packet_t
65 uint8_t version; /* we use only version 4 */
66 uint8_t timestamp[4]; /* creation time of the key */
67 uint8_t algo; /* we only use DSA or RSA */
68 /* the multi precision integers, with their 2 bytes length header */
69 union {
70 struct {
71 uint8_t p[2 + 128];
72 uint8_t q[2 + 20];
73 uint8_t g[2 + 128];
74 uint8_t y[2 + 128];
75 } dsa;
76 struct {
77 uint8_t n[2 + 4096 / 8];
78 uint8_t e[2 + 4096 / 8];
79 } rsa;
80 } sig;
83 /* used for public key and file signatures */
84 struct signature_packet_t
86 uint8_t version; /* 3 or 4 */
88 uint8_t type;
89 uint8_t public_key_algo; /* DSA or RSA */
90 uint8_t digest_algo;
92 uint8_t hash_verification[2];
93 uint8_t issuer_longid[8];
95 union /* version specific data */
97 struct
99 uint8_t hashed_data_len[2]; /* scalar number */
100 uint8_t *hashed_data; /* hashed_data_len bytes */
101 uint8_t unhashed_data_len[2]; /* scalar number */
102 uint8_t *unhashed_data; /* unhashed_data_len bytes */
103 } v4;
104 struct
106 uint8_t hashed_data_len; /* MUST be 5 */
107 uint8_t timestamp[4]; /* 4 bytes scalar number */
108 } v3;
109 } specific;
111 /* The part below is made of consecutive MPIs, their number and size being
112 * public-key-algorithm dependent.
114 union {
115 struct {
116 uint8_t r[2 + 20];
117 uint8_t s[2 + 20];
118 } dsa;
119 struct {
120 uint8_t s[2 + 4096 / 8];
121 } rsa;
122 } algo_specific;
125 typedef struct public_key_packet_t public_key_packet_t;
126 typedef struct signature_packet_t signature_packet_t;
128 struct public_key_t
130 uint8_t longid[8]; /* Long id */
131 uint8_t *psz_username; /* USER ID */
133 public_key_packet_t key; /* Public key packet */
135 signature_packet_t sig; /* Signature packet, by the embedded key */
138 typedef struct public_key_t public_key_t;
140 typedef struct _DSAKEY
142 BLOBHEADER blobheader;
143 DSSPUBKEY_VER3 dsspubkeyver3;
144 BYTE p[128]; // prime modulus
145 BYTE q[20]; // large factor of P-1
146 BYTE g[128]; // the generator parameter
147 BYTE y[128]; // (G^X) mod P
148 } DSAKEY;
150 typedef struct _RSAKEY
152 BLOBHEADER blobheader;
153 RSAPUBKEY rsapubkey;
154 BYTE n[4096 / 8];
155 } RSAKEY;
157 int VerifyIntegrity(const CString &filename, const CString &signatureFilename, CUpdateDownloader *updateDownloader);