Changes between 0.9.7 and 0.9.8 [xx XXX xxxx]
+ *) Key-generation can now be implemented in RSA_METHOD, DSA_METHOD
+ and DH_METHOD (eg. by ENGINE implementations) to override the normal
+ software implementations. For DSA and DH, parameter generation can
+ also be overriden by providing the appropriate method callbacks.
+ [Geoff Thorpe]
+
*) Change the "progress" mechanism used in key-generation and
primality testing to functions that take a new BN_GENCB pointer in
place of callback/argument pairs. The new API functions have "_ex"
int (*finish)(DH *dh);
int flags;
char *app_data;
+ /* If this is non-NULL, it will be used to generate parameters */
+ int (*generate_params)(DH *dh, int prime_len, int generator, BN_GENCB *cb);
} DH_METHOD;
struct dh_st
#include <openssl/bn.h>
#include <openssl/dh.h>
+static int dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB *cb);
+
+int DH_generate_parameters_ex(DH *ret, int prime_len, int generator, BN_GENCB *cb)
+ {
+ if(ret->meth->generate_params)
+ return ret->meth->generate_params(ret, prime_len, generator, cb);
+ return dh_builtin_genparams(ret, prime_len, generator, cb);
+ }
+
/* We generate DH parameters as follows
* find a prime q which is prime_len/2 bits long.
* p=(2*q)+1 or (p-1)/2 = q
* It's just as OK (and in some sense better) to use a generator of the
* order-q subgroup.
*/
-int DH_generate_parameters_ex(DH *ret, int prime_len, int generator, BN_GENCB *cb)
+static int dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB *cb)
{
BIGNUM *t1,*t2;
int g,ok= -1;
dh_init,
dh_finish,
0,
+NULL,
NULL
};
int (*finish)(DSA *dsa);
int flags;
char *app_data;
+ /* If this is non-NULL, it is used to generate DSA parameters */
+ int (*dsa_paramgen)(DSA *dsa, int bits,
+ unsigned char *seed, int seed_len,
+ int *counter_ret, unsigned long *h_ret,
+ BN_GENCB *cb);
+ /* If this is non-NULL, it is used to generate DSA keys */
+ int (*dsa_keygen)(DSA *dsa);
} DSA_METHOD;
struct dsa_st
#include <openssl/rand.h>
#include <openssl/sha.h>
+static int dsa_builtin_paramgen(DSA *ret, int bits,
+ unsigned char *seed_in, int seed_len,
+ int *counter_ret, unsigned long *h_ret, BN_GENCB *cb);
+
int DSA_generate_parameters_ex(DSA *ret, int bits,
unsigned char *seed_in, int seed_len,
int *counter_ret, unsigned long *h_ret, BN_GENCB *cb)
{
+ if(ret->meth->dsa_paramgen)
+ return ret->meth->dsa_paramgen(ret, bits, seed_in, seed_len,
+ counter_ret, h_ret, cb);
+ return dsa_builtin_paramgen(ret, bits, seed_in, seed_len,
+ counter_ret, h_ret, cb);
+ }
+
+static int dsa_builtin_paramgen(DSA *ret, int bits,
+ unsigned char *seed_in, int seed_len,
+ int *counter_ret, unsigned long *h_ret, BN_GENCB *cb)
+ {
int ok=0;
unsigned char seed[SHA_DIGEST_LENGTH];
unsigned char md[SHA_DIGEST_LENGTH];
#include <openssl/dsa.h>
#include <openssl/rand.h>
+static int dsa_builtin_keygen(DSA *dsa);
+
int DSA_generate_key(DSA *dsa)
+ {
+ if(dsa->meth->dsa_keygen)
+ return dsa->meth->dsa_keygen(dsa);
+ return dsa_builtin_keygen(dsa);
+ }
+
+static int dsa_builtin_keygen(DSA *dsa)
{
int ok=0;
BN_CTX *ctx=NULL;
dsa_init,
dsa_finish,
0,
+NULL,
+NULL,
NULL
};
NULL, /* init */
NULL, /* finish */
0, /* flags */
- NULL /* app_data */
+ NULL, /* app_data */
+ NULL, /* dsa_paramgen */
+ NULL /* dsa_keygen */
};
#endif
NULL,
NULL,
0,
+ NULL,
NULL
};
#endif
NULL, /* init */
NULL, /* finish */
0, /* flags */
- NULL /* app_data */
+ NULL, /* app_data */
+ NULL, /* dsa_paramgen */
+ NULL /* dsa_keygen */
};
#endif
NULL,
NULL,
0,
+ NULL,
NULL
};
#endif
NULL, /* init */
NULL, /* finish */
0, /* flags */
- NULL /* app_data */
+ NULL, /* app_data */
+ NULL, /* dsa_paramgen */
+ NULL /* dsa_keygen */
};
#endif
NULL,
NULL,
0,
+ NULL,
NULL
};
#endif
NULL,
NULL,
0,
+ NULL,
NULL
};
#endif
NULL, /* init */
NULL, /* finish */
0, /* flags */
- NULL /* app_data */
+ NULL, /* app_data */
+ NULL, /* dsa_paramgen */
+ NULL /* dsa_keygen */
};
#endif
NULL,
NULL,
0,
+ NULL,
NULL
};
#endif
NULL, /* init*/
NULL, /* finish*/
0, /* flags*/
- NULL
+ NULL,
+ NULL
};
#endif
NULL,/*finish*/
0,
NULL,
+ NULL,
+ NULL
};
#endif
NULL, /* init */
NULL, /* finish */
0, /* flags */
- NULL /* app_data */
+ NULL, /* app_data */
+ NULL, /* dsa_paramgen */
+ NULL /* dsa_keygen */
};
#endif
NULL,
NULL,
0,
+ NULL,
NULL
};
#endif