updated eel and eapml from more recent versions.

This commit is contained in:
Jocelyn Fiat
2012-06-15 14:57:12 +02:00
parent 0203e0fdc7
commit 5f3749e463
166 changed files with 396 additions and 578 deletions

View File

@@ -0,0 +1,58 @@
note
description: "Cipher Block Chaining mode"
author: "Colin LeMahieu"
date: "$Date: 2011-11-11 18:13:16 +0100 (ven., 11 nov. 2011) $"
revision: "$Revision: 87787 $"
quote: "Just because you do not take an interest in politics doesn't mean politics won't take an interest in you. - Pericles (430 BC)"
class
CBC_DECRYPTION
inherit
ARRAY_FACILITIES
create
make
feature
make (target_a: CBC_TARGET iv: SPECIAL [NATURAL_8] iv_offset: INTEGER_32)
require
iv.valid_index (iv_offset)
iv.valid_index (iv_offset + target_a.block_size - 1)
do
target := target_a
create last.make_filled (0, iv.count)
last.copy_data (iv, iv_offset, 0, last.count)
end
feature
block_size: INTEGER_32
do
result := target.block_size
end
decrypt_block (in: SPECIAL [NATURAL_8] in_offset: INTEGER_32 out_array: SPECIAL [NATURAL_8] out_offset: INTEGER_32)
require
cbc_ready
in.valid_index (in_offset)
in.valid_index (in_offset + block_size - 1)
out_array.valid_index (out_offset)
out_array.valid_index (out_offset + block_size - 1)
do
target.decrypt_block (in, in_offset, out_array, out_offset)
array_xor (last, 0, out_array, out_offset, out_array, out_offset, block_size)
last.copy_data (in, in_offset, 0, block_size)
end
cbc_ready: BOOLEAN
do
result := target.cbc_ready
end
feature {NONE}
last: SPECIAL [NATURAL_8]
target: CBC_TARGET
invariant
last.count = target.block_size
end

View File

@@ -0,0 +1,57 @@
note
description: "Cipher Block Chaining mode"
author: "Colin LeMahieu"
date: "$Date: 2011-11-11 18:13:16 +0100 (ven., 11 nov. 2011) $"
revision: "$Revision: 87787 $"
quote: "Nothing is so permanent as a temporary government program. - Milton Friedman"
class
CBC_ENCRYPTION
inherit
ARRAY_FACILITIES
create
make
feature
make (target_a: CBC_TARGET iv: SPECIAL [NATURAL_8] iv_offset: INTEGER_32)
require
iv.count = target_a.block_size
do
target := target_a
create last.make_filled (0, iv.count)
last.copy_data (iv, iv_offset, 0, last.count)
end
feature
block_size: INTEGER_32
do
result := target.block_size
end
encrypt_block (in: SPECIAL [NATURAL_8] in_offset: INTEGER_32 out_array: SPECIAL [NATURAL_8] out_offset: INTEGER_32)
require
cbc_ready
in.valid_index (in_offset)
in.valid_index (in_offset + block_size - 1)
out_array.valid_index (out_offset)
out_array.valid_index (out_offset + block_size - 1)
do
array_xor (last, 0, in, in_offset, last, 0, block_size)
target.encrypt_block (last, 0, out_array, out_offset)
last.copy_data (out_array, out_offset, 0, block_size)
end
cbc_ready: BOOLEAN
do
result := target.cbc_ready
end
feature {NONE}
last: SPECIAL [NATURAL_8]
target: CBC_TARGET
invariant
last.count = target.block_size
end

View File

