Annotation of embedaddon/strongswan/src/libstrongswan/tests/suites/test_crypter.c, revision 1.1.1.1

1.1       misho       1: /*
                      2:  * Copyright (C) 2013 Andreas Steffen
                      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_suite.h"
                     17: 
                     18: #include <crypto/crypters/crypter.h>
                     19: #include <asn1/oid.h>
                     20: #include <utils/test.h>
                     21: 
                     22: typedef struct {
                     23:        int oid;
                     24:        encryption_algorithm_t alg;
                     25:        size_t key_size;
                     26: }crypter_oid_t;
                     27: 
                     28: static crypter_oid_t oids[] = {
                     29:        { OID_UNKNOWN, ENCR_AES_CBC, 0 },
                     30:        { OID_UNKNOWN, ENCR_CAMELLIA_CBC, 0 },
                     31:        { OID_UNKNOWN, ENCR_UNDEFINED, 0 },
                     32:        { OID_DES_CBC, ENCR_DES, 0 },
                     33:        { OID_3DES_EDE_CBC, ENCR_3DES, 0 },
                     34:        { OID_AES128_CBC, ENCR_AES_CBC, 128 },
                     35:        { OID_AES192_CBC, ENCR_AES_CBC, 192 },
                     36:        { OID_AES256_CBC, ENCR_AES_CBC, 256 },
                     37:        { OID_CAMELLIA128_CBC, ENCR_CAMELLIA_CBC, 128 },
                     38:        { OID_CAMELLIA192_CBC, ENCR_CAMELLIA_CBC, 192 },
                     39:        { OID_CAMELLIA256_CBC, ENCR_CAMELLIA_CBC, 256 },
                     40:        { OID_BLOWFISH_CBC, ENCR_BLOWFISH, 0 }
                     41: };
                     42: 
                     43: START_TEST(test_crypter_from_oid)
                     44: {
                     45:        size_t key_size;
                     46: 
                     47:        ck_assert(encryption_algorithm_from_oid(oids[_i].oid, NULL) ==
                     48:                                                                                    oids[_i].alg);
                     49:        ck_assert(encryption_algorithm_from_oid(oids[_i].oid, &key_size) ==
                     50:                                                                                    oids[_i].alg);
                     51:        ck_assert(key_size == oids[_i].key_size);
                     52: }
                     53: END_TEST
                     54: 
                     55: START_TEST(test_crypter_to_oid)
                     56: {
                     57:        ck_assert(encryption_algorithm_to_oid(oids[_i].alg,
                     58:                                                                              oids[_i].key_size) == oids[_i].oid);
                     59: }
                     60: END_TEST
                     61: 
                     62: typedef struct {
                     63:        encryption_algorithm_t alg;
                     64:        bool is_aead;
                     65: }crypter_aead_t;
                     66: 
                     67: static crypter_aead_t aead[] = {
                     68:        { ENCR_AES_CCM_ICV8, TRUE },
                     69:        { ENCR_AES_CCM_ICV12, TRUE },
                     70:        { ENCR_AES_CCM_ICV16, TRUE },
                     71:        { ENCR_AES_GCM_ICV8, TRUE },
                     72:        { ENCR_AES_GCM_ICV12, TRUE },
                     73:        { ENCR_AES_GCM_ICV16, TRUE },
                     74:        { ENCR_NULL_AUTH_AES_GMAC, TRUE },
                     75:        { ENCR_CAMELLIA_CCM_ICV8, TRUE },
                     76:        { ENCR_CAMELLIA_CCM_ICV12, TRUE },
                     77:        { ENCR_CAMELLIA_CCM_ICV16, TRUE },
                     78:        { ENCR_AES_CBC, FALSE },
                     79:        { ENCR_CAMELLIA_CBC, FALSE }
                     80: };
                     81: 
                     82: START_TEST(test_crypter_is_aead)
                     83: {
                     84:        ck_assert(encryption_algorithm_is_aead(aead[_i].alg) == aead[_i].is_aead);
                     85: }
                     86: END_TEST
                     87: 
                     88: Suite *crypter_suite_create()
                     89: {
                     90:        Suite *s;
                     91:        TCase *tc;
                     92: 
                     93:        s = suite_create("crypter");
                     94: 
                     95:        tc = tcase_create("from_oid");
                     96:        tcase_add_loop_test(tc, test_crypter_from_oid, 2, countof(oids));
                     97:        suite_add_tcase(s, tc);
                     98: 
                     99:        tc = tcase_create("to_oid");
                    100:        tcase_add_loop_test(tc, test_crypter_to_oid, 0, countof(oids));
                    101:        suite_add_tcase(s, tc);
                    102: 
                    103:        tc = tcase_create("is_aead");
                    104:        tcase_add_loop_test(tc, test_crypter_is_aead, 0, countof(aead));
                    105:        suite_add_tcase(s, tc);
                    106: 
                    107:        return s;
                    108: }

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