mirror of
https://github.com/strongswan/strongswan.git
synced 2025-10-04 00:00:14 -04:00
key-exchange: Add helper to concatenate shared secrets of several key exchanges
This commit is contained in:
parent
dcd5c945b5
commit
d9d0864349
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2019 Tobias Brunner
|
||||
* Copyright (C) 2010-2020 Tobias Brunner
|
||||
* Copyright (C) 2005-2010 Martin Willi
|
||||
* Copyright (C) 2005 Jan Hutter
|
||||
* HSR Hochschule fuer Technik Rapperswil
|
||||
@ -618,3 +618,43 @@ bool key_exchange_verify_pubkey(key_exchange_method_t ke, chunk_t value)
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
|
||||
/*
|
||||
* Described in header
|
||||
*/
|
||||
bool key_exchange_concat_secrets(array_t *kes, chunk_t *first,
|
||||
chunk_t *others)
|
||||
{
|
||||
key_exchange_t *ke;
|
||||
chunk_t secret;
|
||||
int i;
|
||||
|
||||
if (!array_count(kes))
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
*first = chunk_empty;
|
||||
*others = chunk_empty;
|
||||
for (i = 0; i < array_count(kes); i++)
|
||||
{
|
||||
if (array_get(kes, i, &ke) &&
|
||||
ke->get_shared_secret(ke, &secret))
|
||||
{
|
||||
if (i == 0)
|
||||
{
|
||||
*first = secret;
|
||||
}
|
||||
else
|
||||
{
|
||||
*others = chunk_cat("ss", *others, secret);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
chunk_clear(first);
|
||||
chunk_clear(others);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2019 Tobias Brunner
|
||||
* Copyright (C) 2010-2020 Tobias Brunner
|
||||
* Copyright (C) 2005-2007 Martin Willi
|
||||
* Copyright (C) 2005 Jan Hutter
|
||||
* HSR Hochschule fuer Technik Rapperswil
|
||||
@ -28,6 +28,7 @@ typedef struct key_exchange_t key_exchange_t;
|
||||
typedef struct diffie_hellman_params_t diffie_hellman_params_t;
|
||||
|
||||
#include <library.h>
|
||||
#include <collections/array.h>
|
||||
|
||||
/**
|
||||
* Key exchange method.
|
||||
@ -204,4 +205,16 @@ bool key_exchange_is_ecdh(key_exchange_method_t ke);
|
||||
*/
|
||||
bool key_exchange_verify_pubkey(key_exchange_method_t ke, chunk_t value);
|
||||
|
||||
/**
|
||||
* Return the first shared secret plus the concatenated additional shared
|
||||
* secrets of all the key exchange methods in the given array.
|
||||
*
|
||||
* @param kes array of key_exchange_t*
|
||||
* @param secret first shared secret (allocated)
|
||||
* @param add_secret concatenated additional shared secrets (allocated)
|
||||
* @return TRUE on success
|
||||
*/
|
||||
bool key_exchange_concat_secrets(array_t *kes, chunk_t *secret,
|
||||
chunk_t *add_secret);
|
||||
|
||||
#endif /** KEY_EXCHANGE_H_ @}*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user