Packet streams: avoid double free if silc_id_id2str fails.
[silc.git] / lib / silccore / silcauth.h
index 6f874d959873f13ea2e394bb23cb9123e595a8eb..39b7c328631e42c27342e3362f745b35a2c31491 100644 (file)
@@ -1,10 +1,10 @@
 /*
 
-  silcauth.h 
+  silcauth.h
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  Copyright (C) 2001 - 2002 Pekka Riikonen
+  Copyright (C) 2001 - 2007 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
@@ -22,8 +22,8 @@
  * DESCRIPTION
  *
  * Implementations of the SILC Authentication Payload and authentication
- * routines.  The SILC Authentication Payload is used to deliver 
- * authentication data usually from client to server in purpose of 
+ * routines.  The SILC Authentication Payload is used to deliver
+ * authentication data usually from client to server in purpose of
  * gaining access to some service.  The Payload and the authentication
  * routines supports both passphrase and public key (signature) based
  * authentication.
@@ -40,7 +40,7 @@
 /****d* silccore/SilcAuthAPI/SilcAuthMethod
  *
  * NAME
- * 
+ *
  *    typedef SilcUInt16 SilcAuthMethod;
  *
  * DESCRIPTION
@@ -57,17 +57,30 @@ typedef SilcUInt16 SilcAuthMethod;
 #define SILC_AUTH_PASSWORD    1                   /* Passphrase authentication */
 #define SILC_AUTH_PUBLIC_KEY  2                   /* Public key authentication */
 
-/* Authentication protocol status message (used by all authentication
-   protocols in the SILC). */
-#define SILC_AUTH_OK          0
-#define SILC_AUTH_FAILED      1
+/****d* silccore/SilcAuthAPI/SilcAuthResult
+ *
+ * NAME
+ *
+ *    typedef SilcUInt32 SilcAuthResult;
+ *
+ * DESCRIPTION
+ *
+ *    Authentication protocol status.  Used by all authentication protocols
+ *    in SILC.
+ *
+ * SOURCE
+ */
+typedef SilcUInt32 SilcAuthResult;
+
+#define SILC_AUTH_OK          0              /* Authentication successful */
+#define SILC_AUTH_FAILED      1                     /* Authentication failed */
 /***/
 
 /****s* silccore/SilcAuthAPI/SilcAuthPayload
  *
  * NAME
- * 
- *    typedef struct SilcAuthPayloadStruct *SilcAuthPayload; 
+ *
+ *    typedef struct SilcAuthPayloadStruct *SilcAuthPayload;
  *
  *
  * DESCRIPTION
@@ -148,6 +161,22 @@ void silc_auth_payload_free(SilcAuthPayload payload);
  ***/
 SilcAuthMethod silc_auth_get_method(SilcAuthPayload payload);
 
+/****f* silccore/SilcAuthAPI/silc_auth_get_public_data
+ *
+ * SYNOPSIS
+ *
+ *    unsigned char *silc_auth_get_public_data(SilcAuthPayload payload,
+ *                                             SilcUInt32 *pubdata_len);
+ *
+ * DESCRIPTION
+ *
+ *    Returns the public data (usually random data) from the payload.
+ *    Caller must not free the returned data.
+ *
+ ***/
+unsigned char *silc_auth_get_public_data(SilcAuthPayload payload,
+                                        SilcUInt32 *pubdata_len);
+
 /****f* silccore/SilcAuthAPI/silc_auth_get_data
  *
  * SYNOPSIS
@@ -173,7 +202,7 @@ unsigned char *silc_auth_get_data(SilcAuthPayload payload,
  *                                                  SilcPrivateKey private_key,
  *                                                  SilcRng rng,
  *                                                  SilcHash hash,
- *                                                  const void *id, 
+ *                                                  const void *id,
  *                                                  SilcIdType type);
  *
  * DESCRIPTION
@@ -195,12 +224,41 @@ SilcBuffer silc_auth_public_key_auth_generate(SilcPublicKey public_key,
                                              SilcRng rng, SilcHash hash,
                                              const void *id, SilcIdType type);
 
+/****f* silccore/SilcAuthAPI/silc_auth_public_key_auth_generate_wpub
+ *
+ * SYNOPSIS
+ *
+ *    SilcBuffer
+ *    silc_auth_public_key_auth_generate_wpub(SilcPublicKey public_key,
+ *                                            SilcPrivateKey private_key,
+ *                                            const unsigned char *pubdata,
+ *                                            SilcUInt32 pubdata_len,
+ *                                            SilcHash hash,
+ *                                            const void *id,
+ *                                            SilcIdType type);
+ *
+ * DESCRIPTION
+ *
+ *    Same as silc_auth_public_key_auth_generate but takes the public data
+ *    (usually random data) as argument.  This function can be used when
+ *    the public data must be something else than purely random or its
+ *    structure mut be set before signing.
+ *
+ ***/
+SilcBuffer
+silc_auth_public_key_auth_generate_wpub(SilcPublicKey public_key,
+                                       SilcPrivateKey private_key,
+                                       const unsigned char *pubdata,
+                                       SilcUInt32 pubdata_len,
+                                       SilcHash hash,
+                                       const void *id, SilcIdType type);
+
 /****f* silccore/SilcAuthAPI/silc_auth_public_key_auth_verify
  *
  * SYNOPSIS
  *
- *    bool silc_auth_public_key_auth_verify(SilcAuthPayload payload,
- *                                          SilcPublicKey public_key, 
+ *    SilcBool silc_auth_public_key_auth_verify(SilcAuthPayload payload,
+ *                                          SilcPublicKey public_key,
  *                                          SilcHash hash,
  *                                          const void *id, SilcIdType type);
  *
@@ -210,19 +268,21 @@ SilcBuffer silc_auth_public_key_auth_generate(SilcPublicKey public_key,
  *    successful.
  *
  ***/
