Annotation of embedaddon/strongswan/src/libstrongswan/crypto/prfs/prf.h, revision 1.1

1.1     ! misho       1: /*
        !             2:  * Copyright (C) 2018 Tobias Brunner
        !             3:  * Copyright (C) 2005-2006 Martin Willi
        !             4:  * Copyright (C) 2005 Jan Hutter
        !             5:  * HSR Hochschule fuer Technik Rapperswil
        !             6:  *
        !             7:  * This program is free software; you can redistribute it and/or modify it
        !             8:  * under the terms of the GNU General Public License as published by the
        !             9:  * Free Software Foundation; either version 2 of the License, or (at your
        !            10:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
        !            11:  *
        !            12:  * This program is distributed in the hope that it will be useful, but
        !            13:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
        !            14:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
        !            15:  * for more details.
        !            16:  */
        !            17: 
        !            18: /**
        !            19:  * @defgroup prf prf
        !            20:  * @{ @ingroup crypto
        !            21:  */
        !            22: 
        !            23: #ifndef PRF_H_
        !            24: #define PRF_H_
        !            25: 
        !            26: typedef enum pseudo_random_function_t pseudo_random_function_t;
        !            27: typedef struct prf_t prf_t;
        !            28: 
        !            29: #include <utils/utils.h>
        !            30: #include <utils/chunk.h>
        !            31: 
        !            32: /**
        !            33:  * Pseudo random function, as in IKEv2 RFC 3.3.2.
        !            34:  *
        !            35:  * PRF algorithms not defined in IKEv2 are allocated in "private use" space.
        !            36:  */
        !            37: enum pseudo_random_function_t {
        !            38:        PRF_UNDEFINED = 1024,
        !            39:        /** RFC2104 */
        !            40:        PRF_HMAC_MD5 = 1,
        !            41:        /** RFC2104 */
        !            42:        PRF_HMAC_SHA1 = 2,
        !            43:        /** RFC2104 */
        !            44:        PRF_HMAC_TIGER = 3,
        !            45:        /** RFC4434 */
        !            46:        PRF_AES128_XCBC = 4,
        !            47:        /** RFC4868 */
        !            48:        PRF_HMAC_SHA2_256 = 5,
        !            49:        /** RFC4868. */
        !            50:        PRF_HMAC_SHA2_384 = 6,
        !            51:        /** RFC4868 */
        !            52:        PRF_HMAC_SHA2_512 = 7,
        !            53:        /** RFC4615 */
        !            54:        PRF_AES128_CMAC = 8,
        !            55:        /** FIPS 186-2-change1 */
        !            56:        PRF_FIPS_SHA1_160 = 1025,
        !            57:        /** FIPS 186-2-change1, uses fixed output size of 160bit */
        !            58:        PRF_FIPS_DES = 1026,
        !            59:        /** Keyed hash algorithm using SHA1, used in EAP-AKA:
        !            60:         * This PRF uses SHA1, but XORs the key into the IV. No "Final()" operation
        !            61:         * is applied to the SHA1 state. */
        !            62:        PRF_KEYED_SHA1 = 1027,
        !            63:        /** draft-kanno-ipsecme-camellia-xcbc, not yet assigned by IANA */
        !            64:        PRF_CAMELLIA128_XCBC = 1028,
        !            65: };
        !            66: 
        !            67: /**
        !            68:  * enum name for encryption_algorithm_t.
        !            69:  */
        !            70: extern enum_name_t *pseudo_random_function_names;
        !            71: 
        !            72: /**
        !            73:  * Generic interface for pseudo-random-functions.
        !            74:  */
        !            75: struct prf_t {
        !            76: 
        !            77:        /**
        !            78:         * Generates pseudo random bytes and writes them in the buffer.
        !            79:         *
        !            80:         * @param seed          a chunk containing the seed for the next bytes
        !            81:         * @param buffer        pointer where the generated bytes will be written
        !            82:         * @return                      TRUE if bytes generated successfully
        !            83:         */
        !            84:        bool (*get_bytes)(prf_t *this, chunk_t seed,
        !            85:                                          uint8_t *buffer) __attribute__((warn_unused_result));
        !            86: 
        !            87:        /**
        !            88:         * Generates pseudo random bytes and allocate space for them.
        !            89:         *
        !            90:         * @param seed          a chunk containing the seed for the next bytes
        !            91:         * @param chunk         chunk which will hold generated bytes
        !            92:         * @return                      TRUE if bytes allocated and generated successfully
        !            93:         */
        !            94:        bool (*allocate_bytes)(prf_t *this, chunk_t seed,
        !            95:                                                   chunk_t *chunk) __attribute__((warn_unused_result));
        !            96: 
        !            97:        /**
        !            98:         * Get the block size of this prf_t object.
        !            99:         *
        !           100:         * @return                      block size in bytes
        !           101:         */
        !           102:        size_t (*get_block_size)(prf_t *this);
        !           103: 
        !           104:        /**
        !           105:         * Get the key size of this prf_t object.
        !           106:         *
        !           107:         * This is a suggestion only, all implemented PRFs accept variable key
        !           108:         * length.
        !           109:         *
        !           110:         * @return                      key size in bytes
        !           111:         */
        !           112:        size_t (*get_key_size)(prf_t *this);
        !           113: 
        !           114:        /**
        !           115:         * Set the key for this prf_t object.
        !           116:         *
        !           117:         * @param key           key to set
        !           118:         * @return                      TRUE if key set successfully
        !           119:         */
        !           120:        bool (*set_key)(prf_t *this,
        !           121:                                        chunk_t key) __attribute__((warn_unused_result));
        !           122: 
        !           123:        /**
        !           124:         * Destroys a prf object.
        !           125:         */
        !           126:        void (*destroy)(prf_t *this);
        !           127: };
        !           128: 
        !           129: /**
        !           130:  * Conversion of ASN.1 OID to PRF algorithm.
        !           131:  *
        !           132:  * @param oid                  ASN.1 OID
        !           133:  * @return                             encryption algorithm, PRF_UNDEFINED if OID unsupported
        !           134:  */
        !           135: pseudo_random_function_t pseudo_random_function_from_oid(int oid);
        !           136: 
        !           137: #endif /** PRF_H_ @}*/

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