@@ -0,0 +1,41 @@
note
description: "A block cipher that can be the target of CBC mode"
author: "Colin LeMahieu"
date: "$Date: 2011-11-11 18:13:16 +0100 (ven., 11 nov. 2011) $"
revision: "$Revision: 87787 $"
quote: "I don't make jokes. I just watch the government and report the facts. - Will Rogers"
deferred class
CBC_TARGET
feature
block_size: INTEGER_32
deferred
ensure
Result > 0
end
cbc_ready: BOOLEAN
deferred
end
decrypt_block (in: SPECIAL [NATURAL_8] in_offset: INTEGER_32 out_array: SPECIAL [NATURAL_8] out_offset: INTEGER_32)
require
cbc_ready
in.valid_index (in_offset)
in.valid_index (in_offset + block_size - 1)
out_array.valid_index (out_offset)
out_array.valid_index (out_offset + block_size - 1)
deferred
end
encrypt_block (in: SPECIAL [NATURAL_8] in_offset: INTEGER_32 out_array: SPECIAL [NATURAL_8] out_offset: INTEGER_32)
require
cbc_ready
in.valid_index (in_offset)
in.valid_index (in_offset + block_size - 1)
out_array.valid_index (out_offset)
out_array.valid_index (out_offset + block_size - 1)
deferred
end
end

View File

@@ -0,0 +1,69 @@
note
description: "Cipher Feedback decryption mode"
author: "Colin LeMahieu"
date: "$Date: 2011-11-11 18:13:16 +0100 (ven., 11 nov. 2011) $"
revision: "$Revision: 87787 $"
quote: "The strongest reason for the people to retain the right to bear arms is, as a last resort, to protect themselves against tyranny in government. - Thomas Jefferson"
class
CFB_DECRYPTION
inherit
ARRAY_FACILITIES
create
make
feature
make (target_a: CFB_TARGET iv: SPECIAL [NATURAL_8] iv_offset: INTEGER_32 select_block_size_a: INTEGER_32)
require
iv.valid_index (iv_offset)
iv.valid_index (iv_offset + target_a.block_size - 1)
select_block_size_a > 0
select_block_size_a <= target_a.block_size
do
select_block_size := select_block_size_a
target := target_a
create last.make_filled (0, block_size)
last.copy_data (iv, iv_offset, 0, last.count)
end
feature
block_size: INTEGER_32
do
result := target.block_size
end
select_block_size: INTEGER_32
attribute
ensure
Result > 0
Result <= block_size
end
decrypt_block (in: SPECIAL [NATURAL_8] in_offset: INTEGER_32 out_array: SPECIAL [NATURAL_8] out_offset: INTEGER_32)
require
cfb_ready
in.valid_index (in_offset)
in.valid_index (in_offset + select_block_size - 1)
out_array.valid_index (out_offset)
out_array.valid_index (out_offset + select_block_size - 1)
do
target.encrypt_block (last, 0, out_array, out_offset)
last.overlapping_move (select_block_size, 0, block_size - select_block_size)
last.copy_data (in, in_offset, block_size - select_block_size, select_block_size)
array_xor (out_array, out_offset, in, in_offset, out_array, out_offset, select_block_size)
end
cfb_ready: BOOLEAN
do
result := target.cfb_ready
end
feature {NONE}
last: SPECIAL [NATURAL_8]
target: CFB_TARGET
invariant
last.count = block_size
end

View File

@@ -0,0 +1,69 @@
note
description: "Summary description for {CFB_ENCRYPTION}."
author: "Colin LeMahieu"
date: "$Date: 2011-11-11 18:13:16 +0100 (ven., 11 nov. 2011) $"
revision: "$Revision: 87787 $"
quote: "The era of resisting big government is never over. - Paul Gigot (1998)"
class
CFB_ENCRYPTION
inherit
ARRAY_FACILITIES
create
make
feature
make (target_a: CFB_TARGET iv: SPECIAL [NATURAL_8] iv_offset: INTEGER_32 select_block_size_a: INTEGER_32)
require
iv.valid_index (iv_offset)
iv.valid_index (iv_offset + target_a.block_size - 1)
select_block_size_a > 0
select_block_size_a <= target_a.block_size
do
select_block_size := select_block_size_a
target := target_a
create last.make_filled (0, block_size)
last.copy_data (iv, iv_offset, 0, last.count)
end
feature
block_size: INTEGER_32
do
result := target.block_size
end
select_block_size: INTEGER_32
attribute
ensure
Result > 0
Result <= block_size
end
encrypt_block (in: SPECIAL [NATURAL_8] in_offset: INTEGER_32 out_array: SPECIAL [NATURAL_8] out_offset: INTEGER_32)
require
cfb_ready
in.valid_index (in_offset)
in.valid_index (in_offset + select_block_size - 1)
out_array.valid_index (out_offset)
out_array.valid_index (out_offset + select_block_size - 1)
do
target.encrypt_block (last, 0, out_array, out_offset)
array_xor (out_array, out_offset, in, in_offset, out_array, out_offset, select_block_size)
last.overlapping_move (select_block_size, 0, block_size - select_block_size)
last.copy_data (out_array, out_offset, block_size - select_block_size, select_block_size)
end
cfb_ready: BOOLEAN
do
result := target.cfb_ready
end
feature {NONE}
last: SPECIAL [NATURAL_8]
target: CFB_TARGET
invariant
last.count = block_size
end

