adare_hqc256_0.2.3_bbba6749/adare_hqc256_example/src/adare_hqc256_example.adb

  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
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 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
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
with Ada.Text_IO;
with Interfaces.C;
with Adare_Hqc256.hqc;

use Ada;
use Adare_Hqc256;

procedure Adare_Hqc256_Example is

  -- hint: each type can be copied to other var of same type without problems.

  secret_key1 : aliased hqc.hqc_private_key;
  public_key1 : aliased hqc.hqc_public_key;

  shared_secret1 : aliased hqc.hqc_shared_key;

  shared_secret2 : aliased hqc.hqc_shared_key;

  ciphertext1 : aliased hqc.hqc_ciphertext;

  ciphertext2 : aliased hqc.hqc_ciphertext;

  use all type hqc.hqc_shared_key;
begin

  hqc.hqc_256_kem_keypair (public_key1, secret_key1);

  Text_IO.New_Line;

  Text_IO.Put_Line (" Public Key1" &
    Interfaces.C.To_Ada (hqc.get_hqc_public_key (public_key1), False));

  Text_IO.New_Line;

  Text_IO.Put_Line (" Secret Key1" &
    Interfaces.C.To_Ada (hqc.get_hqc_private_key (secret_key1), False));

  hqc.hqc_256_kem_encode (ciphertext1, shared_secret1, public_key1);

  Text_IO.New_Line;

  Text_IO.Put_Line (" Shared_Secret1" &
    Interfaces.C.To_Ada (hqc.get_hqc_shared_key (shared_secret1), False));

  Text_IO.New_Line;

  Text_IO.Put_Line (" CipherText1" &
     Interfaces.C.To_Ada (hqc.get_hqc_ciphertext (ciphertext1), False));

  ciphertext2 := ciphertext1; -- just for backup or maybe offload

  hqc.hqc_256_kem_decode (shared_secret2, ciphertext1, secret_key1);

  Text_IO.New_Line;

  Text_IO.Put_Line (" Shared_Secret2" &
    Interfaces.C.To_Ada (hqc.get_hqc_shared_key (shared_secret2), False));

  Text_IO.New_Line;

  Text_IO.Put_Line
  (" received shared_secret2 = to sended shared_secret1 ?" &
    Boolean'(shared_secret2 = shared_secret1)'Image);

  Text_IO.New_Line (2);

  b2 :
  declare
    sk1 : Interfaces.C.char_array :=
    hqc.get_hqc_private_key (secret_key1);
    pk1 : Interfaces.C.char_array :=
    hqc.get_hqc_public_key (public_key1);
    ss2 : Interfaces.C.char_array :=
    hqc.get_hqc_shared_key (shared_secret2);
    ct1 : Interfaces.C.char_array :=
    hqc.get_hqc_ciphertext (ciphertext1);
  begin

    Text_IO.Put_Line (" sk1 =>  " & Interfaces.C.To_Ada (sk1, False));

    Text_IO.New_Line;

    Text_IO.Put_Line (" pk =>  " & Interfaces.C.To_Ada (pk1, False));

    Text_IO.New_Line;

    Text_IO.Put_Line ("  =>  " & Interfaces.C.To_Ada (ss2, False));

    Text_IO.New_Line;

    Text_IO.Put_Line ("  =>  " & Interfaces.C.To_Ada (ct1, False));

    Text_IO.New_Line (2);

  end b2;

  Text_IO.Put_Line (" Enjoy!!! :-]");
  Text_IO.New_Line (2);

end Adare_Hqc256_Example;