Alexandre Lision | 907ed2e | 2014-02-04 10:33:09 -0500 | [diff] [blame] | 1 | /* |
| 2 | Copyright (C) 2013 Werner Dittmann |
| 3 | |
| 4 | This library is free software; you can redistribute it and/or |
| 5 | modify it under the terms of the GNU Lesser General Public |
| 6 | License as published by the Free Software Foundation; either |
| 7 | version 2.1 of the License, or (at your option) any later version. |
| 8 | |
| 9 | This library 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 GNU |
| 12 | Lesser General Public License for more details. |
| 13 | |
| 14 | You should have received a copy of the GNU Lesser General Public |
| 15 | License along with this library; if not, write to the Free Software |
| 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | |
| 18 | * In addition, as a special exception, the copyright holders give |
| 19 | * permission to link the code of portions of this program with the |
| 20 | * OpenSSL library under certain conditions as described in each |
| 21 | * individual source file, and distribute linked combinations |
| 22 | * including the two. |
| 23 | * You must obey the GNU General Public License in all respects |
| 24 | * for all of the code used other than OpenSSL. If you modify |
| 25 | * file(s) with this exception, you may extend this exception to your |
| 26 | * version of the file(s), but you are not obligated to do so. If you |
| 27 | * do not wish to do so, delete this exception statement from your |
| 28 | * version. If you delete this exception statement from all source |
| 29 | * files in the program, then also delete it here. |
| 30 | */ |
| 31 | |
| 32 | /** |
| 33 | * @author: Werner Dittmann |
| 34 | */ |
| 35 | |
| 36 | #include <cryptcommon/skeinApi.h> |
| 37 | #include <zrtp/crypto/skein384.h> |
| 38 | |
| 39 | #include <stdlib.h> |
| 40 | |
| 41 | #define SKEIN_SIZE Skein512 |
| 42 | #define SKEIN384_DIGEST_LENGTH 48 |
| 43 | |
| 44 | void skein384(unsigned char *data, unsigned int dataLength, unsigned char *digest ) |
| 45 | { |
| 46 | SkeinCtx_t ctx; |
| 47 | |
| 48 | skeinCtxPrepare(&ctx, SKEIN_SIZE); |
| 49 | skeinInit(&ctx, SKEIN384_DIGEST_LENGTH*8); |
| 50 | skeinUpdate(&ctx, data, dataLength); |
| 51 | |
| 52 | skeinFinal(&ctx, digest); |
| 53 | } |
| 54 | |
| 55 | void skein384(unsigned char *dataChunks[], unsigned int dataChunckLength[], unsigned char *digest) |
| 56 | { |
| 57 | SkeinCtx_t ctx; |
| 58 | |
| 59 | skeinCtxPrepare(&ctx, SKEIN_SIZE); |
| 60 | skeinInit(&ctx, SKEIN384_DIGEST_LENGTH*8); |
| 61 | while(*dataChunks) { |
| 62 | skeinUpdate(&ctx, *dataChunks, *dataChunckLength); |
| 63 | dataChunks++; |
| 64 | dataChunckLength++; |
| 65 | } |
| 66 | skeinFinal(&ctx, digest); |
| 67 | } |
| 68 | |
| 69 | void* createSkein384Context() |
| 70 | { |
| 71 | SkeinCtx_t *ctx = reinterpret_cast<SkeinCtx_t *>(malloc(sizeof(SkeinCtx_t ))); |
| 72 | skeinCtxPrepare(ctx, SKEIN_SIZE); |
| 73 | skeinInit(ctx, SKEIN384_DIGEST_LENGTH*8); |
| 74 | return (void*)ctx; |
| 75 | } |
| 76 | |
| 77 | void closeSkein384Context(void* ctx, unsigned char* digest) |
| 78 | { |
| 79 | SkeinCtx_t* hd = reinterpret_cast<SkeinCtx_t*>(ctx); |
| 80 | |
| 81 | if (digest != NULL) { |
| 82 | skeinFinal(hd, digest); |
| 83 | } |
| 84 | free(hd); |
| 85 | } |
| 86 | |
| 87 | void skein384Ctx(void* ctx, unsigned char* data, unsigned int dataLength) |
| 88 | { |
| 89 | SkeinCtx_t* hd = reinterpret_cast<SkeinCtx_t*>(ctx); |
| 90 | |
| 91 | skeinUpdate(hd, data, dataLength); |
| 92 | } |
| 93 | |
| 94 | void skein384Ctx(void* ctx, unsigned char* dataChunks[], unsigned int dataChunkLength[]) |
| 95 | { |
| 96 | SkeinCtx_t* hd = reinterpret_cast<SkeinCtx_t*>(ctx); |
| 97 | |
| 98 | while (*dataChunks) { |
| 99 | skeinUpdate(hd, *dataChunks, *dataChunkLength); |
| 100 | dataChunks++; |
| 101 | dataChunkLength++; |
| 102 | } |
| 103 | } |