-bool silc_auth_public_key_auth_verify(SilcAuthPayload payload,
-                                     SilcPublicKey public_key, SilcHash hash,
-                                     const void *id, SilcIdType type);
+SilcBool silc_auth_public_key_auth_verify(SilcAuthPayload payload,
+                                         SilcPublicKey public_key,
+                                         SilcHash hash,
+                                         const void *id,
+                                         SilcIdType type);
 
 /****f* silccore/SilcAuthAPI/silc_auth_public_key_auth_verify_data
  *
  * SYNOPSIS
  *
- *    bool silc_auth_public_key_auth_verify_data(const unsigned char *payload,
+ *    SilcBool silc_auth_public_key_auth_verify_data(const unsigned char *payload,
  *                                               SilcUInt32 payload_len,
- *                                               SilcPublicKey public_key, 
+ *                                               SilcPublicKey public_key,
  *                                               SilcHash hash,
- *                                               const void *id, 
+ *                                               const void *id,
  *                                               SilcIdType type);
  *
  * DESCRIPTION
@@ -232,24 +292,25 @@ bool silc_auth_public_key_auth_verify(SilcAuthPayload payload,
  *    was successful.
  *
  ***/
-bool silc_auth_public_key_auth_verify_data(const unsigned char *payload,
-                                          SilcUInt32 payload_len,
-                                          SilcPublicKey public_key, 
-                                          SilcHash hash,
-                                          const void *id, SilcIdType type);
+SilcBool silc_auth_public_key_auth_verify_data(const unsigned char *payload,
+                                              SilcUInt32 payload_len,
+                                              SilcPublicKey public_key,
+                                              SilcHash hash,
+                                              const void *id,
+                                              SilcIdType type);
 
 /****f* silccore/SilcAuthAPI/silc_auth_verify
  *
  * SYNOPSIS
  *
- *    bool silc_auth_verify(SilcAuthPayload payload, 
+ *    SilcBool silc_auth_verify(SilcAuthPayload payload,
  *                          SilcAuthMethod auth_method,
- *                          const void *auth_data, SilcUInt32 auth_data_len, 
+ *                          const void *auth_data, SilcUInt32 auth_data_len,
  *                          SilcHash hash, const void *id, SilcIdType type);
  *
  * DESCRIPTION
  *
- *    Verifies the authentication data directly from the Authentication 
+ *    Verifies the authentication data directly from the Authentication
  *    Payload. Supports all authentication methods. If the authentication
  *    method is passphrase based then the `auth_data' and `auth_data_len'
  *    are the passphrase and its length.  The passphrase MUST be UTF-8
@@ -257,25 +318,25 @@ bool silc_auth_public_key_auth_verify_data(const unsigned char *payload,
  *    `auth_data' is the SilcPublicKey and the `auth_data_len' is ignored.
  *
  ***/
-bool silc_auth_verify(SilcAuthPayload payload, SilcAuthMethod auth_method,
-                     const void *auth_data, SilcUInt32 auth_data_len, 
-                     SilcHash hash, const void *id, SilcIdType type);
+SilcBool silc_auth_verify(SilcAuthPayload payload, SilcAuthMethod auth_method,
+                         const void *auth_data, SilcUInt32 auth_data_len,
+                         SilcHash hash, const void *id, SilcIdType type);
 
 /****f* silccore/SilcAuthAPI/silc_auth_verify_data
  *
  * SYNOPSIS
  *
- *    bool silc_auth_verify_data(const unsigned char *payload, 
+ *    SilcBool silc_auth_verify_data(const unsigned char *payload,
  *                               SilcUInt32 payload_len,
- *                               SilcAuthMethod auth_method, 
+ *                               SilcAuthMethod auth_method,
  *                               const void *auth_data,
- *                               SilcUInt32 auth_data_len, SilcHash hash, 
+ *                               SilcUInt32 auth_data_len, SilcHash hash,
  *                               const void *id, SilcIdType type);
- * 
+ *
  * DESCRIPTION
  *
  *    Same as silc_auth_verify but the payload has not been parsed yet.
- *    Verifies the authentication data directly from the Authentication 
+ *    Verifies the authentication data directly from the Authentication
  *    Payload. Supports all authentication methods. If the authentication
  *    method is passphrase based then the `auth_data' and `auth_data_len'
  *    are the passphrase and its length.  The passphrase MUST be UTF-8
@@ -283,16 +344,17 @@ bool silc_auth_verify(SilcAuthPayload payload, SilcAuthMethod auth_method,
  *    `auth_data' is the SilcPublicKey and the `auth_data_len' is ignored.
  *
  ***/
