summaryrefslogtreecommitdiff
path: root/src/regress/lib/libcrypto/sha512/sha512test.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/regress/lib/libcrypto/sha512/sha512test.c')
-rw-r--r--src/regress/lib/libcrypto/sha512/sha512test.c242
1 files changed, 0 insertions, 242 deletions
diff --git a/src/regress/lib/libcrypto/sha512/sha512test.c b/src/regress/lib/libcrypto/sha512/sha512test.c
deleted file mode 100644
index 0d5121036b..0000000000
--- a/src/regress/lib/libcrypto/sha512/sha512test.c
+++ /dev/null
@@ -1,242 +0,0 @@
1/* $OpenBSD: sha512test.c,v 1.7 2021/12/29 23:02:00 tb Exp $ */
2/* ====================================================================
3 * Copyright (c) 2004 The OpenSSL Project. All rights reserved.
4 * ====================================================================
5 */
6#include <stdio.h>
7#include <string.h>
8#include <stdlib.h>
9
10#include <openssl/sha.h>
11#include <openssl/evp.h>
12#include <openssl/crypto.h>
13
14#if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA512)
15int
16main(int argc, char *argv[])
17{
18 printf("No SHA512 support\n");
19 return (0);
20}
21#else
22
23unsigned char app_c1[SHA512_DIGEST_LENGTH] = {
24 0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba,
25 0xcc, 0x41, 0x73, 0x49, 0xae, 0x20, 0x41, 0x31,
26 0x12, 0xe6, 0xfa, 0x4e, 0x89, 0xa9, 0x7e, 0xa2,
27 0x0a, 0x9e, 0xee, 0xe6, 0x4b, 0x55, 0xd3, 0x9a,
28 0x21, 0x92, 0x99, 0x2a, 0x27, 0x4f, 0xc1, 0xa8,
29 0x36, 0xba, 0x3c, 0x23, 0xa3, 0xfe, 0xeb, 0xbd,
30 0x45, 0x4d, 0x44, 0x23, 0x64, 0x3c, 0xe8, 0x0e,
31 0x2a, 0x9a, 0xc9, 0x4f, 0xa5, 0x4c, 0xa4, 0x9f,
32};
33
34unsigned char app_c2[SHA512_DIGEST_LENGTH] = {
35 0x8e, 0x95, 0x9b, 0x75, 0xda, 0xe3, 0x13, 0xda,
36 0x8c, 0xf4, 0xf7, 0x28, 0x14, 0xfc, 0x14, 0x3f,
37 0x8f, 0x77, 0x79, 0xc6, 0xeb, 0x9f, 0x7f, 0xa1,
38 0x72, 0x99, 0xae, 0xad, 0xb6, 0x88, 0x90, 0x18,
39 0x50, 0x1d, 0x28, 0x9e, 0x49, 0x00, 0xf7, 0xe4,
40 0x33, 0x1b, 0x99, 0xde, 0xc4, 0xb5, 0x43, 0x3a,
41 0xc7, 0xd3, 0x29, 0xee, 0xb6, 0xdd, 0x26, 0x54,
42 0x5e, 0x96, 0xe5, 0x5b, 0x87, 0x4b, 0xe9, 0x09,
43};
44
45unsigned char app_c3[SHA512_DIGEST_LENGTH] = {
46 0xe7, 0x18, 0x48, 0x3d, 0x0c, 0xe7, 0x69, 0x64,
47 0x4e, 0x2e, 0x42, 0xc7, 0xbc, 0x15, 0xb4, 0x63,
48 0x8e, 0x1f, 0x98, 0xb1, 0x3b, 0x20, 0x44, 0x28,
49 0x56, 0x32, 0xa8, 0x03, 0xaf, 0xa9, 0x73, 0xeb,
50 0xde, 0x0f, 0xf2, 0x44, 0x87, 0x7e, 0xa6, 0x0a,
51 0x4c, 0xb0, 0x43, 0x2c, 0xe5, 0x77, 0xc3, 0x1b,
52 0xeb, 0x00, 0x9c, 0x5c, 0x2c, 0x49, 0xaa, 0x2e,
53 0x4e, 0xad, 0xb2, 0x17, 0xad, 0x8c, 0xc0, 0x9b,
54};
55
56unsigned char app_d1[SHA384_DIGEST_LENGTH] = {
57 0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b,
58 0xb5, 0xa0, 0x3d, 0x69, 0x9a, 0xc6, 0x50, 0x07,
59 0x27, 0x2c, 0x32, 0xab, 0x0e, 0xde, 0xd1, 0x63,
60 0x1a, 0x8b, 0x60, 0x5a, 0x43, 0xff, 0x5b, 0xed,
61 0x80, 0x86, 0x07, 0x2b, 0xa1, 0xe7, 0xcc, 0x23,
62 0x58, 0xba, 0xec, 0xa1, 0x34, 0xc8, 0x25, 0xa7,
63};
64
65unsigned char app_d2[SHA384_DIGEST_LENGTH] = {
66 0x09, 0x33, 0x0c, 0x33, 0xf7, 0x11, 0x47, 0xe8,
67 0x3d, 0x19, 0x2f, 0xc7, 0x82, 0xcd, 0x1b, 0x47,
68 0x53, 0x11, 0x1b, 0x17, 0x3b, 0x3b, 0x05, 0xd2,
69 0x2f, 0xa0, 0x80, 0x86, 0xe3, 0xb0, 0xf7, 0x12,
70 0xfc, 0xc7, 0xc7, 0x1a, 0x55, 0x7e, 0x2d, 0xb9,
71 0x66, 0xc3, 0xe9, 0xfa, 0x91, 0x74, 0x60, 0x39,
72};
73
74unsigned char app_d3[SHA384_DIGEST_LENGTH] = {
75 0x9d, 0x0e, 0x18, 0x09, 0x71, 0x64, 0x74, 0xcb,
76 0x08, 0x6e, 0x83, 0x4e, 0x31, 0x0a, 0x4a, 0x1c,
77 0xed, 0x14, 0x9e, 0x9c, 0x00, 0xf2, 0x48, 0x52,
78 0x79, 0x72, 0xce, 0xc5, 0x70, 0x4c, 0x2a, 0x5b,
79 0x07, 0xb8, 0xb3, 0xdc, 0x38, 0xec, 0xc4, 0xeb,
80 0xae, 0x97, 0xdd, 0xd8, 0x7f, 0x3d, 0x89, 0x85,
81};
82
83int
84main(int argc, char **argv)
85{
86 unsigned char md[SHA512_DIGEST_LENGTH];
87 int i;
88 EVP_MD_CTX *evp = NULL;
89
90#ifdef OPENSSL_IA32_SSE2
91 /* Alternative to this is to call OpenSSL_add_all_algorithms...
92 * The below code is retained exclusively for debugging purposes. */
93 {
94 char *env;
95
96 if ((env=getenv("OPENSSL_ia32cap")))
97 OPENSSL_ia32cap = strtoul (env, NULL, 0);
98 }
99#endif
100
101 fprintf(stdout, "Testing SHA-512 ");
102
103 if (!EVP_Digest("abc", 3, md, NULL, EVP_sha512(), NULL))
104 goto err;
105 if (memcmp(md, app_c1, sizeof(app_c1))) {
106 fflush(stdout);
107 fprintf(stderr, "\nTEST 1 of 3 failed.\n");
108 goto err;
109 }
110 fprintf(stdout, ".");
111 fflush(stdout);
112
113 EVP_Digest(
114 "abcdefgh""bcdefghi""cdefghij""defghijk"
115 "efghijkl""fghijklm""ghijklmn""hijklmno"
116 "ijklmnop""jklmnopq""klmnopqr""lmnopqrs"
117 "mnopqrst""nopqrstu",
118 112, md, NULL, EVP_sha512(), NULL);
119 if (memcmp(md, app_c2, sizeof(app_c2))) {
120 fflush(stdout);
121 fprintf(stderr, "\nTEST 2 of 3 failed.\n");
122 goto err;
123 }
124 fprintf(stdout, ".");
125 fflush(stdout);
126
127 if ((evp = EVP_MD_CTX_new()) == NULL) {
128 fflush(stdout);
129 fprintf(stderr, "\nEVP_MD_CTX_new() failed.\n");
130 goto err;
131 }
132 if (!EVP_DigestInit_ex(evp, EVP_sha512(), NULL)) {
133 fflush(stdout);
134 fprintf(stderr, "\nEVP_DigestInit_ex failed.\n");
135 goto err;
136 }
137
138 for (i = 0; i < 1000000; i += 288) {
139 if (!EVP_DigestUpdate(evp,
140 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
141 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
142 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
143 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
144 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
145 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
146 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
147 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
148 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa",
149 (1000000 - i) < 288 ? 1000000 - i : 288)) {
150 fflush(stdout);
151 fprintf(stderr, "\nEVP_DigestUpdate failed.\n");
152 goto err;
153 }
154 }
155 if (!EVP_DigestFinal_ex(evp, md, NULL)) {
156 fflush(stdout);
157 fprintf(stderr, "\nEVP_DigestFinal failed.\n");
158 goto err;
159 }
160 if (!EVP_MD_CTX_reset(evp)) {
161 fflush(stdout);
162 fprintf(stderr, "\nEVP_MD_CTX_reset failed.\n");
163 goto err;
164 }
165
166 if (memcmp(md, app_c3, sizeof(app_c3))) {
167 fflush(stdout);
168 fprintf(stderr, "\nTEST 3 of 3 failed.\n");
169 goto err;
170 }
171 fprintf(stdout, ".");
172 fflush(stdout);
173
174 fprintf(stdout, " passed.\n");
175 fflush(stdout);
176
177 fprintf(stdout, "Testing SHA-384 ");
178
179 EVP_Digest("abc", 3, md, NULL, EVP_sha384(), NULL);
180 if (memcmp(md, app_d1, sizeof(app_d1))) {
181 fflush(stdout);
182 fprintf(stderr, "\nTEST 1 of 3 failed.\n");
183 goto err;
184 }
185 fprintf(stdout, ".");
186 fflush(stdout);
187
188 EVP_Digest(
189 "abcdefgh""bcdefghi""cdefghij""defghijk"
190 "efghijkl""fghijklm""ghijklmn""hijklmno"
191 "ijklmnop""jklmnopq""klmnopqr""lmnopqrs"
192 "mnopqrst""nopqrstu",
193 112, md, NULL, EVP_sha384(), NULL);
194 if (memcmp(md, app_d2, sizeof(app_d2))) {
195 fflush(stdout);
196 fprintf(stderr, "\nTEST 2 of 3 failed.\n");
197 goto err;
198 }
199 fprintf(stdout, ".");
200 fflush(stdout);
201
202 if (!EVP_DigestInit_ex(evp, EVP_sha384(), NULL)) {
203 fflush(stdout);
204 fprintf(stderr, "\nEVP_DigestInit_ex failed.\n");
205 goto err;
206 }
207 for (i = 0; i < 1000000; i += 64) {
208 if (!EVP_DigestUpdate(evp,
209 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
210 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa",
211 (1000000 - i) < 64 ? 1000000 - i : 64)) {
212 fflush(stdout);
213 fprintf(stderr, "\nEVP_DigestUpdate failed.\n");
214 goto err;
215 }
216 }
217 if (!EVP_DigestFinal_ex(evp, md, NULL)) {
218 fflush(stdout);
219 fprintf(stderr, "\nEVP_DigestFinal_ex failed.\n");
220 goto err;
221 }
222 EVP_MD_CTX_free(evp);
223 evp = NULL;
224
225 if (memcmp(md, app_d3, sizeof(app_d3))) {
226 fflush(stdout);
227 fprintf(stderr, "\nTEST 3 of 3 failed.\n");
228 goto err;
229 }
230 fprintf(stdout, ".");
231 fflush(stdout);
232
233 fprintf(stdout, " passed.\n");
234 fflush(stdout);
235
236 return 0;
237
238 err:
239 EVP_MD_CTX_free(evp);
240 return 1;
241}
242#endif