Annotation of embedaddon/strongswan/src/libstrongswan/plugins/test_vectors/test_vectors_plugin.c, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2009 Martin Willi
                      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 "test_vectors_plugin.h"
                     17: 
                     18: #include <crypto/crypto_factory.h>
                     19: #include <crypto/crypto_tester.h>
                     20: 
                     21: /* define symbols of all test vectors */
                     22: #define TEST_VECTOR_CRYPTER(x) extern crypter_test_vector_t x;
                     23: #define TEST_VECTOR_AEAD(x) extern aead_test_vector_t x;
                     24: #define TEST_VECTOR_SIGNER(x) extern signer_test_vector_t x;
                     25: #define TEST_VECTOR_HASHER(x) extern hasher_test_vector_t x;
                     26: #define TEST_VECTOR_PRF(x) extern prf_test_vector_t x;
                     27: #define TEST_VECTOR_XOF(x) extern xof_test_vector_t x;
                     28: #define TEST_VECTOR_DRBG(x) extern drbg_test_vector_t x;
                     29: #define TEST_VECTOR_RNG(x) extern rng_test_vector_t x;
                     30: #define TEST_VECTOR_DH(x) extern dh_test_vector_t x;
                     31: 
                     32: #include "test_vectors.h"
                     33: 
                     34: #undef TEST_VECTOR_CRYPTER
                     35: #undef TEST_VECTOR_AEAD
                     36: #undef TEST_VECTOR_SIGNER
                     37: #undef TEST_VECTOR_HASHER
                     38: #undef TEST_VECTOR_PRF
                     39: #undef TEST_VECTOR_XOF
                     40: #undef TEST_VECTOR_DRBG
                     41: #undef TEST_VECTOR_RNG
                     42: #undef TEST_VECTOR_DH
                     43: 
                     44: #define TEST_VECTOR_CRYPTER(x)
                     45: #define TEST_VECTOR_AEAD(x)
                     46: #define TEST_VECTOR_SIGNER(x)
                     47: #define TEST_VECTOR_HASHER(x)
                     48: #define TEST_VECTOR_PRF(x)
                     49: #define TEST_VECTOR_XOF(x)
                     50: #define TEST_VECTOR_DRBG(x)
                     51: #define TEST_VECTOR_RNG(x)
                     52: #define TEST_VECTOR_DH(x)
                     53: 
                     54: /* create test vector arrays */
                     55: #undef TEST_VECTOR_CRYPTER
                     56: #define TEST_VECTOR_CRYPTER(x) &x,
                     57: static crypter_test_vector_t *crypter[] = {
                     58: #include "test_vectors.h"
                     59: };
                     60: #undef TEST_VECTOR_CRYPTER
                     61: #define TEST_VECTOR_CRYPTER(x)
                     62: 
                     63: #undef TEST_VECTOR_AEAD
                     64: #define TEST_VECTOR_AEAD(x) &x,
                     65: static aead_test_vector_t *aead[] = {
                     66: #include "test_vectors.h"
                     67: };
                     68: #undef TEST_VECTOR_AEAD
                     69: #define TEST_VECTOR_AEAD(x)
                     70: 
                     71: #undef TEST_VECTOR_SIGNER
                     72: #define TEST_VECTOR_SIGNER(x) &x,
                     73: static signer_test_vector_t *signer[] = {
                     74: #include "test_vectors.h"
                     75: };
                     76: #undef TEST_VECTOR_SIGNER
                     77: #define TEST_VECTOR_SIGNER(x)
                     78: 
                     79: #undef TEST_VECTOR_HASHER
                     80: #define TEST_VECTOR_HASHER(x) &x,
                     81: static hasher_test_vector_t *hasher[] = {
                     82: #include "test_vectors.h"
                     83: };
                     84: #undef TEST_VECTOR_HASHER
                     85: #define TEST_VECTOR_HASHER(x)
                     86: 
                     87: #undef TEST_VECTOR_PRF
                     88: #define TEST_VECTOR_PRF(x) &x,
                     89: static prf_test_vector_t *prf[] = {
                     90: #include "test_vectors.h"
                     91: };
                     92: #undef TEST_VECTOR_PRF
                     93: #define TEST_VECTOR_PRF(x)
                     94: 
                     95: #undef TEST_VECTOR_XOF
                     96: #define TEST_VECTOR_XOF(x) &x,
                     97: static xof_test_vector_t *xof[] = {
                     98: #include "test_vectors.h"
                     99: };
                    100: #undef TEST_VECTOR_XOF
                    101: #define TEST_VECTOR_XOF(x)
                    102: 
                    103: #undef TEST_VECTOR_DRBG
                    104: #define TEST_VECTOR_DRBG(x) &x,
                    105: static drbg_test_vector_t *drbg[] = {
                    106: #include "test_vectors.h"
                    107: };
                    108: #undef TEST_VECTOR_DRBG
                    109: #define TEST_VECTOR_DRBG(x)
                    110: 
                    111: #undef TEST_VECTOR_RNG
                    112: #define TEST_VECTOR_RNG(x) &x,
                    113: static rng_test_vector_t *rng[] = {
                    114: #include "test_vectors.h"
                    115: };
                    116: #undef TEST_VECTOR_RNG
                    117: #define TEST_VECTOR_RNG(x)
                    118: 
                    119: #undef TEST_VECTOR_DH
                    120: #define TEST_VECTOR_DH(x) &x,
                    121: static dh_test_vector_t *dh[] = {
                    122: #include "test_vectors.h"
                    123: };
                    124: #undef TEST_VECTOR_DH
                    125: #define TEST_VECTOR_DH(x)
                    126: 
                    127: typedef struct private_test_vectors_plugin_t private_test_vectors_plugin_t;
                    128: 
                    129: /**
                    130:  * private data of test_vectors_plugin
                    131:  */
                    132: struct private_test_vectors_plugin_t {
                    133: 
                    134:        /**
                    135:         * public functions
                    136:         */
                    137:        test_vectors_plugin_t public;
                    138: };
                    139: 
                    140: METHOD(plugin_t, get_name, char*,
                    141:        private_test_vectors_plugin_t *this)
                    142: {
                    143:        return "test-vectors";
                    144: }
                    145: 
                    146: METHOD(plugin_t, get_features, int,
                    147:        private_test_vectors_plugin_t *this, plugin_feature_t *features[])
                    148: {
                    149:        static plugin_feature_t f[] = {
                    150:                PLUGIN_NOOP,
                    151:                        PLUGIN_PROVIDE(CUSTOM, "test-vectors"),
                    152:        };
                    153:        *features = f;
                    154:        return countof(f);
                    155: }
                    156: 
                    157: METHOD(plugin_t, destroy, void,
                    158:        private_test_vectors_plugin_t *this)
                    159: {
                    160:        free(this);
                    161: }
                    162: 
                    163: /*
                    164:  * see header file
                    165:  */
                    166: plugin_t *test_vectors_plugin_create()
                    167: {
                    168:        private_test_vectors_plugin_t *this;
                    169:        int i;
                    170: 
                    171:        INIT(this,
                    172:                .public = {
                    173:                        .plugin = {
                    174:                                .get_name = _get_name,
                    175:                                .get_features = _get_features,
                    176:                                .destroy = _destroy,
                    177:                        },
                    178:                },
                    179:        );
                    180: 
                    181:        for (i = 0; i < countof(crypter); i++)
                    182:        {
                    183:                lib->crypto->add_test_vector(lib->crypto,
                    184:                                                                         ENCRYPTION_ALGORITHM, crypter[i]);
                    185:        }
                    186:        for (i = 0; i < countof(aead); i++)
                    187:        {
                    188:                lib->crypto->add_test_vector(lib->crypto,
                    189:                                                                         AEAD_ALGORITHM, aead[i]);
                    190:        }
                    191:        for (i = 0; i < countof(signer); i++)
                    192:        {
                    193:                lib->crypto->add_test_vector(lib->crypto,
                    194:                                                                         INTEGRITY_ALGORITHM, signer[i]);
                    195:        }
                    196:        for (i = 0; i < countof(hasher); i++)
                    197:        {
                    198:                lib->crypto->add_test_vector(lib->crypto,
                    199:                                                                         HASH_ALGORITHM, hasher[i]);
                    200:        }
                    201:        for (i = 0; i < countof(prf); i++)
                    202:        {
                    203:                lib->crypto->add_test_vector(lib->crypto,
                    204:                                                                         PSEUDO_RANDOM_FUNCTION, prf[i]);
                    205:        }
                    206:        for (i = 0; i < countof(xof); i++)
                    207:        {
                    208:                lib->crypto->add_test_vector(lib->crypto,
                    209:                                                                         EXTENDED_OUTPUT_FUNCTION, xof[i]);
                    210:        }
                    211:        for (i = 0; i < countof(drbg); i++)
                    212:        {
                    213:                lib->crypto->add_test_vector(lib->crypto,
                    214:                                                                         DETERMINISTIC_RANDOM_BIT_GENERATOR, drbg[i]);
                    215:        }
                    216:        for (i = 0; i < countof(rng); i++)
                    217:        {
                    218:                lib->crypto->add_test_vector(lib->crypto,
                    219:                                                                         RANDOM_NUMBER_GENERATOR, rng[i]);
                    220:        }
                    221:        for (i = 0; i < countof(dh); i++)
                    222:        {
                    223:                lib->crypto->add_test_vector(lib->crypto,
                    224:                                                                         DIFFIE_HELLMAN_GROUP, dh[i]);
                    225:        }
                    226: 
                    227:        return &this->public.plugin;
                    228: }

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