- F90807132CF1AD922F6B901A4CD35190646BAAD554E0CBAE71C570909AF0025260DED9BD163657917AF4B08F5B29AEB704076D4F5949D8F6B1D14F60C837800B
+ B9DD611C05352BC2DCD237EE59409CBBABF02068D8639CBDE73B6F273EA1480BB9C40CAB85F83FD7D56CE6CD59BBBE42F171CE90BD1AAAD265109B745FABB808
eucrypt/smg_keccak/tests/smg_keccak-test.adb
(1 . 3)(1 . 4)
348 with SMG_OAEP; use SMG_OAEP;
349 with SMG_Keccak; use SMG_Keccak;
350 with Ada.Exceptions; use Ada.Exceptions;
351 with Ada.Text_IO; use Ada.Text_IO;
(268 . 7)(269 . 7)
353 HexString : String( 1 .. ExpHex'Length );
354 begin
355 Put_Line("---sponge test---");
356 Sponge(Input, Bitrate, Output);
357 Sponge(Input, Output, Bitrate);
358 Put_Line("Input is:");
359 for I of Input loop
360 Put(Bit'Image(I));
(314 . 6)(315 . 123)
362 end if;
363 end test_keccak_function;
364
365 procedure test_bitstream_conversion is
366 S: String := "Aa*/";
367 E: Bitstream( 0 .. 31 ) := (1, 0, 0, 0, 0, 0, 1, 0,
368 1, 0, 0, 0, 0, 1, 1, 0,
369 0, 1, 0, 1, 0, 1, 0, 0,
370 1, 1, 1, 1, 0, 1, 0, 0);
371 B: Bitstream( 0 .. 31 );
372 SS: String := " t ";
373 begin
374 Put_Line("---Testing string to bitstream conversion---");
375 ToBitstream( S, B );
376 if E /= B then
377 Put_Line("FAILED: string to bitstream conversion.");
378 else
379 Put_Line("PASSED: string to bitstream conversion.");
380 end if;
381
382 Put_Line("---Testing bitstream to string conversion---");
383 ToString( B, SS );
384 if SS /= S then
385 Put_Line("FAILED: bitstream to string conversion");
386 Put_Line("EXPECTED: " & S);
387 Put_Line("OUTPUT: " & SS);
388 else
389 Put_Line("PASSED: bitstream to string conversion");
390 end if;
391 end test_bitstream_conversion;
392
393 procedure test_hash_keccak is
394 S: String := "X";
395 O: String := "abc";
396 B: Bitstream( 0 .. 23 );
397 BB: Bitstream( 1.. 8):= (0, 0, 0, 1, 1, 0, 1, 0);
398 Exp: Bitstream( 0 .. 23 ) := (1, 1, 1, 0, 0, 0, 0, 1,
399 0, 1, 1, 0, 0, 0, 1, 0,
400 1, 1, 1, 0, 0, 0, 1, 1);
401 begin
402 Put_Line("----Testing hash keccak on string " & S & "----");
403 HashKeccak(S, O);
404 Put_Line("OUTPUT: " & O);
405 ToBitstream( O, B );
406 if B /= Exp then
407 Put_Line("FAILED: testing hash keccak on string");
408 Put_Line("Output:");
409 for I of B loop
410 Put( Bit'Image( I ) );
411 end loop;
412 new_line(1);
413 Put_Line("Expected:");
414 for I of Exp loop
415 Put( Bit'Image( I ) );
416 end loop;
417 else
418 Put_Line("PASSED: testing hash keccak on string");
419 end if;
420 new_line(1);
421 end test_hash_keccak;
422
423 procedure test_xor_strings is
424 S1 : String := "ABC";
425 S2 : String := "CBA";
426 Exp : String := "...";
427 Result : String := "...";
428 begin
429 Exp( Exp'First ) := Character'Val( 2 );
430 Exp( Exp'First + 1 ) := Character'Val( 0 );
431 Exp( Exp'First + 2 ) := Character'Val( 2 );
432
433 Put_Line("----Testing xor on strings---");
434 XOR_Strings( S1, S2, Result);
435 Put_Line("S1 is " & S1);
436 Put_Line("S2 is " & S2);
437 Put_Line("S1 xor S2 is " & Result);
438 Put_Line("Result is: ");
439 for C of Result loop
440 Put( Natural'Image( Character'Pos( C ) ) );
441 end loop;
442 new_line(1);
443
444 if Result /= Exp then
445 Put_Line("FAILED: xor on strings");
446 else
447 Put_Line("PASSED: xor on strings");
448 end if;
449 end test_xor_strings;
450
451 procedure test_oaep is
452 Msg : String := "abcdefghij jihgfedcba123456789";
453 Encr : OAEP_Block := ( others => ' ' );
454 Decr : OAEP_HALF := ( others => ' ' );
455 Entropy : OAEP_Block := ( others => 'e' );
456 Len : Natural;
457 Flag : Boolean;
458 begin
459 Put_Line("----Testing OAEP Encrypt----");
460 OAEP_Encrypt( Msg, Entropy, Encr );
461
462 Put_Line("----Testing OAEP Decrypt----");
463 OAEP_Decrypt( Encr, Len, Decr, Flag );
464
465 Put_Line("Msg is: " & Msg);
466 Put_Line("Encr is: " & Encr);
467 Put_Line("Decr is: " & Decr);
468 Put_Line("Flag is: " & Boolean'Image( Flag ) );
469 Put_Line("Len is: " & Natural'Image( Len ) );
470
471 if Flag = False or
472 Len /= Msg'Length * 8 or
473 Decr( Decr'First .. Decr'First + Msg'Length - 1 ) /= Msg
474 then
475 Put_Line("FAILED: oaep test");
476 else
477 Put_Line("PASSED: oaep test");
478 end if;
479
480 end test_oaep;
481
482 -- end of helper methods
483
484 --variables
(354 . 4)(472 . 16)
486 -- test flipping octets
487 test_flip;
488
489 -- test bitstream conversion
490 test_bitstream_conversion;
491
492 -- test hash keccak (strings version)
493 test_hash_keccak;
494
495 -- test oaep encrypt + decrypt
496 test_oaep;
497
498 -- test xor on strings
499 test_xor_strings;
500
501 end SMG_Keccak.Test;