Annotation of embedaddon/strongswan/src/libcharon/sa/keymat.c, revision 1.1

1.1     ! misho       1: /*
        !             2:  * Copyright (C) 2011 Tobias Brunner
        !             3:  * HSR Hochschule fuer Technik Rapperswil
        !             4:  *
        !             5:  * This program is free software; you can redistribute it and/or modify it
        !             6:  * under the terms of the GNU General Public License as published by the
        !             7:  * Free Software Foundation; either version 2 of the License, or (at your
        !             8:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
        !             9:  *
        !            10:  * This program is distributed in the hope that it will be useful, but
        !            11:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
        !            12:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
        !            13:  * for more details.
        !            14:  */
        !            15: 
        !            16: #include "keymat.h"
        !            17: 
        !            18: #include <sa/ikev1/keymat_v1.h>
        !            19: #include <sa/ikev2/keymat_v2.h>
        !            20: 
        !            21: static keymat_constructor_t keymat_v1_ctor = NULL, keymat_v2_ctor = NULL;
        !            22: 
        !            23: /**
        !            24:  * See header
        !            25:  */
        !            26: keymat_t *keymat_create(ike_version_t version, bool initiator)
        !            27: {
        !            28:        keymat_t *keymat = NULL;
        !            29: 
        !            30:        switch (version)
        !            31:        {
        !            32:                case IKEV1:
        !            33: #ifdef USE_IKEV1
        !            34:                        keymat = keymat_v1_ctor ? keymat_v1_ctor(initiator)
        !            35:                                                                        : &keymat_v1_create(initiator)->keymat;
        !            36: #endif
        !            37:                        break;
        !            38:                case IKEV2:
        !            39: #ifdef USE_IKEV2
        !            40:                        keymat = keymat_v2_ctor ? keymat_v2_ctor(initiator)
        !            41:                                                                        : &keymat_v2_create(initiator)->keymat;
        !            42: #endif
        !            43:                        break;
        !            44:                default:
        !            45:                        break;
        !            46:        }
        !            47:        return keymat;
        !            48: }
        !            49: 
        !            50: /**
        !            51:  * Implicit key length for an algorithm
        !            52:  */
        !            53: typedef struct {
        !            54:        /** IKEv2 algorithm identifier */
        !            55:        int alg;
        !            56:        /** key length in bits */
        !            57:        int len;
        !            58: } keylen_entry_t;
        !            59: 
        !            60: /**
        !            61:  * See header.
        !            62:  */
        !            63: int keymat_get_keylen_encr(encryption_algorithm_t alg)
        !            64: {
        !            65:        keylen_entry_t map[] = {
        !            66:                {ENCR_DES,                                       64},
        !            67:                {ENCR_3DES,                                     192},
        !            68:                {ENCR_CHACHA20_POLY1305,        256},
        !            69:        };
        !            70:        int i;
        !            71: 
        !            72:        for (i = 0; i < countof(map); i++)
        !            73:        {
        !            74:                if (map[i].alg == alg)
        !            75:                {
        !            76:                        return map[i].len;
        !            77:                }
        !            78:        }
        !            79:        return 0;
        !            80: }
        !            81: 
        !            82: /**
        !            83:  * See header.
        !            84:  */
        !            85: int keymat_get_keylen_integ(integrity_algorithm_t alg)
        !            86: {
        !            87:        keylen_entry_t map[] = {
        !            88:                {AUTH_HMAC_MD5_96,                      128},
        !            89:                {AUTH_HMAC_MD5_128,                     128},
        !            90:                {AUTH_HMAC_SHA1_96,                     160},
        !            91:                {AUTH_HMAC_SHA1_160,            160},
        !            92:                {AUTH_HMAC_SHA2_256_96,         256},
        !            93:                {AUTH_HMAC_SHA2_256_128,        256},
        !            94:                {AUTH_HMAC_SHA2_384_192,        384},
        !            95:                {AUTH_HMAC_SHA2_512_256,        512},
        !            96:                {AUTH_AES_XCBC_96,                      128},
        !            97:                {AUTH_AES_CMAC_96,                      128},
        !            98:        };
        !            99:        int i;
        !           100: 
        !           101:        for (i = 0; i < countof(map); i++)
        !           102:        {
        !           103:                if (map[i].alg == alg)
        !           104:                {
        !           105:                        return map[i].len;
        !           106:                }
        !           107:        }
        !           108:        return 0;
        !           109: }
        !           110: 
        !           111: /**
        !           112:  * See header.
        !           113:  */
        !           114: void keymat_register_constructor(ike_version_t version,
        !           115:                                                                 keymat_constructor_t create)
        !           116: {
        !           117:        switch (version)
        !           118:        {
        !           119:                case IKEV1:
        !           120:                        keymat_v1_ctor = create;
        !           121:                        break;
        !           122:                case IKEV2:
        !           123:                        keymat_v2_ctor = create;
        !           124:                        break;
        !           125:                default:
        !           126:                        break;
        !           127:        }
        !           128: }

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