diff options
author | lloyd <[email protected]> | 2010-03-19 17:59:40 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-03-19 17:59:40 +0000 |
commit | dab16b79c89e54e9551d30dcf54ca89432932dce (patch) | |
tree | fcd4ccce7e442006f8075f8c8a9b298aab5167b3 /src/pubkey/ec_dompar | |
parent | 8fa0099ce0f2f488ca4c5046c6d019125d1d3b68 (diff) |
Add a couple of new helper functions to BER_Decoder:
decode_and_check takes an expected value; if the decoded value does
not match, a Decoding_Error with a specified string is thrown. Useful
for checking embedded version codes.
decode_octet_string_bigint is for decoding INTEGER values that are
stored as OCTET STRINGs. Totally obnoxious and useless, but common
especially in the ECC standards.
Diffstat (limited to 'src/pubkey/ec_dompar')
-rw-r--r-- | src/pubkey/ec_dompar/ec_dompar.cpp | 27 |
1 files changed, 7 insertions, 20 deletions
diff --git a/src/pubkey/ec_dompar/ec_dompar.cpp b/src/pubkey/ec_dompar/ec_dompar.cpp index 42ae9211e..3512060d1 100644 --- a/src/pubkey/ec_dompar/ec_dompar.cpp +++ b/src/pubkey/ec_dompar/ec_dompar.cpp @@ -54,23 +54,20 @@ EC_Domain_Params::EC_Domain_Params(const MemoryRegion<byte>& ber_data) } else if(obj.type_tag == SEQUENCE) { - BigInt ecpVers1(1); - OID curve_type; - SecureVector<byte> sv_a; - SecureVector<byte> sv_b; - BigInt p; + BigInt p, a, b; SecureVector<byte> sv_base_point; BER_Decoder(ber_data) .start_cons(SEQUENCE) - .decode(ecpVers1) + .decode_and_check<u32bit>(1, "Unknown ECC param version code") .start_cons(SEQUENCE) - .decode(curve_type) + .decode_and_check(OID("1.2.840.10045.1.1"), + "Only prime ECC fields supported") .decode(p) .end_cons() .start_cons(SEQUENCE) - .decode(sv_a, OCTET_STRING) - .decode(sv_b, OCTET_STRING) + .decode_octet_string_bigint(a) + .decode_octet_string_bigint(b) .end_cons() .decode(sv_base_point, OCTET_STRING) .decode(order) @@ -78,17 +75,7 @@ EC_Domain_Params::EC_Domain_Params(const MemoryRegion<byte>& ber_data) .end_cons() .verify_end(); - if(ecpVers1 != 1) - throw Decoding_Error("EC_Domain_Params: Unknown version code"); - - // Only prime curves supported - if(curve_type.as_string() != "1.2.840.10045.1.1") - throw Decoding_Error("Unexpected curve type " + curve_type.as_string()); - - curve = CurveGFp(p, - BigInt::decode(sv_a, sv_a.size()), - BigInt::decode(sv_b, sv_b.size())); - + curve = CurveGFp(p, a, b); base_point = OS2ECP(sv_base_point, curve); base_point.check_invariants(); } |