Emeric Vigier | 2f62582 | 2012-08-06 11:09:52 -0400 | [diff] [blame] | 1 | /* |
| 2 | Copyright (C) 2010 Werner Dittmann |
| 3 | |
| 4 | This program is free software: you can redistribute it and/or modify |
| 5 | it under the terms of the GNU General Public License as published by |
| 6 | the Free Software Foundation, either version 3 of the License, or |
| 7 | (at your option) any later version. |
| 8 | |
| 9 | This program is distributed in the hope that it will be useful, |
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | GNU General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU General Public License |
| 15 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | */ |
| 17 | |
| 18 | #include <ccrtp/crypto/macSkein.h> |
| 19 | #include <stdlib.h> |
| 20 | |
| 21 | void macSkein(uint8_t* key, int32_t key_length, |
| 22 | const uint8_t* data, uint32_t data_length, |
| 23 | uint8_t* mac, int32_t mac_length, SkeinSize_t skeinSize) |
| 24 | { |
| 25 | SkeinCtx_t ctx; |
| 26 | |
| 27 | skeinCtxPrepare(&ctx, skeinSize); |
| 28 | |
| 29 | skeinMacInit(&ctx, key, key_length, mac_length); |
| 30 | skeinUpdate(&ctx, data, data_length); |
| 31 | skeinFinal(&ctx, mac); |
| 32 | } |
| 33 | |
| 34 | void macSkein(uint8_t* key, int32_t key_length, |
| 35 | const uint8_t* data[], uint32_t data_length[], |
| 36 | uint8_t* mac, int32_t mac_length, SkeinSize_t skeinSize) |
| 37 | { |
| 38 | SkeinCtx_t ctx; |
| 39 | |
| 40 | skeinCtxPrepare(&ctx, skeinSize); |
| 41 | |
| 42 | skeinMacInit(&ctx, key, key_length, mac_length); |
| 43 | while (*data) { |
| 44 | skeinUpdate(&ctx, *data, *data_length); |
| 45 | data++; |
| 46 | data_length ++; |
| 47 | } |
| 48 | skeinFinal(&ctx, mac); |
| 49 | } |
| 50 | |
| 51 | void* createSkeinMacContext(uint8_t* key, int32_t key_length, |
| 52 | int32_t mac_length, SkeinSize_t skeinSize) |
| 53 | { |
| 54 | SkeinCtx_t* ctx = (SkeinCtx_t*)malloc(sizeof(SkeinCtx_t)); |
| 55 | |
| 56 | skeinCtxPrepare(ctx, skeinSize); |
| 57 | skeinMacInit(ctx, key, key_length, mac_length); |
| 58 | return ctx; |
| 59 | } |
| 60 | |
| 61 | void macSkeinCtx(void* ctx, const uint8_t* data, uint32_t data_length, |
| 62 | uint8_t* mac) |
| 63 | { |
| 64 | SkeinCtx_t* pctx = (SkeinCtx_t*)ctx; |
| 65 | |
| 66 | skeinUpdate(pctx, data, data_length); |
| 67 | skeinFinal(pctx, mac); |
| 68 | skeinReset(pctx); |
| 69 | } |
| 70 | |
| 71 | void macSkeinCtx(void* ctx, const uint8_t* data[], uint32_t data_length[], |
| 72 | uint8_t* mac) |
| 73 | { |
| 74 | SkeinCtx_t* pctx = (SkeinCtx_t*)ctx; |
| 75 | |
| 76 | while (*data) { |
| 77 | skeinUpdate(pctx, *data, *data_length); |
| 78 | data++; |
| 79 | data_length++; |
| 80 | } |
| 81 | skeinFinal(pctx, mac); |
| 82 | skeinReset(pctx); |
| 83 | } |
| 84 | |
| 85 | void freeSkeinMacContext(void* ctx) |
| 86 | { |
| 87 | if (ctx) |
| 88 | free(ctx); |
| 89 | } |