SKE: support for simplified key exchange
[silc.git] / lib / silcske / silcske.h
index 62880540918541e8a8ce4359e9b3d47db16921ea..ecb529fb210a5bf2fa4983790b0d3f16e65f26da 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2000 - 2006 Pekka Riikonen
+  Copyright (C) 2000 - 2014 Pekka Riikonen
 
   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
@@ -75,6 +75,7 @@ typedef enum {
   SILC_SKE_STATUS_SIGNATURE_ERROR,            /* Error computing signature */
   SILC_SKE_STATUS_OUT_OF_MEMORY,              /* System out of memory */
   SILC_SKE_STATUS_TIMEOUT,                    /* Timeout */
+  SILC_SKE_STATUS_PROBE_TIMEOUT,              /* Probe timeout */
 } SilcSKEStatus;
 /***/
 
@@ -116,7 +117,7 @@ typedef enum {
  *
  * SOURCE
  */
-typedef struct {
+typedef struct SilcSKESecurityPropertiesStruct {
   SilcSKESecurityPropertyFlag flags;    /* Flags */
   SilcSKEDiffieHellmanGroup group;      /* Selected Diffie Hellman group */
   SilcCipher cipher;                    /* Selected cipher */
@@ -142,16 +143,16 @@ typedef struct {
  *
  * SOURCE
  */
-typedef struct {
+typedef struct SilcSKEKeyMaterialStruct {
   unsigned char *send_iv;
   unsigned char *receive_iv;
   SilcUInt32 iv_len;
   unsigned char *send_enc_key;
   unsigned char *receive_enc_key;
-  SilcUInt32 enc_key_len;
+  SilcUInt32 enc_key_len;             /* Key length in bits */
   unsigned char *send_hmac_key;
   unsigned char *receive_hmac_key;
-  SilcUInt32 hmac_key_len;
+  SilcUInt32 hmac_key_len;            /* Key length in bytes */
 } *SilcSKEKeyMaterial;
 /***/
 
@@ -171,7 +172,7 @@ typedef struct {
  *    function.
  *
  ***/
-typedef struct {
+typedef struct SilcSKERekeyMaterialStruct {
   unsigned char *send_enc_key;
   char *hash;
   unsigned int enc_key_len  : 23;
@@ -192,7 +193,7 @@ typedef struct {
  *
  * SOURCE
  */
-typedef struct {
+typedef struct SilcSKEParamsObject {
   /* The SKE version string that is sent to the remote end.  This field
      must be set.  Caller must free the pointer. */
   char *version;
@@ -207,6 +208,29 @@ typedef struct {
      the key exchange protocol.  Ignored without SILC_SKE_SP_FLAG_IV_INCLUDED
      flag. */
   SilcUInt16 session_port;
+
+  /* Key exchange timeout in seconds.  If key exchange is not completed in
+     this time it will timeout.  If not specified (zero), default value
+     (30 seconds) will be used. */
+  SilcUInt16 timeout_secs;
+
+  /* Same as timeout_secs but affects only the first packet sent as
+     initiator.  If the responder does not reply to the first packet in this
+     time frame the key exchange will timeout.  If not specified (zero),
+     default value (30 seconds) will be used. */
+  SilcUInt16 probe_timeout_secs;
+
+  /* If TRUE small proposal is sent with only one security property
+     proposed instead of list of all currently registered. */
+  SilcBool small_proposal;
+
+  /* If TRUE protocol does not end in SUCCESS acknowledgements. */
+  SilcBool no_acks;
+
+  /* Pre-allocated security properties to use in negotiation.  If provided
+     the library will perform only key exchange and proposals aren't
+     exchanged at all. */
+  SilcSKESecurityProperties prop;
 } *SilcSKEParams, SilcSKEParamsStruct;
 /***/
 
@@ -347,6 +371,10 @@ typedef void (*SilcSKECompletionCb)(SilcSKE ske,
  *    SILC_SKE_SP_FLAG_MUTUAL is not set and you are initiator.  For
  *    responder both `public_key' and `private_key' must be set.
  *
+ *    When allocating SKE session for rekey, the `repository' and `private_key'
+ *    pointers must be NULL and the SilcSKEVerifyCb callback must not be
+ *    set with silc_ske_set_callbacks.
+ *
  * EXMPALE
  *
  *    // Initiator example
@@ -354,7 +382,7 @@ typedef void (*SilcSKECompletionCb)(SilcSKE ske,
  *    params.flags = SILC_SKE_SP_FLAG_PFS | SILC_SKE_SP_FLAG_MUTUAL;
  *    ske = silc_ske_alloc(rng, scheduler, NULL, pk, prv, app);
  *    silc_ske_set_callbacks(ske, verify_public_key, completion, app);
- *    silc_ske_initiator_start(ske, stream, &params, NULL);
+ *    silc_ske_initiator(ske, stream, &params, NULL);
  *
  ***/
 SilcSKE silc_ske_alloc(SilcRng rng, SilcSchedule schedule,
@@ -404,7 +432,7 @@ void *silc_ske_get_context(SilcSKE ske);
  *    or certificate.  The verification process is most likely asynchronous.
  *    That is why the application must call the completion callback when the
  *    verification process has been completed.  If this SKE session context
- *    is used to perform  rekey, this callback usually is not provided as
+ *    is used to perform rekey, this callback usually is not provided as
  *    argument since sending public key in rekey is not mandatory.  Setting
  *    this callback implies that remote end MUST send its public key.
  *
@@ -421,7 +449,7 @@ void silc_ske_set_callbacks(SilcSKE ske,
                            SilcSKECompletionCb completed,
                            void *context);
 
-/****f* silcske/SilcSKEAPI/silc_ske_initiator_start
+/****f* silcske/SilcSKEAPI/silc_ske_initiator
  *
  * SYNOPSIS
  *
@@ -429,7 +457,7 @@ void silc_ske_set_callbacks(SilcSKE ske,
  *    silc_ske_initiator(SilcSKE ske,
  *                       SilcPacketStream stream,
  *                       SilcSKEParams params,
                        SilcSKEStartPayload start_payload);
*                       SilcSKEStartPayload start_payload);
  *
  * DESCRIPTION
  *
@@ -438,8 +466,9 @@ void silc_ske_set_callbacks(SilcSKE ske,
  *    the protocol has completed.  The `stream' is the network connection
  *    to the remote host.  The SKE library will handle all key exchange
  *    packets sent and received in the `stream' connection.  The library will
- *    also set the remote host's ID automatically to the `stream'.  The
- *    `params' include SKE parameters, and it must be provided.
+ *    also set the remote host's ID automatically to the `stream' if it is
+ *    present in the exchanged packets.  The `params' include SKE parameters,
+ *    and it must be provided.
  *
  *    If the `start_payload' is NULL the library will generate it
  *    automatically.  Caller may provide it if it wants to send its own
@@ -453,11 +482,10 @@ void silc_ske_set_callbacks(SilcSKE ske,
  *    NULL on error.
  *
  ***/
-SilcAsyncOperation
-silc_ske_initiator(SilcSKE ske,
-                  SilcPacketStream stream,
-                  SilcSKEParams params,
-                  SilcSKEStartPayload start_payload);
+SilcAsyncOperation silc_ske_initiator(SilcSKE ske,
+                                     SilcPacketStream stream,
+                                     SilcSKEParams params,
+                                     SilcSKEStartPayload start_payload);
 
 /****f* silcske/SilcSKEAPI/silc_ske_responder
  *
@@ -474,8 +502,10 @@ silc_ske_initiator(SilcSKE ske,
  *    callback that was set in silc_ske_set_callbacks will be called once
  *    the protocol has completed.  The `stream' is the network connection
  *    to the remote host.  The SKE library will handle all key exchange
- *    packets sent and received in the `stream' connection.  The `params'
- *    include SKE parameters, and must be provided.
+ *    packets sent and received in the `stream' connection.  The library will
+ *    also set the remote hosts's ID automatically to the `stream' if it is
+ *    present in the exchanged packets.  The `params' include SKE parameters,
+ *    and must be provided.
  *
  *    This function returns SilcAsyncOperation operation context which can
  *    be used to control the protocol from the application.  Application may
@@ -483,20 +513,73 @@ silc_ske_initiator(SilcSKE ske,
  *    NULL on error.
  *
  ***/
-SilcAsyncOperation
-silc_ske_responder(SilcSKE ske,
-                  SilcPacketStream stream,
-                  SilcSKEParams params);
+SilcAsyncOperation silc_ske_responder(SilcSKE ske,
+                                     SilcPacketStream stream,
+                                     SilcSKEParams params);
 
-SilcAsyncOperation
-silc_ske_rekey_initiator(SilcSKE ske,
-                        SilcPacketStream stream,
-                        SilcSKERekeyMaterial rekey);
+/****f* silcske/SilcSKEAPI/silc_ske_rekey_initiator
+ *
+ * SYNOPSIS
+ *
+ *    SilcAsyncOperation
+ *    silc_ske_rekey_initiator(SilcSKE ske,
+ *                             SilcPacketStream stream,
+ *                             SilcSKERekeyMaterial rekey);
+ *
+ * DESCRIPTION
+ *
+ *    Starts SILC Key Exchange key regeneration (rekey) protocol.  The `rekey'
+ *    is the rekey material received earlier in SilcSKECompletionCb.  That
+ *    same callback is called after the rekey protocol is over to deliver new
+ *    key material and new rekey material.  When the rekey is completed the
+ *    SKE library will automatically update the new keys into `stream'.  The
+ *    completion callback is called after the new keys has been taken into
+ *    use.
+ *
+ *    This function returns SilcAsyncOperation operation context which can
+ *    be used to control the protocol from the application.  Application may
+ *    for example safely abort the protocol at any point, if needed.  Returns
+ *    NULL on error.
+ *
+ ***/
+SilcAsyncOperation silc_ske_rekey_initiator(SilcSKE ske,
+                                           SilcPacketStream stream,
+                                           SilcSKERekeyMaterial rekey);
 
-SilcAsyncOperation
-silc_ske_rekey_responder(SilcSKE ske,
-                        SilcPacketStream stream,
-                        SilcSKERekeyMaterial rekey);
+/****f* silcske/SilcSKEAPI/silc_ske_rekey_responder
+ *
+ * SYNOPSIS
+ *
+ *    SilcAsyncOperation
+ *    silc_ske_rekey_responder(SilcSKE ske,
+ *                             SilcPacketStream stream,
+ *                             SilcSKERekeyMaterial rekey,
+ *                             SilcPacket packet);
+ *
+ * DESCRIPTION
+ *
+ *    Starts SILC Key Exchange key regeneration (rekey) protocol as responder.
+ *    The `rekey' is the rekey material received earlier in
+ *    SilcSKECompletionCb.  That same callback is called after the rekey
+ *    protocol is over to deliver new key material and new rekey material.
+ *    When the rekey is completed the SKE library will automatically update
+ *    the new keys into `stream'.  The completion callback is called after
+ *    the new keys has been taken into use.
+ *
+ *    The `packet' is the SILC_PACKET_REKEY received to start the rekey
+ *    protocol.  If `packet' is NULL it is assumed that the packet will be
+ *    received from the `stream'.
+ *
+ *    This function returns SilcAsyncOperation operation context which can
+ *    be used to control the protocol from the application.  Application may
+ *    for example safely abort the protocol at any point, if needed.  Returns
+ *    NULL on error.
+ *
+ ***/
+SilcAsyncOperation silc_ske_rekey_responder(SilcSKE ske,
+                                           SilcPacketStream stream,
+                                           SilcSKERekeyMaterial rekey,
+                                           SilcPacket packet);
 
 /****f* silcske/SilcSKEAPI/silc_ske_set_keys
  *
@@ -619,7 +702,7 @@ silc_ske_process_key_material_data(unsigned char *data,
  ***/
 void silc_ske_free_key_material(SilcSKEKeyMaterial key);
 
-/****f* silcske/SilcSKEAPI/silc_ske_free_key_material
+/****f* silcske/SilcSKEAPI/silc_ske_free_rekey_material
  *
  * SYNOPSIS
  *