View File

@@ -0,0 +1,31 @@
note
description: "A block cipher that can be the target of CFB mode"
author: "Colin LeMahieu"
date: "$Date: 2011-11-11 18:13:16 +0100 (ven., 11 nov. 2011) $"
revision: "$Revision: 87787 $"
quote: "The ultimate result of shielding men from the effects of folly is to fill the world with fools. - Herbert Spencer (1891)"
deferred class
CFB_TARGET
feature
block_size: INTEGER_32
deferred
ensure
Result > 0
end
cfb_ready: BOOLEAN
deferred
end
encrypt_block (in: SPECIAL [NATURAL_8] in_offset: INTEGER_32 out_array: SPECIAL [NATURAL_8] out_offset: INTEGER_32)
require
cfb_ready
in.valid_index (in_offset)
in.valid_index (in_offset + block_size - 1)
out_array.valid_index (out_offset)
out_array.valid_index (out_offset + block_size - 1)
deferred
end
end

View File

@@ -0,0 +1,57 @@
note
description: "Counter decryption mode"
author: "Colin LeMahieu"
date: "$Date: 2011-11-11 18:13:16 +0100 (ven., 11 nov. 2011) $"
revision: "$Revision: 87787 $"
quote: "If you have been voting for politicians who promise to give you goodies at someone else's expense, then you have no right to complain when they take your money and give it to someone else, including themselves. - Thomas Sowell (1992)"
class
CTR_DECRYPTION
inherit
ARRAY_FACILITIES
create
make
feature
make (target_a: CTR_TARGET iv: INTEGER_X)
do
target := target_a
create counter
counter.copy (iv)
max := counter.one.bit_shift_left_value (block_size * 8)
create counter_array.make_filled (0, block_size)
end
feature
block_size: INTEGER_32
do
result := target.block_size
end
decrypt_block (in: SPECIAL [NATURAL_8] in_offset: INTEGER_32 out_array: SPECIAL [NATURAL_8] out_offset: INTEGER_32)
require
ctr_ready
in.valid_index (in_offset)
in.valid_index (in_offset + block_size - 1)
out_array.valid_index (out_offset)
out_array.valid_index (out_offset + block_size - 1)
do
counter.to_fixed_width_byte_array (counter_array, 0, block_size - 1)
target.encrypt_block (counter_array, 0, out_array, out_offset)
array_xor (out_array, out_offset, in, in_offset, out_array, out_offset, block_size)
counter := (counter + counter.one) \\ max
end
ctr_ready: BOOLEAN
do
result := target.ctr_ready
end
feature {NONE}
counter_array: SPECIAL [NATURAL_8]
counter: INTEGER_X
max: INTEGER_X
target: CTR_TARGET
end

View File

