diff options
Diffstat (limited to 'src/lib/libcrypto/dsa/dsa_asn1.c')
| -rw-r--r-- | src/lib/libcrypto/dsa/dsa_asn1.c | 242 |
1 files changed, 213 insertions, 29 deletions
diff --git a/src/lib/libcrypto/dsa/dsa_asn1.c b/src/lib/libcrypto/dsa/dsa_asn1.c index c6b00923fc..8c5d93105c 100644 --- a/src/lib/libcrypto/dsa/dsa_asn1.c +++ b/src/lib/libcrypto/dsa/dsa_asn1.c | |||
| @@ -1,4 +1,4 @@ | |||
| 1 | /* $OpenBSD: dsa_asn1.c,v 1.15 2015/02/10 05:12:23 jsing Exp $ */ | 1 | /* $OpenBSD: dsa_asn1.c,v 1.16 2015/02/14 15:06:55 jsing Exp $ */ |
| 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | 2 | /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL |
| 3 | * project 2000. | 3 | * project 2000. |
| 4 | */ | 4 | */ |
| @@ -84,10 +84,40 @@ sig_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg) | |||
| 84 | return 1; | 84 | return 1; |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | ASN1_SEQUENCE_cb(DSA_SIG, sig_cb) = { | 87 | static const ASN1_AUX DSA_SIG_aux = { |
| 88 | ASN1_SIMPLE(DSA_SIG, r, CBIGNUM), | 88 | .app_data = NULL, |
| 89 | ASN1_SIMPLE(DSA_SIG, s, CBIGNUM) | 89 | .flags = 0, |
| 90 | } ASN1_SEQUENCE_END_cb(DSA_SIG, DSA_SIG) | 90 | .ref_offset = 0, |
| 91 | .ref_lock = 0, | ||
| 92 | .asn1_cb = sig_cb, | ||
| 93 | .enc_offset = 0, | ||
| 94 | }; | ||
| 95 | static const ASN1_TEMPLATE DSA_SIG_seq_tt[] = { | ||
| 96 | { | ||
| 97 | .flags = 0, | ||
| 98 | .tag = 0, | ||
| 99 | .offset = offsetof(DSA_SIG, r), | ||
| 100 | .field_name = "r", | ||
| 101 | .item = &CBIGNUM_it, | ||
| 102 | }, | ||
| 103 | { | ||
| 104 | .flags = 0, | ||
| 105 | .tag = 0, | ||
| 106 | .offset = offsetof(DSA_SIG, s), | ||
| 107 | .field_name = "s", | ||
| 108 | .item = &CBIGNUM_it, | ||
| 109 | }, | ||
| 110 | }; | ||
| 111 | |||
| 112 | const ASN1_ITEM DSA_SIG_it = { | ||
| 113 | .itype = ASN1_ITYPE_SEQUENCE, | ||
| 114 | .utype = V_ASN1_SEQUENCE, | ||
| 115 | .templates = DSA_SIG_seq_tt, | ||
| 116 | .tcount = sizeof(DSA_SIG_seq_tt) / sizeof(ASN1_TEMPLATE), | ||
| 117 | .funcs = &DSA_SIG_aux, | ||
| 118 | .size = sizeof(DSA_SIG), | ||
| 119 | .sname = "DSA_SIG", | ||
| 120 | }; | ||
| 91 | 121 | ||
| 92 | 122 | ||
| 93 | DSA_SIG * | 123 | DSA_SIG * |
| @@ -120,14 +150,68 @@ dsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg) | |||
| 120 | return 1; | 150 | return 1; |
| 121 | } | 151 | } |
| 122 | 152 | ||
| 123 | ASN1_SEQUENCE_cb(DSAPrivateKey, dsa_cb) = { | 153 | static const ASN1_AUX DSAPrivateKey_aux = { |
| 124 | ASN1_SIMPLE(DSA, version, LONG), | 154 | .app_data = NULL, |
| 125 | ASN1_SIMPLE(DSA, p, BIGNUM), | 155 | .flags = 0, |
| 126 | ASN1_SIMPLE(DSA, q, BIGNUM), | 156 | .ref_offset = 0, |
| 127 | ASN1_SIMPLE(DSA, g, BIGNUM), | 157 | .ref_lock = 0, |
| 128 | ASN1_SIMPLE(DSA, pub_key, BIGNUM), | 158 | .asn1_cb = dsa_cb, |
| 129 | ASN1_SIMPLE(DSA, priv_key, BIGNUM) | 159 | .enc_offset = 0, |
| 130 | } ASN1_SEQUENCE_END_cb(DSA, DSAPrivateKey) | 160 | }; |
| 161 | static const ASN1_TEMPLATE DSAPrivateKey_seq_tt[] = { | ||
| 162 | { | ||
| 163 | .flags = 0, | ||
| 164 | .tag = 0, | ||
| 165 | .offset = offsetof(DSA, version), | ||
| 166 | .field_name = "version", | ||
| 167 | .item = &LONG_it, | ||
| 168 | }, | ||
| 169 | { | ||
| 170 | .flags = 0, | ||
| 171 | .tag = 0, | ||
| 172 | .offset = offsetof(DSA, p), | ||
| 173 | .field_name = "p", | ||
| 174 | .item = &BIGNUM_it, | ||
| 175 | }, | ||
| 176 | { | ||
| 177 | .flags = 0, | ||
| 178 | .tag = 0, | ||
| 179 | .offset = offsetof(DSA, q), | ||
| 180 | .field_name = "q", | ||
| 181 | .item = &BIGNUM_it, | ||
| 182 | }, | ||
| 183 | { | ||
| 184 | .flags = 0, | ||
| 185 | .tag = 0, | ||
| 186 | .offset = offsetof(DSA, g), | ||
| 187 | .field_name = "g", | ||
| 188 | .item = &BIGNUM_it, | ||
| 189 | }, | ||
| 190 | { | ||
| 191 | .flags = 0, | ||
| 192 | .tag = 0, | ||
| 193 | .offset = offsetof(DSA, pub_key), | ||
| 194 | .field_name = "pub_key", | ||
| 195 | .item = &BIGNUM_it, | ||
| 196 | }, | ||
| 197 | { | ||
| 198 | .flags = 0, | ||
| 199 | .tag = 0, | ||
| 200 | .offset = offsetof(DSA, priv_key), | ||
| 201 | .field_name = "priv_key", | ||
| 202 | .item = &BIGNUM_it, | ||
| 203 | }, | ||
| 204 | }; | ||
| 205 | |||
| 206 | const ASN1_ITEM DSAPrivateKey_it = { | ||
| 207 | .itype = ASN1_ITYPE_SEQUENCE, | ||
| 208 | .utype = V_ASN1_SEQUENCE, | ||
| 209 | .templates = DSAPrivateKey_seq_tt, | ||
| 210 | .tcount = sizeof(DSAPrivateKey_seq_tt) / sizeof(ASN1_TEMPLATE), | ||
| 211 | .funcs = &DSAPrivateKey_aux, | ||
| 212 | .size = sizeof(DSA), | ||
| 213 | .sname = "DSA", | ||
| 214 | }; | ||
| 131 | 215 | ||
| 132 | 216 | ||
| 133 | DSA * | 217 | DSA * |
| @@ -143,11 +227,47 @@ i2d_DSAPrivateKey(const DSA *a, unsigned char **out) | |||
| 143 | return ASN1_item_i2d((ASN1_VALUE *)a, out, &DSAPrivateKey_it); | 227 | return ASN1_item_i2d((ASN1_VALUE *)a, out, &DSAPrivateKey_it); |
| 144 | } | 228 | } |
| 145 | 229 | ||
| 146 | ASN1_SEQUENCE_cb(DSAparams, dsa_cb) = { | 230 | static const ASN1_AUX DSAparams_aux = { |
| 147 | ASN1_SIMPLE(DSA, p, BIGNUM), | 231 | .app_data = NULL, |
| 148 | ASN1_SIMPLE(DSA, q, BIGNUM), | 232 | .flags = 0, |
| 149 | ASN1_SIMPLE(DSA, g, BIGNUM), | 233 | .ref_offset = 0, |
| 150 | } ASN1_SEQUENCE_END_cb(DSA, DSAparams) | 234 | .ref_lock = 0, |
| 235 | .asn1_cb = dsa_cb, | ||
| 236 | .enc_offset = 0, | ||
| 237 | }; | ||
| 238 | static const ASN1_TEMPLATE DSAparams_seq_tt[] = { | ||
| 239 | { | ||
| 240 | .flags = 0, | ||
| 241 | .tag = 0, | ||
| 242 | .offset = offsetof(DSA, p), | ||
| 243 | .field_name = "p", | ||
| 244 | .item = &BIGNUM_it, | ||
| 245 | }, | ||
| 246 | { | ||
| 247 | .flags = 0, | ||
| 248 | .tag = 0, | ||
| 249 | .offset = offsetof(DSA, q), | ||
| 250 | .field_name = "q", | ||
| 251 | .item = &BIGNUM_it, | ||
| 252 | }, | ||
| 253 | { | ||
| 254 | .flags = 0, | ||
| 255 | .tag = 0, | ||
| 256 | .offset = offsetof(DSA, g), | ||
| 257 | .field_name = "g", | ||
| 258 | .item = &BIGNUM_it, | ||
| 259 | }, | ||
| 260 | }; | ||
| 261 | |||
| 262 | const ASN1_ITEM DSAparams_it = { | ||
| 263 | .itype = ASN1_ITYPE_SEQUENCE, | ||
| 264 | .utype = V_ASN1_SEQUENCE, | ||
| 265 | .templates = DSAparams_seq_tt, | ||
| 266 | .tcount = sizeof(DSAparams_seq_tt) / sizeof(ASN1_TEMPLATE), | ||
| 267 | .funcs = &DSAparams_aux, | ||
| 268 | .size = sizeof(DSA), | ||
| 269 | .sname = "DSA", | ||
| 270 | }; | ||
| 151 | 271 | ||
| 152 | 272 | ||
| 153 | DSA * | 273 | DSA * |
| @@ -170,17 +290,81 @@ i2d_DSAparams(const DSA *a, unsigned char **out) | |||
| 170 | * in a SEQUENCE | 290 | * in a SEQUENCE |
| 171 | */ | 291 | */ |
| 172 | 292 | ||
| 173 | ASN1_SEQUENCE(dsa_pub_internal) = { | 293 | static const ASN1_TEMPLATE dsa_pub_internal_seq_tt[] = { |
| 174 | ASN1_SIMPLE(DSA, pub_key, BIGNUM), | 294 | { |
| 175 | ASN1_SIMPLE(DSA, p, BIGNUM), | 295 | .flags = 0, |
| 176 | ASN1_SIMPLE(DSA, q, BIGNUM), | 296 | .tag = 0, |
| 177 | ASN1_SIMPLE(DSA, g, BIGNUM) | 297 | .offset = offsetof(DSA, pub_key), |
| 178 | } ASN1_SEQUENCE_END_name(DSA, dsa_pub_internal) | 298 | .field_name = "pub_key", |
| 179 | 299 | .item = &BIGNUM_it, | |
| 180 | ASN1_CHOICE_cb(DSAPublicKey, dsa_cb) = { | 300 | }, |
| 181 | ASN1_SIMPLE(DSA, pub_key, BIGNUM), | 301 | { |
| 182 | ASN1_EX_COMBINE(0, 0, dsa_pub_internal) | 302 | .flags = 0, |
| 183 | } ASN1_CHOICE_END_cb(DSA, DSAPublicKey, write_params) | 303 | .tag = 0, |
| 304 | .offset = offsetof(DSA, p), | ||
| 305 | .field_name = "p", | ||
| 306 | .item = &BIGNUM_it, | ||
| 307 | }, | ||
| 308 | { | ||
| 309 | .flags = 0, | ||
| 310 | .tag = 0, | ||
| 311 | .offset = offsetof(DSA, q), | ||
| 312 | .field_name = "q", | ||
| 313 | .item = &BIGNUM_it, | ||
| 314 | }, | ||
| 315 | { | ||
| 316 | .flags = 0, | ||
| 317 | .tag = 0, | ||
| 318 | .offset = offsetof(DSA, g), | ||
| 319 | .field_name = "g", | ||
| 320 | .item = &BIGNUM_it, | ||
| 321 | }, | ||
| 322 | }; | ||
| 323 | |||
| 324 | const ASN1_ITEM dsa_pub_internal_it = { | ||
| 325 | .itype = ASN1_ITYPE_SEQUENCE, | ||
| 326 | .utype = V_ASN1_SEQUENCE, | ||
| 327 | .templates = dsa_pub_internal_seq_tt, | ||
| 328 | .tcount = sizeof(dsa_pub_internal_seq_tt) / sizeof(ASN1_TEMPLATE), | ||
| 329 | .funcs = NULL, | ||
| 330 | .size = sizeof(DSA), | ||
| 331 | .sname = "DSA", | ||
| 332 | }; | ||
| 333 | |||
| 334 | static const ASN1_AUX DSAPublicKey_aux = { | ||
| 335 | .app_data = NULL, | ||
| 336 | .flags = 0, | ||
| 337 | .ref_offset = 0, | ||
| 338 | .ref_lock = 0, | ||
| 339 | .asn1_cb = dsa_cb, | ||
| 340 | .enc_offset = 0, | ||
| 341 | }; | ||
| 342 | static const ASN1_TEMPLATE DSAPublicKey_ch_tt[] = { | ||
| 343 | { | ||
| 344 | .flags = 0, | ||
| 345 | .tag = 0, | ||
| 346 | .offset = offsetof(DSA, pub_key), | ||
| 347 | .field_name = "pub_key", | ||
| 348 | .item = &BIGNUM_it, | ||
| 349 | }, | ||
| 350 | { | ||
| 351 | .flags = 0 | ASN1_TFLG_COMBINE, | ||
| 352 | .tag = 0, | ||
| 353 | .offset = 0, | ||
| 354 | .field_name = NULL, | ||
| 355 | .item = &dsa_pub_internal_it, | ||
| 356 | }, | ||
| 357 | }; | ||
| 358 | |||
| 359 | const ASN1_ITEM DSAPublicKey_it = { | ||
| 360 | .itype = ASN1_ITYPE_CHOICE, | ||
| 361 | .utype = offsetof(DSA, write_params), | ||
| 362 | .templates = DSAPublicKey_ch_tt, | ||
| 363 | .tcount = sizeof(DSAPublicKey_ch_tt) / sizeof(ASN1_TEMPLATE), | ||
| 364 | .funcs = &DSAPublicKey_aux, | ||
| 365 | .size = sizeof(DSA), | ||
| 366 | .sname = "DSA", | ||
| 367 | }; | ||
| 184 | 368 | ||
| 185 | 369 | ||
| 186 | DSA * | 370 | DSA * |
