1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
*
* OpenOffice.org - a multi-platform office productivity suite
*
* This file is part of OpenOffice.org.
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
*
************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <rtl/digest.h>
static const char *digest_in_MD[] =
{
"",
"a",
"abc",
"message digest",
"abcdefghijklmnopqrstuvwxyz",
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
"12345678901234567890123456789012345678901234567890123456789012345678901234567890",
NULL,
};
static const char *digest_out_MD2[]=
{
"8350e5a3e24c153df2275c9f80692773",
"32ec01ec4a6dac72c0ab96fb34c0b5d1",
"da853b0d3f88d99b30283a69e6ded6bb",
"ab4f496bfb2a530b219ff33031fe06b0",
"4e8ddff3650292ab5a4108c3aa47940b",
"da33def2a42df13975352846c30338cd",
"d5976f79d83d3a0dc9806c3c66f3efd8",
};
static const char *digest_out_MD5[]=
{
"d41d8cd98f00b204e9800998ecf8427e",
"0cc175b9c0f1b6a831c399e269772661",
"900150983cd24fb0d6963f7d28e17f72",
"f96b697d7cb7938d525a2f31aaf161d0",
"c3fcd3d76192e4007dfb496cca67e13b",
"d174ab98d277d9f5a5611c2c9f419d9f",
"57edf4a22be3c955ac49da2e2107b67a",
};
static const char *digest_in_SHA[]=
{
"abc",
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
NULL,
};
static const char *digest_out_SHA_0[]=
{
"0164b8a914cd2a5e74c4f7ff082c4d97f1edf880",
"d2516ee1acfa5baf33dfc1c471e438449ef134c8",
};
static const char *digest_out_SHA_1[]=
{
"a9993e364706816aba3e25717850c26c9cd0d89d",
"84983e441c3bd26ebaae4aa1f95129e5e54670f1",
};
static const char *digest_bigout_SHA_0=
"3232affa48628a26653b5aaa44541fd90d690603";
static const char *digest_bigout_SHA_1=
"34aa973cd4c4daa4f61eeb2bdbad27316534016f";
static const char digest_key_HMAC_MD5_1[] =
{
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b, 0x0b,
0x00
};
static const char digest_key_HMAC_MD5_2[] =
{
/* "Jefe" */
'J', 'e', 'f', 'e',
0x00
};
static const unsigned char digest_key_HMAC_MD5_3[] =
{
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA,
0x00
};
static const char *digest_key_HMAC_MD5[] =
{
(const char*)&digest_key_HMAC_MD5_1,
(const char*)&digest_key_HMAC_MD5_2, /* "Jefe", */
(const char*)&digest_key_HMAC_MD5_3,
NULL
};
static const unsigned char digest_in_HMAC_MD5_3[] =
{
0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD, 0xDD,
0xDD, 0xDD,
0x00
};
static const char *digest_in_HMAC_MD5[] =
{
"Hi There",
"what do ya want for nothing?",
(const char*)&digest_in_HMAC_MD5_3,
NULL
};
static const char *digest_out_HMAC_MD5[] =
{
"9294727a3638bb1c13f48ef8158bfc9d",
"750c783e6ab0b503eaa86e310a5db738",
"56be34521d144c88dbb8c733f0e8b3f6",
NULL
};
static const char *digest_out_HMAC_SHA1[] =
{
/* unofficial, i.e. not verified */
"675b0b3a1b4ddf4e124872da6c2f632bfed957e9",
"effcdf6ae5eb2fa2d27416d5f184df9c259a7c79",
"d730594d167e35d5956fd8003d0db3d3f46dc7bb",
NULL
};
static char *pt (unsigned char *md, int length)
{
int i;
static char buf[80];
for (i=0; i<length; i++)
sprintf(&(buf[i*2]),"%02x",md[i]);
return(buf);
}
int SAL_CALL main (void)
{
const char **P,**R, **Q;
char *p;
int i=1, err=0;
unsigned char md[80];
unsigned char buffer[1000];
rtlDigest Digest;
P=digest_in_MD;
R=digest_out_MD2;
i = 1;
while (*P)
{
rtl_digest_MD2 (*P, strlen(*P), md, sizeof(md));
p=pt (md, RTL_DIGEST_LENGTH_MD2);
if (strcmp (p, *R))
{
printf("error calculating MD2 on '%s'\n",*P);
printf("got %s instead of %s\n",p,*R);
err++;
}
else
printf("test (MD2) %d ok\n",i);
i++;
R++;
P++;
}
P=digest_in_MD;
R=digest_out_MD5;
i=1;
while (*P)
{
rtl_digest_MD5 (*P, strlen(*P), md, sizeof(md));
p=pt (md, RTL_DIGEST_LENGTH_MD5);
if (strcmp (p, *R))
{
printf("error calculating MD5 on '%s'\n",*P);
printf("got %s instead of %s\n",p,*R);
err++;
}
else
printf("test (MD5) %d ok\n",i);
i++;
R++;
P++;
}
P=digest_in_SHA;
R=digest_out_SHA_0;
i=1;
while (*P)
{
rtl_digest_SHA (*P, strlen(*P), md, sizeof(md));
p=pt (md, RTL_DIGEST_LENGTH_SHA);
if (strcmp (p, *R))
{
printf("error calculating SHA-0 on '%s'\n",*P);
printf("got %s instead of %s\n",p,*R);
err++;
}
else
printf("test (SHA-0) %d ok\n",i);
i++;
R++;
P++;
}
memset (buffer, 'a', sizeof(buffer));
R = &digest_bigout_SHA_0;
Digest = rtl_digest_createSHA();
for (i=0; i<1000; i++)
rtl_digest_updateSHA (Digest, buffer, sizeof(buffer));
rtl_digest_getSHA (Digest, md, sizeof(md));
rtl_digest_destroySHA (Digest);
p=pt (md, RTL_DIGEST_LENGTH_SHA);
if (strcmp (p, *R))
{
printf("error calculating SHA-0 on '%s'\n",p);
printf("got %s instead of %s\n",p,*R);
err++;
}
else
printf("test (SHA-0) n ok\n");
P=digest_in_SHA;
R=digest_out_SHA_1;
i=1;
while (*P)
{
rtl_digest_SHA1 (*P, strlen(*P), md, sizeof(md));
p=pt (md, RTL_DIGEST_LENGTH_SHA1);
if (strcmp (p, *R))
{
printf("error calculating SHA-1 on '%s'\n",*P);
printf("got %s instead of %s\n",p,*R);
err++;
}
else
printf("test (SHA-1) %d ok\n",i);
i++;
R++;
P++;
}
memset (buffer, 'a', sizeof(buffer));
R = &digest_bigout_SHA_1;
Digest = rtl_digest_createSHA1();
for (i=0; i<1000; i++)
rtl_digest_updateSHA1 (Digest, buffer, sizeof(buffer));
rtl_digest_getSHA1 (Digest, md, sizeof(md));
rtl_digest_destroySHA1 (Digest);
p=pt (md, RTL_DIGEST_LENGTH_SHA1);
if (strcmp (p, *R))
{
printf("error calculating SHA-1 on '%s'\n",p);
printf("got %s instead of %s\n",p,*R);
err++;
}
else
printf("test (SHA-1) n ok\n");
P=digest_in_HMAC_MD5;
Q=digest_key_HMAC_MD5;
R=digest_out_HMAC_MD5;
Digest = rtl_digest_createHMAC_MD5();
i = 1;
while (*P)
{
rtl_digest_initHMAC_MD5 (Digest, (const sal_uInt8*)(*Q), strlen(*Q));
rtl_digest_updateHMAC_MD5 (Digest, *P, strlen(*P));
rtl_digest_getHMAC_MD5 (Digest, md, sizeof(md));
p=pt (md, RTL_DIGEST_LENGTH_HMAC_MD5);
if (strcmp (p, *R))
{
printf("error calculating HMAC-MD5 on '%s'\n",*P);
printf("got %s instead of %s\n",p,*R);
err++;
}
else
printf("test (HMAC-MD5) %d ok\n",i);
i++;
R++;
P++;
Q++;
}
rtl_digest_destroyHMAC_MD5 (Digest);
P=digest_in_HMAC_MD5;
Q=digest_key_HMAC_MD5;
R=digest_out_HMAC_SHA1;
Digest = rtl_digest_createHMAC_SHA1();
i = 1;
while (*P)
{
rtl_digest_initHMAC_SHA1 (Digest, (const sal_uInt8*)(*Q), strlen(*Q));
rtl_digest_updateHMAC_SHA1 (Digest, (const sal_uInt8*)(*P), strlen(*P));
rtl_digest_getHMAC_SHA1 (Digest, md, sizeof(md));
p=pt (md, RTL_DIGEST_LENGTH_HMAC_SHA1);
if (strcmp (p, *R))
{
printf("error calculating HMAC-SHA-1 on '%s'\n",*P);
printf("got %s instead of %s\n",p,*R);
err++;
}
else
printf("test (HMAC-SHA-1) %d ok\n",i);
i++;
P++;
Q++;
R++;
}
rtl_digest_destroyHMAC_SHA1 (Digest);
P=digest_in_HMAC_MD5;
Q=digest_key_HMAC_MD5;
rtl_digest_PBKDF2 (
md, RTL_DIGEST_LENGTH_MD5, /* [out] derived key */
(const sal_uInt8*)(Q[1]), strlen(Q[1]), /* [in] password */
(const sal_uInt8*)(P[1]), strlen(P[1]), /* [in] salt */
1000); /* [in] iteration count */
p=pt (md, RTL_DIGEST_LENGTH_MD5);
if (strcmp (p, "6349e09cb6b8c1485cfa9780ee3264df"))
{
printf("error calculating PBKDF2 on '%s'\n", P[1]);
err++;
}
else
printf("test (PBKDF2) %d ok\n", 1);
return (err);
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|