TLS/SSL and crypto library
Revisión | e6738d4be8d4ef42f213921351e7e9df79be7d1a (tree) |
---|---|
Tiempo | 2004-02-03 00:25:30 |
Autor | Ben Laurie <ben@open...> |
Commiter | Ben Laurie |
Improve test suite.
@@ -23,6 +23,7 @@ | ||
23 | 23 | #include <openssl/sha.h> |
24 | 24 | #include <openssl/err.h> |
25 | 25 | #include <openssl/fips.h> |
26 | +#include <openssl/md5.h> | |
26 | 27 | |
27 | 28 | #ifndef OPENSSL_FIPS |
28 | 29 | int main(int argc, char *argv[]) |
@@ -65,7 +66,8 @@ static int FIPS_des_test() | ||
65 | 66 | DES_cblock ciphertext; |
66 | 67 | DES_cblock buf; |
67 | 68 | |
68 | - DES_set_key(&userkey, &key); | |
69 | + if(DES_set_key(&userkey, &key)) | |
70 | + return 0; | |
69 | 71 | DES_ecb_encrypt( &plaintext, &ciphertext, &key, 1); |
70 | 72 | DES_ecb_encrypt( &ciphertext, &buf, &key, 0); |
71 | 73 | if (memcmp(buf, plaintext, sizeof(buf))) |
@@ -86,7 +88,8 @@ static int FIPS_dsa_test() | ||
86 | 88 | dsa = DSA_generate_parameters(512,NULL,0,NULL,NULL,NULL,NULL); |
87 | 89 | if (!dsa) |
88 | 90 | return 0; |
89 | - DSA_generate_key(dsa); | |
91 | + if(!DSA_generate_key(dsa)) | |
92 | + return 0; | |
90 | 93 | if ( DSA_sign(0,dgst,strlen(dgst),sig,&siglen,dsa) != 1 ) |
91 | 94 | return 0; |
92 | 95 | if ( DSA_verify(0,dgst,strlen(dgst),sig,siglen,dsa) != 1 ) |
@@ -138,6 +141,24 @@ static int FIPS_sha1_test() | ||
138 | 141 | return 1; |
139 | 142 | } |
140 | 143 | |
144 | +/* MD5: generate hash of known digest value and compate to known | |
145 | + precomputed correct hash */ | |
146 | + | |
147 | +static int md5_test() | |
148 | + { | |
149 | + unsigned char digest[MD5_DIGEST_LENGTH] = | |
150 | + { 0x48, 0x50, 0xf0, 0xa3, 0x3a, 0xed, 0xd3, 0xaf, 0x6e, 0x47, 0x7f, 0x83, 0x02, 0xb1, 0x09, 0x68 }; | |
151 | + char str[] = "etaonrishd"; | |
152 | + | |
153 | + unsigned char md[MD5_DIGEST_LENGTH]; | |
154 | + | |
155 | + if (!MD5(str,strlen(str),md)) | |
156 | + return 0; | |
157 | + if (memcmp(md,digest,sizeof(md))) | |
158 | + return 0; | |
159 | + return 1; | |
160 | + } | |
161 | + | |
141 | 162 | static int Error; |
142 | 163 | const char * Fail(const char *msg) |
143 | 164 | { |
@@ -150,6 +171,11 @@ int main(int argc,char **argv) | ||
150 | 171 | |
151 | 172 | printf("\tFIPS-mode test application\n\n"); |
152 | 173 | |
174 | + /* Non-Approved cryptographic operation | |
175 | + */ | |
176 | + printf("0. Non-Approved cryptographic operation..."); | |
177 | + printf( md5_test() ? "successful\n" : Fail("FAILED!\n") ); | |
178 | + | |
153 | 179 | /* Power-up self test failure |
154 | 180 | */ |
155 | 181 | printf("1. Automatic power-up self test..."); |
@@ -205,6 +231,12 @@ int main(int argc,char **argv) | ||
205 | 231 | printf("7. SHA-1 hash..."); |
206 | 232 | printf( FIPS_sha1_test() ? "successful\n" : Fail("FAILED!\n") ); |
207 | 233 | |
234 | + /* Non-Approved cryptographic operation | |
235 | + */ | |
236 | + printf("8. Non-Approved cryptographic operation..."); | |
237 | + printf( md5_test() ? Fail("passed INCORRECTLY!\n") | |
238 | + : "failed as expected\n" ); | |
239 | + | |
208 | 240 | printf("\nAll tests completed with %d errors\n", Error); |
209 | 241 | return 0; |
210 | 242 | } |