| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | #include <stdio.h> |
|---|
| 44 | #include <string.h> |
|---|
| 45 | #include "wizard/WizardsToolkit.h" |
|---|
| 46 | #include "validate.h" |
|---|
| 47 | |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | #define AbsoluteValue(x) ((x) < 0 ? -(x) : (x)) |
|---|
| 52 | #define CipherKey "FakeKey" |
|---|
| 53 | #define CipherId "FakeID" |
|---|
| 54 | #define CipherPlaintext "1234567890abcde" |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | |
|---|
| 61 | |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | |
|---|
| 68 | |
|---|
| 69 | |
|---|
| 70 | |
|---|
| 71 | |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | |
|---|
| 81 | static long PrintValidateString(FILE *file,const char *format,...) |
|---|
| 82 | { |
|---|
| 83 | char |
|---|
| 84 | string[MaxTextExtent]; |
|---|
| 85 | |
|---|
| 86 | long |
|---|
| 87 | length; |
|---|
| 88 | |
|---|
| 89 | va_list |
|---|
| 90 | operands; |
|---|
| 91 | |
|---|
| 92 | va_start(operands,format); |
|---|
| 93 | length=FormatWizardStringList(string,MaxTextExtent,format,operands); |
|---|
| 94 | va_end(operands); |
|---|
| 95 | if (length < 0) |
|---|
| 96 | return(-1); |
|---|
| 97 | return((long) fwrite(string,(size_t) length,1,file)); |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | static WizardBooleanType TestAES(void) |
|---|
| 101 | { |
|---|
| 102 | CipherInfo |
|---|
| 103 | *cipher_info; |
|---|
| 104 | |
|---|
| 105 | register long |
|---|
| 106 | i; |
|---|
| 107 | |
|---|
| 108 | StringInfo |
|---|
| 109 | *ciphertext, |
|---|
| 110 | *key, |
|---|
| 111 | *plaintext, |
|---|
| 112 | *results; |
|---|
| 113 | |
|---|
| 114 | WizardBooleanType |
|---|
| 115 | clone, |
|---|
| 116 | pass; |
|---|
| 117 | |
|---|
| 118 | (void) PrintValidateString(stdout,"testing aes encipher:\n"); |
|---|
| 119 | pass=WizardTrue; |
|---|
| 120 | cipher_info=AcquireCipherInfo(AESCipher,CBCMode); |
|---|
| 121 | for (i=0; i < AESEncipherTestVectors; i++) |
|---|
| 122 | { |
|---|
| 123 | (void) PrintValidateString(stdout," test %ld (%ld bit key) ",i+1,(long) |
|---|
| 124 | (8*aes_encipher_test_vector[i].key_length)); |
|---|
| 125 | key=AcquireStringInfo(aes_encipher_test_vector[i].key_length); |
|---|
| 126 | SetStringInfoDatum(key,aes_encipher_test_vector[i].key); |
|---|
| 127 | SetCipherKey(cipher_info,key); |
|---|
| 128 | ResetCipherNonce(cipher_info); |
|---|
| 129 | plaintext=AcquireStringInfo(aes_encipher_test_vector[i].length); |
|---|
| 130 | SetStringInfoDatum(plaintext,aes_encipher_test_vector[i].plaintext); |
|---|
| 131 | ciphertext=EncipherCipher(cipher_info,plaintext); |
|---|
| 132 | results=AcquireStringInfo(aes_encipher_test_vector[i].result_length); |
|---|
| 133 | SetStringInfoDatum(results,aes_encipher_test_vector[i].result); |
|---|
| 134 | clone=CompareStringInfo(ciphertext,results) == 0 ? WizardTrue : WizardFalse; |
|---|
| 135 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 136 | "fail"); |
|---|
| 137 | if (clone == WizardFalse) |
|---|
| 138 | pass=WizardFalse; |
|---|
| 139 | results=DestroyStringInfo(results); |
|---|
| 140 | key=DestroyStringInfo(key); |
|---|
| 141 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 142 | } |
|---|
| 143 | cipher_info=DestroyCipherInfo(cipher_info); |
|---|
| 144 | (void) PrintValidateString(stdout,"testing aes decipher:\n"); |
|---|
| 145 | cipher_info=AcquireCipherInfo(AESCipher,CBCMode); |
|---|
| 146 | for (i=0; i < AESDecipherTestVectors; i++) |
|---|
| 147 | { |
|---|
| 148 | (void) PrintValidateString(stdout," test %ld (%ld bit key) ",i+1,(long) |
|---|
| 149 | (8*aes_decipher_test_vector[i].key_length)); |
|---|
| 150 | key=AcquireStringInfo(aes_decipher_test_vector[i].key_length); |
|---|
| 151 | SetStringInfoDatum(key,aes_decipher_test_vector[i].key); |
|---|
| 152 | SetCipherKey(cipher_info,key); |
|---|
| 153 | ResetCipherNonce(cipher_info); |
|---|
| 154 | ciphertext=AcquireStringInfo(aes_decipher_test_vector[i].length); |
|---|
| 155 | SetStringInfoDatum(ciphertext,aes_decipher_test_vector[i].plaintext); |
|---|
| 156 | plaintext=DecipherCipher(cipher_info,ciphertext); |
|---|
| 157 | results=AcquireStringInfo(aes_decipher_test_vector[i].length); |
|---|
| 158 | SetStringInfoDatum(results,aes_decipher_test_vector[i].result); |
|---|
| 159 | clone=CompareStringInfo(plaintext,results) == 0 ? WizardTrue : WizardFalse; |
|---|
| 160 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 161 | "fail"); |
|---|
| 162 | if (clone == WizardFalse) |
|---|
| 163 | pass=WizardFalse; |
|---|
| 164 | results=DestroyStringInfo(results); |
|---|
| 165 | key=DestroyStringInfo(key); |
|---|
| 166 | ciphertext=DestroyStringInfo(ciphertext); |
|---|
| 167 | } |
|---|
| 168 | cipher_info=DestroyCipherInfo(cipher_info); |
|---|
| 169 | |
|---|
| 170 | |
|---|
| 171 | |
|---|
| 172 | (void) PrintValidateString(stdout,"testing aes non-blocksize " |
|---|
| 173 | "encipher/decipher:\n"); |
|---|
| 174 | cipher_info=AcquireCipherInfo(AESCipher,CBCMode); |
|---|
| 175 | key=StringToStringInfo(CipherKey); |
|---|
| 176 | SetCipherKey(cipher_info,key); |
|---|
| 177 | ResetCipherNonce(cipher_info); |
|---|
| 178 | key=DestroyStringInfo(key); |
|---|
| 179 | plaintext=StringToStringInfo(CipherPlaintext); |
|---|
| 180 | (void) PrintValidateString(stdout," test 0 "); |
|---|
| 181 | ciphertext=EncipherCipher(cipher_info,plaintext); |
|---|
| 182 | key=StringToStringInfo(CipherKey); |
|---|
| 183 | SetCipherKey(cipher_info,key); |
|---|
| 184 | ResetCipherNonce(cipher_info); |
|---|
| 185 | key=DestroyStringInfo(key); |
|---|
| 186 | plaintext=DecipherCipher(cipher_info,ciphertext); |
|---|
| 187 | results=StringToStringInfo(CipherPlaintext); |
|---|
| 188 | clone=CompareStringInfo(plaintext,results) == 0 ? WizardTrue : WizardFalse; |
|---|
| 189 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 190 | "fail"); |
|---|
| 191 | if (clone == WizardFalse) |
|---|
| 192 | pass=WizardFalse; |
|---|
| 193 | results=DestroyStringInfo(results); |
|---|
| 194 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 195 | cipher_info=DestroyCipherInfo(cipher_info); |
|---|
| 196 | |
|---|
| 197 | |
|---|
| 198 | |
|---|
| 199 | (void) PrintValidateString(stdout,"testing aes CTR-mode encipher/decipher:\n"); |
|---|
| 200 | cipher_info=AcquireCipherInfo(AESCipher,CTRMode); |
|---|
| 201 | key=StringToStringInfo(CipherKey); |
|---|
| 202 | SetCipherKey(cipher_info,key); |
|---|
| 203 | ResetCipherNonce(cipher_info); |
|---|
| 204 | key=DestroyStringInfo(key); |
|---|
| 205 | plaintext=StringToStringInfo(CipherPlaintext); |
|---|
| 206 | (void) PrintValidateString(stdout," test 0 "); |
|---|
| 207 | ciphertext=EncipherCipher(cipher_info,plaintext); |
|---|
| 208 | key=StringToStringInfo(CipherKey); |
|---|
| 209 | SetCipherKey(cipher_info,key); |
|---|
| 210 | ResetCipherNonce(cipher_info); |
|---|
| 211 | key=DestroyStringInfo(key); |
|---|
| 212 | plaintext=DecipherCipher(cipher_info,ciphertext); |
|---|
| 213 | results=StringToStringInfo(CipherPlaintext); |
|---|
| 214 | clone=CompareStringInfo(plaintext,results) == 0 ? WizardTrue : WizardFalse; |
|---|
| 215 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 216 | "fail"); |
|---|
| 217 | if (clone == WizardFalse) |
|---|
| 218 | pass=WizardFalse; |
|---|
| 219 | results=DestroyStringInfo(results); |
|---|
| 220 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 221 | cipher_info=DestroyCipherInfo(cipher_info); |
|---|
| 222 | return(pass); |
|---|
| 223 | } |
|---|
| 224 | |
|---|
| 225 | static WizardBooleanType TestAuthenticate(const char *passphrase) |
|---|
| 226 | { |
|---|
| 227 | AuthenticateInfo |
|---|
| 228 | *authenticate_info; |
|---|
| 229 | |
|---|
| 230 | ExceptionInfo |
|---|
| 231 | *exception; |
|---|
| 232 | |
|---|
| 233 | StringInfo |
|---|
| 234 | *key; |
|---|
| 235 | |
|---|
| 236 | WizardBooleanType |
|---|
| 237 | clone, |
|---|
| 238 | pass; |
|---|
| 239 | |
|---|
| 240 | (void) PrintValidateString(stdout,"testing secret authentication:\n"); |
|---|
| 241 | authenticate_info=AcquireAuthenticateInfo(SecretAuthenticateMethod, |
|---|
| 242 | (const char *) NULL,SHA256Hash); |
|---|
| 243 | (void) PrintValidateString(stdout," generate authenticate key:\n"); |
|---|
| 244 | if (passphrase != (const char *) NULL) |
|---|
| 245 | SetAuthenticatePassphrase(authenticate_info,passphrase); |
|---|
| 246 | SetAuthenticateKeyLength(authenticate_info,1024); |
|---|
| 247 | exception=AcquireExceptionInfo(); |
|---|
| 248 | pass=GenerateAuthenticateKey(authenticate_info,exception); |
|---|
| 249 | (void) PrintValidateString(stdout,"%s.\n",pass != WizardFalse ? "pass" : |
|---|
| 250 | "fail"); |
|---|
| 251 | key=CloneStringInfo(GetAuthenticateKey(authenticate_info)); |
|---|
| 252 | (void) PrintValidateString(stdout," authenticate key:\n"); |
|---|
| 253 | if (passphrase != (const char *) NULL) |
|---|
| 254 | SetAuthenticatePassphrase(authenticate_info,passphrase); |
|---|
| 255 | clone=AuthenticateKey(authenticate_info,exception); |
|---|
| 256 | exception=DestroyExceptionInfo(exception); |
|---|
| 257 | clone&=CompareStringInfo(GetAuthenticateKey(authenticate_info),key) == 0 ? |
|---|
| 258 | WizardTrue : WizardFalse; |
|---|
| 259 | if (clone == WizardFalse) |
|---|
| 260 | pass=WizardFalse; |
|---|
| 261 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 262 | "fail"); |
|---|
| 263 | key=DestroyStringInfo(key); |
|---|
| 264 | authenticate_info=DestroyAuthenticateInfo(authenticate_info); |
|---|
| 265 | return(pass); |
|---|
| 266 | } |
|---|
| 267 | |
|---|
| 268 | static WizardBooleanType TestBZIPEntropy(void) |
|---|
| 269 | { |
|---|
| 270 | EntropyInfo |
|---|
| 271 | *entropy_info; |
|---|
| 272 | |
|---|
| 273 | ExceptionInfo |
|---|
| 274 | *exception; |
|---|
| 275 | |
|---|
| 276 | register long |
|---|
| 277 | i; |
|---|
| 278 | |
|---|
| 279 | StringInfo |
|---|
| 280 | *chaos, |
|---|
| 281 | *plaintext; |
|---|
| 282 | |
|---|
| 283 | WizardBooleanType |
|---|
| 284 | clone, |
|---|
| 285 | pass, |
|---|
| 286 | status; |
|---|
| 287 | |
|---|
| 288 | (void) PrintValidateString(stdout,"testing bzip entropy:\n"); |
|---|
| 289 | pass=WizardTrue; |
|---|
| 290 | exception=AcquireExceptionInfo(); |
|---|
| 291 | entropy_info=AcquireEntropyInfo(BZIPEntropy,6); |
|---|
| 292 | for (i=0; i < ZipTestVectors; i++) |
|---|
| 293 | { |
|---|
| 294 | (void) PrintValidateString(stdout," test %ld ",i); |
|---|
| 295 | plaintext=StringToStringInfo((char *) bzip_test_vector[i].plaintext); |
|---|
| 296 | status=IncreaseEntropy(entropy_info,plaintext,exception); |
|---|
| 297 | chaos=AcquireStringInfo(bzip_test_vector[i].chaossize); |
|---|
| 298 | SetStringInfoDatum(chaos,bzip_test_vector[i].chaos); |
|---|
| 299 | clone=CompareStringInfo(GetEntropyChaos(entropy_info),chaos) == 0 ? |
|---|
| 300 | WizardTrue : WizardFalse; |
|---|
| 301 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 302 | "fail"); |
|---|
| 303 | if (clone == WizardFalse) |
|---|
| 304 | pass=WizardFalse; |
|---|
| 305 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 306 | chaos=DestroyStringInfo(chaos); |
|---|
| 307 | } |
|---|
| 308 | entropy_info=DestroyEntropyInfo(entropy_info); |
|---|
| 309 | (void) PrintValidateString(stdout,"testing bzip restore entropy:\n"); |
|---|
| 310 | pass=WizardTrue; |
|---|
| 311 | entropy_info=AcquireEntropyInfo(BZIPEntropy,6); |
|---|
| 312 | for (i=0; i < ZipTestVectors; i++) |
|---|
| 313 | { |
|---|
| 314 | (void) PrintValidateString(stdout," test %ld ",i); |
|---|
| 315 | chaos=AcquireStringInfo(bzip_test_vector[i].chaossize); |
|---|
| 316 | SetStringInfoDatum(chaos,bzip_test_vector[i].chaos); |
|---|
| 317 | status=RestoreEntropy(entropy_info, |
|---|
| 318 | strlen((char *) bzip_test_vector[i].plaintext),chaos,exception); |
|---|
| 319 | plaintext=StringToStringInfo((char *) bzip_test_vector[i].plaintext); |
|---|
| 320 | clone=CompareStringInfo(GetEntropyChaos(entropy_info),plaintext) == 0 ? |
|---|
| 321 | WizardTrue : WizardFalse; |
|---|
| 322 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 323 | "fail"); |
|---|
| 324 | if (clone == WizardFalse) |
|---|
| 325 | pass=WizardFalse; |
|---|
| 326 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 327 | chaos=DestroyStringInfo(chaos); |
|---|
| 328 | } |
|---|
| 329 | entropy_info=DestroyEntropyInfo(entropy_info); |
|---|
| 330 | exception=DestroyExceptionInfo(exception); |
|---|
| 331 | return(pass); |
|---|
| 332 | } |
|---|
| 333 | |
|---|
| 334 | static WizardBooleanType TestCRC64(void) |
|---|
| 335 | { |
|---|
| 336 | HashInfo |
|---|
| 337 | *hash_info; |
|---|
| 338 | |
|---|
| 339 | register long |
|---|
| 340 | i; |
|---|
| 341 | |
|---|
| 342 | StringInfo |
|---|
| 343 | *plaintext, |
|---|
| 344 | *results; |
|---|
| 345 | |
|---|
| 346 | WizardBooleanType |
|---|
| 347 | clone, |
|---|
| 348 | pass; |
|---|
| 349 | |
|---|
| 350 | (void) PrintValidateString(stdout,"testing crc64:\n"); |
|---|
| 351 | pass=WizardTrue; |
|---|
| 352 | hash_info=AcquireHashInfo(CRC64Hash); |
|---|
| 353 | for (i=0; i < CRC64TestVectors; i++) |
|---|
| 354 | { |
|---|
| 355 | (void) PrintValidateString(stdout," test %ld ",i); |
|---|
| 356 | InitializeHash(hash_info); |
|---|
| 357 | plaintext=StringToStringInfo((char *) crc64_test_vector[i].plaintext); |
|---|
| 358 | UpdateHash(hash_info,plaintext); |
|---|
| 359 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 360 | FinalizeHash(hash_info); |
|---|
| 361 | results=AcquireStringInfo(GetStringInfoLength(GetHashDigest(hash_info))); |
|---|
| 362 | SetStringInfoDatum(results,crc64_test_vector[i].digest); |
|---|
| 363 | clone=CompareStringInfo(GetHashDigest(hash_info),results) == 0 ? |
|---|
| 364 | WizardTrue : WizardFalse; |
|---|
| 365 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 366 | "fail"); |
|---|
| 367 | if (clone == WizardFalse) |
|---|
| 368 | pass=WizardFalse; |
|---|
| 369 | results=DestroyStringInfo(results); |
|---|
| 370 | } |
|---|
| 371 | |
|---|
| 372 | |
|---|
| 373 | |
|---|
| 374 | (void) PrintValidateString(stdout," test %ld ",i); |
|---|
| 375 | InitializeHash(hash_info); |
|---|
| 376 | plaintext=StringToStringInfo("ABCDEFGHIJKLMNOPQRSTUVWXYZabcde"); |
|---|
| 377 | UpdateHash(hash_info,plaintext); |
|---|
| 378 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 379 | plaintext=StringToStringInfo("fghijklmnopqrstuvwxyz0123456789"); |
|---|
| 380 | UpdateHash(hash_info,plaintext); |
|---|
| 381 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 382 | FinalizeHash(hash_info); |
|---|
| 383 | results=AcquireStringInfo(GetStringInfoLength(GetHashDigest(hash_info))); |
|---|
| 384 | SetStringInfoDatum(results,crc64_test_vector[5].digest); |
|---|
| 385 | clone=CompareStringInfo(GetHashDigest(hash_info),results) == 0 ? |
|---|
| 386 | WizardTrue : WizardFalse; |
|---|
| 387 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 388 | "fail"); |
|---|
| 389 | if (clone == WizardFalse) |
|---|
| 390 | pass=WizardFalse; |
|---|
| 391 | results=DestroyStringInfo(results); |
|---|
| 392 | hash_info=DestroyHashInfo(hash_info); |
|---|
| 393 | return(pass); |
|---|
| 394 | } |
|---|
| 395 | |
|---|
| 396 | static WizardBooleanType TestHMACMD5(void) |
|---|
| 397 | { |
|---|
| 398 | register long |
|---|
| 399 | i; |
|---|
| 400 | |
|---|
| 401 | HMACInfo |
|---|
| 402 | *hmac_info; |
|---|
| 403 | |
|---|
| 404 | StringInfo |
|---|
| 405 | *key, |
|---|
| 406 | *message, |
|---|
| 407 | *results; |
|---|
| 408 | |
|---|
| 409 | WizardBooleanType |
|---|
| 410 | clone, |
|---|
| 411 | pass; |
|---|
| 412 | |
|---|
| 413 | (void) PrintValidateString(stdout,"testing hmac-md5:\n"); |
|---|
| 414 | pass=WizardTrue; |
|---|
| 415 | hmac_info=AcquireHMACInfo(MD5Hash); |
|---|
| 416 | for (i=0; i < HMACMD5TestVectors; i++) |
|---|
| 417 | { |
|---|
| 418 | (void) PrintValidateString(stdout," test %ld ",i); |
|---|
| 419 | key=StringToStringInfo((char *) hmac_md5_test_vector[i].key); |
|---|
| 420 | message=StringToStringInfo((char *) hmac_md5_test_vector[i].plaintext); |
|---|
| 421 | ConstructHMAC(hmac_info,key,message); |
|---|
| 422 | results=AcquireStringInfo(GetStringInfoLength(GetHMACDigest(hmac_info))); |
|---|
| 423 | SetStringInfoDatum(results,hmac_md5_test_vector[i].digest); |
|---|
| 424 | clone=CompareStringInfo(GetHMACDigest(hmac_info),results) == 0 ? |
|---|
| 425 | WizardTrue : WizardFalse; |
|---|
| 426 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 427 | "fail"); |
|---|
| 428 | if (clone == WizardFalse) |
|---|
| 429 | pass=WizardFalse; |
|---|
| 430 | results=DestroyStringInfo(results); |
|---|
| 431 | key=DestroyStringInfo(key); |
|---|
| 432 | message=DestroyStringInfo(message); |
|---|
| 433 | } |
|---|
| 434 | hmac_info=DestroyHMACInfo(hmac_info); |
|---|
| 435 | return(pass); |
|---|
| 436 | } |
|---|
| 437 | |
|---|
| 438 | static WizardBooleanType TestHMACSHA1(void) |
|---|
| 439 | { |
|---|
| 440 | register long |
|---|
| 441 | i; |
|---|
| 442 | |
|---|
| 443 | HMACInfo |
|---|
| 444 | *hmac_info; |
|---|
| 445 | |
|---|
| 446 | StringInfo |
|---|
| 447 | *key, |
|---|
| 448 | *message, |
|---|
| 449 | *results; |
|---|
| 450 | |
|---|
| 451 | WizardBooleanType |
|---|
| 452 | clone, |
|---|
| 453 | pass; |
|---|
| 454 | |
|---|
| 455 | (void) PrintValidateString(stdout,"testing hmac_sha1:\n"); |
|---|
| 456 | pass=WizardTrue; |
|---|
| 457 | hmac_info=AcquireHMACInfo(SHA1Hash); |
|---|
| 458 | for (i=0; i < HMACSHA1TestVectors; i++) |
|---|
| 459 | { |
|---|
| 460 | (void) PrintValidateString(stdout," test %ld ",i); |
|---|
| 461 | key=StringToStringInfo((char *) hmac_sha1_test_vector[i].key); |
|---|
| 462 | message=StringToStringInfo((char *) hmac_sha1_test_vector[i].plaintext); |
|---|
| 463 | SetStringInfoDatum(message,hmac_sha1_test_vector[i].plaintext); |
|---|
| 464 | ConstructHMAC(hmac_info,key,message); |
|---|
| 465 | results=AcquireStringInfo(GetStringInfoLength(GetHMACDigest(hmac_info))); |
|---|
| 466 | SetStringInfoDatum(results,hmac_sha1_test_vector[i].digest); |
|---|
| 467 | clone=CompareStringInfo(GetHMACDigest(hmac_info),results) == 0 ? |
|---|
| 468 | WizardTrue : WizardFalse; |
|---|
| 469 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 470 | "fail"); |
|---|
| 471 | if (clone == WizardFalse) |
|---|
| 472 | pass=WizardFalse; |
|---|
| 473 | results=DestroyStringInfo(results); |
|---|
| 474 | key=DestroyStringInfo(key); |
|---|
| 475 | message=DestroyStringInfo(message); |
|---|
| 476 | } |
|---|
| 477 | hmac_info=DestroyHMACInfo(hmac_info); |
|---|
| 478 | return(pass); |
|---|
| 479 | } |
|---|
| 480 | |
|---|
| 481 | static WizardBooleanType TestHMACSHA256(void) |
|---|
| 482 | { |
|---|
| 483 | register long |
|---|
| 484 | i; |
|---|
| 485 | |
|---|
| 486 | HMACInfo |
|---|
| 487 | *hmac_info; |
|---|
| 488 | |
|---|
| 489 | StringInfo |
|---|
| 490 | *key, |
|---|
| 491 | *message, |
|---|
| 492 | *results; |
|---|
| 493 | |
|---|
| 494 | WizardBooleanType |
|---|
| 495 | clone, |
|---|
| 496 | pass; |
|---|
| 497 | |
|---|
| 498 | (void) PrintValidateString(stdout,"testing hmac-sha256:\n"); |
|---|
| 499 | pass=WizardTrue; |
|---|
| 500 | hmac_info=AcquireHMACInfo(SHA256Hash); |
|---|
| 501 | for (i=0; i < HMACSHA256TestVectors; i++) |
|---|
| 502 | { |
|---|
| 503 | (void) PrintValidateString(stdout," test %ld ",i); |
|---|
| 504 | key=StringToStringInfo((char *) hmac_sha256_test_vector[i].key); |
|---|
| 505 | message=StringToStringInfo((char *) hmac_sha256_test_vector[i].plaintext); |
|---|
| 506 | ConstructHMAC(hmac_info,key,message); |
|---|
| 507 | results=AcquireStringInfo(GetStringInfoLength(GetHMACDigest(hmac_info))); |
|---|
| 508 | SetStringInfoDatum(results,hmac_sha256_test_vector[i].digest); |
|---|
| 509 | clone=CompareStringInfo(GetHMACDigest(hmac_info),results) == 0 ? |
|---|
| 510 | WizardTrue : WizardFalse; |
|---|
| 511 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 512 | "fail"); |
|---|
| 513 | if (clone == WizardFalse) |
|---|
| 514 | pass=WizardFalse; |
|---|
| 515 | results=DestroyStringInfo(results); |
|---|
| 516 | key=DestroyStringInfo(key); |
|---|
| 517 | message=DestroyStringInfo(message); |
|---|
| 518 | } |
|---|
| 519 | hmac_info=DestroyHMACInfo(hmac_info); |
|---|
| 520 | return(pass); |
|---|
| 521 | } |
|---|
| 522 | |
|---|
| 523 | static WizardBooleanType TestKeymap(void) |
|---|
| 524 | { |
|---|
| 525 | KeyInfo |
|---|
| 526 | *key_info; |
|---|
| 527 | |
|---|
| 528 | StringInfo |
|---|
| 529 | *id, |
|---|
| 530 | *key, |
|---|
| 531 | *target_key; |
|---|
| 532 | |
|---|
| 533 | WizardBooleanType |
|---|
| 534 | clone, |
|---|
| 535 | pass; |
|---|
| 536 | |
|---|
| 537 | (void) PrintValidateString(stdout,"testing key map:\n"); |
|---|
| 538 | key_info=AcquireKeyInfo(); |
|---|
| 539 | id=StringToStringInfo(CipherId); |
|---|
| 540 | key=StringToStringInfo(CipherKey); |
|---|
| 541 | (void) PrintValidateString(stdout," test 0 "); |
|---|
| 542 | pass=SetKeyInfo(key_info,id,key); |
|---|
| 543 | (void) PrintValidateString(stdout,"%s.\n", |
|---|
| 544 | pass != WizardFalse ? "pass" : "fail"); |
|---|
| 545 | (void) PrintValidateString(stdout," test 1 "); |
|---|
| 546 | target_key=GetKeyInfo(key_info,id); |
|---|
| 547 | clone=WizardFalse; |
|---|
| 548 | if (target_key != (StringInfo *) NULL) |
|---|
| 549 | clone=CompareStringInfo(key,target_key) == 0 ? WizardTrue : WizardFalse; |
|---|
| 550 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 551 | "fail"); |
|---|
| 552 | if (clone == WizardFalse) |
|---|
| 553 | pass=WizardFalse; |
|---|
| 554 | target_key=DestroyStringInfo(target_key); |
|---|
| 555 | key=DestroyStringInfo(key); |
|---|
| 556 | id=DestroyStringInfo(id); |
|---|
| 557 | DestroyKeyInfo(key_info); |
|---|
| 558 | return(pass); |
|---|
| 559 | } |
|---|
| 560 | |
|---|
| 561 | static WizardBooleanType TestLogEvent(void) |
|---|
| 562 | { |
|---|
| 563 | WizardBooleanType |
|---|
| 564 | pass; |
|---|
| 565 | |
|---|
| 566 | (void) PrintValidateString(stdout,"testing log event:\n"); |
|---|
| 567 | (void) SetLogEventMask("User"); |
|---|
| 568 | pass=LogWizardEvent(UserEvent,__FILE__,"TestLogEvent",__LINE__, |
|---|
| 569 | "Testing validation suite"); |
|---|
| 570 | (void) PrintValidateString(stdout," test 0 "); |
|---|
| 571 | (void) PrintValidateString(stdout,"%s.\n",pass != WizardFalse ? "pass" : |
|---|
| 572 | "fail"); |
|---|
| 573 | return(pass); |
|---|
| 574 | } |
|---|
| 575 | |
|---|
| 576 | static WizardBooleanType TestMD5(void) |
|---|
| 577 | { |
|---|
| 578 | HashInfo |
|---|
| 579 | *hash_info; |
|---|
| 580 | |
|---|
| 581 | register long |
|---|
| 582 | i; |
|---|
| 583 | |
|---|
| 584 | StringInfo |
|---|
| 585 | *plaintext, |
|---|
| 586 | *results; |
|---|
| 587 | |
|---|
| 588 | WizardBooleanType |
|---|
| 589 | clone, |
|---|
| 590 | pass; |
|---|
| 591 | |
|---|
| 592 | (void) PrintValidateString(stdout,"testing md5:\n"); |
|---|
| 593 | pass=WizardTrue; |
|---|
| 594 | hash_info=AcquireHashInfo(MD5Hash); |
|---|
| 595 | for (i=0; i < MD5TestVectors; i++) |
|---|
| 596 | { |
|---|
| 597 | (void) PrintValidateString(stdout," test %ld ",i); |
|---|
| 598 | InitializeHash(hash_info); |
|---|
| 599 | plaintext=StringToStringInfo((char *) md5_test_vector[i].plaintext); |
|---|
| 600 | UpdateHash(hash_info,plaintext); |
|---|
| 601 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 602 | FinalizeHash(hash_info); |
|---|
| 603 | results=AcquireStringInfo(GetHashDigestsize(hash_info)); |
|---|
| 604 | SetStringInfoDatum(results,md5_test_vector[i].digest); |
|---|
| 605 | clone=CompareStringInfo(GetHashDigest(hash_info),results) == 0 ? |
|---|
| 606 | WizardTrue : WizardFalse; |
|---|
| 607 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 608 | "fail"); |
|---|
| 609 | if (clone == WizardFalse) |
|---|
| 610 | pass=WizardFalse; |
|---|
| 611 | results=DestroyStringInfo(results); |
|---|
| 612 | } |
|---|
| 613 | |
|---|
| 614 | |
|---|
| 615 | |
|---|
| 616 | (void) PrintValidateString(stdout," test %ld ",i); |
|---|
| 617 | InitializeHash(hash_info); |
|---|
| 618 | plaintext=StringToStringInfo("ABCDEFGHIJKLMNOPQRSTUVWXYZabcde"); |
|---|
| 619 | UpdateHash(hash_info,plaintext); |
|---|
| 620 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 621 | plaintext=StringToStringInfo("fghijklmnopqrstuvwxyz0123456789"); |
|---|
| 622 | UpdateHash(hash_info,plaintext); |
|---|
| 623 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 624 | FinalizeHash(hash_info); |
|---|
| 625 | results=AcquireStringInfo(GetHashDigestsize(hash_info)); |
|---|
| 626 | SetStringInfoDatum(results,md5_test_vector[5].digest); |
|---|
| 627 | clone=CompareStringInfo(GetHashDigest(hash_info),results) == 0 ? |
|---|
| 628 | WizardTrue : WizardFalse; |
|---|
| 629 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 630 | "fail"); |
|---|
| 631 | if (clone == WizardFalse) |
|---|
| 632 | pass=WizardFalse; |
|---|
| 633 | results=DestroyStringInfo(results); |
|---|
| 634 | hash_info=DestroyHashInfo(hash_info); |
|---|
| 635 | return(pass); |
|---|
| 636 | } |
|---|
| 637 | |
|---|
| 638 | static WizardBooleanType TestMemory(void) |
|---|
| 639 | { |
|---|
| 640 | register long |
|---|
| 641 | i; |
|---|
| 642 | |
|---|
| 643 | WizardBooleanType |
|---|
| 644 | pass; |
|---|
| 645 | |
|---|
| 646 | void |
|---|
| 647 | *memory; |
|---|
| 648 | |
|---|
| 649 | (void) PrintValidateString(stdout,"testing memory:\n"); |
|---|
| 650 | pass=WizardTrue; |
|---|
| 651 | for (i=1; i < 8; i++) |
|---|
| 652 | { |
|---|
| 653 | (void) PrintValidateString(stdout," test %ld ",i); |
|---|
| 654 | memory=AcquireQuantumMemory((size_t) (i << i << i),sizeof(unsigned char)); |
|---|
| 655 | (void) PrintValidateString(stdout,"%s.\n",memory != (void *) NULL ? "pass" : |
|---|
| 656 | "fail"); |
|---|
| 657 | pass=memory != (void *) NULL ? WizardTrue : WizardFalse; |
|---|
| 658 | if (memory != (void *) NULL) |
|---|
| 659 | memory=RelinquishWizardMemory(memory); |
|---|
| 660 | } |
|---|
| 661 | return(pass); |
|---|
| 662 | } |
|---|
| 663 | |
|---|
| 664 | static WizardBooleanType TestMime(void) |
|---|
| 665 | { |
|---|
| 666 | const MimeInfo |
|---|
| 667 | *mime_info; |
|---|
| 668 | |
|---|
| 669 | ExceptionInfo |
|---|
| 670 | *exception; |
|---|
| 671 | |
|---|
| 672 | StringInfo |
|---|
| 673 | *content; |
|---|
| 674 | |
|---|
| 675 | WizardBooleanType |
|---|
| 676 | pass; |
|---|
| 677 | |
|---|
| 678 | (void) PrintValidateString(stdout,"testing mime:\n"); |
|---|
| 679 | (void) PrintValidateString(stdout," test 0 "); |
|---|
| 680 | pass=WizardFalse; |
|---|
| 681 | content=StringToStringInfo("#include <stdio.h> int main() { exit(0); }"); |
|---|
| 682 | exception=AcquireExceptionInfo(); |
|---|
| 683 | mime_info=GetMimeInfo("main.c",GetStringInfoDatum(content), |
|---|
| 684 | GetStringInfoLength(content),exception); |
|---|
| 685 | content=DestroyStringInfo(content); |
|---|
| 686 | exception=DestroyExceptionInfo(exception); |
|---|
| 687 | if (mime_info != (const MimeInfo *) NULL) |
|---|
| 688 | pass=strcmp(GetMimeType(mime_info),"text/x-csrc") == 0 ? |
|---|
| 689 | WizardTrue : WizardFalse; |
|---|
| 690 | (void) PrintValidateString(stdout,"%s.\n",pass != WizardFalse ? "pass" : |
|---|
| 691 | "fail"); |
|---|
| 692 | return(pass); |
|---|
| 693 | } |
|---|
| 694 | |
|---|
| 695 | static WizardBooleanType TestRandomKey(void) |
|---|
| 696 | { |
|---|
| 697 | double |
|---|
| 698 | value; |
|---|
| 699 | |
|---|
| 700 | RandomInfo |
|---|
| 701 | *random_info; |
|---|
| 702 | |
|---|
| 703 | register long |
|---|
| 704 | i; |
|---|
| 705 | |
|---|
| 706 | StringInfo |
|---|
| 707 | *key; |
|---|
| 708 | |
|---|
| 709 | WizardBooleanType |
|---|
| 710 | clone, |
|---|
| 711 | pass; |
|---|
| 712 | |
|---|
| 713 | (void) PrintValidateString(stdout,"testing random key:\n"); |
|---|
| 714 | random_info=AcquireRandomInfo(SHA256Hash); |
|---|
| 715 | key=GetRandomKey(random_info,256); |
|---|
| 716 | key=DestroyStringInfo(key); |
|---|
| 717 | pass=WizardTrue; |
|---|
| 718 | (void) PrintValidateString(stdout," test 0 "); |
|---|
| 719 | (void) PrintValidateString(stdout,"%s.\n",pass != WizardFalse ? "pass" : |
|---|
| 720 | "fail"); |
|---|
| 721 | (void) PrintValidateString(stdout," test 1 "); |
|---|
| 722 | value=0.0; |
|---|
| 723 | for (i=0; i < 1000000; i++) |
|---|
| 724 | value+=GetRandomValue(random_info); |
|---|
| 725 | value/=i; |
|---|
| 726 | clone=(WizardBooleanType) (AbsoluteValue(value-0.5) < 0.001); |
|---|
| 727 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 728 | "fail"); |
|---|
| 729 | if (clone == WizardFalse) |
|---|
| 730 | pass=WizardFalse; |
|---|
| 731 | random_info=DestroyRandomInfo(random_info); |
|---|
| 732 | return(pass); |
|---|
| 733 | } |
|---|
| 734 | |
|---|
| 735 | static WizardBooleanType TestSerpent(void) |
|---|
| 736 | { |
|---|
| 737 | CipherInfo |
|---|
| 738 | *cipher_info; |
|---|
| 739 | |
|---|
| 740 | register long |
|---|
| 741 | i; |
|---|
| 742 | |
|---|
| 743 | StringInfo |
|---|
| 744 | *ciphertext, |
|---|
| 745 | *key, |
|---|
| 746 | *plaintext, |
|---|
| 747 | *results; |
|---|
| 748 | |
|---|
| 749 | WizardBooleanType |
|---|
| 750 | clone, |
|---|
| 751 | pass; |
|---|
| 752 | |
|---|
| 753 | (void) PrintValidateString(stdout,"testing serpent encipher:\n"); |
|---|
| 754 | pass=WizardTrue; |
|---|
| 755 | cipher_info=AcquireCipherInfo(SerpentCipher,CBCMode); |
|---|
| 756 | for (i=0; i < SerpentEncipherTestVectors; i++) |
|---|
| 757 | { |
|---|
| 758 | (void) PrintValidateString(stdout," test %ld (%ld bit key) ",i+1,(long) |
|---|
| 759 | (8*serpent_encipher_test_vector[i].key_length)); |
|---|
| 760 | key=AcquireStringInfo(serpent_encipher_test_vector[i].key_length); |
|---|
| 761 | SetStringInfoDatum(key,serpent_encipher_test_vector[i].key); |
|---|
| 762 | SetCipherKey(cipher_info,key); |
|---|
| 763 | ResetCipherNonce(cipher_info); |
|---|
| 764 | plaintext=AcquireStringInfo(sizeof( |
|---|
| 765 | serpent_encipher_test_vector[i].plaintext)); |
|---|
| 766 | SetStringInfoDatum(plaintext,serpent_encipher_test_vector[i].plaintext); |
|---|
| 767 | ciphertext=EncipherCipher(cipher_info,plaintext); |
|---|
| 768 | results=AcquireStringInfo(sizeof(serpent_encipher_test_vector[i].result)); |
|---|
| 769 | SetStringInfoDatum(results,serpent_encipher_test_vector[i].result); |
|---|
| 770 | clone=CompareStringInfo(ciphertext,results) == 0 ? WizardTrue : WizardFalse; |
|---|
| 771 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 772 | "fail"); |
|---|
| 773 | if (clone == WizardFalse) |
|---|
| 774 | pass=WizardFalse; |
|---|
| 775 | results=DestroyStringInfo(results); |
|---|
| 776 | key=DestroyStringInfo(key); |
|---|
| 777 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 778 | } |
|---|
| 779 | cipher_info=DestroyCipherInfo(cipher_info); |
|---|
| 780 | (void) PrintValidateString(stdout,"testing serpent decipher:\n"); |
|---|
| 781 | cipher_info=AcquireCipherInfo(SerpentCipher,CBCMode); |
|---|
| 782 | for (i=0; i < SerpentDecipherTestVectors; i++) |
|---|
| 783 | { |
|---|
| 784 | (void) PrintValidateString(stdout," test %ld (%ld bit key) ",i+1,(long) |
|---|
| 785 | (8*serpent_decipher_test_vector[i].key_length)); |
|---|
| 786 | key=AcquireStringInfo(serpent_decipher_test_vector[i].key_length); |
|---|
| 787 | SetStringInfoDatum(key,serpent_decipher_test_vector[i].key); |
|---|
| 788 | SetCipherKey(cipher_info,key); |
|---|
| 789 | ResetCipherNonce(cipher_info); |
|---|
| 790 | ciphertext=AcquireStringInfo(sizeof( |
|---|
| 791 | serpent_decipher_test_vector[i].plaintext)); |
|---|
| 792 | SetStringInfoDatum(ciphertext,serpent_decipher_test_vector[i].plaintext); |
|---|
| 793 | plaintext=DecipherCipher(cipher_info,ciphertext); |
|---|
| 794 | results=AcquireStringInfo(sizeof(serpent_decipher_test_vector[i].result)); |
|---|
| 795 | SetStringInfoDatum(results,serpent_decipher_test_vector[i].result); |
|---|
| 796 | clone=CompareStringInfo(plaintext,results) == 0 ? WizardTrue : WizardFalse; |
|---|
| 797 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 798 | "fail"); |
|---|
| 799 | if (clone == WizardFalse) |
|---|
| 800 | pass=WizardFalse; |
|---|
| 801 | results=DestroyStringInfo(results); |
|---|
| 802 | key=DestroyStringInfo(key); |
|---|
| 803 | ciphertext=DestroyStringInfo(ciphertext); |
|---|
| 804 | } |
|---|
| 805 | cipher_info=DestroyCipherInfo(cipher_info); |
|---|
| 806 | |
|---|
| 807 | |
|---|
| 808 | |
|---|
| 809 | (void) PrintValidateString(stdout,"testing serpent non-blocksize " |
|---|
| 810 | "encipher/decipher:\n"); |
|---|
| 811 | cipher_info=AcquireCipherInfo(SerpentCipher,CBCMode); |
|---|
| 812 | key=StringToStringInfo(CipherKey); |
|---|
| 813 | SetCipherKey(cipher_info,key); |
|---|
| 814 | ResetCipherNonce(cipher_info); |
|---|
| 815 | key=DestroyStringInfo(key); |
|---|
| 816 | plaintext=StringToStringInfo(CipherPlaintext); |
|---|
| 817 | (void) PrintValidateString(stdout," test 0 "); |
|---|
| 818 | ciphertext=EncipherCipher(cipher_info,plaintext); |
|---|
| 819 | key=StringToStringInfo(CipherKey); |
|---|
| 820 | SetCipherKey(cipher_info,key); |
|---|
| 821 | ResetCipherNonce(cipher_info); |
|---|
| 822 | key=DestroyStringInfo(key); |
|---|
| 823 | plaintext=DecipherCipher(cipher_info,ciphertext); |
|---|
| 824 | results=StringToStringInfo(CipherPlaintext); |
|---|
| 825 | clone=CompareStringInfo(plaintext,results) == 0 ? WizardTrue : WizardFalse; |
|---|
| 826 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 827 | "fail"); |
|---|
| 828 | if (clone == WizardFalse) |
|---|
| 829 | pass=WizardFalse; |
|---|
| 830 | results=DestroyStringInfo(results); |
|---|
| 831 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 832 | cipher_info=DestroyCipherInfo(cipher_info); |
|---|
| 833 | |
|---|
| 834 | |
|---|
| 835 | |
|---|
| 836 | (void) PrintValidateString(stdout,"testing serpent CTR-mode " |
|---|
| 837 | "encipher/decipher:\n"); |
|---|
| 838 | cipher_info=AcquireCipherInfo(SerpentCipher,CTRMode); |
|---|
| 839 | key=StringToStringInfo(CipherKey); |
|---|
| 840 | SetCipherKey(cipher_info,key); |
|---|
| 841 | ResetCipherNonce(cipher_info); |
|---|
| 842 | key=DestroyStringInfo(key); |
|---|
| 843 | plaintext=StringToStringInfo(CipherPlaintext); |
|---|
| 844 | (void) PrintValidateString(stdout," test 0 "); |
|---|
| 845 | ciphertext=EncipherCipher(cipher_info,plaintext); |
|---|
| 846 | key=StringToStringInfo(CipherKey); |
|---|
| 847 | SetCipherKey(cipher_info,key); |
|---|
| 848 | ResetCipherNonce(cipher_info); |
|---|
| 849 | key=DestroyStringInfo(key); |
|---|
| 850 | plaintext=DecipherCipher(cipher_info,ciphertext); |
|---|
| 851 | results=StringToStringInfo(CipherPlaintext); |
|---|
| 852 | clone=CompareStringInfo(plaintext,results) == 0 ? WizardTrue : WizardFalse; |
|---|
| 853 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 854 | "fail"); |
|---|
| 855 | if (clone == WizardFalse) |
|---|
| 856 | pass=WizardFalse; |
|---|
| 857 | results=DestroyStringInfo(results); |
|---|
| 858 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 859 | cipher_info=DestroyCipherInfo(cipher_info); |
|---|
| 860 | return(pass); |
|---|
| 861 | } |
|---|
| 862 | |
|---|
| 863 | static WizardBooleanType TestSHA1(void) |
|---|
| 864 | { |
|---|
| 865 | HashInfo |
|---|
| 866 | *hash_info; |
|---|
| 867 | |
|---|
| 868 | register long |
|---|
| 869 | i; |
|---|
| 870 | |
|---|
| 871 | StringInfo |
|---|
| 872 | *plaintext, |
|---|
| 873 | *results; |
|---|
| 874 | |
|---|
| 875 | WizardBooleanType |
|---|
| 876 | clone, |
|---|
| 877 | pass; |
|---|
| 878 | |
|---|
| 879 | (void) PrintValidateString(stdout,"testing sha1:\n"); |
|---|
| 880 | pass=WizardTrue; |
|---|
| 881 | hash_info=AcquireHashInfo(SHA1Hash); |
|---|
| 882 | for (i=0; i < SHA1TestVectors; i++) |
|---|
| 883 | { |
|---|
| 884 | (void) PrintValidateString(stdout," test %ld ",i); |
|---|
| 885 | InitializeHash(hash_info); |
|---|
| 886 | plaintext=StringToStringInfo((char *) sha1_test_vector[i].plaintext); |
|---|
| 887 | UpdateHash(hash_info,plaintext); |
|---|
| 888 | FinalizeHash(hash_info); |
|---|
| 889 | results=AcquireStringInfo(GetStringInfoLength(GetHashDigest(hash_info))); |
|---|
| 890 | SetStringInfoDatum(results,sha1_test_vector[i].digest); |
|---|
| 891 | clone=CompareStringInfo(GetHashDigest(hash_info),results) == 0 ? |
|---|
| 892 | WizardTrue : WizardFalse; |
|---|
| 893 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 894 | "fail"); |
|---|
| 895 | if (clone == WizardFalse) |
|---|
| 896 | pass=WizardFalse; |
|---|
| 897 | results=DestroyStringInfo(results); |
|---|
| 898 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 899 | } |
|---|
| 900 | |
|---|
| 901 | |
|---|
| 902 | |
|---|
| 903 | (void) PrintValidateString(stdout," test %ld ",i); |
|---|
| 904 | InitializeHash(hash_info); |
|---|
| 905 | plaintext=StringToStringInfo("abcdbcdecdefdefgefghfghighij"); |
|---|
| 906 | UpdateHash(hash_info,plaintext); |
|---|
| 907 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 908 | plaintext=StringToStringInfo("hijkijkljklmklmnlmnomnopnopq"); |
|---|
| 909 | UpdateHash(hash_info,plaintext); |
|---|
| 910 | FinalizeHash(hash_info); |
|---|
| 911 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 912 | results=AcquireStringInfo(GetStringInfoLength(GetHashDigest(hash_info))); |
|---|
| 913 | SetStringInfoDatum(results,sha1_test_vector[1].digest); |
|---|
| 914 | clone=CompareStringInfo(GetHashDigest(hash_info),results) == 0 ? |
|---|
| 915 | WizardTrue : WizardFalse; |
|---|
| 916 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 917 | "fail"); |
|---|
| 918 | if (clone == WizardFalse) |
|---|
| 919 | pass=WizardFalse; |
|---|
| 920 | results=DestroyStringInfo(results); |
|---|
| 921 | hash_info=DestroyHashInfo(hash_info); |
|---|
| 922 | return(pass); |
|---|
| 923 | } |
|---|
| 924 | |
|---|
| 925 | static WizardBooleanType TestSHA256(void) |
|---|
| 926 | { |
|---|
| 927 | HashInfo |
|---|
| 928 | *hash_info; |
|---|
| 929 | |
|---|
| 930 | register long |
|---|
| 931 | i; |
|---|
| 932 | |
|---|
| 933 | StringInfo |
|---|
| 934 | *plaintext, |
|---|
| 935 | *results; |
|---|
| 936 | |
|---|
| 937 | WizardBooleanType |
|---|
| 938 | clone, |
|---|
| 939 | pass; |
|---|
| 940 | |
|---|
| 941 | (void) PrintValidateString(stdout,"testing sha256:\n"); |
|---|
| 942 | pass=WizardTrue; |
|---|
| 943 | hash_info=AcquireHashInfo(SHA256Hash); |
|---|
| 944 | for (i=0; i < SHA256TestVectors; i++) |
|---|
| 945 | { |
|---|
| 946 | (void) PrintValidateString(stdout," test %ld ",i); |
|---|
| 947 | InitializeHash(hash_info); |
|---|
| 948 | plaintext=StringToStringInfo((char *) sha256_test_vector[i].plaintext); |
|---|
| 949 | UpdateHash(hash_info,plaintext); |
|---|
| 950 | FinalizeHash(hash_info); |
|---|
| 951 | results=AcquireStringInfo(GetStringInfoLength(GetHashDigest(hash_info))); |
|---|
| 952 | SetStringInfoDatum(results,sha256_test_vector[i].digest); |
|---|
| 953 | clone=CompareStringInfo(GetHashDigest(hash_info),results) == 0 ? |
|---|
| 954 | WizardTrue : WizardFalse; |
|---|
| 955 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 956 | "fail"); |
|---|
| 957 | if (clone == WizardFalse) |
|---|
| 958 | pass=WizardFalse; |
|---|
| 959 | results=DestroyStringInfo(results); |
|---|
| 960 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 961 | } |
|---|
| 962 | |
|---|
| 963 | |
|---|
| 964 | |
|---|
| 965 | (void) PrintValidateString(stdout," test %ld ",i); |
|---|
| 966 | InitializeHash(hash_info); |
|---|
| 967 | plaintext=StringToStringInfo("abcdbcdecdefdefgefghfghighij"); |
|---|
| 968 | UpdateHash(hash_info,plaintext); |
|---|
| 969 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 970 | plaintext=StringToStringInfo("hijkijkljklmklmnlmnomnopnopq"); |
|---|
| 971 | UpdateHash(hash_info,plaintext); |
|---|
| 972 | FinalizeHash(hash_info); |
|---|
| 973 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 974 | results=AcquireStringInfo(GetStringInfoLength(GetHashDigest(hash_info))); |
|---|
| 975 | SetStringInfoDatum(results,sha256_test_vector[1].digest); |
|---|
| 976 | clone=CompareStringInfo(GetHashDigest(hash_info),results) == 0 ? |
|---|
| 977 | WizardTrue : WizardFalse; |
|---|
| 978 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 979 | "fail"); |
|---|
| 980 | if (clone == WizardFalse) |
|---|
| 981 | pass=WizardFalse; |
|---|
| 982 | results=DestroyStringInfo(results); |
|---|
| 983 | hash_info=DestroyHashInfo(hash_info); |
|---|
| 984 | return(pass); |
|---|
| 985 | } |
|---|
| 986 | |
|---|
| 987 | static WizardBooleanType TestSHA384(void) |
|---|
| 988 | { |
|---|
| 989 | HashInfo |
|---|
| 990 | *hash_info; |
|---|
| 991 | |
|---|
| 992 | register long |
|---|
| 993 | i; |
|---|
| 994 | |
|---|
| 995 | StringInfo |
|---|
| 996 | *plaintext, |
|---|
| 997 | *results; |
|---|
| 998 | |
|---|
| 999 | WizardBooleanType |
|---|
| 1000 | clone, |
|---|
| 1001 | pass; |
|---|
| 1002 | |
|---|
| 1003 | (void) PrintValidateString(stdout,"testing sha384:\n"); |
|---|
| 1004 | pass=WizardTrue; |
|---|
| 1005 | hash_info=AcquireHashInfo(SHA384Hash); |
|---|
| 1006 | for (i=0; i < SHA384TestVectors; i++) |
|---|
| 1007 | { |
|---|
| 1008 | (void) PrintValidateString(stdout," test %ld ",i); |
|---|
| 1009 | InitializeHash(hash_info); |
|---|
| 1010 | plaintext=StringToStringInfo((char *) sha384_test_vector[i].plaintext); |
|---|
| 1011 | UpdateHash(hash_info,plaintext); |
|---|
| 1012 | FinalizeHash(hash_info); |
|---|
| 1013 | results=AcquireStringInfo(GetStringInfoLength(GetHashDigest(hash_info))); |
|---|
| 1014 | SetStringInfoDatum(results,sha384_test_vector[i].digest); |
|---|
| 1015 | clone=CompareStringInfo(GetHashDigest(hash_info),results) == 0 ? |
|---|
| 1016 | WizardTrue : WizardFalse; |
|---|
| 1017 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 1018 | "fail"); |
|---|
| 1019 | if (clone == WizardFalse) |
|---|
| 1020 | pass=WizardFalse; |
|---|
| 1021 | results=DestroyStringInfo(results); |
|---|
| 1022 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 1023 | } |
|---|
| 1024 | |
|---|
| 1025 | |
|---|
| 1026 | |
|---|
| 1027 | (void) PrintValidateString(stdout," test %ld ",i); |
|---|
| 1028 | InitializeHash(hash_info); |
|---|
| 1029 | plaintext=StringToStringInfo("abcdbcdecdefdefgefghfghighij"); |
|---|
| 1030 | UpdateHash(hash_info,plaintext); |
|---|
| 1031 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 1032 | plaintext=StringToStringInfo("hijkijkljklmklmnlmnomnopnopq"); |
|---|
| 1033 | UpdateHash(hash_info,plaintext); |
|---|
| 1034 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 1035 | FinalizeHash(hash_info); |
|---|
| 1036 | results=AcquireStringInfo(GetStringInfoLength(GetHashDigest(hash_info))); |
|---|
| 1037 | SetStringInfoDatum(results,sha384_test_vector[1].digest); |
|---|
| 1038 | clone=CompareStringInfo(GetHashDigest(hash_info),results) == 0 ? |
|---|
| 1039 | WizardTrue : WizardFalse; |
|---|
| 1040 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 1041 | "fail"); |
|---|
| 1042 | if (clone == WizardFalse) |
|---|
| 1043 | pass=WizardFalse; |
|---|
| 1044 | results=DestroyStringInfo(results); |
|---|
| 1045 | hash_info=DestroyHashInfo(hash_info); |
|---|
| 1046 | return(pass); |
|---|
| 1047 | } |
|---|
| 1048 | |
|---|
| 1049 | static WizardBooleanType TestSHA512(void) |
|---|
| 1050 | { |
|---|
| 1051 | HashInfo |
|---|
| 1052 | *hash_info; |
|---|
| 1053 | |
|---|
| 1054 | register long |
|---|
| 1055 | i; |
|---|
| 1056 | |
|---|
| 1057 | StringInfo |
|---|
| 1058 | *plaintext, |
|---|
| 1059 | *results; |
|---|
| 1060 | |
|---|
| 1061 | WizardBooleanType |
|---|
| 1062 | clone, |
|---|
| 1063 | pass; |
|---|
| 1064 | |
|---|
| 1065 | (void) PrintValidateString(stdout,"testing sha512:\n"); |
|---|
| 1066 | pass=WizardTrue; |
|---|
| 1067 | hash_info=AcquireHashInfo(SHA512Hash); |
|---|
| 1068 | for (i=0; i < SHA512TestVectors; i++) |
|---|
| 1069 | { |
|---|
| 1070 | (void) PrintValidateString(stdout," test %ld ",i); |
|---|
| 1071 | InitializeHash(hash_info); |
|---|
| 1072 | plaintext=StringToStringInfo((char *) sha512_test_vector[i].plaintext); |
|---|
| 1073 | UpdateHash(hash_info,plaintext); |
|---|
| 1074 | FinalizeHash(hash_info); |
|---|
| 1075 | results=AcquireStringInfo(GetStringInfoLength(GetHashDigest(hash_info))); |
|---|
| 1076 | SetStringInfoDatum(results,sha512_test_vector[i].digest); |
|---|
| 1077 | clone=CompareStringInfo(GetHashDigest(hash_info),results) == 0 ? |
|---|
| 1078 | WizardTrue : WizardFalse; |
|---|
| 1079 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 1080 | "fail"); |
|---|
| 1081 | if (clone == WizardFalse) |
|---|
| 1082 | pass=WizardFalse; |
|---|
| 1083 | results=DestroyStringInfo(results); |
|---|
| 1084 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 1085 | } |
|---|
| 1086 | |
|---|
| 1087 | |
|---|
| 1088 | |
|---|
| 1089 | (void) PrintValidateString(stdout," test %ld ",i); |
|---|
| 1090 | InitializeHash(hash_info); |
|---|
| 1091 | plaintext=StringToStringInfo("abcdbcdecdefdefgefghfghighij"); |
|---|
| 1092 | UpdateHash(hash_info,plaintext); |
|---|
| 1093 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 1094 | plaintext=StringToStringInfo("hijkijkljklmklmnlmnomnopnopq"); |
|---|
| 1095 | UpdateHash(hash_info,plaintext); |
|---|
| 1096 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 1097 | FinalizeHash(hash_info); |
|---|
| 1098 | results=AcquireStringInfo(GetStringInfoLength(GetHashDigest(hash_info))); |
|---|
| 1099 | SetStringInfoDatum(results,sha512_test_vector[1].digest); |
|---|
| 1100 | clone=CompareStringInfo(GetHashDigest(hash_info),results) == 0 ? |
|---|
| 1101 | WizardTrue : WizardFalse; |
|---|
| 1102 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 1103 | "fail"); |
|---|
| 1104 | if (clone == WizardFalse) |
|---|
| 1105 | pass=WizardFalse; |
|---|
| 1106 | results=DestroyStringInfo(results); |
|---|
| 1107 | hash_info=DestroyHashInfo(hash_info); |
|---|
| 1108 | return(pass); |
|---|
| 1109 | } |
|---|
| 1110 | |
|---|
| 1111 | static WizardBooleanType TestString(void) |
|---|
| 1112 | { |
|---|
| 1113 | StringInfo |
|---|
| 1114 | *string_info; |
|---|
| 1115 | |
|---|
| 1116 | WizardBooleanType |
|---|
| 1117 | pass; |
|---|
| 1118 | |
|---|
| 1119 | WizardSizeType |
|---|
| 1120 | crc; |
|---|
| 1121 | |
|---|
| 1122 | (void) PrintValidateString(stdout,"testing string:\n"); |
|---|
| 1123 | (void) PrintValidateString(stdout," test 0 "); |
|---|
| 1124 | string_info=StringToStringInfo("abcdbcdecdefdefgefghfghighij"); |
|---|
| 1125 | crc=GetStringInfoCRC(string_info); |
|---|
| 1126 | pass=crc == (WizardSizeType) 0xb8823aef888dfdd3LL ? WizardTrue : WizardFalse; |
|---|
| 1127 | (void) PrintValidateString(stdout,"%s.\n",pass != WizardFalse ? "pass" : |
|---|
| 1128 | "fail"); |
|---|
| 1129 | string_info=DestroyStringInfo(string_info); |
|---|
| 1130 | return(pass); |
|---|
| 1131 | } |
|---|
| 1132 | |
|---|
| 1133 | static WizardBooleanType TestTwofish(void) |
|---|
| 1134 | { |
|---|
| 1135 | CipherInfo |
|---|
| 1136 | *cipher_info; |
|---|
| 1137 | |
|---|
| 1138 | register long |
|---|
| 1139 | i; |
|---|
| 1140 | |
|---|
| 1141 | StringInfo |
|---|
| 1142 | *ciphertext, |
|---|
| 1143 | *key, |
|---|
| 1144 | *nonce, |
|---|
| 1145 | *plaintext, |
|---|
| 1146 | *results; |
|---|
| 1147 | |
|---|
| 1148 | WizardBooleanType |
|---|
| 1149 | clone, |
|---|
| 1150 | pass; |
|---|
| 1151 | |
|---|
| 1152 | (void) PrintValidateString(stdout,"testing twofish encipher:\n"); |
|---|
| 1153 | pass=WizardTrue; |
|---|
| 1154 | cipher_info=AcquireCipherInfo(TwofishCipher,CBCMode); |
|---|
| 1155 | for (i=0; i < TwofishEncipherTestVectors; i++) |
|---|
| 1156 | { |
|---|
| 1157 | (void) PrintValidateString(stdout," test %ld (%ld bit key) ",i+1,(long) |
|---|
| 1158 | (8*twofish_encipher_test_vector[i].key_length)); |
|---|
| 1159 | key=AcquireStringInfo(twofish_encipher_test_vector[i].key_length); |
|---|
| 1160 | SetStringInfoDatum(key,twofish_encipher_test_vector[i].key); |
|---|
| 1161 | SetCipherKey(cipher_info,key); |
|---|
| 1162 | ResetCipherNonce(cipher_info); |
|---|
| 1163 | nonce=AcquireStringInfo(sizeof(twofish_encipher_test_vector[i].nonce)); |
|---|
| 1164 | SetStringInfoDatum(nonce,twofish_encipher_test_vector[i].nonce); |
|---|
| 1165 | SetCipherNonce(cipher_info,nonce); |
|---|
| 1166 | plaintext=AcquireStringInfo(twofish_encipher_test_vector[i].length); |
|---|
| 1167 | SetStringInfoDatum(plaintext,twofish_encipher_test_vector[i].plaintext); |
|---|
| 1168 | ciphertext=EncipherCipher(cipher_info,plaintext); |
|---|
| 1169 | results=AcquireStringInfo(twofish_encipher_test_vector[i].result_length); |
|---|
| 1170 | SetStringInfoDatum(results,twofish_encipher_test_vector[i].result); |
|---|
| 1171 | clone=CompareStringInfo(ciphertext,results) == 0 ? WizardTrue : WizardFalse; |
|---|
| 1172 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 1173 | "fail"); |
|---|
| 1174 | if (clone == WizardFalse) |
|---|
| 1175 | pass=WizardFalse; |
|---|
| 1176 | results=DestroyStringInfo(results); |
|---|
| 1177 | key=DestroyStringInfo(key); |
|---|
| 1178 | nonce=DestroyStringInfo(nonce); |
|---|
| 1179 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 1180 | } |
|---|
| 1181 | cipher_info=DestroyCipherInfo(cipher_info); |
|---|
| 1182 | (void) PrintValidateString(stdout,"testing twofish decipher:\n"); |
|---|
| 1183 | cipher_info=AcquireCipherInfo(TwofishCipher,CBCMode); |
|---|
| 1184 | for (i=0; i < TwofishDecipherTestVectors; i++) |
|---|
| 1185 | { |
|---|
| 1186 | (void) PrintValidateString(stdout," test %ld (%ld bit key) ",i+1,(long) |
|---|
| 1187 | (8*twofish_decipher_test_vector[i].key_length)); |
|---|
| 1188 | key=AcquireStringInfo(twofish_decipher_test_vector[i].key_length); |
|---|
| 1189 | SetStringInfoDatum(key,twofish_decipher_test_vector[i].key); |
|---|
| 1190 | SetCipherKey(cipher_info,key); |
|---|
| 1191 | ResetCipherNonce(cipher_info); |
|---|
| 1192 | nonce=AcquireStringInfo(sizeof(twofish_encipher_test_vector[i].nonce)); |
|---|
| 1193 | SetStringInfoDatum(nonce,twofish_encipher_test_vector[i].nonce); |
|---|
| 1194 | SetCipherNonce(cipher_info,nonce); |
|---|
| 1195 | ciphertext=AcquireStringInfo(twofish_decipher_test_vector[i].length); |
|---|
| 1196 | SetStringInfoDatum(ciphertext,twofish_decipher_test_vector[i].plaintext); |
|---|
| 1197 | plaintext=DecipherCipher(cipher_info,ciphertext); |
|---|
| 1198 | results=AcquireStringInfo(twofish_decipher_test_vector[i].length); |
|---|
| 1199 | SetStringInfoDatum(results,twofish_decipher_test_vector[i].result); |
|---|
| 1200 | clone=CompareStringInfo(plaintext,results) == 0 ? WizardTrue : WizardFalse; |
|---|
| 1201 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 1202 | "fail"); |
|---|
| 1203 | if (clone == WizardFalse) |
|---|
| 1204 | pass=WizardFalse; |
|---|
| 1205 | results=DestroyStringInfo(results); |
|---|
| 1206 | key=DestroyStringInfo(key); |
|---|
| 1207 | nonce=DestroyStringInfo(nonce); |
|---|
| 1208 | ciphertext=DestroyStringInfo(ciphertext); |
|---|
| 1209 | } |
|---|
| 1210 | cipher_info=DestroyCipherInfo(cipher_info); |
|---|
| 1211 | |
|---|
| 1212 | |
|---|
| 1213 | |
|---|
| 1214 | (void) PrintValidateString(stdout,"testing twofish non-blocksize " |
|---|
| 1215 | "encipher/decipher:\n"); |
|---|
| 1216 | cipher_info=AcquireCipherInfo(TwofishCipher,CBCMode); |
|---|
| 1217 | key=StringToStringInfo(CipherKey); |
|---|
| 1218 | SetCipherKey(cipher_info,key); |
|---|
| 1219 | ResetCipherNonce(cipher_info); |
|---|
| 1220 | key=DestroyStringInfo(key); |
|---|
| 1221 | plaintext=StringToStringInfo(CipherPlaintext); |
|---|
| 1222 | (void) PrintValidateString(stdout," test 0 "); |
|---|
| 1223 | ciphertext=EncipherCipher(cipher_info,plaintext); |
|---|
| 1224 | key=StringToStringInfo(CipherKey); |
|---|
| 1225 | SetCipherKey(cipher_info,key); |
|---|
| 1226 | ResetCipherNonce(cipher_info); |
|---|
| 1227 | key=DestroyStringInfo(key); |
|---|
| 1228 | plaintext=DecipherCipher(cipher_info,ciphertext); |
|---|
| 1229 | results=StringToStringInfo(CipherPlaintext); |
|---|
| 1230 | clone=CompareStringInfo(plaintext,results) == 0 ? WizardTrue : WizardFalse; |
|---|
| 1231 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 1232 | "fail"); |
|---|
| 1233 | if (clone == WizardFalse) |
|---|
| 1234 | pass=WizardFalse; |
|---|
| 1235 | results=DestroyStringInfo(results); |
|---|
| 1236 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 1237 | cipher_info=DestroyCipherInfo(cipher_info); |
|---|
| 1238 | |
|---|
| 1239 | |
|---|
| 1240 | |
|---|
| 1241 | (void) PrintValidateString(stdout,"testing twofish CTR-mode " |
|---|
| 1242 | "encipher/decipher:\n"); |
|---|
| 1243 | cipher_info=AcquireCipherInfo(TwofishCipher,CTRMode); |
|---|
| 1244 | key=StringToStringInfo(CipherKey); |
|---|
| 1245 | SetCipherKey(cipher_info,key); |
|---|
| 1246 | ResetCipherNonce(cipher_info); |
|---|
| 1247 | key=DestroyStringInfo(key); |
|---|
| 1248 | plaintext=StringToStringInfo(CipherPlaintext); |
|---|
| 1249 | (void) PrintValidateString(stdout," test 0 "); |
|---|
| 1250 | ciphertext=EncipherCipher(cipher_info,plaintext); |
|---|
| 1251 | key=StringToStringInfo(CipherKey); |
|---|
| 1252 | SetCipherKey(cipher_info,key); |
|---|
| 1253 | ResetCipherNonce(cipher_info); |
|---|
| 1254 | key=DestroyStringInfo(key); |
|---|
| 1255 | plaintext=DecipherCipher(cipher_info,ciphertext); |
|---|
| 1256 | results=StringToStringInfo(CipherPlaintext); |
|---|
| 1257 | clone=CompareStringInfo(plaintext,results) == 0 ? WizardTrue : WizardFalse; |
|---|
| 1258 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 1259 | "fail"); |
|---|
| 1260 | if (clone == WizardFalse) |
|---|
| 1261 | pass=WizardFalse; |
|---|
| 1262 | results=DestroyStringInfo(results); |
|---|
| 1263 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 1264 | cipher_info=DestroyCipherInfo(cipher_info); |
|---|
| 1265 | return(pass); |
|---|
| 1266 | } |
|---|
| 1267 | |
|---|
| 1268 | static WizardBooleanType TestZIPEntropy(void) |
|---|
| 1269 | { |
|---|
| 1270 | EntropyInfo |
|---|
| 1271 | *entropy_info; |
|---|
| 1272 | |
|---|
| 1273 | ExceptionInfo |
|---|
| 1274 | *exception; |
|---|
| 1275 | |
|---|
| 1276 | register long |
|---|
| 1277 | i; |
|---|
| 1278 | |
|---|
| 1279 | StringInfo |
|---|
| 1280 | *chaos, |
|---|
| 1281 | *plaintext; |
|---|
| 1282 | |
|---|
| 1283 | WizardBooleanType |
|---|
| 1284 | clone, |
|---|
| 1285 | pass, |
|---|
| 1286 | status; |
|---|
| 1287 | |
|---|
| 1288 | (void) PrintValidateString(stdout,"testing zip entropy:\n"); |
|---|
| 1289 | pass=WizardTrue; |
|---|
| 1290 | exception=AcquireExceptionInfo(); |
|---|
| 1291 | entropy_info=AcquireEntropyInfo(ZIPEntropy,6); |
|---|
| 1292 | for (i=0; i < ZipTestVectors; i++) |
|---|
| 1293 | { |
|---|
| 1294 | (void) PrintValidateString(stdout," test %ld ",i); |
|---|
| 1295 | plaintext=StringToStringInfo((char *) zip_test_vector[i].plaintext); |
|---|
| 1296 | status=IncreaseEntropy(entropy_info,plaintext,exception); |
|---|
| 1297 | chaos=AcquireStringInfo(zip_test_vector[i].chaossize); |
|---|
| 1298 | SetStringInfoDatum(chaos,zip_test_vector[i].chaos); |
|---|
| 1299 | clone=CompareStringInfo(GetEntropyChaos(entropy_info),chaos) == 0 ? |
|---|
| 1300 | WizardTrue : WizardFalse; |
|---|
| 1301 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 1302 | "fail"); |
|---|
| 1303 | if (clone == WizardFalse) |
|---|
| 1304 | pass=WizardFalse; |
|---|
| 1305 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 1306 | chaos=DestroyStringInfo(chaos); |
|---|
| 1307 | } |
|---|
| 1308 | entropy_info=DestroyEntropyInfo(entropy_info); |
|---|
| 1309 | (void) PrintValidateString(stdout,"testing zip restore entropy:\n"); |
|---|
| 1310 | pass=WizardTrue; |
|---|
| 1311 | entropy_info=AcquireEntropyInfo(ZIPEntropy,6); |
|---|
| 1312 | for (i=0; i < ZipTestVectors; i++) |
|---|
| 1313 | { |
|---|
| 1314 | (void) PrintValidateString(stdout," test %ld ",i); |
|---|
| 1315 | chaos=AcquireStringInfo(zip_test_vector[i].chaossize); |
|---|
| 1316 | SetStringInfoDatum(chaos,zip_test_vector[i].chaos); |
|---|
| 1317 | status=RestoreEntropy(entropy_info, |
|---|
| 1318 | strlen((char *) zip_test_vector[i].plaintext),chaos,exception); |
|---|
| 1319 | plaintext=StringToStringInfo((char *) zip_test_vector[i].plaintext); |
|---|
| 1320 | clone=CompareStringInfo(GetEntropyChaos(entropy_info),plaintext) == 0 ? |
|---|
| 1321 | WizardTrue : WizardFalse; |
|---|
| 1322 | (void) PrintValidateString(stdout,"%s.\n",clone != WizardFalse ? "pass" : |
|---|
| 1323 | "fail"); |
|---|
| 1324 | if (clone == WizardFalse) |
|---|
| 1325 | pass=WizardFalse; |
|---|
| 1326 | plaintext=DestroyStringInfo(plaintext); |
|---|
| 1327 | chaos=DestroyStringInfo(chaos); |
|---|
| 1328 | } |
|---|
| 1329 | entropy_info=DestroyEntropyInfo(entropy_info); |
|---|
| 1330 | exception=DestroyExceptionInfo(exception); |
|---|
| 1331 | return(pass); |
|---|
| 1332 | } |
|---|
| 1333 | |
|---|
| 1334 | int main(int argc,char **argv) |
|---|
| 1335 | { |
|---|
| 1336 | const char |
|---|
| 1337 | *passphrase; |
|---|
| 1338 | |
|---|
| 1339 | WizardBooleanType |
|---|
| 1340 | pass; |
|---|
| 1341 | |
|---|
| 1342 | |
|---|
| 1343 | |
|---|
| 1344 | |
|---|
| 1345 | passphrase=(const char *) NULL; |
|---|
| 1346 | if (argc > 0) |
|---|
| 1347 | passphrase=argv[1]; |
|---|
| 1348 | WizardsToolkitGenesis(*argv); |
|---|
| 1349 | (void) PrintValidateString(stdout,"Version: %s\n", |
|---|
| 1350 | GetWizardVersion((unsigned long *) NULL)); |
|---|
| 1351 | (void) PrintValidateString(stdout,"Copyright: %s\n\n", |
|---|
| 1352 | GetWizardCopyright()); |
|---|
| 1353 | (void) PrintValidateString(stdout,"Wizard Validation Suite\n\n"); |
|---|
| 1354 | pass=TestMemory(); |
|---|
| 1355 | if (TestString() == WizardFalse) |
|---|
| 1356 | pass=WizardFalse; |
|---|
| 1357 | if (TestLogEvent() == WizardFalse) |
|---|
| 1358 | pass=WizardFalse; |
|---|
| 1359 | #if !defined(__WINDOWS__) |
|---|
| 1360 | if (TestMime() == WizardFalse) |
|---|
| 1361 | pass=WizardFalse; |
|---|
| 1362 | #endif |
|---|
| 1363 | if (TestCRC64() == WizardFalse) |
|---|
| 1364 | pass=WizardFalse; |
|---|
| 1365 | if (TestMD5() == WizardFalse) |
|---|
| 1366 | pass=WizardFalse; |
|---|
| 1367 | if (TestSHA1() == WizardFalse) |
|---|
| 1368 | pass=WizardFalse; |
|---|
| 1369 | if (TestSHA256() == WizardFalse) |
|---|
| 1370 | pass=WizardFalse; |
|---|
| 1371 | if (TestSHA384() == WizardFalse) |
|---|
| 1372 | pass=WizardFalse; |
|---|
| 1373 | if (TestSHA512() == WizardFalse) |
|---|
| 1374 | pass=WizardFalse; |
|---|
| 1375 | if (TestHMACMD5() == WizardFalse) |
|---|
| 1376 | pass=WizardFalse; |
|---|
| 1377 | if (TestHMACSHA1() == WizardFalse) |
|---|
| 1378 | pass=WizardFalse; |
|---|
| 1379 | if (TestHMACSHA256() == WizardFalse) |
|---|
| 1380 | pass=WizardFalse; |
|---|
| 1381 | if (TestAES() == WizardFalse) |
|---|
| 1382 | pass=WizardFalse; |
|---|
| 1383 | if (TestSerpent() == WizardFalse) |
|---|
| 1384 | pass=WizardFalse; |
|---|
| 1385 | if (TestTwofish() == WizardFalse) |
|---|
| 1386 | pass=WizardFalse; |
|---|
| 1387 | if (TestZIPEntropy() == WizardFalse) |
|---|
| 1388 | pass=WizardFalse; |
|---|
| 1389 | if (TestBZIPEntropy() == WizardFalse) |
|---|
| 1390 | pass=WizardFalse; |
|---|
| 1391 | if (TestRandomKey() == WizardFalse) |
|---|
| 1392 | pass=WizardFalse; |
|---|
| 1393 | if (TestKeymap() == WizardFalse) |
|---|
| 1394 | pass=WizardFalse; |
|---|
| 1395 | if (TestAuthenticate(passphrase) == WizardFalse) |
|---|
| 1396 | pass=WizardFalse; |
|---|
| 1397 | if (pass != WizardFalse) |
|---|
| 1398 | (void) PrintValidateString(stdout,"validation: passed.\n"); |
|---|
| 1399 | else |
|---|
| 1400 | (void) PrintValidateString(stdout,"validation: failed.\n"); |
|---|
| 1401 | WizardsToolkitTerminus(); |
|---|
| 1402 | return(pass == WizardFalse ? 1 : 0); |
|---|
| 1403 | } |
|---|