diff options
author | Joel Sing <jsing@cvs.openbsd.org> | 2015-07-25 14:36:40 +0000 |
---|---|---|
committer | Joel Sing <jsing@cvs.openbsd.org> | 2015-07-25 14:36:40 +0000 |
commit | 358a1b2f41da5ae70b4c3df6cabe6985d88313bc (patch) | |
tree | 20a3957bbf14d5d1ab18d6b23376dba577a5a89a /lib | |
parent | 3127ec3f3cf6671c582fc3bc3d7874cbc48b1d11 (diff) |
Expand ASN.1 template macros - the generated assembly only differs by
changes to line numbers.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libcrypto/ec/ec_asn1.c | 406 |
1 files changed, 351 insertions, 55 deletions
diff --git a/lib/libcrypto/ec/ec_asn1.c b/lib/libcrypto/ec/ec_asn1.c index e1d3f6bad7d..0ee949134ec 100644 --- a/lib/libcrypto/ec/ec_asn1.c +++ b/lib/libcrypto/ec/ec_asn1.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ec_asn1.c,v 1.14 2015/03/20 03:02:51 doug Exp $ */ +/* $OpenBSD: ec_asn1.c,v 1.15 2015/07/25 14:36:39 jsing Exp $ */ /* * Written by Nils Larsch for the OpenSSL project. */ @@ -198,11 +198,39 @@ typedef struct ec_privatekey_st { } EC_PRIVATEKEY; /* the OpenSSL ASN.1 definitions */ -ASN1_SEQUENCE(X9_62_PENTANOMIAL) = { - ASN1_SIMPLE(X9_62_PENTANOMIAL, k1, LONG), - ASN1_SIMPLE(X9_62_PENTANOMIAL, k2, LONG), - ASN1_SIMPLE(X9_62_PENTANOMIAL, k3, LONG) -} ASN1_SEQUENCE_END(X9_62_PENTANOMIAL) +static const ASN1_TEMPLATE X9_62_PENTANOMIAL_seq_tt[] = { + { + .flags = 0, + .tag = 0, + .offset = offsetof(X9_62_PENTANOMIAL, k1), + .field_name = "k1", + .item = &LONG_it, + }, + { + .flags = 0, + .tag = 0, + .offset = offsetof(X9_62_PENTANOMIAL, k2), + .field_name = "k2", + .item = &LONG_it, + }, + { + .flags = 0, + .tag = 0, + .offset = offsetof(X9_62_PENTANOMIAL, k3), + .field_name = "k3", + .item = &LONG_it, + }, +}; + +const ASN1_ITEM X9_62_PENTANOMIAL_it = { + .itype = ASN1_ITYPE_SEQUENCE, + .utype = V_ASN1_SEQUENCE, + .templates = X9_62_PENTANOMIAL_seq_tt, + .tcount = sizeof(X9_62_PENTANOMIAL_seq_tt) / sizeof(ASN1_TEMPLATE), + .funcs = NULL, + .size = sizeof(X9_62_PENTANOMIAL), + .sname = "X9_62_PENTANOMIAL", +}; DECLARE_ASN1_ALLOC_FUNCTIONS(X9_62_PENTANOMIAL) @@ -218,19 +246,93 @@ X9_62_PENTANOMIAL_free(X9_62_PENTANOMIAL *a) ASN1_item_free((ASN1_VALUE *)a, &X9_62_PENTANOMIAL_it); } -ASN1_ADB_TEMPLATE(char_two_def) = ASN1_SIMPLE(X9_62_CHARACTERISTIC_TWO, p.other, ASN1_ANY); - -ASN1_ADB(X9_62_CHARACTERISTIC_TWO) = { - ADB_ENTRY(NID_X9_62_onBasis, ASN1_SIMPLE(X9_62_CHARACTERISTIC_TWO, p.onBasis, ASN1_NULL)), - ADB_ENTRY(NID_X9_62_tpBasis, ASN1_SIMPLE(X9_62_CHARACTERISTIC_TWO, p.tpBasis, ASN1_INTEGER)), - ADB_ENTRY(NID_X9_62_ppBasis, ASN1_SIMPLE(X9_62_CHARACTERISTIC_TWO, p.ppBasis, X9_62_PENTANOMIAL)) -} ASN1_ADB_END(X9_62_CHARACTERISTIC_TWO, 0, type, 0, &char_two_def_tt, NULL); +static const ASN1_TEMPLATE char_two_def_tt = { + .flags = 0, + .tag = 0, + .offset = offsetof(X9_62_CHARACTERISTIC_TWO, p.other), + .field_name = "p.other", + .item = &ASN1_ANY_it, +}; -ASN1_SEQUENCE(X9_62_CHARACTERISTIC_TWO) = { - ASN1_SIMPLE(X9_62_CHARACTERISTIC_TWO, m, LONG), - ASN1_SIMPLE(X9_62_CHARACTERISTIC_TWO, type, ASN1_OBJECT), - ASN1_ADB_OBJECT(X9_62_CHARACTERISTIC_TWO) -} ASN1_SEQUENCE_END(X9_62_CHARACTERISTIC_TWO) +static const ASN1_ADB_TABLE X9_62_CHARACTERISTIC_TWO_adbtbl[] = { + { + .value = NID_X9_62_onBasis, + .tt = { + .flags = 0, + .tag = 0, + .offset = offsetof(X9_62_CHARACTERISTIC_TWO, p.onBasis), + .field_name = "p.onBasis", + .item = &ASN1_NULL_it, + }, + + }, + { + .value = NID_X9_62_tpBasis, + .tt = { + .flags = 0, + .tag = 0, + .offset = offsetof(X9_62_CHARACTERISTIC_TWO, p.tpBasis), + .field_name = "p.tpBasis", + .item = &ASN1_INTEGER_it, + }, + + }, + { + .value = NID_X9_62_ppBasis, + .tt = { + .flags = 0, + .tag = 0, + .offset = offsetof(X9_62_CHARACTERISTIC_TWO, p.ppBasis), + .field_name = "p.ppBasis", + .item = &X9_62_PENTANOMIAL_it, + }, + + }, +}; + +static const ASN1_ADB X9_62_CHARACTERISTIC_TWO_adb = { + .flags = 0, + .offset = offsetof(X9_62_CHARACTERISTIC_TWO, type), + .app_items = 0, + .tbl = X9_62_CHARACTERISTIC_TWO_adbtbl, + .tblcount = sizeof(X9_62_CHARACTERISTIC_TWO_adbtbl) / sizeof(ASN1_ADB_TABLE), + .default_tt = &char_two_def_tt, + .null_tt = NULL, +}; + +static const ASN1_TEMPLATE X9_62_CHARACTERISTIC_TWO_seq_tt[] = { + { + .flags = 0, + .tag = 0, + .offset = offsetof(X9_62_CHARACTERISTIC_TWO, m), + .field_name = "m", + .item = &LONG_it, + }, + { + .flags = 0, + .tag = 0, + .offset = offsetof(X9_62_CHARACTERISTIC_TWO, type), + .field_name = "type", + .item = &ASN1_OBJECT_it, + }, + { + .flags = ASN1_TFLG_ADB_OID, + .tag = -1, + .offset = 0, + .field_name = "X9_62_CHARACTERISTIC_TWO", + .item = (const ASN1_ITEM *)&X9_62_CHARACTERISTIC_TWO_adb, + }, +}; + +const ASN1_ITEM X9_62_CHARACTERISTIC_TWO_it = { + .itype = ASN1_ITYPE_SEQUENCE, + .utype = V_ASN1_SEQUENCE, + .templates = X9_62_CHARACTERISTIC_TWO_seq_tt, + .tcount = sizeof(X9_62_CHARACTERISTIC_TWO_seq_tt) / sizeof(ASN1_TEMPLATE), + .funcs = NULL, + .size = sizeof(X9_62_CHARACTERISTIC_TWO), + .sname = "X9_62_CHARACTERISTIC_TWO", +}; DECLARE_ASN1_ALLOC_FUNCTIONS(X9_62_CHARACTERISTIC_TWO) X9_62_CHARACTERISTIC_TWO * @@ -244,32 +346,164 @@ X9_62_CHARACTERISTIC_TWO_free(X9_62_CHARACTERISTIC_TWO *a) { ASN1_item_free((ASN1_VALUE *)a, &X9_62_CHARACTERISTIC_TWO_it); } -ASN1_ADB_TEMPLATE(fieldID_def) = ASN1_SIMPLE(X9_62_FIELDID, p.other, ASN1_ANY); - -ASN1_ADB(X9_62_FIELDID) = { - ADB_ENTRY(NID_X9_62_prime_field, ASN1_SIMPLE(X9_62_FIELDID, p.prime, ASN1_INTEGER)), - ADB_ENTRY(NID_X9_62_characteristic_two_field, ASN1_SIMPLE(X9_62_FIELDID, p.char_two, X9_62_CHARACTERISTIC_TWO)) -} ASN1_ADB_END(X9_62_FIELDID, 0, fieldType, 0, &fieldID_def_tt, NULL); - -ASN1_SEQUENCE(X9_62_FIELDID) = { - ASN1_SIMPLE(X9_62_FIELDID, fieldType, ASN1_OBJECT), - ASN1_ADB_OBJECT(X9_62_FIELDID) -} ASN1_SEQUENCE_END(X9_62_FIELDID) - -ASN1_SEQUENCE(X9_62_CURVE) = { - ASN1_SIMPLE(X9_62_CURVE, a, ASN1_OCTET_STRING), - ASN1_SIMPLE(X9_62_CURVE, b, ASN1_OCTET_STRING), - ASN1_OPT(X9_62_CURVE, seed, ASN1_BIT_STRING) -} ASN1_SEQUENCE_END(X9_62_CURVE) - -ASN1_SEQUENCE(ECPARAMETERS) = { - ASN1_SIMPLE(ECPARAMETERS, version, LONG), - ASN1_SIMPLE(ECPARAMETERS, fieldID, X9_62_FIELDID), - ASN1_SIMPLE(ECPARAMETERS, curve, X9_62_CURVE), - ASN1_SIMPLE(ECPARAMETERS, base, ASN1_OCTET_STRING), - ASN1_SIMPLE(ECPARAMETERS, order, ASN1_INTEGER), - ASN1_OPT(ECPARAMETERS, cofactor, ASN1_INTEGER) -} ASN1_SEQUENCE_END(ECPARAMETERS) +static const ASN1_TEMPLATE fieldID_def_tt = { + .flags = 0, + .tag = 0, + .offset = offsetof(X9_62_FIELDID, p.other), + .field_name = "p.other", + .item = &ASN1_ANY_it, +}; + +static const ASN1_ADB_TABLE X9_62_FIELDID_adbtbl[] = { + { + .value = NID_X9_62_prime_field, + .tt = { + .flags = 0, + .tag = 0, + .offset = offsetof(X9_62_FIELDID, p.prime), + .field_name = "p.prime", + .item = &ASN1_INTEGER_it, + }, + + }, + { + .value = NID_X9_62_characteristic_two_field, + .tt = { + .flags = 0, + .tag = 0, + .offset = offsetof(X9_62_FIELDID, p.char_two), + .field_name = "p.char_two", + .item = &X9_62_CHARACTERISTIC_TWO_it, + }, + + }, +}; + +static const ASN1_ADB X9_62_FIELDID_adb = { + .flags = 0, + .offset = offsetof(X9_62_FIELDID, fieldType), + .app_items = 0, + .tbl = X9_62_FIELDID_adbtbl, + .tblcount = sizeof(X9_62_FIELDID_adbtbl) / sizeof(ASN1_ADB_TABLE), + .default_tt = &fieldID_def_tt, + .null_tt = NULL, +}; + +static const ASN1_TEMPLATE X9_62_FIELDID_seq_tt[] = { + { + .flags = 0, + .tag = 0, + .offset = offsetof(X9_62_FIELDID, fieldType), + .field_name = "fieldType", + .item = &ASN1_OBJECT_it, + }, + { + .flags = ASN1_TFLG_ADB_OID, + .tag = -1, + .offset = 0, + .field_name = "X9_62_FIELDID", + .item = (const ASN1_ITEM *)&X9_62_FIELDID_adb, + }, +}; + +const ASN1_ITEM X9_62_FIELDID_it = { + .itype = ASN1_ITYPE_SEQUENCE, + .utype = V_ASN1_SEQUENCE, + .templates = X9_62_FIELDID_seq_tt, + .tcount = sizeof(X9_62_FIELDID_seq_tt) / sizeof(ASN1_TEMPLATE), + .funcs = NULL, + .size = sizeof(X9_62_FIELDID), + .sname = "X9_62_FIELDID", +}; + +static const ASN1_TEMPLATE X9_62_CURVE_seq_tt[] = { + { + .flags = 0, + .tag = 0, + .offset = offsetof(X9_62_CURVE, a), + .field_name = "a", + .item = &ASN1_OCTET_STRING_it, + }, + { + .flags = 0, + .tag = 0, + .offset = offsetof(X9_62_CURVE, b), + .field_name = "b", + .item = &ASN1_OCTET_STRING_it, + }, + { + .flags = ASN1_TFLG_OPTIONAL, + .tag = 0, + .offset = offsetof(X9_62_CURVE, seed), + .field_name = "seed", + .item = &ASN1_BIT_STRING_it, + }, +}; + +const ASN1_ITEM X9_62_CURVE_it = { + .itype = ASN1_ITYPE_SEQUENCE, + .utype = V_ASN1_SEQUENCE, + .templates = X9_62_CURVE_seq_tt, + .tcount = sizeof(X9_62_CURVE_seq_tt) / sizeof(ASN1_TEMPLATE), + .funcs = NULL, + .size = sizeof(X9_62_CURVE), + .sname = "X9_62_CURVE", +}; + +static const ASN1_TEMPLATE ECPARAMETERS_seq_tt[] = { + { + .flags = 0, + .tag = 0, + .offset = offsetof(ECPARAMETERS, version), + .field_name = "version", + .item = &LONG_it, + }, + { + .flags = 0, + .tag = 0, + .offset = offsetof(ECPARAMETERS, fieldID), + .field_name = "fieldID", + .item = &X9_62_FIELDID_it, + }, + { + .flags = 0, + .tag = 0, + .offset = offsetof(ECPARAMETERS, curve), + .field_name = "curve", + .item = &X9_62_CURVE_it, + }, + { + .flags = 0, + .tag = 0, + .offset = offsetof(ECPARAMETERS, base), + .field_name = "base", + .item = &ASN1_OCTET_STRING_it, + }, + { + .flags = 0, + .tag = 0, + .offset = offsetof(ECPARAMETERS, order), + .field_name = "order", + .item = &ASN1_INTEGER_it, + }, + { + .flags = ASN1_TFLG_OPTIONAL, + .tag = 0, + .offset = offsetof(ECPARAMETERS, cofactor), + .field_name = "cofactor", + .item = &ASN1_INTEGER_it, + }, +}; + +const ASN1_ITEM ECPARAMETERS_it = { + .itype = ASN1_ITYPE_SEQUENCE, + .utype = V_ASN1_SEQUENCE, + .templates = ECPARAMETERS_seq_tt, + .tcount = sizeof(ECPARAMETERS_seq_tt) / sizeof(ASN1_TEMPLATE), + .funcs = NULL, + .size = sizeof(ECPARAMETERS), + .sname = "ECPARAMETERS", +}; DECLARE_ASN1_ALLOC_FUNCTIONS(ECPARAMETERS) ECPARAMETERS * @@ -284,11 +518,39 @@ ECPARAMETERS_free(ECPARAMETERS *a) ASN1_item_free((ASN1_VALUE *)a, &ECPARAMETERS_it); } -ASN1_CHOICE(ECPKPARAMETERS) = { - ASN1_SIMPLE(ECPKPARAMETERS, value.named_curve, ASN1_OBJECT), - ASN1_SIMPLE(ECPKPARAMETERS, value.parameters, ECPARAMETERS), - ASN1_SIMPLE(ECPKPARAMETERS, value.implicitlyCA, ASN1_NULL) -} ASN1_CHOICE_END(ECPKPARAMETERS) +static const ASN1_TEMPLATE ECPKPARAMETERS_ch_tt[] = { + { + .flags = 0, + .tag = 0, + .offset = offsetof(ECPKPARAMETERS, value.named_curve), + .field_name = "value.named_curve", + .item = &ASN1_OBJECT_it, + }, + { + .flags = 0, + .tag = 0, + .offset = offsetof(ECPKPARAMETERS, value.parameters), + .field_name = "value.parameters", + .item = &ECPARAMETERS_it, + }, + { + .flags = 0, + .tag = 0, + .offset = offsetof(ECPKPARAMETERS, value.implicitlyCA), + .field_name = "value.implicitlyCA", + .item = &ASN1_NULL_it, + }, +}; + +const ASN1_ITEM ECPKPARAMETERS_it = { + .itype = ASN1_ITYPE_CHOICE, + .utype = offsetof(ECPKPARAMETERS, type), + .templates = ECPKPARAMETERS_ch_tt, + .tcount = sizeof(ECPKPARAMETERS_ch_tt) / sizeof(ASN1_TEMPLATE), + .funcs = NULL, + .size = sizeof(ECPKPARAMETERS), + .sname = "ECPKPARAMETERS", +}; DECLARE_ASN1_FUNCTIONS_const(ECPKPARAMETERS) DECLARE_ASN1_ENCODE_FUNCTIONS_const(ECPKPARAMETERS, ECPKPARAMETERS) @@ -317,12 +579,46 @@ ECPKPARAMETERS_free(ECPKPARAMETERS *a) ASN1_item_free((ASN1_VALUE *)a, &ECPKPARAMETERS_it); } -ASN1_SEQUENCE(EC_PRIVATEKEY) = { - ASN1_SIMPLE(EC_PRIVATEKEY, version, LONG), - ASN1_SIMPLE(EC_PRIVATEKEY, privateKey, ASN1_OCTET_STRING), - ASN1_EXP_OPT(EC_PRIVATEKEY, parameters, ECPKPARAMETERS, 0), - ASN1_EXP_OPT(EC_PRIVATEKEY, publicKey, ASN1_BIT_STRING, 1) -} ASN1_SEQUENCE_END(EC_PRIVATEKEY) +static const ASN1_TEMPLATE EC_PRIVATEKEY_seq_tt[] = { + { + .flags = 0, + .tag = 0, + .offset = offsetof(EC_PRIVATEKEY, version), + .field_name = "version", + .item = &LONG_it, + }, + { + .flags = 0, + .tag = 0, + .offset = offsetof(EC_PRIVATEKEY, privateKey), + .field_name = "privateKey", + .item = &ASN1_OCTET_STRING_it, + }, + { + .flags = ASN1_TFLG_EXPLICIT | ASN1_TFLG_OPTIONAL, + .tag = 0, + .offset = offsetof(EC_PRIVATEKEY, parameters), + .field_name = "parameters", + .item = &ECPKPARAMETERS_it, + }, + { + .flags = ASN1_TFLG_EXPLICIT | ASN1_TFLG_OPTIONAL, + .tag = 1, + .offset = offsetof(EC_PRIVATEKEY, publicKey), + .field_name = "publicKey", + .item = &ASN1_BIT_STRING_it, + }, +}; + +const ASN1_ITEM EC_PRIVATEKEY_it = { + .itype = ASN1_ITYPE_SEQUENCE, + .utype = V_ASN1_SEQUENCE, + .templates = EC_PRIVATEKEY_seq_tt, + .tcount = sizeof(EC_PRIVATEKEY_seq_tt) / sizeof(ASN1_TEMPLATE), + .funcs = NULL, + .size = sizeof(EC_PRIVATEKEY), + .sname = "EC_PRIVATEKEY", +}; DECLARE_ASN1_FUNCTIONS_const(EC_PRIVATEKEY) DECLARE_ASN1_ENCODE_FUNCTIONS_const(EC_PRIVATEKEY, EC_PRIVATEKEY) |