Return to mac_prf.c CVS log | Up to [ELWIX - Embedded LightWeight unIX -] / embedaddon / strongswan / src / libstrongswan / crypto / prfs |
1.1 misho 1: /* 2: * Copyright (C) 2012 Tobias Brunner 3: * Copyright (C) 2005-2006 Martin Willi 4: * Copyright (C) 2005 Jan Hutter 5: * HSR Hochschule fuer Technik Rapperswil 6: * 7: * This program is free software; you can redistribute it and/or modify it 8: * under the terms of the GNU General Public License as published by the 9: * Free Software Foundation; either version 2 of the License, or (at your 10: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>. 11: * 12: * This program is distributed in the hope that it will be useful, but 13: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 14: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15: * for more details. 16: */ 17: 18: #include "mac_prf.h" 19: 20: typedef struct private_prf_t private_prf_t; 21: 22: /** 23: * Private data of a mac_prf_t object. 24: */ 25: struct private_prf_t { 26: 27: /** 28: * Public interface 29: */ 30: prf_t public; 31: 32: /** 33: * MAC to use 34: */ 35: mac_t *mac; 36: }; 37: 38: METHOD(prf_t, get_bytes, bool, 39: private_prf_t *this, chunk_t seed, uint8_t *buffer) 40: { 41: return this->mac->get_mac(this->mac, seed, buffer); 42: } 43: 44: METHOD(prf_t, allocate_bytes, bool, 45: private_prf_t *this, chunk_t seed, chunk_t *chunk) 46: { 47: if (chunk) 48: { 49: *chunk = chunk_alloc(this->mac->get_mac_size(this->mac)); 50: return this->mac->get_mac(this->mac, seed, chunk->ptr); 51: } 52: return this->mac->get_mac(this->mac, seed, NULL); 53: } 54: 55: METHOD(prf_t, get_block_size, size_t, 56: private_prf_t *this) 57: { 58: return this->mac->get_mac_size(this->mac); 59: } 60: 61: METHOD(prf_t, get_key_size, size_t, 62: private_prf_t *this) 63: { 64: /* IKEv2 uses MAC size as key size */ 65: return this->mac->get_mac_size(this->mac); 66: } 67: 68: METHOD(prf_t, set_key, bool, 69: private_prf_t *this, chunk_t key) 70: { 71: return this->mac->set_key(this->mac, key); 72: } 73: 74: METHOD(prf_t, destroy, void, 75: private_prf_t *this) 76: { 77: this->mac->destroy(this->mac); 78: free(this); 79: } 80: 81: /* 82: * Described in header. 83: */ 84: prf_t *mac_prf_create(mac_t *mac) 85: { 86: private_prf_t *this; 87: 88: INIT(this, 89: .public = { 90: .get_bytes = _get_bytes, 91: .allocate_bytes = _allocate_bytes, 92: .get_block_size = _get_block_size, 93: .get_key_size = _get_key_size, 94: .set_key = _set_key, 95: .destroy = _destroy, 96: }, 97: .mac = mac, 98: ); 99: 100: return &this->public; 101: }