@@ -0,0 +1,57 @@
note
description: "Counter encryption mode"
author: "Colin LeMahieu"
date: "$Date: 2011-11-11 18:13:16 +0100 (ven., 11 nov. 2011) $"
revision: "$Revision: 87787 $"
quote: "There never was a good war or a bad peace. - Benjamin Franklin (1773) "
class
CTR_ENCRYPTION
inherit
ARRAY_FACILITIES
create
make
feature
make (target_a: CTR_TARGET iv: INTEGER_X)
do
target := target_a
create counter
counter.copy (iv)
max := counter.one.bit_shift_left_value (block_size * 8)
create counter_array.make_filled (0, block_size)
end
feature
block_size: INTEGER_32
do
result := target.block_size
end
encrypt_block (in: SPECIAL [NATURAL_8] in_offset: INTEGER_32 out_array: SPECIAL [NATURAL_8] out_offset: INTEGER_32)
require
ctr_ready
in.valid_index (in_offset)
in.valid_index (in_offset + block_size - 1)
out_array.valid_index (out_offset)
out_array.valid_index (out_offset + block_size - 1)
do
counter.to_fixed_width_byte_array (counter_array, 0, block_size - 1)
target.encrypt_block (counter_array, 0, out_array, out_offset)
array_xor (out_array, out_offset, in, in_offset, out_array, out_offset, block_size)
counter := (counter + counter.one) \\ max
end
ctr_ready: BOOLEAN
do
result := target.ctr_ready
end
feature {NONE}
counter_array: SPECIAL [NATURAL_8]
counter: INTEGER_X
max: INTEGER_X
target: CTR_TARGET
end

View File

@@ -0,0 +1,31 @@
note
description: "A block cipher that can be the target of CTR mode"
author: "Colin LeMahieu"
date: "$Date: 2011-11-11 18:13:16 +0100 (ven., 11 nov. 2011) $"
revision: "$Revision: 87787 $"
quote: "Everything that is really great and inspiring is created by the individual who can labor in freedom. - Albert Einstein"
deferred class
CTR_TARGET
feature
block_size: INTEGER_32
deferred
ensure
Result > 0
end
ctr_ready: BOOLEAN
deferred
end
encrypt_block (in: SPECIAL [NATURAL_8] in_offset: INTEGER_32 out_array: SPECIAL [NATURAL_8] out_offset: INTEGER_32)
require
ctr_ready
in.valid_index (in_offset)
in.valid_index (in_offset + block_size - 1)
out_array.valid_index (out_offset)
out_array.valid_index (out_offset + block_size - 1)
deferred
end
end

View File

@@ -0,0 +1,44 @@
note
description: "Electronic Codebook decryption mode"
author: "Colin LeMahieu"
date: "$Date: 2011-11-11 18:13:16 +0100 (ven., 11 nov. 2011) $"
revision: "$Revision: 87787 $"
quote: "There are just two rules of governance in a free society: Mind your own business. Keep your hands to yourself. - P.J. O'Rourke (1993)"
class
ECB_DECRYPTION
create
make
feature
make (target_a: ECB_TARGET)
do
target := target_a
end
feature
block_size: INTEGER_32
do
result := target.block_size
end
decrypt_block (in: SPECIAL [NATURAL_8] in_offset: INTEGER_32 out_array: SPECIAL [NATURAL_8] out_offset: INTEGER_32)
require
ecb_ready
in.valid_index (in_offset)
in.valid_index (in_offset + block_size - 1)
out_array.valid_index (out_offset)
out_array.valid_index (out_offset + block_size - 1)
do
target.decrypt_block (in, in_offset, out_array, out_offset)
end
ecb_ready: BOOLEAN
do
result := target.ecb_ready
end
feature {NONE}
target: ECB_TARGET
end

View File

@@ -0,0 +1,44 @@
note
description: "Electronic Codebook encryption mode"
author: "Colin LeMahieu"
date: "$Date: 2011-11-11 18:13:16 +0100 (ven., 11 nov. 2011) $"
revision: "$Revision: 87787 $"
quote: "Necessity is the plea for every infringement of human freedom. It is the argument of tyrants; it is the creed of slaves. - William Pitt (1783)"
class
ECB_ENCRYPTION
create
make
feature
make (target_a: ECB_TARGET)
do
target := target_a
end
feature
block_size: INTEGER_32
do
result := target.block_size
end
encrypt_block (in: SPECIAL [NATURAL_8] in_offset: INTEGER_32 out_array: SPECIAL [NATURAL_8] out_offset: INTEGER_32)
require
ecb_ready
in.valid_index (in_offset)
in.valid_index (in_offset + block_size - 1)
out_array.valid_index (out_offset)
out_array.valid_index (out_offset + block_size - 1)
do
target.encrypt_block (in, in_offset, out_array, out_offset)
end
ecb_ready: BOOLEAN
do
result := target.ecb_ready
end
feature {NONE}
target: ECB_TARGET
end

