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

1.1     ! misho       1: /*
        !             2:  * Copyright (C) 2009 Martin Willi
        !             3:  * Copyright (C) 2016-2019 Andreas Steffen
        !             4:  * HSR Hochschule fuer Technik Rapperswil
        !             5:  *
        !             6:  * This program is free software; you can redistribute it and/or modify it
        !             7:  * under the terms of the GNU General Public License as published by the
        !             8:  * Free Software Foundation; either version 2 of the License, or (at your
        !             9:  * option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
        !            10:  *
        !            11:  * This program is distributed in the hope that it will be useful, but
        !            12:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
        !            13:  * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
        !            14:  * for more details.
        !            15:  */
        !            16: 
        !            17: /**
        !            18:  * @defgroup crypto_tester crypto_tester
        !            19:  * @{ @ingroup crypto
        !            20:  */
        !            21: 
        !            22: #ifndef CRYPTO_TESTER_H_
        !            23: #define CRYPTO_TESTER_H_
        !            24: 
        !            25: typedef struct crypto_tester_t crypto_tester_t;
        !            26: 
        !            27: #include <crypto/crypto_factory.h>
        !            28: 
        !            29: typedef struct crypter_test_vector_t crypter_test_vector_t;
        !            30: typedef struct aead_test_vector_t aead_test_vector_t;
        !            31: typedef struct signer_test_vector_t signer_test_vector_t;
        !            32: typedef struct hasher_test_vector_t hasher_test_vector_t;
        !            33: typedef struct prf_test_vector_t prf_test_vector_t;
        !            34: typedef struct xof_test_vector_t xof_test_vector_t;
        !            35: typedef struct drbg_test_vector_t drbg_test_vector_t;
        !            36: typedef struct rng_test_vector_t rng_test_vector_t;
        !            37: typedef struct dh_test_vector_t dh_test_vector_t;
        !            38: 
        !            39: struct crypter_test_vector_t {
        !            40:        /** encryption algorithm this vector tests */
        !            41:        encryption_algorithm_t alg;
        !            42:        /** key length to use, in bytes */
        !            43:        size_t key_size;
        !            44:        /** encryption key of test vector */
        !            45:        u_char *key;
        !            46:        /** initialization vector, using crypters blocksize bytes */
        !            47:        u_char *iv;
        !            48:        /** length of plain and cipher text */
        !            49:        size_t len;
        !            50:        /** plain text */
        !            51:        u_char *plain;
        !            52:        /** cipher text */
        !            53:        u_char *cipher;
        !            54: };
        !            55: 
        !            56: struct aead_test_vector_t {
        !            57:        /** encryption algorithm this vector tests */
        !            58:        encryption_algorithm_t alg;
        !            59:        /** key length to use, in bytes */
        !            60:        size_t key_size;
        !            61:        /** salt length to use, in bytes */
        !            62:        size_t salt_size;
        !            63:        /** encryption key of test vector */
        !            64:        u_char *key;
        !            65:        /** initialization vector, using crypters blocksize bytes */
        !            66:        u_char *iv;
        !            67:        /** length of associated data */
        !            68:        size_t alen;
        !            69:        /** associated data */
        !            70:        u_char *adata;
        !            71:        /** length of plain text */
        !            72:        size_t len;
        !            73:        /** plain text */
        !            74:        u_char *plain;
        !            75:        /** cipher text */
        !            76:        u_char *cipher;
        !            77: };
        !            78: 
        !            79: struct signer_test_vector_t {
        !            80:        /** signer algorithm this test vector tests */
        !            81:        integrity_algorithm_t alg;
        !            82:        /** key to use, with a length the algorithm expects */
        !            83:        u_char *key;
        !            84:        /** size of the input data */
        !            85:        size_t len;
        !            86:        /** input data */
        !            87:        u_char *data;
        !            88:        /** expected output, with output size of the tested algorithm */
        !            89:        u_char *mac;
        !            90: };
        !            91: 
        !            92: struct hasher_test_vector_t {
        !            93:        /** hash algorithm this test vector tests */
        !            94:        hash_algorithm_t alg;
        !            95:        /** length of the input data */
        !            96:        size_t len;
        !            97:        /** input data */
        !            98:        u_char *data;
        !            99:        /** expected hash, with hash size of the tested algorithm */
        !           100:        u_char *hash;
        !           101: };
        !           102: 
        !           103: struct prf_test_vector_t {
        !           104:        /** prf algorithm this test vector tests */
        !           105:        pseudo_random_function_t alg;
        !           106:        /** is this PRF stateful? */
        !           107:        bool stateful;
        !           108:        /** key length to use, in bytes */
        !           109:        size_t key_size;
        !           110:        /** key to use */
        !           111:        u_char *key;
        !           112:        /** size of the seed data */
        !           113:        size_t len;
        !           114:        /** seed data */
        !           115:        u_char *seed;
        !           116:        /** expected output, with block size of the tested algorithm */
        !           117:        u_char *out;
        !           118: };
        !           119: 
        !           120: struct xof_test_vector_t {
        !           121:        /** xof algorithm this test vector tests */
        !           122:        ext_out_function_t alg;
        !           123:        /** size of the seed data */
        !           124:        size_t len;
        !           125:        /** seed data */
        !           126:        u_char *seed;
        !           127:        /** size of the output */
        !           128:        size_t out_len;
        !           129:        /** expected output of size*/
        !           130:        u_char *out;
        !           131: };
        !           132: 
        !           133: struct drbg_test_vector_t {
        !           134:        /** drbg type this test vector tests */
        !           135:        drbg_type_t type;
        !           136:        /** security strength in bits */
        !           137:        uint32_t strength;
        !           138:        /** optional personalization string */
        !           139:        chunk_t personalization_str;
        !           140:        /** entropy_input | nonce | entropy_input_reseed */
        !           141:        chunk_t entropy;
        !           142:        /** returned output bits */
        !           143:        chunk_t out;
        !           144: };
        !           145: 
        !           146: /**
        !           147:  * Test vector for a RNG.
        !           148:  *
        !           149:  * Contains a callback function to analyze the output of a RNG,
        !           150:  */
        !           151: struct rng_test_vector_t {
        !           152:        /** quality of random data this test vector tests */
        !           153:        rng_quality_t quality;
        !           154:        /** callback function to test RNG output, returns TRUE if data ok */
        !           155:        bool (*test)(void *user, chunk_t data);
        !           156:        /** number of bytes the function requests */
        !           157:        size_t len;
        !           158:        /** user data passed back to the test() function on invocation */
        !           159:        void *user;
        !           160: };
        !           161: 
        !           162: struct dh_test_vector_t {
        !           163:        /** diffie hellman group to test */
        !           164:        diffie_hellman_group_t group;
        !           165:        /** private value of alice */
        !           166:        u_char *priv_a;
        !           167:        /** private value of bob */
        !           168:        u_char *priv_b;
        !           169:        /** length of private values */
        !           170:        size_t priv_len;
        !           171:        /** expected public value of alice */
        !           172:        u_char *pub_a;
        !           173:        /** expected public value of bob */
        !           174:        u_char *pub_b;
        !           175:        /** size of public values */
        !           176:        size_t pub_len;
        !           177:        /** expected shared secret */
        !           178:        u_char *shared;
        !           179:        /** size of shared secret */
        !           180:        size_t shared_len;
        !           181: };
        !           182: 
        !           183: /**
        !           184:  * Cryptographic primitive testing framework.
        !           185:  */
        !           186: struct crypto_tester_t {
        !           187: 
        !           188:        /**
        !           189:         * Test a crypter algorithm, optionally using a specified key size.
        !           190:         *
        !           191:         * @param alg                   algorithm to test
        !           192:         * @param key_size              key size to test, 0 for default
        !           193:         * @param create                constructor function for the crypter
        !           194:         * @param speed                 speed test result, NULL to omit
        !           195:         * @return                              TRUE if test passed
        !           196:         */
        !           197:        bool (*test_crypter)(crypto_tester_t *this, encryption_algorithm_t alg,
        !           198:                                                 size_t key_size, crypter_constructor_t create,
        !           199:                                                 u_int *speed, const char *plugin_name);
        !           200: 
        !           201:        /**
        !           202:         * Test an aead algorithm, optionally using a specified key size.
        !           203:         *
        !           204:         * @param alg                   algorithm to test
        !           205:         * @param key_size              key size to test, 0 for default
        !           206:         * @param salt_size             salt length to test, 0 for default
        !           207:         * @param create                constructor function for the aead transform
        !           208:         * @param speed                 speed test result, NULL to omit
        !           209:         * @return                              TRUE if test passed
        !           210:         */
        !           211:        bool (*test_aead)(crypto_tester_t *this, encryption_algorithm_t alg,
        !           212:                                          size_t key_size, size_t salt_size,
        !           213:                                          aead_constructor_t create,
        !           214:                                          u_int *speed, const char *plugin_name);
        !           215:        /**
        !           216:         * Test a signer algorithm.
        !           217:         *
        !           218:         * @param alg                   algorithm to test
        !           219:         * @param create                constructor function for the signer
        !           220:         * @param speed                 speed test result, NULL to omit
        !           221:         * @return                              TRUE if test passed
        !           222:         */
        !           223:        bool (*test_signer)(crypto_tester_t *this, integrity_algorithm_t alg,
        !           224:                                                signer_constructor_t create,
        !           225:                                                u_int *speed, const char *plugin_name);
        !           226:        /**
        !           227:         * Test a hasher algorithm.
        !           228:         *
        !           229:         * @param alg                   algorithm to test
        !           230:         * @param create                constructor function for the hasher
        !           231:         * @param speed                 speed test result, NULL to omit
        !           232:         * @return                              TRUE if test passed
        !           233:         */
        !           234:        bool (*test_hasher)(crypto_tester_t *this, hash_algorithm_t alg,
        !           235:                                                hasher_constructor_t create,
        !           236:                                                u_int *speed, const char *plugin_name);
        !           237:        /**
        !           238:         * Test a PRF algorithm.
        !           239:         *
        !           240:         * @param alg                   algorithm to test
        !           241:         * @param create                constructor function for the PRF
        !           242:         * @param speed                 speed test result, NULL to omit
        !           243:         * @return                              TRUE if test passed
        !           244:         */
        !           245:        bool (*test_prf)(crypto_tester_t *this, pseudo_random_function_t alg,
        !           246:                                         prf_constructor_t create,
        !           247:                                         u_int *speed, const char *plugin_name);
        !           248:        /**
        !           249:         * Test an XOF algorithm.
        !           250:         *
        !           251:         * @param alg                   algorithm to test
        !           252:         * @param create                constructor function for the XOF
        !           253:         * @param speed                 speed test result, NULL to omit
        !           254:         * @return                              TRUE if test passed
        !           255:         */
        !           256:        bool (*test_xof)(crypto_tester_t *this, ext_out_function_t alg,
        !           257:                                         xof_constructor_t create,
        !           258:                                         u_int *speed, const char *plugin_name);
        !           259:        /**
        !           260:         * Test a DRBG type.
        !           261:         *
        !           262:         * @param type                  DRBG type to test
        !           263:         * @param create                constructor function for the DRBG
        !           264:         * @param speed                 speed test result, NULL to omit
        !           265:         * @return                              TRUE if test passed
        !           266:         */
        !           267:        bool (*test_drbg)(crypto_tester_t *this, drbg_type_t type,
        !           268:                                          drbg_constructor_t create,
        !           269:                                          u_int *speed, const char *plugin_name);
        !           270:        /**
        !           271:         * Test a RNG implementation.
        !           272:         *
        !           273:         * @param alg                   algorithm to test
        !           274:         * @param create                constructor function for the RNG
        !           275:         * @param speed                 speed test result, NULL to omit
        !           276:         * @return                              TRUE if test passed
        !           277:         */
        !           278:        bool (*test_rng)(crypto_tester_t *this, rng_quality_t quality,
        !           279:                                         rng_constructor_t create,
        !           280:                                         u_int *speed, const char *plugin_name);
        !           281:        /**
        !           282:         * Test a Diffie-Hellman implementation.
        !           283:         *
        !           284:         * @param group                 group to test
        !           285:         * @param create                constructor function for the DH backend
        !           286:         * @param speed                 speed test result, NULL to omit
        !           287:         * @return                              TRUE if test passed
        !           288:         */
        !           289:        bool (*test_dh)(crypto_tester_t *this, diffie_hellman_group_t group,
        !           290:                                        dh_constructor_t create,
        !           291:                                        u_int *speed, const char *plugin_name);
        !           292: 
        !           293:        /**
        !           294:         * Add a test vector to test a crypter.
        !           295:         *
        !           296:         * @param vector                pointer to test vector
        !           297:         */
        !           298:        void (*add_crypter_vector)(crypto_tester_t *this,
        !           299:                                                           crypter_test_vector_t *vector);
        !           300:        /**
        !           301:         * Add a test vector to test an aead transform.
        !           302:         *
        !           303:         * @param vector                pointer to test vector
        !           304:         */
        !           305:        void (*add_aead_vector)(crypto_tester_t *this,
        !           306:                                                        aead_test_vector_t *vector);
        !           307:        /**
        !           308:         * Add a test vector to test a signer.
        !           309:         *
        !           310:         * @param vector                pointer to test vector
        !           311:         */
        !           312:        void (*add_signer_vector)(crypto_tester_t *this,
        !           313:                                                          signer_test_vector_t *vector);
        !           314:        /**
        !           315:         * Add a test vector to test a hasher.
        !           316:         *
        !           317:         * @param vector                pointer to test vector
        !           318:         */
        !           319:        void (*add_hasher_vector)(crypto_tester_t *this,
        !           320:                                                          hasher_test_vector_t *vector);
        !           321:        /**
        !           322:         * Add a test vector to test a PRF.
        !           323:         *
        !           324:         * @param vector                pointer to test vector
        !           325:         */
        !           326:        void (*add_prf_vector)(crypto_tester_t *this, prf_test_vector_t *vector);
        !           327: 
        !           328:        /**
        !           329:         * Add a test vector to test an XOF.
        !           330:         *
        !           331:         * @param vector                pointer to test vector
        !           332:         */
        !           333:        void (*add_xof_vector)(crypto_tester_t *this, xof_test_vector_t *vector);
        !           334: 
        !           335:        /**
        !           336:         * Add a test vector to test a DRBG.
        !           337:         *
        !           338:         * @param vector                pointer to test vector
        !           339:         */
        !           340:        void (*add_drbg_vector)(crypto_tester_t *this, drbg_test_vector_t *vector);
        !           341: 
        !           342:        /**
        !           343:         * Add a test vector to test a RNG.
        !           344:         *
        !           345:         * @param vector                pointer to test vector
        !           346:         */
        !           347:        void (*add_rng_vector)(crypto_tester_t *this, rng_test_vector_t *vector);
        !           348: 
        !           349:        /**
        !           350:         * Add a test vector to test a Diffie-Hellman backend.
        !           351:         *
        !           352:         * @param vector                pointer to test vector
        !           353:         */
        !           354:        void (*add_dh_vector)(crypto_tester_t *this, dh_test_vector_t *vector);
        !           355: 
        !           356:        /**
        !           357:         * Destroy a crypto_tester_t.
        !           358:         */
        !           359:        void (*destroy)(crypto_tester_t *this);
        !           360: };
        !           361: 
        !           362: /**
        !           363:  * Create a crypto_tester instance.
        !           364:  */
        !           365: crypto_tester_t *crypto_tester_create();
        !           366: 
        !           367: #endif /** CRYPTO_TESTER_H_ @}*/

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