diff options
Diffstat (limited to 'src/lib/libcrypto/sha/sha1test.c')
-rw-r--r-- | src/lib/libcrypto/sha/sha1test.c | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/src/lib/libcrypto/sha/sha1test.c b/src/lib/libcrypto/sha/sha1test.c index 3c62a218b4..499a1cf5af 100644 --- a/src/lib/libcrypto/sha/sha1test.c +++ b/src/lib/libcrypto/sha/sha1test.c | |||
@@ -59,57 +59,70 @@ | |||
59 | #include <stdio.h> | 59 | #include <stdio.h> |
60 | #include <string.h> | 60 | #include <string.h> |
61 | #include <stdlib.h> | 61 | #include <stdlib.h> |
62 | #include "sha.h" | 62 | |
63 | #ifdef OPENSSL_NO_SHA | ||
64 | int main(int argc, char *argv[]) | ||
65 | { | ||
66 | printf("No SHA support\n"); | ||
67 | return(0); | ||
68 | } | ||
69 | #else | ||
70 | #include <openssl/evp.h> | ||
71 | #include <openssl/sha.h> | ||
72 | |||
73 | #ifdef CHARSET_EBCDIC | ||
74 | #include <openssl/ebcdic.h> | ||
75 | #endif | ||
63 | 76 | ||
64 | #undef SHA_0 /* FIPS 180 */ | 77 | #undef SHA_0 /* FIPS 180 */ |
65 | #define SHA_1 /* FIPS 180-1 */ | 78 | #define SHA_1 /* FIPS 180-1 */ |
66 | 79 | ||
67 | char *test[]={ | 80 | static char *test[]={ |
68 | "abc", | 81 | "abc", |
69 | "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", | 82 | "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", |
70 | NULL, | 83 | NULL, |
71 | }; | 84 | }; |
72 | 85 | ||
73 | #ifdef SHA_0 | 86 | #ifdef SHA_0 |
74 | char *ret[]={ | 87 | static char *ret[]={ |
75 | "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880", | 88 | "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880", |
76 | "d2516ee1acfa5baf33dfc1c471e438449ef134c8", | 89 | "d2516ee1acfa5baf33dfc1c471e438449ef134c8", |
77 | }; | 90 | }; |
78 | char *bigret= | 91 | static char *bigret= |
79 | "3232affa48628a26653b5aaa44541fd90d690603"; | 92 | "3232affa48628a26653b5aaa44541fd90d690603"; |
80 | #endif | 93 | #endif |
81 | #ifdef SHA_1 | 94 | #ifdef SHA_1 |
82 | char *ret[]={ | 95 | static char *ret[]={ |
83 | "a9993e364706816aba3e25717850c26c9cd0d89d", | 96 | "a9993e364706816aba3e25717850c26c9cd0d89d", |
84 | "84983e441c3bd26ebaae4aa1f95129e5e54670f1", | 97 | "84983e441c3bd26ebaae4aa1f95129e5e54670f1", |
85 | }; | 98 | }; |
86 | char *bigret= | 99 | static char *bigret= |
87 | "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; | 100 | "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; |
88 | #endif | 101 | #endif |
89 | 102 | ||
90 | #ifndef NOPROTO | ||
91 | static char *pt(unsigned char *md); | 103 | static char *pt(unsigned char *md); |
92 | #else | 104 | int main(int argc, char *argv[]) |
93 | static char *pt(); | ||
94 | #endif | ||
95 | |||
96 | int main(argc,argv) | ||
97 | int argc; | ||
98 | char *argv[]; | ||
99 | { | 105 | { |
100 | int i,err=0; | 106 | int i,err=0; |
101 | unsigned char **P,**R; | 107 | unsigned char **P,**R; |
102 | static unsigned char buf[1000]; | 108 | static unsigned char buf[1000]; |
103 | char *p,*r; | 109 | char *p,*r; |
104 | SHA_CTX c; | 110 | EVP_MD_CTX c; |
105 | unsigned char md[SHA_DIGEST_LENGTH]; | 111 | unsigned char md[SHA_DIGEST_LENGTH]; |
106 | 112 | ||
113 | #ifdef CHARSET_EBCDIC | ||
114 | ebcdic2ascii(test[0], test[0], strlen(test[0])); | ||
115 | ebcdic2ascii(test[1], test[1], strlen(test[1])); | ||
116 | #endif | ||
117 | |||
118 | EVP_MD_CTX_init(&c); | ||
107 | P=(unsigned char **)test; | 119 | P=(unsigned char **)test; |
108 | R=(unsigned char **)ret; | 120 | R=(unsigned char **)ret; |
109 | i=1; | 121 | i=1; |
110 | while (*P != NULL) | 122 | while (*P != NULL) |
111 | { | 123 | { |
112 | p=pt(SHA1(*P,(unsigned long)strlen((char *)*P),NULL)); | 124 | EVP_Digest(*P,(unsigned long)strlen((char *)*P),md,NULL,EVP_sha1(), NULL); |
125 | p=pt(md); | ||
113 | if (strcmp(p,(char *)*R) != 0) | 126 | if (strcmp(p,(char *)*R) != 0) |
114 | { | 127 | { |
115 | printf("error calculating SHA1 on '%s'\n",*P); | 128 | printf("error calculating SHA1 on '%s'\n",*P); |
@@ -124,10 +137,13 @@ char *argv[]; | |||
124 | } | 137 | } |
125 | 138 | ||
126 | memset(buf,'a',1000); | 139 | memset(buf,'a',1000); |
127 | SHA1_Init(&c); | 140 | #ifdef CHARSET_EBCDIC |
141 | ebcdic2ascii(buf, buf, 1000); | ||
142 | #endif /*CHARSET_EBCDIC*/ | ||
143 | EVP_DigestInit_ex(&c,EVP_sha1(), NULL); | ||
128 | for (i=0; i<1000; i++) | 144 | for (i=0; i<1000; i++) |
129 | SHA1_Update(&c,buf,1000); | 145 | EVP_DigestUpdate(&c,buf,1000); |
130 | SHA1_Final(md,&c); | 146 | EVP_DigestFinal_ex(&c,md,NULL); |
131 | p=pt(md); | 147 | p=pt(md); |
132 | 148 | ||
133 | r=bigret; | 149 | r=bigret; |
@@ -140,11 +156,11 @@ char *argv[]; | |||
140 | else | 156 | else |
141 | printf("test 3 ok\n"); | 157 | printf("test 3 ok\n"); |
142 | exit(err); | 158 | exit(err); |
159 | EVP_MD_CTX_cleanup(&c); | ||
143 | return(0); | 160 | return(0); |
144 | } | 161 | } |
145 | 162 | ||
146 | static char *pt(md) | 163 | static char *pt(unsigned char *md) |
147 | unsigned char *md; | ||
148 | { | 164 | { |
149 | int i; | 165 | int i; |
150 | static char buf[80]; | 166 | static char buf[80]; |
@@ -153,3 +169,4 @@ unsigned char *md; | |||
153 | sprintf(&(buf[i*2]),"%02x",md[i]); | 169 | sprintf(&(buf[i*2]),"%02x",md[i]); |
154 | return(buf); | 170 | return(buf); |
155 | } | 171 | } |
172 | #endif | ||