Remove EXHEADER, TEST, APPS, links:, install: and uninstall: where relevant
[openssl.git] / test / sha512t.c
1 /* crypto/sha/sha512t.c */
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 unsigned char app_c1[SHA512_DIGEST_LENGTH] = {
15     0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba,
16     0xcc, 0x41, 0x73, 0x49, 0xae, 0x20, 0x41, 0x31,
17     0x12, 0xe6, 0xfa, 0x4e, 0x89, 0xa9, 0x7e, 0xa2,
18     0x0a, 0x9e, 0xee, 0xe6, 0x4b, 0x55, 0xd3, 0x9a,
19     0x21, 0x92, 0x99, 0x2a, 0x27, 0x4f, 0xc1, 0xa8,
20     0x36, 0xba, 0x3c, 0x23, 0xa3, 0xfe, 0xeb, 0xbd,
21     0x45, 0x4d, 0x44, 0x23, 0x64, 0x3c, 0xe8, 0x0e,
22     0x2a, 0x9a, 0xc9, 0x4f, 0xa5, 0x4c, 0xa4, 0x9f
23 };
24
25 unsigned char app_c2[SHA512_DIGEST_LENGTH] = {
26     0x8e, 0x95, 0x9b, 0x75, 0xda, 0xe3, 0x13, 0xda,
27     0x8c, 0xf4, 0xf7, 0x28, 0x14, 0xfc, 0x14, 0x3f,
28     0x8f, 0x77, 0x79, 0xc6, 0xeb, 0x9f, 0x7f, 0xa1,
29     0x72, 0x99, 0xae, 0xad, 0xb6, 0x88, 0x90, 0x18,
30     0x50, 0x1d, 0x28, 0x9e, 0x49, 0x00, 0xf7, 0xe4,
31     0x33, 0x1b, 0x99, 0xde, 0xc4, 0xb5, 0x43, 0x3a,
32     0xc7, 0xd3, 0x29, 0xee, 0xb6, 0xdd, 0x26, 0x54,
33     0x5e, 0x96, 0xe5, 0x5b, 0x87, 0x4b, 0xe9, 0x09
34 };
35
36 unsigned char app_c3[SHA512_DIGEST_LENGTH] = {
37     0xe7, 0x18, 0x48, 0x3d, 0x0c, 0xe7, 0x69, 0x64,
38     0x4e, 0x2e, 0x42, 0xc7, 0xbc, 0x15, 0xb4, 0x63,
39     0x8e, 0x1f, 0x98, 0xb1, 0x3b, 0x20, 0x44, 0x28,
40     0x56, 0x32, 0xa8, 0x03, 0xaf, 0xa9, 0x73, 0xeb,
41     0xde, 0x0f, 0xf2, 0x44, 0x87, 0x7e, 0xa6, 0x0a,
42     0x4c, 0xb0, 0x43, 0x2c, 0xe5, 0x77, 0xc3, 0x1b,
43     0xeb, 0x00, 0x9c, 0x5c, 0x2c, 0x49, 0xaa, 0x2e,
44     0x4e, 0xad, 0xb2, 0x17, 0xad, 0x8c, 0xc0, 0x9b
45 };
46
47 unsigned char app_d1[SHA384_DIGEST_LENGTH] = {
48     0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b,
49     0xb5, 0xa0, 0x3d, 0x69, 0x9a, 0xc6, 0x50, 0x07,
50     0x27, 0x2c, 0x32, 0xab, 0x0e, 0xde, 0xd1, 0x63,
51     0x1a, 0x8b, 0x60, 0x5a, 0x43, 0xff, 0x5b, 0xed,
52     0x80, 0x86, 0x07, 0x2b, 0xa1, 0xe7, 0xcc, 0x23,
53     0x58, 0xba, 0xec, 0xa1, 0x34, 0xc8, 0x25, 0xa7
54 };
55
56 unsigned char app_d2[SHA384_DIGEST_LENGTH] = {
57     0x09, 0x33, 0x0c, 0x33, 0xf7, 0x11, 0x47, 0xe8,
58     0x3d, 0x19, 0x2f, 0xc7, 0x82, 0xcd, 0x1b, 0x47,
59     0x53, 0x11, 0x1b, 0x17, 0x3b, 0x3b, 0x05, 0xd2,
60     0x2f, 0xa0, 0x80, 0x86, 0xe3, 0xb0, 0xf7, 0x12,
61     0xfc, 0xc7, 0xc7, 0x1a, 0x55, 0x7e, 0x2d, 0xb9,
62     0x66, 0xc3, 0xe9, 0xfa, 0x91, 0x74, 0x60, 0x39
63 };
64
65 unsigned char app_d3[SHA384_DIGEST_LENGTH] = {
66     0x9d, 0x0e, 0x18, 0x09, 0x71, 0x64, 0x74, 0xcb,
67     0x08, 0x6e, 0x83, 0x4e, 0x31, 0x0a, 0x4a, 0x1c,
68     0xed, 0x14, 0x9e, 0x9c, 0x00, 0xf2, 0x48, 0x52,
69     0x79, 0x72, 0xce, 0xc5, 0x70, 0x4c, 0x2a, 0x5b,
70     0x07, 0xb8, 0xb3, 0xdc, 0x38, 0xec, 0xc4, 0xeb,
71     0xae, 0x97, 0xdd, 0xd8, 0x7f, 0x3d, 0x89, 0x85
72 };
73
74 int main(int argc, char **argv)
75 {
76     unsigned char md[SHA512_DIGEST_LENGTH];
77     int i;
78     EVP_MD_CTX evp;
79
80 # ifdef OPENSSL_IA32_SSE2
81     /*
82      * Alternative to this is to call OpenSSL_add_all_algorithms... The below
83      * code is retained exclusively for debugging purposes.
84      */
85     {
86         char *env;
87
88         if ((env = getenv("OPENSSL_ia32cap")))
89             OPENSSL_ia32cap = strtoul(env, NULL, 0);
90     }
91 # endif
92
93     fprintf(stdout, "Testing SHA-512 ");
94
95     EVP_Digest("abc", 3, md, NULL, EVP_sha512(), NULL);
96     if (memcmp(md, app_c1, sizeof(app_c1))) {
97         fflush(stdout);
98         fprintf(stderr, "\nTEST 1 of 3 failed.\n");
99         return 1;
100     } else
101         fprintf(stdout, ".");
102     fflush(stdout);
103
104     EVP_Digest("abcdefgh" "bcdefghi" "cdefghij" "defghijk"
105                "efghijkl" "fghijklm" "ghijklmn" "hijklmno"
106                "ijklmnop" "jklmnopq" "klmnopqr" "lmnopqrs"
107                "mnopqrst" "nopqrstu", 112, md, NULL, EVP_sha512(), NULL);
108     if (memcmp(md, app_c2, sizeof(app_c2))) {
109         fflush(stdout);
110         fprintf(stderr, "\nTEST 2 of 3 failed.\n");
111         return 1;
112     } else
113         fprintf(stdout, ".");
114     fflush(stdout);
115
116     EVP_MD_CTX_init(&evp);
117     EVP_DigestInit_ex(&evp, EVP_sha512(), NULL);
118     for (i = 0; i < 1000000; i += 288)
119         EVP_DigestUpdate(&evp, "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
120                          "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
121                          "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
122                          "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
123                          "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
124                          "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
125                          "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
126                          "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
127                          "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa",
128                          (1000000 - i) < 288 ? 1000000 - i : 288);
129     EVP_DigestFinal_ex(&evp, md, NULL);
130     EVP_MD_CTX_cleanup(&evp);
131
132     if (memcmp(md, app_c3, sizeof(app_c3))) {
133         fflush(stdout);
134         fprintf(stderr, "\nTEST 3 of 3 failed.\n");
135         return 1;
136     } else
137         fprintf(stdout, ".");
138     fflush(stdout);
139
140     fprintf(stdout, " passed.\n");
141     fflush(stdout);
142
143     fprintf(stdout, "Testing SHA-384 ");
144
145     EVP_Digest("abc", 3, md, NULL, EVP_sha384(), NULL);
146     if (memcmp(md, app_d1, sizeof(app_d1))) {
147         fflush(stdout);
148         fprintf(stderr, "\nTEST 1 of 3 failed.\n");
149         return 1;
150     } else
151         fprintf(stdout, ".");
152     fflush(stdout);
153
154     EVP_Digest("abcdefgh" "bcdefghi" "cdefghij" "defghijk"
155                "efghijkl" "fghijklm" "ghijklmn" "hijklmno"
156                "ijklmnop" "jklmnopq" "klmnopqr" "lmnopqrs"
157                "mnopqrst" "nopqrstu", 112, md, NULL, EVP_sha384(), NULL);
158     if (memcmp(md, app_d2, sizeof(app_d2))) {
159         fflush(stdout);
160         fprintf(stderr, "\nTEST 2 of 3 failed.\n");
161         return 1;
162     } else
163         fprintf(stdout, ".");
164     fflush(stdout);
165
166     EVP_MD_CTX_init(&evp);
167     EVP_DigestInit_ex(&evp, EVP_sha384(), NULL);
168     for (i = 0; i < 1000000; i += 64)
169         EVP_DigestUpdate(&evp, "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa"
170                          "aaaaaaaa" "aaaaaaaa" "aaaaaaaa" "aaaaaaaa",
171                          (1000000 - i) < 64 ? 1000000 - i : 64);
172     EVP_DigestFinal_ex(&evp, md, NULL);
173     EVP_MD_CTX_cleanup(&evp);
174
175     if (memcmp(md, app_d3, sizeof(app_d3))) {
176         fflush(stdout);
177         fprintf(stderr, "\nTEST 3 of 3 failed.\n");
178         return 1;
179     } else
180         fprintf(stdout, ".");
181     fflush(stdout);
182
183     fprintf(stdout, " passed.\n");
184     fflush(stdout);
185
186     return 0;
187 }