ada/spark: all warnings, warn strict, style checks

* enable all common warnings through default value of CC_ADA_WARN
* treat warnings like errors through default value of CC_ADA_WARN_STRICT
* enable almost all style checks through default value of CC_ADA_WARN_STRICT
* style fixes for aes_cbc_4k
* disable strict warnings and style checks for libsparkcrypto and spark lib

Ref #3848
This commit is contained in:
Martin Stein
2019-09-29 01:49:02 +02:00
committed by Norman Feske
parent 3f97269988
commit f3eaeb08ef
15 changed files with 202 additions and 180 deletions

View File

@ -24,16 +24,20 @@ is
type Padding_Type is array (Natural range <>) of Byte;
type Block_Number_Text_Type is record
Block_Number : Block_Number_Type;
Padding : Padding_Type(1 .. 8);
Padding : Padding_Type (1 .. 8);
end record
with Size => 128;
Block_Number_Text : constant Block_Number_Text_Type :=
(Block_Number => Block_Number, Padding => (others => 0));
type Block_Number_Plaintext_Base_Type is array (Natural range <>) of Byte;
type Block_Number_Plaintext_Base_Type
is array (Natural range <>) of Byte;
subtype Block_Number_Plaintext_Index_Type is Natural range 1 .. 16;
subtype Block_Number_Plaintext_Type is Block_Number_Plaintext_Base_Type (Block_Number_Plaintext_Index_Type);
subtype Block_Number_Plaintext_Type
is Block_Number_Plaintext_Base_Type (Block_Number_Plaintext_Index_Type);
function Convert is new Ada.Unchecked_Conversion
(Block_Number_Text_Type, Block_Number_Plaintext_Type);
@ -42,11 +46,15 @@ is
(Natural, Byte, IV_Key_Base_Type);
function Encrypt is new LSC.AES_Generic.Encrypt
(Natural, Byte, Block_Number_Plaintext_Base_Type, Natural, Byte, Ciphertext_Base_Type);
(Natural, Byte, Block_Number_Plaintext_Base_Type, Natural, Byte,
Ciphertext_Base_Type);
begin
return Encrypt (Plaintext => Convert(Block_Number_Text),
Key => Enc_Key(Hash(Key), LSC.AES_Generic.L256)) (Natural'First .. Natural'First + 15);
begin
return
Encrypt (
Plaintext => Convert (Block_Number_Text),
Key => Enc_Key (Hash (Key), LSC.AES_Generic.L256))
(Natural'First .. Natural'First + 15);
end Init_IV;
procedure Encrypt (Key : Key_Type;
@ -58,18 +66,18 @@ is
(Natural, Byte, Key_Base_Type);
procedure Encrypt is new LSC.AES_Generic.CBC.Encrypt
(Natural, Byte, Plaintext_Base_Type, Natural, Byte, Ciphertext_Base_Type);
(Natural, Byte, Plaintext_Base_Type, Natural, Byte,
Ciphertext_Base_Type);
IV : constant Ciphertext_Base_Type := Init_IV(Key, Block_Number);
IV : constant Ciphertext_Base_Type := Init_IV (Key, Block_Number);
begin
Encrypt (Plaintext => Plaintext,
IV => IV,
Key => Enc_Key(Key, LSC.AES_Generic.L256),
Key => Enc_Key (Key, LSC.AES_Generic.L256),
Ciphertext => Ciphertext);
end Encrypt;
procedure Decrypt (Key : Key_Type;
Block_Number : Block_Number_Type;
Ciphertext : Ciphertext_Type;
@ -79,12 +87,13 @@ is
(Natural, Byte, Key_Base_Type);
procedure Decrypt is new LSC.AES_Generic.CBC.Decrypt
(Natural, Byte, Plaintext_Base_Type, Natural, Byte, Ciphertext_Base_Type);
(Natural, Byte, Plaintext_Base_Type, Natural, Byte,
Ciphertext_Base_Type);
begin
Decrypt (Ciphertext => Ciphertext,
IV => Init_IV(Key, Block_Number),
Key => Dec_Key(Key, LSC.AES_Generic.L256),
IV => Init_IV (Key, Block_Number),
Key => Dec_Key (Key, LSC.AES_Generic.L256),
Plaintext => Plaintext);
end Decrypt;

View File

@ -1,11 +1,11 @@
package Aes_Cbc_4k with SPARK_Mode
is
-- pragma Pure; -- not possible because libsparkcrypto is not known as pure
-- pragma Pure; -- not possible because libsparkcrypto is not known as pure
type Byte is mod 2**8 with Size => 8;
type Key_Base_type is array (Natural range <>) of Byte;
subtype Key_Type is Key_Base_type (1 .. 32);
type Key_Base_Type is array (Natural range <>) of Byte;
subtype Key_Type is Key_Base_Type (1 .. 32);
type Block_Number_Type is mod 2**64 with Size => 64;
type Plaintext_Base_Type is array (Natural range <>) of Byte;
@ -22,7 +22,9 @@ is
Ciphertext : out Ciphertext_Type)
with Export,
Convention => C,
External_Name => "_ZN10Aes_cbc_4k7encryptERKNS_3KeyENS_12Block_numberERKNS_9PlaintextERNS_10CiphertextE";
External_Name =>
"_ZN10Aes_cbc_4k7encryptERKNS_3KeyENS_12Block_numberERKNS_" &
"9PlaintextERNS_10CiphertextE";
procedure Decrypt (Key : Key_Type;
Block_Number : Block_Number_Type;
@ -30,6 +32,8 @@ is
Plaintext : out Plaintext_Type)
with Export,
Convention => C,
External_Name => "_ZN10Aes_cbc_4k7decryptERKNS_3KeyENS_12Block_numberERKNS_10CiphertextERNS_9PlaintextE";
External_Name =>
"_ZN10Aes_cbc_4k7decryptERKNS_3KeyENS_12Block_numberERKNS_" &
"10CiphertextERNS_9PlaintextE";
end Aes_Cbc_4k;