blob: 94cff638119851fc993d9938cb70ac449d039568 [file] [log] [blame]
Alexandre Lision7fd5d3d2013-12-04 13:06:40 -05001/*
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/skein256.h>
38
39#include <stdlib.h>
40
41void skein256(unsigned char *data, unsigned int dataLength, unsigned char *digest )
42{
43 SkeinCtx_t ctx;
44
45 skeinCtxPrepare(&ctx, SKEIN_SIZE);
46 skeinInit(&ctx, SKEIN256_DIGEST_LENGTH*8);
47 skeinUpdate(&ctx, data, dataLength);
48
49 skeinFinal(&ctx, digest);
50}
51
52void skein256(unsigned char *dataChunks[], unsigned int dataChunckLength[], unsigned char *digest)
53{
54 SkeinCtx_t ctx;
55
56 skeinCtxPrepare(&ctx, SKEIN_SIZE);
57 skeinInit(&ctx, SKEIN256_DIGEST_LENGTH*8);
58 while(*dataChunks) {
59 skeinUpdate(&ctx, *dataChunks, *dataChunckLength);
60 dataChunks++;
61 dataChunckLength++;
62 }
63 skeinFinal(&ctx, digest);
64}
65
66void* createSkein256Context()
67{
68 SkeinCtx_t *ctx = reinterpret_cast<SkeinCtx_t *>(malloc(sizeof(SkeinCtx_t )));
69 skeinCtxPrepare(ctx, SKEIN_SIZE);
70 skeinInit(ctx, SKEIN256_DIGEST_LENGTH*8);
71 return (void*)ctx;
72}
73
74void closeSkein256Context(void* ctx, unsigned char* digest)
75{
76 SkeinCtx_t* hd = reinterpret_cast<SkeinCtx_t*>(ctx);
77
78 if (digest != NULL) {
79 skeinFinal(hd, digest);
80 }
81 free(hd);
82}
83
84void skein256Ctx(void* ctx, unsigned char* data, unsigned int dataLength)
85{
86 SkeinCtx_t* hd = reinterpret_cast<SkeinCtx_t*>(ctx);
87
88 skeinUpdate(hd, data, dataLength);
89}
90
91void skein256Ctx(void* ctx, unsigned char* dataChunks[], unsigned int dataChunkLength[])
92{
93 SkeinCtx_t* hd = reinterpret_cast<SkeinCtx_t*>(ctx);
94
95 while (*dataChunks) {
96 skeinUpdate(hd, *dataChunks, *dataChunkLength);
97 dataChunks++;
98 dataChunkLength++;
99 }
100}