libimcv: Moved REST API from imv_swid and imv_swima to libimcv
[strongswan.git] / src / libsimaka / simaka_message.h
index 0fd21ad..2393d34 100644 (file)
 #ifndef SIMAKA_MESSAGE_H_
 #define SIMAKA_MESSAGE_H_
 
-#include <enum.h>
-#include <daemon.h>
+#include <utils/utils.h>
+#include <eap/eap.h>
 
 #include "simaka_crypto.h"
 
-typedef struct simaka_message_t simaka_message_t;
 typedef enum simaka_attribute_t simaka_attribute_t;
 typedef enum simaka_subtype_t simaka_subtype_t;
 typedef enum simaka_notification_t simaka_notification_t;
 typedef enum simaka_client_error_t simaka_client_error_t;
+typedef struct simaka_message_t simaka_message_t;
 
 /**
  * Subtypes of EAP-SIM/AKA messages
@@ -176,7 +176,7 @@ struct simaka_message_t {
         *
         * @return                      EAP message identifier
         */
-       u_int8_t (*get_identifier)(simaka_message_t *this);
+       uint8_t (*get_identifier)(simaka_message_t *this);
 
        /**
         * Get the EAP type of the message.
@@ -214,12 +214,14 @@ struct simaka_message_t {
         * Parse a message, with optional attribute decryption.
         *
         * This method does not verify message integrity, as the key is available
-        * only after the payload has been parsed.
+        * only after the payload has been parsed. It might be necessary to call
+        * parse twice, as key derivation data in EAP-SIM/AKA is in the same
+        * packet as encrypted data.
         *
         * @param crypto        EAP-SIM/AKA crypto helper
         * @return                      TRUE if message parsed successfully
         */
-       bool (*parse)(simaka_message_t *this, simaka_crypto_t *crypto);
+       bool (*parse)(simaka_message_t *this);
 
        /**
         * Verify the message integrity of a parsed message.
@@ -228,18 +230,16 @@ struct simaka_message_t {
         * @param sigdata       additional data to include in signature, if any
         * @return                      TRUE if message integrity check successful
         */
-       bool (*verify)(simaka_message_t *this, simaka_crypto_t *crypto,
-                                  chunk_t sigdata);
+       bool (*verify)(simaka_message_t *this, chunk_t sigdata);
 
        /**
         * Generate a message, optionally encrypt attributes and create a MAC.
         *
-        * @param crypto        EAP-SIM/AKA crypto helper
         * @param sigdata       additional data to include in signature, if any
-        * @return                      generated eap payload, NULL if failed
+        * @param gen           allocated generated data, if successful
+        * @return                      TRUE if successful
         */
-       eap_payload_t* (*generate)(simaka_message_t *this, simaka_crypto_t *crypto,
-                                                          chunk_t sigdata);
+       bool (*generate)(simaka_message_t *this, chunk_t sigdata, chunk_t *gen);
 
        /**
         * Destroy a simaka_message_t.
@@ -254,17 +254,21 @@ struct simaka_message_t {
  * @param identifier   EAP message identifier
  * @param type                 EAP type: EAP-SIM or EAP-AKA
  * @param subtype              subtype of the EAP message
+ * @param crypto               EAP-SIM/AKA crypto helper
  * @return                             empty message of requested kind, NULL on error
  */
-simaka_message_t *simaka_message_create(bool request, u_int8_t identifier,
-                                                               eap_type_t type, simaka_subtype_t subtype);
+simaka_message_t *simaka_message_create(bool request, uint8_t identifier,
+                                                                       eap_type_t type, simaka_subtype_t subtype,
+                                                                       simaka_crypto_t *crypto);
 
 /**
  * Create an simaka_message from a chunk of data.
  *
- * @param payload              payload to create message from
+ * @param data                 message data to parse
+ * @param crypto               EAP-SIM/AKA crypto helper
  * @return                             EAP message, NULL on error
  */
-simaka_message_t *simaka_message_create_from_payload(eap_payload_t *payload);
+simaka_message_t *simaka_message_create_from_payload(chunk_t data,
+                                                                                                        simaka_crypto_t *crypto);
 
 #endif /** SIMAKA_MESSAGE_H_ @}*/