proposal: Add IKEv1 transform number on which a proposal is based
authorTobias Brunner <tobias@strongswan.org>
Thu, 6 Feb 2020 14:39:45 +0000 (15:39 +0100)
committerTobias Brunner <tobias@strongswan.org>
Fri, 6 Mar 2020 09:31:30 +0000 (10:31 +0100)
src/libstrongswan/crypto/proposal/proposal.c
src/libstrongswan/crypto/proposal/proposal.h

index 560303f..af2c687 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2008-2018 Tobias Brunner
+ * Copyright (C) 2008-2020 Tobias Brunner
  * Copyright (C) 2006-2010 Martin Willi
  * Copyright (C) 2013-2015 Andreas Steffen
  * HSR Hochschule fuer Technik Rapperswil
@@ -70,7 +70,12 @@ struct private_proposal_t {
        /**
         * Proposal number
         */
-       u_int number;
+       uint8_t number;
+
+       /**
+        * Transform number (IKEv1 only)
+        */
+       uint8_t transform_number;
 };
 
 /**
@@ -455,12 +460,14 @@ METHOD(proposal_t, select_proposal, proposal_t*,
 
        if (flags & PROPOSAL_PREFER_SUPPLIED)
        {
-               selected = proposal_create(this->protocol, this->number);
+               selected = proposal_create_v1(this->protocol, this->number,
+                                                                         this->transform_number);
                selected->set_spi(selected, this->spi);
        }
        else
        {
-               selected = proposal_create(this->protocol, other->get_number(other));
+               selected = proposal_create_v1(this->protocol, other->get_number(other),
+                                                                         other->get_transform_number(other));
                selected->set_spi(selected, other->get_spi(other));
        }
 
@@ -539,12 +546,18 @@ static bool algo_list_equals(private_proposal_t *this, proposal_t *other,
        return equals;
 }
 
-METHOD(proposal_t, get_number, u_int,
+METHOD(proposal_t, get_number, uint8_t,
        private_proposal_t *this)
 {
        return this->number;
 }
 
+METHOD(proposal_t, get_transform_number, uint8_t,
+       private_proposal_t *this)
+{
+       return this->transform_number;
+}
+
 METHOD(proposal_t, equals, bool,
        private_proposal_t *this, proposal_t *other)
 {
@@ -598,6 +611,7 @@ METHOD(proposal_t, clone_, proposal_t*,
 
        clone->spi = this->spi;
        clone->number = this->number;
+       clone->transform_number = this->transform_number;
 
        return &clone->public;
 }
@@ -918,7 +932,8 @@ METHOD(proposal_t, destroy, void,
 /*
  * Described in header
  */
-proposal_t *proposal_create(protocol_id_t protocol, u_int number)
+proposal_t *proposal_create_v1(protocol_id_t protocol, uint8_t number,
+                                                          uint8_t transform)
 {
        private_proposal_t *this;
 
@@ -935,12 +950,14 @@ proposal_t *proposal_create(protocol_id_t protocol, u_int number)
                        .set_spi = _set_spi,
                        .get_spi = _get_spi,
                        .get_number = _get_number,
+                       .get_transform_number = _get_transform_number,
                        .equals = _equals,
                        .clone = _clone_,
                        .destroy = _destroy,
                },
                .protocol = protocol,
                .number = number,
+               .transform_number = transform,
                .transforms = array_create(sizeof(entry_t), 0),
                .types = array_create(sizeof(transform_type_t), 0),
        );
@@ -948,6 +965,14 @@ proposal_t *proposal_create(protocol_id_t protocol, u_int number)
        return &this->public;
 }
 
+/*
+ * Described in header
+ */
+proposal_t *proposal_create(protocol_id_t protocol, uint8_t number)
+{
+       return proposal_create_v1(protocol, number, 0);
+}
+
 /**
  * Add supported IKE algorithms to proposal
  */
index 6a9cdba..b8c2fba 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009-2019 Tobias Brunner
+ * Copyright (C) 2009-2020 Tobias Brunner
  * Copyright (C) 2006 Martin Willi
  * HSR Hochschule fuer Technik Rapperswil
  *
@@ -181,7 +181,14 @@ struct proposal_t {
         *
         * @return                              proposal number
         */
-       u_int (*get_number)(proposal_t *this);
+       uint8_t (*get_number)(proposal_t *this);
+
+       /**
+        * Get number of the transform on which this proposal is based (IKEv1 only)
+        *
+        * @return                              transform number (or 0)
+        */
+       uint8_t (*get_transform_number)(proposal_t *this);
 
        /**
         * Check for the equality of two proposals.
@@ -212,7 +219,18 @@ struct proposal_t {
  * @param number                       proposal number, as encoded in SA payload
  * @return                                     proposal_t object
  */
-proposal_t *proposal_create(protocol_id_t protocol, u_int number);
+proposal_t *proposal_create(protocol_id_t protocol, uint8_t number);
+
+/**
+ * Create a proposal for IKE, ESP or AH that includes a transform number.
+ *
+ * @param protocol                     protocol, such as PROTO_ESP
+ * @param number                       proposal number, as encoded in SA payload
+ * @param transform                    transform number, as encoded in payload
+ * @return                                     proposal_t object
+ */
+proposal_t *proposal_create_v1(protocol_id_t protocol, uint8_t number,
+                                                          uint8_t transform);
 
 /**
  * Create a default proposal.