2005-11-18 08:19:12 +00:00
|
|
|
/**
|
|
|
|
* @file diffie_hellman.h
|
|
|
|
*
|
2005-11-24 16:22:04 +00:00
|
|
|
* @brief Interface of diffie_hellman_t.
|
2005-11-18 08:19:12 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2005 Jan Hutter, Martin Willi
|
|
|
|
* Hochschule fuer Technik Rapperswil
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
|
|
|
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
|
|
* for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef DIFFIE_HELLMAN_H_
|
|
|
|
#define DIFFIE_HELLMAN_H_
|
|
|
|
|
2005-11-23 09:24:35 +00:00
|
|
|
#include <types.h>
|
2005-11-24 16:22:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
typedef enum diffie_hellman_group_t diffie_hellman_group_t;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Diffie-Hellman group.
|
|
|
|
*
|
|
|
|
* The modulus (or group) to use for a Diffie-Hellman calculation.
|
|
|
|
*
|
2006-03-07 09:42:15 +00:00
|
|
|
* See IKEv2 RFC 3.3.2 and RFC 3526.
|
2005-12-06 15:10:11 +00:00
|
|
|
*
|
2005-11-29 06:59:05 +00:00
|
|
|
* @ingroup transforms
|
2005-11-24 16:22:04 +00:00
|
|
|
*/
|
|
|
|
enum diffie_hellman_group_t {
|
|
|
|
MODP_UNDEFINED = 1024,
|
|
|
|
MODP_768_BIT = 1,
|
|
|
|
MODP_1024_BIT = 2,
|
|
|
|
MODP_1536_BIT = 5,
|
|
|
|
MODP_2048_BIT = 14,
|
|
|
|
MODP_3072_BIT = 15,
|
|
|
|
MODP_4096_BIT = 16,
|
|
|
|
MODP_6144_BIT = 17,
|
|
|
|
MODP_8192_BIT = 18
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2005-12-06 15:10:11 +00:00
|
|
|
* String mappings for diffie_hellman_group_t.
|
2005-11-24 16:22:04 +00:00
|
|
|
*/
|
|
|
|
extern mapping_t diffie_hellman_group_m[];
|
|
|
|
|
2005-11-18 08:19:12 +00:00
|
|
|
|
2005-11-24 11:30:19 +00:00
|
|
|
typedef struct diffie_hellman_t diffie_hellman_t;
|
|
|
|
|
2005-11-18 08:19:12 +00:00
|
|
|
/**
|
2005-11-24 16:22:04 +00:00
|
|
|
* @brief Implementation of the widely used Diffie-Hellman algorithm.
|
2005-11-18 08:19:12 +00:00
|
|
|
*
|
2005-12-06 15:10:11 +00:00
|
|
|
* @b Constructors:
|
|
|
|
* - diffie_hellman_create()
|
|
|
|
*
|
2005-11-24 16:22:04 +00:00
|
|
|
* @ingroup transforms
|
2005-11-18 08:19:12 +00:00
|
|
|
*/
|
2005-11-24 11:30:19 +00:00
|
|
|
struct diffie_hellman_t {
|
2005-11-18 08:19:12 +00:00
|
|
|
|
|
|
|
/**
|
2005-11-24 16:22:04 +00:00
|
|
|
* @brief Returns the shared secret of this diffie hellman exchange.
|
2005-11-18 08:19:12 +00:00
|
|
|
*
|
2005-11-24 16:22:04 +00:00
|
|
|
* @warning Space for returned secret is allocated and must be
|
|
|
|
* freed by the caller.
|
2005-11-18 08:19:12 +00:00
|
|
|
*
|
|
|
|
* @param this calling diffie_hellman_t object
|
|
|
|
* @param[out] secret shared secret will be written into this chunk
|
|
|
|
* @return
|
2005-12-06 15:10:11 +00:00
|
|
|
* - SUCCESS
|
2005-11-18 08:19:12 +00:00
|
|
|
* - FAILED if not both DH values are set
|
|
|
|
*/
|
|
|
|
status_t (*get_shared_secret) (diffie_hellman_t *this, chunk_t *secret);
|
|
|
|
|
|
|
|
/**
|
2005-11-24 16:22:04 +00:00
|
|
|
* @brief Sets the public value of partner.
|
2005-11-18 08:19:12 +00:00
|
|
|
*
|
2005-12-06 15:10:11 +00:00
|
|
|
* chunk gets cloned and can be destroyed afterwards.
|
2005-11-18 08:19:12 +00:00
|
|
|
*
|
|
|
|
* @param this calling diffie_hellman_t object
|
|
|
|
* @param public_value public value of partner
|
|
|
|
*/
|
2005-11-28 20:29:47 +00:00
|
|
|
void (*set_other_public_value) (diffie_hellman_t *this, chunk_t public_value);
|
2005-11-18 08:19:12 +00:00
|
|
|
|
|
|
|
/**
|
2005-11-24 16:22:04 +00:00
|
|
|
* @brief Gets the public value of partner.
|
2005-11-18 08:19:12 +00:00
|
|
|
*
|
2005-12-06 15:10:11 +00:00
|
|
|
* @warning Space for returned chunk is allocated and must be
|
|
|
|
* freed by the caller.
|
2005-11-18 08:19:12 +00:00
|
|
|
*
|
|
|
|
* @param this calling diffie_hellman_t object
|
2005-11-24 16:22:04 +00:00
|
|
|
* @param[out] public_value public value of partner is stored at this location
|
2005-11-18 08:19:12 +00:00
|
|
|
* @return
|
2005-12-06 15:10:11 +00:00
|
|
|
* - SUCCESS
|
2005-11-18 08:19:12 +00:00
|
|
|
* - FAILED if other public value not set
|
|
|
|
*/
|
|
|
|
status_t (*get_other_public_value) (diffie_hellman_t *this, chunk_t *public_value);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Gets the public value of caller
|
|
|
|
*
|
2005-12-06 15:10:11 +00:00
|
|
|
* @warning Space for returned chunk is allocated and must be
|
|
|
|
* freed by the caller.
|
2005-11-18 08:19:12 +00:00
|
|
|
*
|
|
|
|
* @param this calling diffie_hellman_t object
|
2005-11-28 20:29:47 +00:00
|
|
|
* @param[out] public_value public value of caller is stored at this location
|
2005-11-18 08:19:12 +00:00
|
|
|
*/
|
2005-11-29 06:58:34 +00:00
|
|
|
void (*get_my_public_value) (diffie_hellman_t *this, chunk_t *public_value);
|
2006-02-14 14:52:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get the DH group used.
|
|
|
|
*
|
|
|
|
* @param this calling diffie_hellman_t object
|
|
|
|
* @return DH group set in construction
|
|
|
|
*/
|
|
|
|
diffie_hellman_group_t (*get_dh_group) (diffie_hellman_t *this);
|
2005-11-18 08:19:12 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Destroys an diffie_hellman_t object.
|
|
|
|
*
|
2005-11-24 16:22:04 +00:00
|
|
|
* @param this diffie_hellman_t object to destroy
|
2005-11-18 08:19:12 +00:00
|
|
|
*/
|
2005-11-28 20:29:47 +00:00
|
|
|
void (*destroy) (diffie_hellman_t *this);
|
2005-11-18 08:19:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2005-11-24 16:22:04 +00:00
|
|
|
* @brief Creates a new diffie_hellman_t object.
|
2005-11-18 08:19:12 +00:00
|
|
|
*
|
2005-11-24 16:22:04 +00:00
|
|
|
* The first diffie hellman public value gets automatically created.
|
2005-11-18 08:19:12 +00:00
|
|
|
*
|
|
|
|
* @param dh_group_number Diffie Hellman group number to use
|
|
|
|
* @return
|
2005-11-28 20:29:47 +00:00
|
|
|
* - diffie_hellman_t object
|
|
|
|
* - NULL if dh group not supported
|
2005-11-24 16:22:04 +00:00
|
|
|
*
|
|
|
|
* @ingroup transforms
|
2005-11-18 08:19:12 +00:00
|
|
|
*/
|
2005-11-18 14:40:15 +00:00
|
|
|
diffie_hellman_t *diffie_hellman_create(diffie_hellman_group_t dh_group_number);
|
2005-11-18 08:19:12 +00:00
|
|
|
|
|
|
|
#endif /*DIFFIE_HELLMAN_H_*/
|