4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2002-2003 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * HMAC SHA-1 test cases as defined by RFC 2202.
32 * The test uses predefined keys, data and digests. The data and keys
33 * are used by the HMAC SHA-1 implemention to produce a hash digest and
34 * the the result is compared against the expected digest.
41 #include "hmac_sha1.h"
42 #include "hmac_test.h"
45 typedef struct test_data
{
46 unsigned char key
[80];
48 unsigned char data
[80];
50 unsigned char digest
[20];
64 getxdata(td
[0].key
, "0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b",
67 (void) strcpy((char *)td
[0].data
, "Hi There");
68 getxdata(td
[0].digest
, "b617318655057264e28bc0b6fb378c8ef146be00", 20);
71 (void) strcpy((char *)td
[1].key
, "Jefe");
73 (void) strcpy((char *)td
[1].data
, "what do ya want for nothing?");
74 getxdata(td
[1].digest
, "effcdf6ae5eb2fa2d27416d5f184df9c259a7c79", 20);
77 getxdata(td
[2].key
, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
80 getxdata(td
[2].data
, "ddddddddddddddddddddddddddddddddddddddddddddd"
81 "ddddddddddddddddddddddddddddddddddddddddddddddddddddddd", 50);
82 getxdata(td
[2].digest
, "125d7342b9ac11cd91a39af48aa17b4f63f175d3", 20);
85 getxdata(td
[3].key
, "0102030405060708090a0b0c0d0e0f1011121314151617"
86 "1819", td
[3].keylen
);
88 getxdata(td
[3].data
, "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd"
89 "cdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcdcd",
91 getxdata(td
[3].digest
, "4c9007f4026250c6bc8414f9bf50c86c2d7235da", 20);
94 getxdata(td
[4].key
, "0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c",
97 (void) strcpy((char *)td
[4].data
, "Test With Truncation");
98 getxdata(td
[4].digest
, "4c1a03424b55e07fe7f27be1d58bb9324a9a5a04", 20);
101 getxdata(td
[5].key
, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
102 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
103 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
106 (void) strcpy((char *)td
[5].data
,
107 "Test Using Larger Than Block-Size Key - Hash Key First");
108 getxdata(td
[5].digest
, "aa4ae5e15272d00e95705637ce8a3b55ed402112", 20);
111 getxdata(td
[6].key
, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
112 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
113 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
116 (void) strcpy((char *)td
[6].data
,
117 "Test Using Larger Than Block-Size Key and Larger Than One "
119 getxdata(td
[6].digest
, "e8e99d0f45237d786d6bbaa7965c7808bbff1a91", 20);
121 num
= sizeof (td
) / sizeof (test_data_t
);
122 for (i
= 0; i
< num
; i
++) {
125 (void) printf("Test #%d ", i
);
126 HMACInit(&sha
, td
[i
].key
, td
[i
].keylen
);
127 HMACUpdate(&sha
, td
[i
].data
, td
[i
].datalen
);
128 HMACFinal(&sha
, td
[i
].key
, td
[i
].keylen
, digest
);
130 if (bcmp(digest
, td
[i
].digest
, 20) != 0) {
131 (void) printf("FAILED\n");
134 (void) printf("PASSED\n");