Return to padlock_plugin.c CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / strongswan / src / libstrongswan / plugins / padlock |
1.1 misho 1: /* 2: * Copyright (C) 2013 Tobias Brunner 3: * Copyright (C) 2008 Martin Willi 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: #include "padlock_plugin.h" 18: #include "padlock_aes_crypter.h" 19: #include "padlock_sha1_hasher.h" 20: #include "padlock_rng.h" 21: 22: #include <stdio.h> 23: 24: #include <library.h> 25: #include <plugins/plugin_feature.h> 26: #include <utils/cpu_feature.h> 27: #include <utils/debug.h> 28: 29: typedef struct private_padlock_plugin_t private_padlock_plugin_t; 30: typedef enum padlock_feature_t padlock_feature_t; 31: 32: /** 33: * private data of aes_plugin 34: */ 35: struct private_padlock_plugin_t { 36: 37: /** 38: * public functions 39: */ 40: padlock_plugin_t public; 41: 42: /** 43: * features supported by Padlock 44: */ 45: cpu_feature_t features; 46: }; 47: 48: METHOD(plugin_t, get_name, char*, 49: private_padlock_plugin_t *this) 50: { 51: return "padlock"; 52: } 53: 54: METHOD(plugin_t, get_features, int, 55: private_padlock_plugin_t *this, plugin_feature_t *features[]) 56: { 57: static plugin_feature_t f_rng[] = { 58: PLUGIN_REGISTER(RNG, padlock_rng_create), 59: PLUGIN_PROVIDE(RNG, RNG_WEAK), 60: PLUGIN_PROVIDE(RNG, RNG_STRONG), 61: PLUGIN_PROVIDE(RNG, RNG_TRUE), 62: }; 63: static plugin_feature_t f_aes[] = { 64: PLUGIN_REGISTER(CRYPTER, padlock_aes_crypter_create), 65: PLUGIN_PROVIDE(CRYPTER, ENCR_AES_CBC, 16), 66: }; 67: static plugin_feature_t f_sha1[] = { 68: PLUGIN_REGISTER(HASHER, padlock_sha1_hasher_create), 69: PLUGIN_PROVIDE(HASHER, HASH_SHA1), 70: }; 71: static plugin_feature_t f[countof(f_rng) + countof(f_aes) + 72: countof(f_sha1)] = {}; 73: static int count = 0; 74: 75: if (!count) 76: { /* initialize only once */ 77: if (this->features & CPU_FEATURE_PADLOCK_RNG_ENABLED) 78: { 79: plugin_features_add(f, f_rng, countof(f_rng), &count); 80: } 81: if (this->features & CPU_FEATURE_PADLOCK_ACE2_ENABLED) 82: { 83: plugin_features_add(f, f_aes, countof(f_aes), &count); 84: } 85: if (this->features & CPU_FEATURE_PADLOCK_PHE_ENABLED) 86: { 87: plugin_features_add(f, f_sha1, countof(f_sha1), &count); 88: } 89: } 90: *features = f; 91: return count; 92: } 93: 94: METHOD(plugin_t, destroy, void, 95: private_padlock_plugin_t *this) 96: { 97: free(this); 98: } 99: 100: /* 101: * see header file 102: */ 103: plugin_t *padlock_plugin_create() 104: { 105: private_padlock_plugin_t *this; 106: 107: INIT(this, 108: .public = { 109: .plugin = { 110: .get_name = _get_name, 111: .get_features = _get_features, 112: .destroy = _destroy, 113: }, 114: }, 115: .features = cpu_feature_get_all(), 116: ); 117: 118: DBG1(DBG_LIB, "Padlock features supported:%s%s%s%s%s, enabled:%s%s%s%s%s", 119: this->features & CPU_FEATURE_PADLOCK_RNG_AVAILABLE ? " RNG" : "", 120: this->features & CPU_FEATURE_PADLOCK_ACE_AVAILABLE ? " ACE" : "", 121: this->features & CPU_FEATURE_PADLOCK_ACE2_AVAILABLE ? " ACE2" : "", 122: this->features & CPU_FEATURE_PADLOCK_PHE_AVAILABLE ? " PHE" : "", 123: this->features & CPU_FEATURE_PADLOCK_PMM_AVAILABLE ? " PMM" : "", 124: this->features & CPU_FEATURE_PADLOCK_RNG_ENABLED ? " RNG" : "", 125: this->features & CPU_FEATURE_PADLOCK_ACE_ENABLED ? " ACE" : "", 126: this->features & CPU_FEATURE_PADLOCK_ACE2_ENABLED ? " ACE2" : "", 127: this->features & CPU_FEATURE_PADLOCK_PHE_ENABLED ? " PHE" : "", 128: this->features & CPU_FEATURE_PADLOCK_PMM_ENABLED ? " PMM" : ""); 129: 130: return &this->public.plugin; 131: }