Implement handling of EC parameter seeds (new functions
EC_GROUP_set_seed(), EC_GROUP_get0_seed(), EC_GROUP_get_seed_len()). New functions ECPKParameters_print(), ECPKParameters_print_fp(). Submitted by: Nils Larsch
This commit is contained in:
@@ -86,6 +86,7 @@ typedef struct ec_group_st
|
||||
-- curve coefficients
|
||||
-- optional generator with associated information (order, cofactor)
|
||||
-- optional extra data (TODO: precomputed table for fast computation of multiples of generator)
|
||||
-- ASN1 stuff
|
||||
*/
|
||||
EC_GROUP;
|
||||
|
||||
@@ -116,9 +117,18 @@ EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *);
|
||||
int EC_GROUP_get_order(const EC_GROUP *, BIGNUM *order, BN_CTX *);
|
||||
int EC_GROUP_get_cofactor(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *);
|
||||
|
||||
void EC_GROUP_set_nid(EC_GROUP *, int);
|
||||
void EC_GROUP_set_nid(EC_GROUP *, int); /* curve name */
|
||||
int EC_GROUP_get_nid(const EC_GROUP *);
|
||||
|
||||
void EC_GROUP_set_asn1_flag(EC_GROUP *, int flag);
|
||||
int EC_GROUP_get_asn1_flag(const EC_GROUP *);
|
||||
|
||||
void EC_GROUP_set_point_conversion_form(EC_GROUP *, point_conversion_form_t);
|
||||
point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *);
|
||||
|
||||
unsigned char *EC_GROUP_get0_seed(const EC_GROUP *);
|
||||
size_t EC_GROUP_get_seed_len(const EC_GROUP *);
|
||||
size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len);
|
||||
|
||||
/* We don't have types for field specifications and field elements in general.
|
||||
* Otherwise we could declare
|
||||
@@ -242,11 +252,6 @@ DECLARE_ASN1_ENCODE_FUNCTIONS_const(ECPKPARAMETERS, ECPKPARAMETERS)
|
||||
EC_GROUP *EC_ASN1_pkparameters2group(const ECPKPARAMETERS *);
|
||||
ECPKPARAMETERS *EC_ASN1_group2pkparameters(const EC_GROUP *, ECPKPARAMETERS *);
|
||||
|
||||
void EC_GROUP_set_asn1_flag(EC_GROUP *, int flag);
|
||||
int EC_GROUP_get_asn1_flag(const EC_GROUP *);
|
||||
|
||||
void EC_GROUP_set_point_conversion_form(EC_GROUP *, point_conversion_form_t);
|
||||
point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *);
|
||||
|
||||
EC_GROUP *d2i_ECParameters(EC_GROUP **, const unsigned char **in, long len);
|
||||
int i2d_ECParameters(const EC_GROUP *, unsigned char **out);
|
||||
@@ -255,6 +260,13 @@ EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len);
|
||||
int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out);
|
||||
|
||||
|
||||
#ifndef OPENSSL_NO_BIO
|
||||
int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off);
|
||||
#endif
|
||||
#ifndef OPENSSL_NO_FP_API
|
||||
int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off);
|
||||
#endif
|
||||
|
||||
|
||||
/* BEGIN ERROR CODES */
|
||||
/* The following lines are auto generated by the script mkerr.pl. Any changes
|
||||
@@ -269,6 +281,8 @@ void ERR_load_EC_strings(void);
|
||||
#define EC_F_D2I_ECDSAPARAMETERS 154
|
||||
#define EC_F_D2I_ECPARAMETERS 155
|
||||
#define EC_F_D2I_ECPKPARAMETERS 161
|
||||
#define EC_F_ECPKPARAMETERS_PRINT 166
|
||||
#define EC_F_ECPKPARAMETERS_PRINT_FP 167
|
||||
#define EC_F_EC_ASN1_GROUP2CURVE 159
|
||||
#define EC_F_EC_ASN1_GROUP2FIELDID 156
|
||||
#define EC_F_EC_ASN1_GROUP2PARAMETERS 160
|
||||
|
||||
@@ -70,12 +70,14 @@ static ERR_STRING_DATA EC_str_functs[]=
|
||||
{ERR_PACK(0,EC_F_D2I_ECDSAPARAMETERS,0), "d2i_ECDSAParameters"},
|
||||
{ERR_PACK(0,EC_F_D2I_ECPARAMETERS,0), "d2i_ECParameters"},
|
||||
{ERR_PACK(0,EC_F_D2I_ECPKPARAMETERS,0), "d2i_ECPKParameters"},
|
||||
{ERR_PACK(0,EC_F_ECPKPARAMETERS_PRINT,0), "ECPKParameters_print"},
|
||||
{ERR_PACK(0,EC_F_ECPKPARAMETERS_PRINT_FP,0), "ECPKParameters_print_fp"},
|
||||
{ERR_PACK(0,EC_F_EC_ASN1_GROUP2CURVE,0), "EC_ASN1_GROUP2CURVE"},
|
||||
{ERR_PACK(0,EC_F_EC_ASN1_GROUP2FIELDID,0), "EC_ASN1_GROUP2FIELDID"},
|
||||
{ERR_PACK(0,EC_F_EC_ASN1_GROUP2PARAMETERS,0), "EC_ASN1_GROUP2PARAMETERS"},
|
||||
{ERR_PACK(0,EC_F_EC_ASN1_GROUP2PKPARAMETERS,0), "EC_ASN1_GROUP2PKPARAMETERS"},
|
||||
{ERR_PACK(0,EC_F_EC_ASN1_GROUP2PKPARAMETERS,0), "EC_ASN1_group2pkparameters"},
|
||||
{ERR_PACK(0,EC_F_EC_ASN1_PARAMETERS2GROUP,0), "EC_ASN1_PARAMETERS2GROUP"},
|
||||
{ERR_PACK(0,EC_F_EC_ASN1_PKPARAMETERS2GROUP,0), "EC_ASN1_PKPARAMETERS2GROUP"},
|
||||
{ERR_PACK(0,EC_F_EC_ASN1_PKPARAMETERS2GROUP,0), "EC_ASN1_pkparameters2group"},
|
||||
{ERR_PACK(0,EC_F_EC_GFP_MONT_FIELD_DECODE,0), "ec_GFp_mont_field_decode"},
|
||||
{ERR_PACK(0,EC_F_EC_GFP_MONT_FIELD_ENCODE,0), "ec_GFp_mont_field_encode"},
|
||||
{ERR_PACK(0,EC_F_EC_GFP_MONT_FIELD_MUL,0), "ec_GFp_mont_field_mul"},
|
||||
|
||||
@@ -148,14 +148,14 @@ struct ec_group_st {
|
||||
int asn1_flag; /* flag to control the asn1 encoding */
|
||||
point_conversion_form_t asn1_form;
|
||||
|
||||
unsigned char *seed; /* optional seed for parameters (appears in ASN1) */
|
||||
size_t seed_len;
|
||||
|
||||
void *extra_data;
|
||||
void *(*extra_data_dup_func)(void *);
|
||||
void (*extra_data_free_func)(void *);
|
||||
void (*extra_data_clear_free_func)(void *);
|
||||
|
||||
unsigned char *seed; /* XXX */
|
||||
size_t seed_len; /* XXX */
|
||||
|
||||
/* The following members are handled by the method functions,
|
||||
* even if they appear generic */
|
||||
|
||||
|
||||
@@ -100,7 +100,7 @@ EC_GROUP *EC_GROUP_new(const EC_METHOD *meth)
|
||||
|
||||
ret->curve_name = 0;
|
||||
ret->asn1_flag = 0;
|
||||
ret->asn1_form = POINT_CONVERSION_COMPRESSED;
|
||||
ret->asn1_form = POINT_CONVERSION_UNCOMPRESSED;
|
||||
|
||||
ret->seed = NULL;
|
||||
ret->seed_len = 0;
|
||||
@@ -345,6 +345,39 @@ point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *group
|
||||
}
|
||||
|
||||
|
||||
size_t EC_GROUP_set_seed(EC_GROUP *group, const unsigned char *p, size_t len)
|
||||
{
|
||||
if (group->seed)
|
||||
{
|
||||
OPENSSL_free(group->seed);
|
||||
group->seed = NULL;
|
||||
group->seed_len = 0;
|
||||
}
|
||||
|
||||
if (!len || !p)
|
||||
return 1;
|
||||
|
||||
if ((group->seed = OPENSSL_malloc(len)) == NULL)
|
||||
return 0;
|
||||
memcpy(group->seed, p, len);
|
||||
group->seed_len = len;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
|
||||
unsigned char *EC_GROUP_get0_seed(const EC_GROUP *group)
|
||||
{
|
||||
return group->seed;
|
||||
}
|
||||
|
||||
|
||||
size_t EC_GROUP_get_seed_len(const EC_GROUP *group)
|
||||
{
|
||||
return group->seed_len;
|
||||
}
|
||||
|
||||
|
||||
int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
|
||||
{
|
||||
if (group->meth->group_set_curve_GFp == 0)
|
||||
|
||||
Reference in New Issue
Block a user