8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / common / net / wanboot / crypt / sha1_test.c
blob8293e00ba1bdc04d5d92cb11ebe5498e0875ca7f
1 /*
2 * CDDL HEADER START
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
7 * with the License.
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]
20 * CDDL HEADER END
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 * sha1_test.c
32 * Description:
33 * This file will exercise the SHA-1 code performing the three
34 * tests documented in FIPS PUB 180-1 plus one which calls
35 * SHA1Input with an exact multiple of 512 bits, plus a few
36 * error test checks.
38 * Portability Issues:
39 * None.
43 #include <stdio.h>
44 #include <strings.h>
46 #include <sys/sha1.h>
47 #include "sha1_test.h"
48 #include "cmn_test.h"
51 * Define patterns for testing
53 #define TEST1 "abc"
54 #define TEST2a "abcdbcdecdefdefgefghfghighijhi"
55 #define TEST2b "jkijkljklmklmnlmnomnopnopq"
56 #define TEST2 TEST2a TEST2b
57 #define TEST3 "a"
58 #define TEST4a "01234567012345670123456701234567"
59 #define TEST4b "01234567012345670123456701234567"
61 /* an exact multiple of 512 bits */
62 #define TEST4 TEST4a TEST4b
64 static char *testarray[4] = {
65 TEST1,
66 TEST2,
67 TEST3,
68 TEST4
71 static int repeatcount[4] = { 1, 1, 1000000, 10 };
73 static char *resultarray[4] = {
74 "A9993E364706816ABA3E25717850C26C9CD0D89D",
75 "84983E441C3BD26EBAAE4AA1F95129E5E54670F1",
76 "34AA973CD4C4DAA4F61EEB2BDBAD27316534016F",
77 "DEA356A2CDDD90C7A7ECEDC5EBB563934F460452"
80 int
81 sha1test(void)
83 SHA1_CTX sha;
84 int fail;
85 int i;
86 int j;
87 uint8_t digest[20];
88 uint8_t rdigest[20];
91 * Perform SHA-1 tests
93 for (j = 0; j < 4; ++j) {
94 fail = 0;
95 (void) printf("Test #%d ", j+1);
97 SHA1Init(&sha);
99 for (i = 0; i < repeatcount[j]; ++i) {
100 SHA1Update(&sha, (unsigned char *)testarray[j],
101 strlen(testarray[j]));
104 SHA1Final(digest, &sha);
106 getxdata(rdigest, resultarray[j], 20);
107 if (bcmp(digest, rdigest, 20) != 0) {
108 (void) printf("FAILED\n");
109 fail++;
110 } else {
111 (void) printf("PASSED\n");
115 return (fail);