Return to rdrand_plugin.c CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / strongswan / src / libstrongswan / plugins / rdrand |
1.1 misho 1: /* 2: * Copyright (C) 2012 Martin Willi 3: * Copyright (C) 2012 revosec AG 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 "rdrand_plugin.h" 17: #include "rdrand_rng.h" 18: 19: #include <stdio.h> 20: 21: #include <library.h> 22: #include <utils/debug.h> 23: #include <utils/cpu_feature.h> 24: 25: typedef struct private_rdrand_plugin_t private_rdrand_plugin_t; 26: typedef enum cpuid_feature_t cpuid_feature_t; 27: 28: /** 29: * private data of rdrand_plugin 30: */ 31: struct private_rdrand_plugin_t { 32: 33: /** 34: * public functions 35: */ 36: rdrand_plugin_t public; 37: }; 38: 39: METHOD(plugin_t, get_name, char*, 40: private_rdrand_plugin_t *this) 41: { 42: return "rdrand"; 43: } 44: 45: METHOD(plugin_t, get_features, int, 46: private_rdrand_plugin_t *this, plugin_feature_t *features[]) 47: { 48: static plugin_feature_t f[] = { 49: PLUGIN_REGISTER(RNG, rdrand_rng_create), 50: PLUGIN_PROVIDE(RNG, RNG_WEAK), 51: PLUGIN_PROVIDE(RNG, RNG_STRONG), 52: PLUGIN_PROVIDE(RNG, RNG_TRUE), 53: PLUGIN_DEPENDS(CRYPTER, ENCR_AES_CBC, 16), 54: }; 55: *features = f; 56: if (cpu_feature_available(CPU_FEATURE_RDRAND)) 57: { 58: DBG2(DBG_LIB, "detected RDRAND support, enabled"); 59: return countof(f); 60: } 61: DBG2(DBG_LIB, "no RDRAND support detected, disabled"); 62: return 0; 63: } 64: 65: METHOD(plugin_t, destroy, void, 66: private_rdrand_plugin_t *this) 67: { 68: free(this); 69: } 70: 71: /* 72: * see header file 73: */ 74: plugin_t *rdrand_plugin_create() 75: { 76: private_rdrand_plugin_t *this; 77: 78: INIT(this, 79: .public = { 80: .plugin = { 81: .get_name = _get_name, 82: .get_features = _get_features, 83: .reload = (void*)return_false, 84: .destroy = _destroy, 85: }, 86: }, 87: ); 88: 89: return &this->public.plugin; 90: }