Added a MODP_CUSTOM DH group which takes g and p as constructor arguments
This commit is contained in:
@@ -308,7 +308,7 @@ METHOD(crypto_factory_t, create_rng, rng_t*,
|
|||||||
}
|
}
|
||||||
|
|
||||||
METHOD(crypto_factory_t, create_dh, diffie_hellman_t*,
|
METHOD(crypto_factory_t, create_dh, diffie_hellman_t*,
|
||||||
private_crypto_factory_t *this, diffie_hellman_group_t group)
|
private_crypto_factory_t *this, diffie_hellman_group_t group, ...)
|
||||||
{
|
{
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
entry_t *entry;
|
entry_t *entry;
|
||||||
@@ -320,7 +320,21 @@ METHOD(crypto_factory_t, create_dh, diffie_hellman_t*,
|
|||||||
{
|
{
|
||||||
if (entry->algo == group)
|
if (entry->algo == group)
|
||||||
{
|
{
|
||||||
diffie_hellman = entry->create_dh(group);
|
if (group == MODP_CUSTOM)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
chunk_t g, p;
|
||||||
|
|
||||||
|
va_start(args, group);
|
||||||
|
g = va_arg(args, chunk_t);
|
||||||
|
p = va_arg(args, chunk_t);
|
||||||
|
va_end(args);
|
||||||
|
diffie_hellman = entry->create_dh(MODP_CUSTOM, g, p);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
diffie_hellman = entry->create_dh(group);
|
||||||
|
}
|
||||||
if (diffie_hellman)
|
if (diffie_hellman)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -65,8 +65,11 @@ typedef rng_t* (*rng_constructor_t)(rng_quality_t quality);
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor function for diffie hellman
|
* Constructor function for diffie hellman
|
||||||
|
*
|
||||||
|
* The DH constructor accepts additional arguments for:
|
||||||
|
* - MODP_CUSTOM: chunk_t generator, chunk_t prime
|
||||||
*/
|
*/
|
||||||
typedef diffie_hellman_t* (*dh_constructor_t)(diffie_hellman_group_t group);
|
typedef diffie_hellman_t* (*dh_constructor_t)(diffie_hellman_group_t group, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles crypto modules and creates instances.
|
* Handles crypto modules and creates instances.
|
||||||
@@ -129,11 +132,13 @@ struct crypto_factory_t {
|
|||||||
/**
|
/**
|
||||||
* Create a diffie hellman instance.
|
* Create a diffie hellman instance.
|
||||||
*
|
*
|
||||||
|
* Additional arguments are passed to the DH constructor.
|
||||||
|
*
|
||||||
* @param group diffie hellman group
|
* @param group diffie hellman group
|
||||||
* @return diffie_hellman_t instance, NULL if not supported
|
* @return diffie_hellman_t instance, NULL if not supported
|
||||||
*/
|
*/
|
||||||
diffie_hellman_t* (*create_dh)(crypto_factory_t *this,
|
diffie_hellman_t* (*create_dh)(crypto_factory_t *this,
|
||||||
diffie_hellman_group_t group);
|
diffie_hellman_group_t group, ...);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a crypter constructor.
|
* Register a crypter constructor.
|
||||||
|
|||||||
@@ -38,9 +38,10 @@ ENUM_NEXT(diffie_hellman_group_names, MODP_1024_160, ECP_224_BIT, ECP_521_BIT,
|
|||||||
"MODP_2048_256",
|
"MODP_2048_256",
|
||||||
"ECP_192",
|
"ECP_192",
|
||||||
"ECP_224");
|
"ECP_224");
|
||||||
ENUM_NEXT(diffie_hellman_group_names, MODP_NULL, MODP_NULL, ECP_224_BIT,
|
ENUM_NEXT(diffie_hellman_group_names, MODP_NULL, MODP_CUSTOM, ECP_224_BIT,
|
||||||
"MODP_NULL");
|
"MODP_NULL",
|
||||||
ENUM_END(diffie_hellman_group_names, MODP_NULL);
|
"MODP_CUSTOM");
|
||||||
|
ENUM_END(diffie_hellman_group_names, MODP_CUSTOM);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -57,6 +57,8 @@ enum diffie_hellman_group_t {
|
|||||||
ECP_224_BIT = 26,
|
ECP_224_BIT = 26,
|
||||||
/** insecure NULL diffie hellman group for testing, in PRIVATE USE */
|
/** insecure NULL diffie hellman group for testing, in PRIVATE USE */
|
||||||
MODP_NULL = 1024,
|
MODP_NULL = 1024,
|
||||||
|
/** MODP group with custon generator, prime */
|
||||||
|
MODP_CUSTOM = 1025,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user