View File

@@ -0,0 +1,41 @@
note
description: "A block cipher that can be the target of ECB mode"
author: "Colin LeMahieu"
date: "$Date: 2011-11-11 18:13:16 +0100 (ven., 11 nov. 2011) $"
revision: "$Revision: 87787 $"
quote: "A government that is big enough to give you all you want is big enough to take it all away. - Barry Goldwater (1964)"
deferred class
ECB_TARGET
feature
block_size: INTEGER_32
deferred
ensure
Result > 0
end
ecb_ready: BOOLEAN
deferred
end
decrypt_block (in: SPECIAL [NATURAL_8] in_offset: INTEGER_32 out_array: SPECIAL [NATURAL_8] out_offset: INTEGER_32)
require
ecb_ready
in.valid_index (in_offset)
in.valid_index (in_offset + block_size - 1)
out_array.valid_index (out_offset)
out_array.valid_index (out_offset + block_size - 1)
deferred
end
encrypt_block (in: SPECIAL [NATURAL_8] in_offset: INTEGER_32 out_array: SPECIAL [NATURAL_8] out_offset: INTEGER_32)
require
ecb_ready
in.valid_index (in_offset)
in.valid_index (in_offset + block_size - 1)
out_array.valid_index (out_offset)
out_array.valid_index (out_offset + block_size - 1)
deferred
end
end

View File

@@ -0,0 +1,45 @@
note
description: "Summary description for {MODE_TEST_DATA}."
author: "Colin LeMahieu"
date: "$Date: 2011-11-11 18:13:16 +0100 (ven., 11 nov. 2011) $"
revision: "$Revision: 87787 $"
quote: "The only thing necessary for evil to triumph is for good men to do nothing. - Edmund Burke"
deferred class
MODE_TEST_DATA
feature
make_data
local
block_1_text: INTEGER_X
block_2_text: INTEGER_X
block_3_text: INTEGER_X
block_4_text: INTEGER_X
iv_text: INTEGER_X
do
create block_1_text.make_from_hex_string ("6bc1bee22e409f96e93d7e117393172a")
create block_1.make_filled (0, 16)
block_1_text.to_fixed_width_byte_array (block_1, 0, 15)
create block_2_text.make_from_hex_string ("ae2d8a571e03ac9c9eb76fac45af8e51")
create block_2.make_filled (0, 16)
block_2_text.to_fixed_width_byte_array (block_2, 0, 15)
create block_3_text.make_from_hex_string ("30c81c46a35ce411e5fbc1191a0a52ef")
create block_3.make_filled (0, 16)
block_3_text.to_fixed_width_byte_array (block_3, 0, 15)
create block_4_text.make_from_hex_string ("f69f2445df4f9b17ad2b417be66c3710")
create block_4.make_filled (0, 16)
block_4_text.to_fixed_width_byte_array (block_4, 0, 15)
create iv_text.make_from_hex_string ("000102030405060708090a0b0c0d0e0f")
create iv.make_filled (0, 16)
iv_text.to_fixed_width_byte_array (iv, 0, 15)
create iv_counter.make_from_hex_string ("f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff")
end
block_1: SPECIAL [NATURAL_8]
block_2: SPECIAL [NATURAL_8]
block_3: SPECIAL [NATURAL_8]
block_4: SPECIAL [NATURAL_8]
iv: SPECIAL [NATURAL_8]
iv_counter: INTEGER_X
end

View File