-bool silc_auth_verify_data(const unsigned char *payload, 
-                          SilcUInt32 payload_len,
-                          SilcAuthMethod auth_method, const void *auth_data,
-                          SilcUInt32 auth_data_len, SilcHash hash, 
-                          const void *id, SilcIdType type);
+SilcBool silc_auth_verify_data(const unsigned char *payload,
+                              SilcUInt32 payload_len,
+                              SilcAuthMethod auth_method,
+                              const void *auth_data,
+                              SilcUInt32 auth_data_len, SilcHash hash,
+                              const void *id, SilcIdType type);
 
 /****s* silccore/SilcAuthAPI/SilcKeyAgreementPayload
  *
  * NAME
- * 
+ *
  *    typedef struct SilcKeyAgreementPayloadStruct *SilcKeyAgreementPayload;
  *
  * DESCRIPTION
@@ -309,7 +371,7 @@ typedef struct SilcKeyAgreementPayloadStruct *SilcKeyAgreementPayload;
  *
  * SYNOPSIS
  *
- *    SilcKeyAgreementPayload 
+ *    SilcKeyAgreementPayload
  *    silc_key_agreement_payload_parse(const unsigned char *payload,
  *                                     SilcUInt32 payload_len);
  *
@@ -318,7 +380,7 @@ typedef struct SilcKeyAgreementPayloadStruct *SilcKeyAgreementPayload;
  *    Parses and returns an allocated Key Agreement payload.
  *
  ***/
-SilcKeyAgreementPayload 
+SilcKeyAgreementPayload
 silc_key_agreement_payload_parse(const unsigned char *payload,
                                 SilcUInt32 payload_len);
 
@@ -327,15 +389,18 @@ silc_key_agreement_payload_parse(const unsigned char *payload,
  * SYNOPSIS
  *
  *    SilcBuffer silc_key_agreement_payload_encode(char *hostname,
- *                                                 SilcUInt32 port);
+ *                                                 SilcUInt16 protocol,
+ *                                                 SilcUInt16 port);
  *
  * DESCRIPTION
  *
- *    Encodes the Key Agreement protocol and returns the encoded buffer
+ *    Encodes the Key Agreement payload and returns the encoded buffer.
+ *    The `protocol' is 0 for TCP and 1 for UDP.
  *
  ***/
 SilcBuffer silc_key_agreement_payload_encode(const char *hostname,
-                                            SilcUInt32 port);
+                                            SilcUInt16 protocol,
+                                            SilcUInt16 port);
 
 /****f* silccore/SilcAuthAPI/silc_key_agreement_payload_free
  *
@@ -345,7 +410,7 @@ SilcBuffer silc_key_agreement_payload_encode(const char *hostname,
  *
  * DESCRIPTION
  *
- *    Frees the Key Agreement protocol and all data in it.
+ *    Frees the Key Agreement payload and all data in it.
  *
  ***/
 void silc_key_agreement_payload_free(SilcKeyAgreementPayload payload);
@@ -365,11 +430,26 @@ void silc_key_agreement_payload_free(SilcKeyAgreementPayload payload);
  ***/
 char *silc_key_agreement_get_hostname(SilcKeyAgreementPayload payload);
 
+/****f* silccore/SilcAuthAPI/silc_key_agreement_get_protocol
+ *
+ * SYNOPSIS
+ *
+ *    SilcUInt16
+ *    silc_key_agreement_get_protocol(SilcKeyAgreementPayload payload);
+ *
+ * DESCRIPTION
+ *
+ *    Returns the protocol in the payload.  The protocol is either TCP (0)
+ *    or UDP (1).
+ *
+ ***/
+SilcUInt16 silc_key_agreement_get_protocol(SilcKeyAgreementPayload payload);
+
 /****f* silccore/SilcAuthAPI/silc_key_agreement_get_port
  *
  * SYNOPSIS
  *
- *    SilcUInt32 silc_key_agreement_get_port(SilcKeyAgreementPayload payload);
+ *    SilcUInt16 silc_key_agreement_get_port(SilcKeyAgreementPayload payload);
  *
  * DESCRIPTION
  *
@@ -378,6 +458,6 @@ char *silc_key_agreement_get_hostname(SilcKeyAgreementPayload payload);
  *    the SILC Key Exchange protocol.
  *
  ***/
-SilcUInt32 silc_key_agreement_get_port(SilcKeyAgreementPayload payload);
+SilcUInt16 silc_key_agreement_get_port(SilcKeyAgreementPayload payload);
 
 #endif