Annotation of embedaddon/strongswan/src/libcharon/encoding/payloads/encrypted_payload.h, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2014-2018 Tobias Brunner
                      3:  * Copyright (C) 2005-2010 Martin Willi
                      4:  * Copyright (C) 2010 revosec AG
                      5:  * Copyright (C) 2005 Jan Hutter
                      6:  * HSR Hochschule fuer Technik Rapperswil
                      7:  *
                      8:  * This program is free software; you can redistribute it and/or modify it
                      9:  * under the terms of the GNU General Public License as published by the
                     10:  * Free Software Foundation; either version 2 of the License, or (at your
                     11:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
                     12:  *
                     13:  * This program is distributed in the hope that it will be useful, but
                     14:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     15:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
                     16:  * for more details.
                     17:  */
                     18: 
                     19: /**
                     20:  * @defgroup encrypted_payload encrypted_payload
                     21:  * @{ @ingroup payloads
                     22:  */
                     23: 
                     24: #ifndef ENCRYPTED_PAYLOAD_H_
                     25: #define ENCRYPTED_PAYLOAD_H_
                     26: 
                     27: typedef struct encrypted_payload_t encrypted_payload_t;
                     28: 
                     29: #include <library.h>
                     30: #include <crypto/aead.h>
                     31: #include <encoding/payloads/payload.h>
                     32: #include <encoding/generator.h>
                     33: 
                     34: /**
                     35:  * The encrypted payload as described in RFC section 3.14.
                     36:  */
                     37: struct encrypted_payload_t {
                     38: 
                     39:        /**
                     40:         * Implements payload_t interface.
                     41:         */
                     42:        payload_t payload_interface;
                     43: 
                     44:        /**
                     45:         * Get the payload length.
                     46:         *
                     47:         * @return                      (expected) payload length
                     48:         */
                     49:        size_t (*get_length)(encrypted_payload_t *this);
                     50: 
                     51:        /**
                     52:         * Adds a payload to this encryption payload.
                     53:         *
                     54:         * @param payload               payload_t object to add
                     55:         */
                     56:        void (*add_payload) (encrypted_payload_t *this, payload_t *payload);
                     57: 
                     58:        /**
                     59:         * Remove the first payload in the list
                     60:         *
                     61:         * @param payload               removed payload
                     62:         * @return                              payload, NULL if none left
                     63:         */
                     64:        payload_t* (*remove_payload)(encrypted_payload_t *this);
                     65: 
                     66:        /**
                     67:         * Uses the given generator to generate the contained payloads.
                     68:         *
                     69:         * @param generator             generator used to generate the contained payloads
                     70:         */
                     71:        void (*generate_payloads)(encrypted_payload_t *this,
                     72:                                                          generator_t *generator);
                     73: 
                     74:        /**
                     75:         * Set the AEAD transform to use.
                     76:         *
                     77:         * @param aead                  aead transform to use
                     78:         */
                     79:        void (*set_transform)(encrypted_payload_t *this, aead_t *aead);
                     80: 
                     81:        /**
                     82:         * Get the AEAD transform that to use (or was used).
                     83:         *
                     84:         * @param aead                  aead transform to use (or was used)
                     85:         */
                     86:        aead_t *(*get_transform)(encrypted_payload_t *this);
                     87: 
                     88:        /**
                     89:         * Generate, encrypt and sign contained payloads.
                     90:         *
                     91:         * @param mid                   message ID
                     92:         * @param assoc                 associated data
                     93:         * @return
                     94:         *                                              - SUCCESS if encryption successful
                     95:         *                                              - FAILED if encryption failed
                     96:         *                                              - INVALID_STATE if aead not supplied, but needed
                     97:         */
                     98:        status_t (*encrypt) (encrypted_payload_t *this, uint64_t mid,
                     99:                                                 chunk_t assoc);
                    100: 
                    101:        /**
                    102:         * Decrypt, verify and parse contained payloads.
                    103:         *
                    104:         * @param assoc                 associated data
                    105:         * @return
                    106:         *                                              - SUCCESS if parsing successful
                    107:         *                                              - PARSE_ERROR if sub-payload parsing failed
                    108:         *                                              - VERIFY_ERROR if sub-payload verification failed
                    109:         *                                              - FAILED if integrity check failed
                    110:         *                                              - INVALID_STATE if aead not supplied, but needed
                    111:         */
                    112:        status_t (*decrypt) (encrypted_payload_t *this, chunk_t assoc);
                    113: 
                    114:        /**
                    115:         * Destroys an encrypted_payload_t object.
                    116:         */
                    117:        void (*destroy) (encrypted_payload_t *this);
                    118: };
                    119: 
                    120: /**
                    121:  * Creates an empty encrypted_payload_t object.
                    122:  *
                    123:  * @param type         PLV2_ENCRYPTED or PLV1_ENCRYPTED
                    124:  * @return                     encrypted_payload_t object
                    125:  */
                    126: encrypted_payload_t *encrypted_payload_create(payload_type_t type);
                    127: 
                    128: /**
                    129:  * Creates an encrypted payload with the given plain text data and next payload
                    130:  * type.
                    131:  *
                    132:  * @param next         next payload type
                    133:  * @param plain                plaintext data (gets adopted)
                    134:  * @return                     encrypted_payload_t object
                    135:  */
                    136: encrypted_payload_t *encrypted_payload_create_from_plain(payload_type_t next,
                    137:                                                                                                                 chunk_t plain);
                    138: 
                    139: #endif /** ENCRYPTED_PAYLOAD_H_ @}*/

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>