@@ -0,0 +1,55 @@
note
description: "Output Feedback decryption mode"
author: "Colin LeMahieu"
date: "$Date: 2011-11-11 18:13:16 +0100 (ven., 11 nov. 2011) $"
revision: "$Revision: 87787 $"
quote: "Sometimes it is said that man cannot be trusted with the government of himself. Can he, then, be trusted with the government of others? - Thomas Jefferson (1801)"
class
OFB_DECRYPTION
inherit
ARRAY_FACILITIES
create
make
feature
make (target_a: OFB_TARGET iv: SPECIAL [NATURAL_8] iv_offset: INTEGER_32)
require
iv.valid_index (iv_offset)
iv.valid_index (iv_offset + target_a.block_size - 1)
do
target := target_a
create last.make_filled (0, block_size)
last.copy_data (iv, iv_offset, 0, block_size)
end
feature
block_size: INTEGER_32
do
result := target.block_size
end
decrypt_block (in: SPECIAL [NATURAL_8] in_offset: INTEGER_32 out_array: SPECIAL [NATURAL_8] out_offset: INTEGER_32)
require
ofb_ready
in.valid_index (in_offset)
in.valid_index (in_offset + block_size - 1)
out_array.valid_index (out_offset)
out_array.valid_index (out_offset + block_size - 1)
do
target.encrypt_block (last, 0, out_array, out_offset)
last.copy_data (out_array, out_offset, 0, block_size)
array_xor (last, 0, in, in_offset, out_array, out_offset, block_size)
end
ofb_ready: BOOLEAN
do
result := target.ofb_ready
end
feature {NONE}
last: SPECIAL [NATURAL_8]
target: OFB_TARGET
end

View File

@@ -0,0 +1,55 @@
note
description: "Output Feedback encryption mode"
author: "Colin LeMahieu"
date: "$Date: 2011-11-11 18:13:16 +0100 (ven., 11 nov. 2011) $"
revision: "$Revision: 87787 $"
quote: "Power tends to corrupt, and absolute power corrupts absolutely. - Lord Acton (1887)"
class
OFB_ENCRYPTION
inherit
ARRAY_FACILITIES
create
make
feature
make (target_a: OFB_TARGET iv: SPECIAL [NATURAL_8] iv_offset: INTEGER_32)
require
iv.valid_index (iv_offset)
iv.valid_index (iv_offset + target_a.block_size - 1)
do
target := target_a
create last.make_filled (0, block_size)
last.copy_data (iv, iv_offset, 0, block_size)
end
feature
block_size: INTEGER_32
do
result := target.block_size
end
encrypt_block (in: SPECIAL [NATURAL_8] in_offset: INTEGER_32 out_array: SPECIAL [NATURAL_8] out_offset: INTEGER_32)
require
ofb_ready
in.valid_index (in_offset)
in.valid_index (in_offset + block_size - 1)
out_array.valid_index (out_offset)
out_array.valid_index (out_offset + block_size - 1)
do
target.encrypt_block (last, 0, out_array, out_offset)
last.copy_data (out_array, out_offset, 0, block_size)
array_xor (last, 0, in, in_offset, out_array, out_offset, block_size)
end
ofb_ready: BOOLEAN
do
result := target.ofb_ready
end
feature {NONE}
last: SPECIAL [NATURAL_8]
target: OFB_TARGET
end

View File

@@ -0,0 +1,31 @@
note
description: "A block cipher that can be the target of OFB mode"
author: "Colin LeMahieu"
date: "$Date: 2011-11-11 18:13:16 +0100 (ven., 11 nov. 2011) $"
revision: "$Revision: 87787 $"
quote: "Political power grows out of the barrel of a gun. - Mao Zedong (1938)"
deferred class
OFB_TARGET
feature
block_size: INTEGER_32
deferred
ensure
Result > 0
end
ofb_ready: BOOLEAN
deferred
end
encrypt_block (in: SPECIAL [NATURAL_8] in_offset: INTEGER_32 out_array: SPECIAL [NATURAL_8] out_offset: INTEGER_32)
require
ofb_ready
in.valid_index (in_offset)
in.valid_index (in_offset + block_size - 1)
out_array.valid_index (out_offset)
out_array.valid_index (out_offset + block_size - 1)
deferred
end
end